PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: kaotkbliss on 11 August, 2004, 10:48:48

Title: random responses from a trigbot
Post by: kaotkbliss on 11 August, 2004, 10:48:48
My script for my trigbot is something like this:

trigs = {

["trig"]="response",
["another trig"]="another response",
}

etc etc. what I would like is for some of the triggers to have multiple responses, 1 chosen randomly (such as when someone types the bots name 1 of 5 or so responses is randomly displayed.)
Title:
Post by: Herodes on 11 August, 2004, 12:45:05
I made this a while ago ...
try to see if you can make it work as it is not tested with the particular table provided ...
In the proper version there is a separate file that contains over 1500 lines ... :)))

in this one try a sentence with the word ' hunt ' ..
--- Absurd Talker v 1
--- by Herodes
-------------------------------------------------------------------
--- an advanced version of the triggerbot idea by Ptaczek
--- U need the 'everythin.tbl' file to be in the same dir with this file to run error-free... (hopefully found in the same .rar)
--- This can randomly answer and randomly replace signified words in the strings in a random way.
--- You'll see when u try ... hopefully
---
--- currently if it has a user sends 2 or more triggers in one chat line it triggs for both ...
--- and also there has to be a way to make it a bit easier to put values in the tables...
--- 1 more thing is that we need it to be fail safe ... :(  
--- (if word-to-be-replaced- isnt a array in the big table it should have an error ... )
---
--- pls be more than free to take it further  ---
---------------------------------------------------------------------
---ADviCE ---
--- It is better for complicated stuff to find a way to break the process down to pieces and to confirm avery step as u develop it ...
--- Also sometimes it helps to start from the end... It all depends on the type of the action....
---------------------------------------------------------------------
Bot = "BigTalker"

all = {
["hunt"]  = {
"I used to hunt s with in the .",
"Have you been hunting with ?",
"Are there s in forest ?" },
["forest"] = {
"Green Break",
" Tropical Ice",
"Geek Valley"},
["name"] = {
"Herodes",
"Nightlitch",
"plop",
"Typhoon",
"Tezlo",
"kepp",
"kaotkbliss" },
["animal"] = {
"horse",
"cow",
"bird",
"hawk",
"crane",
"tiger"
"lion",
"rhino"},
}


function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
data = strsub(data, 1, strlen(data)-1 )
s,e,msg = strfind(data, "%b<>%s+(.*)")
for trig , ans in all do
if ( strfind( strlower(msg), trig) ) then
local replace = ans[random(1, getn(ans) )] --- Do( replace )
if strfind(replace, "<" ) then
s,e,instr = strfind(replace, "<(.*)>") --- Do(instr)
replans = all[instr][random(1, getn(all[instr]) )] --- Do(replans)
local fini = gsub(ans[random(1, getn(ans) )], "%b<>", all[instr][random(1, getn(all[instr]) )] )
Do(fini)
else Do(replace)
end
end
end
end
end

function Do(msg)
if msg then
SendToAll(Bot, msg)
elseif msg == nil then
SendToOps(Bot, "is nill")
else
SendToOps(Bot, "not there ".. tostring(msg))
end
end
Title:
Post by: Troubadour on 11 August, 2004, 13:41:37
----- Try this

botname = "Triggerino"

trigs = {
                hehe={
     "BWahaha, [CURUSER] das lache,  Hahahaha.",
     "Huh! [CURUSER]  waar lach je om?",
     "Als jij lacht, gaat heel mijn beeldscherm heen en weer!",
     "hehehehe",
     "hohohohoh"
                                 },

         haha={
     "BWahaha, [CURUSER] das lache,  Hahahaha.",
     "Huh! [CURUSER]  waar lach je om?",
     "Als jij lacht, gaat heel mijn beeldscherm heen en weer!",
     "hehehehe",
     "hohohohoh"
                                 },
                                   
         lmao={
     "BWahaha, [CURUSER] das lache,  Hahahaha.",
     "Huh! [CURUSER]  waar lach je om?",
     "Als jij lacht, gaat heel mijn beeldscherm heen en weer!",
     "hehehehe",
     "hohohohoh"
                                 },

         bye={
       "Ajuu, [CURUSER]",
       "Bye, [CURUSER]   .....*sniff*",
      "Hey,  [CURUSER] waarom ga je weg, ach moet je ook zelf weten. Tot sinas!",
      "*Snif* we zullen je missen, [CURUSER]!",
      "<----*zwaait met zijn armen*"
                                 },

         cya={
       "Ajuu, [CURUSER]",
       "Bye, [CURUSER]   .....*sniff*",
      "Hey,  [CURUSER] waarom ga je weg, ach moet je ook zelf weten. Tot sinas!",
      "*Snif* we zullen je missen, [CURUSER]!",
      "<----*zwaait met zijn armen*"
                                  },

         ["cu"]={
       "Ajuu, [CURUSER]",
       "Bye, [CURUSER]   .....*sniff*",
      "Hey,  [CURUSER] waarom ga je weg, ach moet je ook zelf weten. Tot sinas!",
      "*Snif* we zullen je missen, [CURUSER]!",
      "<----*zwaait met zijn armen*"
                               },
      
         fuck={
      "Denk eraan [CURUSER]!! Hier zitten ook kinderen, volgende keer word je verwijderd door ons!"
                               },

         fucker={
      "Denk eraan [CURUSER]!! Hier zitten ook kinderen, volgende keer word je verwijderd door ons!"
                               },

         ["hallo"]={
        "Hallo [CURUSER]",
        "Hoi  [CURUSER]",
        "Hoe gaat ie [CURUSER]",
        "Hi [CURUSER]",
        "Hey [CURUSER], alles kits?"
                             },

         hello={
        "Hallo [CURUSER]",
        "Hoi  [CURUSER]",
        "Hoe gaat ie [CURUSER]",
        "Hi [CURUSER]",
        "Hey [CURUSER], alles kits?"
                             },

         hey={
        "Hallo [CURUSER]",
        "Hoi  [CURUSER]",
        "Hoe gaat ie [CURUSER]",
        "Hi [CURUSER]",
        "Hey [CURUSER], alles kits?"
                             },

         dronken={
   "ikke DronKen? -*- hik -*-",
   "pftftt doe mij er nog maar eentje   pfffttttttt",
   "Zoveel heb ik niet gehad...",
   "Ik ben niet dronken!!",
   "Hooguit aangeschoten.....",
   "pfftt!",
   "oohhh koppie zeer",
   "*BURP*",
   "*HICK*"
                               },

         ["bot"]={
   "Direct Connect bots zijn niks aan...",
   "Wie? Ikke? Dacht ut niet...",
   "Niet liegen, ik lees met jullie mee!",
   "Ik? HAHA",
   "en zeker ook nog blond!"
                                  },

         drug={
   "drugz?",
   "illegale substantie?",
   "sniiiiiifffffff",
   "is dat niet legaal in Amsterdam?",
   "das voor mij niet te betalen",
   "*snif* ahh!"
                                },                    

         pils={
   "gulp, gulp, gulp",
   "hik!",
   "Krijg er dorst van...",
   "Geef die fles maar door!",
   "*burp*",
   "of een cola rum gaat er ook wel in!"
                                 },

         sorry={
        "ok",
        "tuurlijk",
        "ja, dat zal wel!",
        "ok"
                             },

         wassup={
        "ben aan het eten",
        "ik eet pizza :)",
        "ben aan het buikdansen",
        "hacking microsoft.com",
        "kijk maar op de homepage bij de webcam"
                           },
                 
         ["ben jij"]={
   "maakt het wat uit dan ?",
   "hoezo?",
   "tuurlijk niet, doe niet zo raar",
   "misschien",
   "beroepsgeheim",
   "jij dan?"
                               },

         yep={
   "jazeker",
   "yep",
   "100%",
   "tuurlijk!",
   "daar kun je gif op innemen",
   "dat kan ik bevestigen!",
   "correct",
   "zekers"
                              },
                 
   }


function Main()
frmHub:RegBot(botname)
end

function DataArrival(curUser, data)

       
   if( strsub(data, 1, 1) == "<" ) then
      -- get the msg only using regular expression
      s,e,msg = strfind(data, "%b<>%s+(.+)")
                                       
      -- look in the table
      for key, value in trigs do
                for key2, value2 in value do
                     
   if( strfind( strlower(msg), key) ) then
                 else break  
   end

        if( strfind( strlower(msg), "!me") ) then
                  t="**"..curUser.sName
                  data=gsub (msg, "!me", t, 1 )
   end

      SendToAll( data ) -- send the original data
                   
            SetTimer(1800)
                  StartTimer()
      answer, x = gsub(value[random(1,getn(value))], "%b[]", curUser.sName)

   return 1; -- tell the hub we have processed the data
   end
   end  
   end
end

function OnTimer()
   SendToAll( botname, answer ) -- send bot's answer
   StopTimer()
end
Title:
Post by: kaotkbliss on 12 August, 2004, 00:29:31
thanks Troubadour, it worked... thanks :)
Title: Trigger
Post by: pat on 16 September, 2004, 00:59:27
Can any help me to get this script to work in DCDM++
Title:
Post by: BottledHate on 16 September, 2004, 02:07:18
QuoteOriginally posted by pat
Can any help me to get this script to work in DCDM++

