PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Conversion Requests => Topic started by: Massi on 11 June, 2021, 10:35:32

Title: ChatBot Px
Post by: Massi on 11 June, 2021, 10:35:32
Please, convert in Lua 5.3.4 for Ptokax 0.5.2.2 Thanks  :)

--[[ ChatBot 1.0g LUA 5.11 [Strict][API 2] By Mutor 11/22/07 Requested by sphinx Yet another trigger bot, this one for the new API -Allows for multiple repsonses to a common trigger -Allows for (adjustable) random delay for response -Allows for regular expression in trigger 'patterns' -Uses all repsonses before repeating a response -Provides 'debug' reporting for pattern testing +Changes from 1.0 11/23/07 +Added support for API 1 [old API] Requested by sphinx +Changes from 1.0b 03/18/08 -Removed support for API 1, now API 2 strict again :P +Added option to register bot. Requested by Annie +Changes from 1.0c 03/20/08 +Added start/stop toggle command for operators. Requested by P_pan +Added option to enable chatbot at script start +Added status message for connecting operators. +Changes from 1.0d 03/27/08 +Added random messages option, if chat idle for 'x 'mins. Requested by uffetjur +Added sample idle chat strings. +Changes from 1.0e 03/28/08 +Addded replaceable parameters in 'IdleChat' for various hub/custom strings +Added a few more IdleChat strings ~Changed idle chat functional only when there are online users +Changes from 1.0f 09/15/08 +Added responses to statements to bot +Added a few more Wds strings ~Minor code changes otherwise ]] --[[ Start Settings]]-- -- Set the name for the Bot [Hub Bot = SetMan.GetString(21)] local Bot = "[Verbosity]" -- Register the Bot? [ie show in user list] true/false local RegBot = true -- Description for bot, used if RegBot = true local Desc = "Yet another trigger bot" -- Set the min/max delay time [in seconds]for repsonse local DelayRange = {3,10} -- Your nick for debugging patterns ["" = disabled / "YourNick" = Send To You / "Ops" = Send To Ops] local DebugNick = "" --"Mutor" -- Command to turn chatbot on/off local ChatCmd = "chatbot" -- Chat responses enabled at script start? local ChatOn = true -- Add your trigger words/repsonses. Maintain table format [(user) will be replaced with user's nick] local Wds = { ["^h[i^.]$"] = {"Hello (user)","Hey There","Welcome back (user)","Wow look what the cat dragged in...."}, [" *who[%?| |^%a]+"] = {"I don't know who (user)","Who? Beats me (user)?"}, [" *hello "] = {"Hi (user)!","Greetings","When did you get out (user)?"}, ["cya.*"] = {"See you later (user)","So long"}, ["g[o|d]- *morning *.*$"] = {"Morning (user)","Did you sleep well (user)?"}, ["g[o|d]- *bye *.*$"] = {"Later (user)","Goodbye","Peace out playa","Bye for now (user)"}, ["g[o|d]- *night *.*$"] = {"Sleep well (user)","Goodnight (user)","G'night then"}, ["g[o|d]- *evening *.*$"] = {"Evening (user)","Is it evening (user)?"}, ["^back$"] = {"Welcome back (user)","(user), while you were afk your parole officer stopped by."}, ["later"] = {"Later (user)","Goodbye","Cya","peace out playa","You outtie (user)? ...Ahhiiite"}, ["%a+%?[ %|^%a]*"] = {"I dunno (user)","Good question (user)...","Are you asking me?","Sorry (user), I don't know.","I have no idea (user)"}, ["b[b|r][b|s|l]"] = {"See you (user)","See you in a while (user)","Ok hamma, later."}, ["wb"] = {"Welcome back","You have returned, now we can start the party"}, ["peace -"] = {"Peace to you (user)","Be well (user)","Give my regards to your parole officer (user)"}, ["^l[o]+l.*"] = {"haha",":D",":D","That's funny (user)"}, ["rofl"] = {"OK (user), you can get off the floor now.","It wasnt that funny :D"}, ["lmao"] = {"Great (user), now what will you use for an ass?.","hehe :D","I don't get it"}, ["lag[g|y|]*[i|n|g]*"] = {"Sorry, (user), the ISP sucks.","What|do|you|mean|lag|(user)?|There's no |...lag."}, ["%:[d|)]$"] = {"What are you smiling about (user)?","Smile (user), everyone loves a moron."}, ["%:[p|b]$"] = {"You are one cheeky fucker (user)","If you stick out your tongue (user), be prepared to use it!","Nyaaahhh :P"}, ["%;[d|p|b]$"] = {"Got someting in your eye (user)?","(user), are you coming on to me?"}, ["anyone [g|o|t]-%s*[h|a|v|e]*"] = {"Although it becomes you, don't beg (user)","Try searching (user)"}, ["got slot"] = {"No slot begging (user)","Just queue it up (user)"}, ["need sleep"] = {"Ahh to sleep, per chance to dream","Get some rest (user) you look like shit.","Sleep well"}, ["typo"] = {"Nice typing skills (user)","Care to type that again?"}, ["y[n]*hub"] = {"Oooh YnHub, do they make that for adults now?","I like PtokaX much better!"}, ["[.]lua[.]*"] = {"Luaistheshit (user)","mmmmmmm ....looahh"}, ["regme"] = {"Yooohoo operators, (user) wants to register!","Sorry (user), I'm just a bot!"}, ["kk"] = {"Agreed (user)","Ahhiiite"}, ["shut up"] = {"Bite me (user)","I can't shut up (user), I'm female"}, --[""] = {"",""} } -- Enable random messages after x minutes of idle main chat [0 = disable] -- ***Note: This feature only functions if there are online users. local Idle = 30 -- If 'Idle' above is enabled, set messages below. -- *** Certain strings will be replaced as follows: -- [Desc] = Hub Description,[Admin] = Admins Nick, [Hub] = Hub Name, [List] = Hub list, -- [Bot] = Hub Bot, [OpChat] = OpChat name, [Lang] Hub language, [Addr] = Hub address, -- [Email] = Owner Email, [Topic] = current hub topic, [User] = random online user nick -- Don't use any such tags [-- comment lines] unless they are set in the PtokaX GUI local IdleChat = { "Dammit! [User] killed the chat again.","Roll over [User], you're snoring again.", "Yawn...","ZZZZZZZZZzzzzzz.......","Shut up! All of you.", "Where did everyone go?","Parlez-vous Anglais?","Okay the bar is now open, who needs a drink?", "Okay [User], I'm here now, you can start the party!","Help I've fallen and I... ...hey nice carpet.", "[User] isn't around? Thank God!","Has anyone seen [User]", "Welcome to [Hub] where you can get a good snooze.", "Hehe, it's dead in here, the real party is in [OpChat]", "Is this [Hub] or the city morgue?","One tequila, two tequila, three tequila, ...floor.", "Man alive [Admin], this is boring.","Next mood swing......six minutes", "Welcome to [Hub], where the dead come to sleep.", "With a description like [Desc], I expected more chatter.", "You're right [User], [Admin] IS dead sexy...", "ECHO! ECho! Echo' echo ....", "...Changing hub topic from '[Topic]' to 'Snoozefest "..os.date("%Y").."'", "Hello!? This IS an [Lang] speaking hub isn't it?", "Uh-oh am I alone here again?", "Wow, you can here a pin drop in here. Well at least [User] is quiet for a change.", "It's true [User], I DO like the sound of my own voice", "Does anyone mind if I eat this last cookie?", "I'll tell ya [User], it's lonely at the top ....of the user list :P", "Don't worry about me, I'll just sit here and look beautiful in contrast to [User].", "Ok fine [User], I'll just take these naked women and all this beer someplace else!", "[User] are you ignoring me?", "[Bot]'s mom was a Commodore 64", "I have seen more activity watching the grass grow.", "ZZZZZZZZZZzzzzzz........", } local BotStrings = { {{"shut the fuck","shut up","stfu"},{"I can't shut up (user), I'm female","Wait (user) I'm trying to imagine you with a personality.","you shut up (user)","I will speak if I want","You're not the boss of me (user)"}}, {{"fuck[^%a]","go fuck"},{"No fuck you (user)","Talk to the hand (user)","500,000 sperm and you were the fastest (user)?"}}, {{"dick","tool","penis"},{"Then suck me","bite me (user)","Don't piss me off (user) I'm running out of places to hide the bodies.",}}, {{"stupid","dumb","retard"},{"I'm damn smarter than you (user)","If I throw a stick, will you leave (user)?","I'm trying to imagine you with a personality.","Sorry (user), I can be no smater than my author"}}, {{"bot","robot","script"},{"Bot? I am as real as you are (user)","The village called for ya (user), ...they want their idiot back."}}, {{" *script *"},{"I am what happens when letters have sex","I am, therefore I Lua"}}, {{"hate","suck","fag","jerk","gay"},{"Don't hate the playa (user), hate the game","Don't be a hater (user)","Okay, okay! I take it back. Unfuck you!!!","I don't have an attitude problem. You have a perception problem.",}}, } --[[ End Settings]]-- ChkBotStr = function(str) local bot,s = Bot:gsub("%p%c",""),"" for wrd in str:lower():gmatch("([^%p ]+)") do if bot:lower():find(wrd:gsub("%p%c","%%%1")) then for i,v in ipairs(BotStrings) do for a,b in ipairs(v[1]) do if str:lower():find(b:lower()) then local reply = v[2][math.random(#v[2])] return reply end end end end end end local Trigs,Used,Tmr,IdleTime,IdleUsed,Clean,LastNick = {},{},0,os.time(),{},os.time() + 30000,"" OnStartup = function() local HubChat = {} if Bot == "" then Bot = SetMan.GetString(21) end if RegBot and Bot ~= SetMan.GetString(21) then Core.RegBot(Bot,Desc,"",true) end if not SetMan.GetString(34) then SetMan.SetString(34,"English") SetMan.Save() end Tmr = TmrMan.AddTimer(1000) for i,v in pairs(Wds) do Used[i] = {"",#v} end collectgarbage("collect") end OnTimer = function(Id) if Id == Tmr then if next(Trigs) then local i,r = ChkTrigs() if i and r then Core.SendToAll("<"..Bot.."> "..r.."|") table.remove(Trigs,i) end end if Idle > 0 and next(IdleChat) and ((os.time() - IdleTime)/60) > Idle then IdleTime = os.time()-1 if #IdleUsed >= #IdleChat then IdleUsed = {} end local Chk = function(int) for i,v in ipairs(IdleUsed) do if int == v then return true end end end math.randomseed(os.time()) local x = math.random(#IdleChat) while Chk(x) do x = math.random(#IdleChat) end table.insert(IdleUsed,x) local chat,nick = IdleChat[x] local t = Core.GetOnlineUsers() if next(t) then nick = t[math.random(#t)].sNick while nick:lower() == LastNick:lower() do nick = t[math.random(#t)].sNick end LastNick = nick local tab = { {"%[Hub%]",0},{"%[Admin%]",1},{"%[Addr%]",2},{"%[Desc%]",5},{"%[Redir%]",6}, {"%[List%]",7},{"%[Topic%]",10},{"%[Bot%]",21},{"%[OpChat%]",24},{"%[Email%]",30}, {"%[Lang%]",34},{"%[User%]",nick}, } for i,v in ipairs(tab) do if type(v[2]) == "number" then chat = chat:gsub(v[1],SetMan.GetString(v[2]) or "%1: Not Set In GUI!") else chat = chat:gsub(v[1],v[2]) end end Core.SendToAll("<"..Bot.."> "..chat.."|") end end if os.time() > Clean then Clean = os.time() + 30000 collectgarbage("collect") end end end ChkTrigs = function(t) local n = os.time() for i,v in ipairs(Trigs) do if n > v[1] then return i,v[2] end end end OpConnected = function(user) local x,t,p = ChatOn,{["true"]= "enabled",["false"] = "disabled"},SetMan.GetString(29):sub(1,1) Core.SendToUser(user,"<"..Bot.."> ChatBot is currently "..t[tostring(x)].. ", type "..p..ChatCmd:lower().." to change it's status.|") end ChatArrival = function(user, data) if Core.GetUserValue(user,11) then local _,_,cmd = data:lower():find("^%b<> ["..SetMan.GetString(29).."]("..ChatCmd:lower()..")|$") if cmd then local x,t = ChatOn,{["true"]= "enabled",["false"] = "disabled"} if x then x = false else x = true end ChatOn = x return Core.SendToUser(user,"<"..Bot.."> ChatBot is now "..t[tostring(x)].."|"),true end end if ChatOn and not data:lower():find("^%b<> ["..SetMan.GetString(29).."][%a]+") then IdleTime = os.time()-1 local dat = data:sub(1,-2):gsub("^%b<> ","") local ret = ChkBotStr(dat) if ret then local delay = os.time() + math.random(math.max(2,DelayRange[1]),math.min(15,DelayRange[2])) table.insert(Trigs,{delay,ret:gsub("%(user%)",user.sNick)}) else for i,v in pairs(Wds) do if dat:lower():find(i:lower()) then if DebugNick ~= "" then local x,r = i:gsub("|","|"),"\t" r = r:rep(12).." is kicking because:" local msg = "<"..Bot.."> Trigger: '"..x.."' found in: " if DebugNick:lower() == "ops" then Core.SendToOps(msg..data.."|"..msg..r) else local op = Core.GetUser(DebugNick) if op then Core.SendToUser(op,msg..data.."|"..msg..r) end end end if Used[i][2] <= 0 then Used[i] = {"",#v} end local x = math.random(#v) while Used[i][1]:find(x) do x = math.random(#v) end Used[i][1] = Used[i][1]..tostring(x) Used[i][2] = Used[i][2] - 1 local reply = v[x] math.randomseed(os.time()) local delay = os.time() + math.random(math.max(2,DelayRange[1]),math.min(15,DelayRange[2])) table.insert(Trigs,{delay,reply:gsub("%(user%)",user.sNick)}) break end end end end end

Best Regards,
Massimiliano
Title: Re: ChatBot Px
Post by: Cêñoßy†ê on 28 June, 2021, 14:52:13
Did works just fine with PtokaX 0.5.2.2 [556] Lua 5.3


[15:49:35 | 127.0.0.1 | ] <Cêñoßy†ê> good morning
[15:49:46] <[Verbosity]> Did you sleep well Cêñoßy†ê?




--[[

ChatBot 1.0g LUA 5.11 [Strict][API 2]

By Mutor 11/22/07
Requested by sphinx

Yet another trigger bot, this one for the new API

-Allows for multiple repsonses to a common trigger
-Allows for (adjustable) random delay for response
-Allows for regular expression in trigger 'patterns'
-Uses all repsonses before repeating a response
-Provides 'debug' reporting for pattern testing

+Changes from 1.0 11/23/07
+Added support for API 1 [old API] Requested by sphinx

+Changes from 1.0b 03/18/08
-Removed support for API 1, now API 2 strict again :P
+Added option to register bot. Requested by Annie

+Changes from 1.0c 03/20/08
+Added start/stop toggle command for operators. Requested by P_pan
+Added option to enable chatbot at script start
+Added status message for connecting operators.

+Changes from 1.0d 03/27/08
+Added random messages option, if chat idle for 'x 'mins. Requested by uffetjur
+Added sample idle chat strings.

+Changes from 1.0e 03/28/08
+Addded replaceable parameters in 'IdleChat' for various hub/custom strings
+Added a few more IdleChat strings
~Changed idle chat functional only when there are online users

+Changes from 1.0f 09/15/08
+Added responses to statements to bot
+Added a few more Wds strings
~Minor code changes otherwise
]]

--[[ Start Settings]]--

-- Set the name for the Bot [Hub Bot = SetMan.GetString(SetMan.tStrings.HubBotNick)]
local Bot = "[Verbosity]"
-- Register the Bot? [ie show in user list] true/false
local RegBot = true
-- Description for bot, used if RegBot = true
local Desc = "Yet another trigger bot"
-- Set the min/max delay time [in seconds]for repsonse
local DelayRange = {3,10}
-- Your nick for debugging patterns ["" = disabled / "YourNick" = Send To You / "Ops" = Send To Ops]
local DebugNick = "" --"Mutor"
-- Command to turn chatbot on/off
local ChatCmd = "chatbot"
-- Chat responses enabled at script start?
local ChatOn = true
-- Add your trigger words/repsonses. Maintain table format [(user) will be replaced with user's nick]
local Wds = {
["^h[i^.]$"] = {"Hello (user)","Hey There","Welcome back (user)","Wow look what the cat dragged in...."},
[" *who[%?| |^%a]+"] = {"I don't know who (user)","Who? Beats me (user)?"},
[" *hello "] = {"Hi (user)!","Greetings","When did you get out (user)?"},
["cya.*"] = {"See you later (user)","So long"},
["g[o|d]- *morning *.*$"] = {"Morning (user)","Did you sleep well (user)?"},
["g[o|d]- *bye *.*$"] = {"Later (user)","Goodbye","Peace out playa","Bye for now (user)"},
["g[o|d]- *night *.*$"] = {"Sleep well (user)","Goodnight (user)","G'night then"},
["g[o|d]- *evening *.*$"] = {"Evening (user)","Is it evening (user)?"},
["^back$"] = {"Welcome back (user)","(user), while you were afk your parole officer stopped by."},
["later"] = {"Later (user)","Goodbye","Cya","peace out playa","You outtie (user)? ...Ahhiiite"},
["%a+%?[ %|^%a]*"] = {"I dunno (user)","Good question (user)...","Are you asking me?","Sorry (user), I don't know.","I have no idea (user)"},
["b[b|r][b|s|l]"] = {"See you (user)","See you in a while (user)","Ok hamma, later."},
["wb"] = {"Welcome back","You have returned, now we can start the party"},
["peace -"] = {"Peace to you (user)","Be well (user)","Give my regards to your parole officer (user)"},
["^l[o]+l.*"] = {"haha",":D",":D","That's funny (user)"},
["rofl"] = {"OK (user), you can get off the floor now.","It wasnt that funny :D"},
["lmao"] = {"Great (user), now what will you use for an ass?.","hehe :D","I don't get it"},
["lag[g|y|]*[i|n|g]*"] = {"Sorry, (user), the ISP sucks.","What|do|you|mean|lag|(user)?|There's no |...lag."},
["%:[d|)]$"] = {"What are you smiling about (user)?","Smile (user), everyone loves a moron."},
["%:[p|b]$"] = {"You are one cheeky fucker (user)","If you stick out your tongue (user), be prepared to use it!","Nyaaahhh :P"},
["%;[d|p|b]$"] = {"Got someting in your eye (user)?","(user), are you coming on to me?"},
["anyone [g|o|t]-%s*[h|a|v|e]*"] = {"Although it becomes you, don't beg (user)","Try searching (user)"},
["got slot"] = {"No slot begging (user)","Just queue it up (user)"},
["need sleep"] = {"Ahh to sleep, per chance to dream","Get some rest (user) you look like shit.","Sleep well"},
["typo"] = {"Nice typing skills (user)","Care to type that again?"},
["y[n]*hub"] = {"Oooh YnHub, do they make that for adults now?","I like PtokaX much better!"},
["[.]lua[.]*"] = {"Luaistheshit (user)","mmmmmmm ....looahh"},
["regme"] = {"Yooohoo operators, (user) wants to register!","Sorry (user), I'm just a bot!"},
["kk"] = {"Agreed (user)","Ahhiiite"},
["shut up"] = {"Bite me (user)","I can't shut up (user), I'm female"},
--[""] = {"",""}
}
-- Enable random messages after x minutes of idle main chat [0 = disable]
-- ***Note: This feature only functions if there are online users.
local Idle = 30
-- If 'Idle' above is enabled, set messages below.
-- *** Certain strings will be replaced as follows:
-- [Desc] = Hub Description,[Admin] = Admins Nick, [Hub] = Hub Name, [List] = Hub list,
-- [Bot] = Hub Bot, [OpChat] = OpChat name, [Lang] Hub language, [Addr] = Hub address,
-- [Email] = Owner Email, [Topic] = current hub topic, [User] = random online user nick
-- Don't use any such tags [-- comment lines] unless they are set in the PtokaX GUI
local IdleChat = {
"Dammit! [User] killed the chat again.","Roll over [User], you're snoring again.",
"Yawn...","ZZZZZZZZZzzzzzz.......","Shut up! All of you.",
"Where did everyone go?","Parlez-vous Anglais?","Okay the bar is now open, who needs a drink?",
"Okay [User], I'm here now, you can start the party!","Help I've fallen and I...   ...hey nice carpet.",
"[User] isn't around? Thank God!","Has anyone seen [User]",
"Welcome to [Hub] where you can get a good snooze.",
"Hehe, it's dead in here, the real party is in [OpChat]",
"Is this [Hub] or the city morgue?","One tequila, two tequila, three tequila,   ...floor.",
"Man alive [Admin], this is boring.","Next mood swing......six minutes",
"Welcome to [Hub], where the dead come to sleep.",
"With a description like [Desc], I expected more chatter.",
"You're right [User], [Admin] IS dead sexy...",
"ECHO! ECho! Echo' echo ....",
"...Changing hub topic from '[Topic]' to 'Snoozefest "..os.date("%Y").."'",
"Hello!? This IS an [Lang] speaking hub isn't it?",
"Uh-oh am I alone here again?",
"Wow, you can here a pin drop in here. Well at least [User] is quiet for a change.",
"It's true [User], I DO like the sound of my own voice",
"Does anyone mind if I eat this last cookie?",
"I'll tell ya [User], it's lonely at the top    ....of the user list :P",
"Don't worry about me, I'll just sit here and look beautiful in contrast to [User].",
"Ok fine [User], I'll just take these naked women and all this beer someplace else!",
"[User] are you ignoring me?",
"[Bot]'s mom was a Commodore 64",
"I have seen more activity watching the grass grow.",
"ZZZZZZZZZZzzzzzz........",
}
local BotStrings = {
{{"shut the fuck","shut up","stfu"},{"I can't shut up (user), I'm female","Wait (user) I'm trying to imagine you with a personality.","you shut up (user)","I will speak if I want","You're not the boss of me (user)"}},
{{"fuck[^%a]","go fuck"},{"No fuck you (user)","Talk to the hand (user)","500,000 sperm and you were the fastest (user)?"}},
{{"dick","tool","penis"},{"Then suck me","bite me (user)","Don't piss me off (user) I'm running out of places to hide the bodies.",}},
{{"stupid","dumb","retard"},{"I'm damn smarter than you (user)","If I throw a stick, will you leave (user)?","I'm trying to imagine you with a personality.","Sorry (user), I can be no smater than my author"}},
{{"bot","robot","script"},{"Bot? I am as real as you are (user)","The village called for ya (user), ...they want their idiot back."}},
{{" *script *"},{"I am what happens when letters have sex","I am, therefore I Lua"}},
{{"hate","suck","fag","jerk","gay"},{"Don't hate the playa (user), hate the game","Don't be a hater (user)","Okay, okay! I take it back. Unfuck you!!!","I don't have an attitude problem. You have a perception problem.",}},
}
--[[ End Settings]]--

ChkBotStr = function(str)
local bot,s = Bot:gsub("%p%c",""),""
for wrd in str:lower():gmatch("([^%p ]+)") do
if bot:lower():find(wrd:gsub("%p%c","%%%1")) then
for i,v in ipairs(BotStrings) do
for a,b in ipairs(v[1]) do
if str:lower():find(b:lower()) then
local reply = v[2][math.random(#v[2])]
return reply
end
end
end
end
end
end

local Trigs,Used,Tmr,IdleTime,IdleUsed,Clean,LastNick = {},{},0,os.time(),{},os.time() + 30000,""
OnStartup = function()
local HubChat = {}
if Bot == "" then Bot = SetMan.GetString(SetMan.tStrings.HubBotNick) end
if RegBot and Bot ~= SetMan.GetString(SetMan.tStrings.HubBotNick) then Core.RegBot(Bot,Desc,"",true) end
if not SetMan.GetString(34) then SetMan.SetString(34,"English") SetMan.Save() end
Tmr = TmrMan.AddTimer(1000)
for i,v in pairs(Wds) do Used[i] = {"",#v} end
collectgarbage("collect")
end

OnTimer = function(Id)
if Id == Tmr then
if next(Trigs) then
local i,r = ChkTrigs()
if i and r then Core.SendToAll("<"..Bot.."> "..r.."|") table.remove(Trigs,i) end
end
if Idle > 0 and next(IdleChat) and ((os.time() - IdleTime)/60) > Idle then
IdleTime = os.time()-1
if #IdleUsed >= #IdleChat then IdleUsed = {} end
local Chk = function(int)
for i,v in ipairs(IdleUsed) do if int == v then return true end end
end
math.randomseed(os.time())
local x = math.random(#IdleChat)
while Chk(x) do x = math.random(#IdleChat) end
table.insert(IdleUsed,x)
local chat,nick = IdleChat[x]
local t = Core.GetOnlineUsers()
if next(t) then
nick = t[math.random(#t)].sNick
while nick:lower() == LastNick:lower() do nick = t[math.random(#t)].sNick end
LastNick = nick
local tab = {
{"%[Hub%]",0},{"%[Admin%]",1},{"%[Addr%]",2},{"%[Desc%]",5},{"%[Redir%]",6},
{"%[List%]",7},{"%[Topic%]",10},{"%[Bot%]",21},{"%[OpChat%]",24},{"%[Email%]",30},
{"%[Lang%]",34},{"%[User%]",nick},
}
for i,v in ipairs(tab) do
if type(v[2]) == "number" then
chat = chat:gsub(v[1],SetMan.GetString(v[2]) or "%1: Not Set In GUI!")
else
chat = chat:gsub(v[1],v[2])
end
end
Core.SendToAll("<"..Bot.."> "..chat.."|")
end
end
if os.time() > Clean then Clean = os.time() + 30000 collectgarbage("collect") end
end
end

ChkTrigs = function(t)
local n = os.time()
for i,v in ipairs(Trigs) do if n > v[1] then return i,v[2] end end
end

OpConnected = function(user)
local x,t,p = ChatOn,{["true"]= "enabled",["false"] = "disabled"},SetMan.GetString(29):sub(1,1)
Core.SendToUser(user,"<"..Bot.."> ChatBot is currently "..t[tostring(x)]..
", type "..p..ChatCmd:lower().." to change it's status.|")
end

ChatArrival = function(user, data)
if Core.GetUserValue(user,11) then
local _,_,cmd = data:lower():find("^%b<> ["..SetMan.GetString(29).."]("..ChatCmd:lower()..")|$")
if cmd then
local x,t = ChatOn,{["true"]= "enabled",["false"] = "disabled"}
if x then x = false else x = true end ChatOn = x
return Core.SendToUser(user,"<"..Bot.."> ChatBot is now "..t[tostring(x)].."|"),true
end
end
if ChatOn and not data:lower():find("^%b<> ["..SetMan.GetString(29).."][%a]+") then
IdleTime = os.time()-1
local dat = data:sub(1,-2):gsub("^%b<> ","")
local ret = ChkBotStr(dat)
if ret then
local delay = os.time() + math.random(math.max(2,DelayRange[1]),math.min(15,DelayRange[2]))
table.insert(Trigs,{delay,ret:gsub("%(user%)",user.sNick)})
else
for i,v in pairs(Wds) do
if dat:lower():find(i:lower()) then
if DebugNick ~= "" then
local x,r = i:gsub("|","&#124;"),"\t"
r = r:rep(12).." is kicking because:"
local msg = "<"..Bot.."> Trigger: '"..x.."' found in: "
if DebugNick:lower() == "ops" then
Core.SendToOps(msg..data.."|"..msg..r)
else
local op = Core.GetUser(DebugNick)
if op then Core.SendToUser(op,msg..data.."|"..msg..r) end
end
end
if Used[i][2] <= 0 then Used[i] = {"",#v} end
local x = math.random(#v)
while Used[i][1]:find(x) do x = math.random(#v) end
Used[i][1] = Used[i][1]..tostring(x)
Used[i][2] = Used[i][2] - 1
local reply = v[x]
math.randomseed(os.time())
local delay = os.time() + math.random(math.max(2,DelayRange[1]),math.min(15,DelayRange[2]))
table.insert(Trigs,{delay,reply:gsub("%(user%)",user.sNick)})
break
end
end
end
end
end

Title: Re: ChatBot Px
Post by: Massi on 29 June, 2021, 13:45:04
Very good! Thanks for your support, assistance and testing :) and excuse me  ;)

Best Regards,
Massimiliano