---------------------------------------------------- -- code: -- Thks to Ptaczek for his TrickerBot.lua -- Thks to Skrollster, for the random synthax (http://lua.bcs-solutions.de/thread.php?threadid=291&boardid=15&sid=d4de5272887ab85292a4078fa73ba6be) -- Thks to MatrixX for some help, too... (http://lua.bcs-solutions.de/thread.php?threadid=3&boardid=7&sid=6541fa822c277b66330f5bc1f409f4cc&page=2) -- And thks to the others, for their help... ;o) ---------------------------------------------------------------- -- seNsi: the 'clever' Bot :p -- Description: -- Each 20 min, Bot is talking alone, with random questions... -- If someone speaks again on main chat, there is a random answer, and then the timer is starting again. -- If the user says a known trig (ex: 'hey '), and the bot was feeling alone, Bot will choose the correct answer (ex:'Yessss,...[USER] happy to hear U again,, :))') -- Sorry for the 'a' synthax (a = 0, a = 1, etc...), but I'm quite nb in lua... -- Hope u'll enjoy it ! :o) ---------------------------------------------------------------- Bot = "Wiseguy" trigs = { bye="See ya [USER]", ["fine u"]="I am lame... ", ["need some"]="Hum... maybe pray for it...", ["loool"]="Yeah, [USER] ! It was really funny...", ["its fine"]="good...", ["take care"]="U 2... :o)" } idlequestions = { "Anybody here?", "I.am Boored", "All are sleeping ?!", "Haaaaaaaaloooooooooo !!! ", "Don't leave me alone.... :'(", } idleanswers = { "Aaaahh, dear [USER]... i was feeling quite alone.... :o)", "Yessss,...[USER] happy to hear U again,, :))", "Sorry to disturb u, [USER], but i was quite upset... :s ", "Thks, [USER]... i thought something was wrong with ur keyboard...", "OOhhh, [USER]... i'm not alone at this universe... :))" } idlemorninganswers = { "Wow... [USER]... ur night was certainly short.... :p", "Yeahh !!! GOOOOOD MORNIIIIIIIIIING [USER] !", "So, [USER],...coffee for me please, yep... :o)" } idlemorning = { "Driiiiiiing... Time to Wake Uuuuuuuuuuup !! :D", "GOOOOOD MORNIIIIIIIIIING HUBSTERRRRRRRRRRRRRS !!!!!!!", "Hmm.....Someone is awake ??!!" } idleevening = { "Time to have a drink, no ? :o)", "Hum hum... place is really quiet, at this time... :'(", "At this time, u shouldn't sleep... :-(" } idleeveninganswers = { "Well, at least... Some of us are still alive,... cool :D", "I was upset,... that's all... :(", "It's time...If u offer me a drink... i couldn't say no.... :p" } sec = 1000 min = 60 * sec hour = 60 * min index = nil function Main() quiet = "false" talk = "allow" WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "false" SetTimer(30*min) StartTimer() frmHub:RegBot(botname) end function DataArrival(user, data) -- Pm events -- if(strsub(data, 1, 4) == "$To:") then data=strsub(data,1,strlen(data)-1) s,e,whoTo = strfind(data,"$To:%s+(%S+)") if (whoTo == botname) then s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)") if (user.bOperator) then if (cmd=="!quiet") then quiet = "true" talk = "notallow" StopTimer() user:SendPM(botname,"Ok,...I'll be quiet now... :s") end if (cmd=="!talk") then talk = "allow" quiet = "false" WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "false" StartTimer() user:SendPM(botname, "Ahh... i'm back :)") end end end end -- Main Chat events -- if( strsub(data, 1, 1) == "<" ) then data=strsub(data,1,strlen(data)-1) s,e,cmd = strfind( data, "%b<>%s+(%S+)" ) s,e,mess = strfind(data, "%b<> ([%w ]*)") -- Trigs Answers -- for key, value in trigs do -- Answer to mess command if bot is allowed to speak -- if mess or cmd and talk == "allow" then -- Answer to the trig, with 1 trig response, if bot wasn't quiet since a while -- if WaitingForAnswerAfterQuiet == "false" then if( strfind( strlower(mess), key) ) or ( strfind( strlower(cmd), key) ) then answer, x = gsub(value, "%b[]", user.sName) SendToAll(Bot, answer ) break end end end end -- Restart the timer each time someone is talking on the main chat, if bot is allowed to talk -- if mess or cmd then if talk == "allow" then if iscommand(cmd) or iscommand(mess) then else StopTimer() StartTimer() end end end -- Quiet the bot (ops command) -- if (cmd=="!quiet") then if user.bOperator then quiet = "true" talk = "notallow" SendToAll(Bot, "Ok,...I'll be quiet now... :s") StopTimer() else -- Answer if a user try to use the command !quiet and if it is allowed to talk - then, check if the bot was quiet or not before -- if talk == "allow" and WaitingForAnswerAfterQuiet == "false" then SendToAll(Bot, "hum...hum...") end end end -- Allow the bot to talk (ops command) -- if (cmd=="!talk") then if user.bOperator then talk = "allow" quiet = "false" WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "false" StartTimer() SendToAll(Bot, "Ahh... i'm back :)") else -- Answer if a user try to use the command !talk and if it is allowed to talk - then, check if the bot was quiet or not before -- if talk == "allow" and WaitingForAnswerAfterQuiet == "false" then SendToAll(Bot, "hum...") end end end -- Receiving entries on the main chat -- if cmd or mess then if talk == "allow" then -- Morning Answer -- if WaitingForAnswerMorning == "true" then -- Ignore the line commands begining with '+'/'!'/'#'/'?'. Bot won't replye - nicest, i think... :o) -- if iscommand(cmd) or iscommand(mess) then else -- Answer to chat entries -- index = random(1,getn(idlemorninganswers)) answer, x = gsub(idlemorninganswers[index], "%b[]", user.sName) SendToAll(Bot, answer) WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "false" end end -- Evening Answer -- if WaitingForAnswerEvening == "true" then -- Ignore the line commands begining with '+'/'!'/'#'/'?'. Bot won't replye - nicest, i think... :o) -- if iscommand(cmd) or iscommand(mess) then else -- Answer to chat entries -- index = random(1,getn(idleeveninganswers)) answer, x = gsub(idleeveninganswers[index], "%b[]", user.sName) SendToAll(Bot, answer) WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "false" end end -- Answer after the bot was too quiet -- if WaitingForAnswerAfterQuiet == "true" then -- Ignore the line commands begining with '+'/'!'/'#'/'?'. Bot won't replye - nicest, i think... :o) -- if iscommand(cmd) or iscommand(mess) then else -- Answer to chat entries -- index = random(1,getn(idleanswers)) answer, x = gsub(idleanswers[index], "%b[]", user.sName) SendToAll(Bot, answer) WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "false" end end end end end end function OnTimer() time() trig = "notdone" -- Idle trigs, for the morning, and the evening :o) -- if H=="07" then index = random(1,getn(idlemorning)) SendToAll(Bot, idlemorning[index]) WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "true" WaitingForAnswerEvening = "false" StartTimer() trig = "done" end if H=="19" then index = random(1,getn(idleevening)) SendToAll(Bot, idleevening[index]) WaitingForAnswerAfterQuiet = "false" WaitingForAnswerMorning = "false" WaitingForAnswerEvening = "true" StartTimer() trig = "done" end -- Others idle trigs -- if trig == "notdone" then index = random(1,getn(idlequestions)) SendToAll(Bot, idlequestions[index]) WaitingForAnswerAfterQuiet = "true" end end -- Get Time -- function time() S = date("%S") H = date("%H") M = date("%M") D = date("%d") MM = date("%m") Y = date("%y") return H end function iscommand(str) return strsub(str, 1, 1) == "!" or strsub(str, 1, 1) == "?" or strsub(str, 1, 1) == "+" or strsub(str, 1, 1) == "#" end