sure!




trigs = {
hehe={
"BWahaha, [CURUSER] das lache, Hahahaha.",
"Huh! [CURUSER] waar lach je om?",
"Als jij lacht, gaat heel mijn beeldscherm heen en weer!",
"hehehehe",
"hohohohoh"
},

haha={
"BWahaha, [CURUSER] das lache, Hahahaha.",
"Huh! [CURUSER] waar lach je om?",
"Als jij lacht, gaat heel mijn beeldscherm heen en weer!",
"hehehehe",
"hohohohoh"
},

lmao={
"BWahaha, [CURUSER] das lache, Hahahaha.",
"Huh! [CURUSER] waar lach je om?",
"Als jij lacht, gaat heel mijn beeldscherm heen en weer!",
"hehehehe",
"hohohohoh"
},

bye={
"Ajuu, [CURUSER]",
"Bye, [CURUSER] .....*sniff*",
"Hey, [CURUSER] waarom ga je weg, ach moet je ook zelf weten. Tot sinas!",
"*Snif* we zullen je missen, [CURUSER]!",
"<----*zwaait met zijn armen*"
},

cya={
"Ajuu, [CURUSER]",
"Bye, [CURUSER] .....*sniff*",
"Hey, [CURUSER] waarom ga je weg, ach moet je ook zelf weten. Tot sinas!",
"*Snif* we zullen je missen, [CURUSER]!",
"<----*zwaait met zijn armen*"
},

["cu"]={
"Ajuu, [CURUSER]",
"Bye, [CURUSER] .....*sniff*",
"Hey, [CURUSER] waarom ga je weg, ach moet je ook zelf weten. Tot sinas!",
"*Snif* we zullen je missen, [CURUSER]!",
"<----*zwaait met zijn armen*"
},

fuck={
"Denk eraan [CURUSER]!! Hier zitten ook kinderen, volgende keer word je verwijderd door ons!"
},

fucker={
"Denk eraan [CURUSER]!! Hier zitten ook kinderen, volgende keer word je verwijderd door ons!"
},

["hallo"]={
"Hallo [CURUSER]",
"Hoi [CURUSER]",
"Hoe gaat ie [CURUSER]",
"Hi [CURUSER]",
"Hey [CURUSER], alles kits?"
},

hello={
"Hallo [CURUSER]",
"Hoi [CURUSER]",
"Hoe gaat ie [CURUSER]",
"Hi [CURUSER]",
"Hey [CURUSER], alles kits?"
},

hey={
"Hallo [CURUSER]",
"Hoi [CURUSER]",
"Hoe gaat ie [CURUSER]",
"Hi [CURUSER]",
"Hey [CURUSER], alles kits?"
},

dronken={
"ikke DronKen? -*- hik -*-",
"pftftt doe mij er nog maar eentje pfffttttttt",
"Zoveel heb ik niet gehad...",
"Ik ben niet dronken!!",
"Hooguit aangeschoten.....",
"pfftt!",
"oohhh koppie zeer",
"*BURP*",
"*HICK*"
},

["bot"]={
"Direct Connect bots zijn niks aan...",
"Wie? Ikke? Dacht ut niet...",
"Niet liegen, ik lees met jullie mee!",
"Ik? HAHA",
"en zeker ook nog blond!"
},

drug={
"drugz?",
"illegale substantie?",
"sniiiiiifffffff",
"is dat niet legaal in Amsterdam?",
"das voor mij niet te betalen",
"*snif* ahh!"
},

pils={
"gulp, gulp, gulp",
"hik!",
"Krijg er dorst van...",
"Geef die fles maar door!",
"*burp*",
"of een cola rum gaat er ook wel in!"
},

sorry={
"ok",
"tuurlijk",
"ja, dat zal wel!",
"ok"
},

wassup={
"ben aan het eten",
"ik eet pizza :)",
"ben aan het buikdansen",
"hacking microsoft.com",
"kijk maar op de homepage bij de webcam"
},

["ben jij"]={
"maakt het wat uit dan ?",
"hoezo?",
"tuurlijk niet, doe niet zo raar",
"misschien",
"beroepsgeheim",
"jij dan?"
},

yep={
"jazeker",
"yep",
"100%",
"tuurlijk!",
"daar kun je gif op innemen",
"dat kan ik bevestigen!",
"correct",
"zekers"
},
}

