I want this to work on ptokaX hub with DC++ users.
-- TriggerBoy.lua, based on TrickerBot.lua, based on Ptokax's TriggerBot, but for native DCH++ lua scripting
-- Original written by ptaczek, modified by arnetheduck, modified by Sedulus (2003)
-- vim:ts=4:sw=4:noet
--
-- added:
-- * multiple triggers with same responses
-- * multiple random responses
-- * names in normal format (no prefix and funky chars)
-- * delayed response (just before next message, if max_delay seconds haven't passed)
dchpp.loadLib( "math" )
dchpp.loadLib( "io" ) -- for os.date()
local botname = "-DJ Senwa $$ [00]"
local delayed_response = 1 -- 1 or nil, if you want the msg immediately
local max_delay = 60 -- seconds within which the response is still valid
local trigs = {
{
{ "lol", "lmao", "roflmao", "ha[ha]+" },
{ "yeah [usr], that was some funny sh*t
},
{
{ "lo[o]+l" },
{ "you drunk [usr]? it wasn't _that_ funny..." },
},
{
{ "bye", "cya", "later!", "goodbye" },
{ "cya [usr]!", "later!", "I'ma expect you back soon [usr]", "ciao [usr], don't be a stranger now
},
{
{ "radio" },
{ "Tune into (address) to hear me play some funky beats" },
},
{
{ "playing" },
{ "Ask Senny, im not sure what he gave me" },
},
}
local last = {
response = nil,
time = nil
}
function dchpp.clientMessage( client, msg )
-- do we need to write some old response?
if delayed_response and last.response then
if os.difftime( os.time(), last.time ) <= max_delay then
dchpp.hubMessage( last.response, botname )
last.response = nil
end
end
-- store new response
chkmsg = " "..string.lower( msg ).." "
for _a, trigarr in trigs do
for _b, trig in trigarr[1] do
local ret,c,match = string.find( chkmsg, "[^a-z]("..trig..")[^a-z]" )
if ret then
local nick = client:getNick()
local moddednick = string.lower( nick )
moddednick = string.gsub( moddednick, "%b[]", "" )
moddednick = string.gsub( moddednick, "%b()", "" )
moddednick = string.gsub( moddednick, "%b{}", "" )
moddednick = string.gsub( moddednick, "[^a-z]*", "" )
if string.len( moddednick ) < 2 then moddednick = nick end
local answer = trigarr[2][math.random( table.getn( trigarr[2] ) )]
answer = string.gsub( answer, "%[wrd%]", match, 1 )
answer = string.gsub( answer, "%[usr%]", moddednick, 1 )
if delayed_response then
last.response = answer
last.time = os.time()
else
dchpp.hubMessage( msg, nick)
dchpp.hubMessage( answer, botname )
return dchpp.ACTION_STOP
end
end
end
end
end