--[[ bot_opchat.lua v0.04 by blastbeat - this script regs an op chat - it exports also a module to access the opchat from other scripts - changelog 0.04: - updated script api, cached table lookups, removed global vars ]]-- --// settings begin //-- 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:getLevel( ) ] and not user:isBot( ) then -- dont send to bots because of possible stack overflows! user[ dispatch ]( nil, msg, from, pm ) -- its maybe confusing, but all 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 user:isBot( ) or not permission[ user:getLevel( ) ] then return true end --local tosid = cmd:np "PM" cmd:setnp( "PM", bot:getSid( ) ) 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 bot_opchat.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 }