shutUP = 1
dcpp:setListener( "chat", "listenfortrigs",
   function( hub, user, text )
      if string.sub(text, 1,6) == "+quiet" then   -- +quiet
         DC():SendHubMessage( hub:getId(), "<"..hub:getOwnNick().."> OK! i'll stfu now.|")
         shutUP = 0
      elseif string.sub(text, 1,6) == "+talk" then -- +talk
         DC():SendHubMessage( hub:getId(), "<"..hub:getOwnNick().."> w0000t, back in action!|")
         shutUP = 1
      else
         if shutUP == 1 then
            bleh(hub,user,text)
         end
      end
   end
)
sTrig = {}
function bleh(h,u,t)
   for k, v in trigs do
      if string.find(string.lower(t), k) then
         sTrig[os.time() + math.random(5)] = {[1]=h, [2] = string.gsub(trigs[k][math.random(1,table.getn(v))], "%b[]", u:getNick())}
         return
      end
   end
end

--//for DCDM++ => v0.035
function dcpp.OnTimer()
   for k,v in sTrig do
      if k < os.time() then
         DC():SendHubMessage( v[1]:getId(), "<"..v[1]:getOwnNick().."> "..v[2].."|")
         sTrig[k] = nil
      end
   end
end

--//for BCDC =< .4032
--dcpp:setListener( "timer", "trigbot",
--   function()
--      for k,v in sTrig do
--         if k < os.time() then
--          DC():SendHubMessage( v[1]:getId(), "<"..v[1]:getOwnNick().."> "..v[2].."|")
--          sTrig[k] = nil
--         end
--      end
--   end
--)

