--[[ bot_opchat.lua v0.05 by blastbeat - this script regs an op chat - it exports also a module to access the opchat from other scripts - changelog 0.05: - updated script api - changelog 0.04: - updated script api, cached table lookups, removed global vars ]]-- --// settings begin //-- local scriptname = "bot_opchat" --[[local profile = "alternative" local settings, err = cfg.loadcfgprofile( profile, scriptname ); settings = settings or { }; err = err and hub.debug( err )]] local permission = { -- who is allowed to join the op chat? [ 0 ] = false, -- unreg [ 10 ] = false, -- guest [ 20 ] = false, -- reg [ 30 ] = false, -- vip [ 40 ] = false, -- svip [ 60 ] = true, -- operator [ 80 ] = true, -- admin [ 100 ] = true, -- hubowner } local nick = "[BOT]OpChat" local desc = "chatroom for operators" --// settings end //-- local hub_getbot = hub.getbot local hub_getuser = hub.getuser local hub_getusers = hub.getusers local opchat, err -- opchat user object local feed = function( msg, dispatch ) -- ok, this is an ugly hack local from, pm if dispatch ~= "send" then -- dispatch is the used send method dispatch = "reply" pm = opchat or hub_getbot( ) -- lol, maybe the opchat dows not exit, but then an error should be reported below from = hub_getbot( ) or opchat -- maybe the hub bot does not exist end for sid, user in pairs( hub_getusers( ) ) do -- send the msg to all ops... if permission[ user:level( ) ] then user[ dispatch ]( nil, msg, from, pm ) -- its maybe confusing, but all user objects have no self arg but a first nil arg, so you can use the ":" style end end end local client = function( bot, cmd ) if cmd:fourcc( ) == "EMSG" then local user = hub_getuser( cmd:mysid( ) ) if not user or not permission[ user:level( ) ] then return true end --local tosid = cmd:getnp "PM" cmd:setnp( "PM", bot:sid( ) ) feed( cmd:adcstring( ), "send" ) end return true end opchat, err = hub.regbot{ nick = nick, desc = desc, client = client } -- reg the bot in hub; in case of an error, report it because of side effects to other scripts err = err and error( err ) hub.debug( "** Loaded " .. scriptname .. ".lua **" ) --// public //-- return { feed = feed, -- use opchat = hub.import "bot_opchat"; opchat.feed( msg ) in other scripts to send a normal message to the opchat }