Luadch example of regging bots
Posted: 01 Feb 2008, 08:19
Luadch can reg bots now, here is a demonstration how to create an op chat (you need some knowledge of the adc protocol):
Code: Select all
hub:regBot{ nick = "[ Bot ] OpChat", desc = "chatroom for operators", --// nick and description of the bot for the userlist
client = function( this, cmd ) --// client is a function, which will be called on every incoming message ( also messages of other bots )
local bot_sid = this:getSid( ) --// this is the bot object which has a sid like every other user
local user_sid = cmd:mySid( ) --// extract the originator sid from the command
local user = hub:getUser{ sid = user_sid } --// get the user object of the originator
if not user or user:isBot( ) or user:getRank( ) < 4 then return end --// dont allow messages from other bots or non-operators
if cmd:fourcc( ) == "EMSG" then --// EMSG means private message to bot
local to_sid = cmd:getNP( "PM", "array" )[ 1 ] --// get body of named parameter "PM" ( is the sid for reply )
cmd:changeNP( "PM", bot_sid, to_sid ) --// insert bot sid
for sid, user in pairs( hub:getUsers( ) ) do
if user:getRank( ) >= 4 then
user:send( cmd:adcString( ) ) --// send adc command to all operators
end
end
end
return true
end
}