-BH
Title:
Post by: pat on 16 September, 2004, 02:21:25
Thanx man
Title:
Post by: pat on 16 September, 2004, 02:30:50
the script works fine thanx

how to add this to the script

if (cmd=="+quiet") then
trigall=0
SendToAll(botname, " Hmf, Okidoki I will be quiet :(( ")
return 1
elseif (cmd=="+talk") then
trigall=1
SendToAll(botname, " Okay, I will talk to you again :-)")
return 1
end
Title:
Post by: BottledHate on 16 September, 2004, 02:54:20
QuoteOriginally posted by pat
the script works fine thanx

how to add this to the script

if (cmd=="+quiet") then
trigall=0
SendToAll(botname, " Hmf, Okidoki I will be quiet :(( ")
return 1
elseif (cmd=="+talk") then
trigall=1
SendToAll(botname, " Okay, I will talk to you again :-)")
return 1
end


you can't block the commands from being seen by all like u can a hub script using 'return 1'

but, i made the changes u requested :) edited in my post above.

-BH
Title:
Post by: pat on 16 September, 2004, 03:02:04
thanx again
Title:
Post by: BottledHate on 16 September, 2004, 03:04:38
QuoteOriginally posted by pat
thanx again


np... glad i could help!

-BH
Title:
Post by: pat on 16 September, 2004, 03:43:16
hello again the script  are very fun =)

but then any type in main the bot answer in 1sec

can it be fixed some timer for the bot to talk ?
like 2-3 sec before he answer

sorry for my bad eng hope you understand

thanx Pat
Title:
Post by: BottledHate on 16 September, 2004, 04:45:20
QuoteOriginally posted by pat
hello again the script  are very fun =)

but then any type in main the bot answer in 1sec

can it be fixed some timer for the bot to talk ?
like 2-3 sec before he answer

sorry for my bad eng hope you understand

thanx Pat

edited above... random time for reply between 1 and 5 seconds.

-BH
Title:
Post by: pat on 16 September, 2004, 12:50:15
Hehe good