seNsi: the 'clever' bot ( lua 5)
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

seNsi: the 'clever' bot ( lua 5)

Started by Dessamator, 30 April, 2005, 16:47:52

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dessamator

--[[
	Thks to Ptaczek for his Trickerbot.lua
	Thks to Skrollster, for the math.random synthax
	Thks to MatrixX for some help, too...
	And thks to the others, for their help... ;o)
----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
	seNsi: the 'clever' bot :p
	Description:
	- Each 20 math.min, bot is talking alone, with math.random questions...
	- If someone speaks again on main chat, there is a math.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)
----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
	- heavily touched by Herodes :: 28/3/2005 ( 16.08 compliant too )
	- many optimizations .. couldn't count them .. just enjoy..
	- some fixes by Dessamator
--]]
bot = {
	["name"] = "SenSi",
	["email"] = "petsagouris@hotmail.com",
	["desc"] = "I am the cleverest bot around ...",
}

Interval = 1 -- every how many minutes ?

s = {}
s.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)",
	}

s.idle ={} -- don't touch this line pls .. if you do don't blame it on me ..

s.idle.questions = {
	"Anybody here?",
	"I'am Boored",
	"All are sleeping ?!",
	"Haaaaaaaaloooooooooo !!! ",
	"Don't leave me alone.... :'(",
	}

s.idle.answers = {
	"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... :))"
	}

s.idle.morninganswers = {
	"Wow... [USER]... ur night was certainly short.... :p",
	"Yeahh !!! GOOOOOD MORNIIIIIIIIIING [USER] !",
	"So, [USER],...coffee for me please, yep... :o)"
	}

s.idle.morning = {
	"Driiiiiiing... Time to Wake Uuuuuuuuuuup !! :D",
	"GOOOOOD MORNIIIIIIIIIING HUBSTERRRRRRRRRRRRRS !!!!!!!",
	"Hmm.....Someone is awake ??!!"
	}

s.idle.evening = {
	"Time to have a drink, no ? :o)",
	"Hum hum... place is really quiet, at this time... :'(",
	"At this time, u shouldn't sleep... :-("
	}

s.idle.eveninganswers = {
	"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"
	}
---trigs end ---

function Main()
	talk = true
	--frmHub:RegBot(bot.name, 1, bot.desc, bot.email)
	bot = bot.name
	w = { ["quiet"] = false,["morn"] = false,["even"] = false,["silence"]=false, }
	SetTimer(Interval*60000)
	StartTimer()
end

function ParseCommands(user, data, pm_start)
	local findstr = (pm_start or "").."%b<>%s+[!#?+](%S+)"
	local _,_, cmd = string.find ( data, findstr )
	if cmd then
tCmd={
["shutup"]=function()
		Talk(false)
		SendToAll(bot, "away")
		StopTimer()
		w.silence =true
end,
	["talk"]=function()
		Talk(true)
		SetWait(false,false,false)
		w.silence =false
		StartTimer()
		SendToAll(bot, "Back")
		
		end,
}
		if tCmd[cmd] then
			return "cmd",tCmd[cmd]()
		else
			return cmd
		end
	end
end

function Talk(b)
	if b then talk = b end
	return talk
end

function ToArrival(user, data)
	if (string.sub(data, 1, string.len(bot)+5 ) == "$To: "..bot ) then
		if user.bOperator then
			if ParseCommands(user, string.sub(data,1, -2), "%$") then
				return 1
			
		end
	end
end

-- Main Chat events --
function ChatArrival(user, data)
	if  user.bOperator and ParseCommands( user, string.sub(data,1, -2))=="cmd" then return 1 end
	local _,_,msg = string.find( data, "%b<>%s*(.*)|")
	local talked = nil
	msg = string.lower(msg)
	for trig, replace in s.trigs do
		if ( w.silence == false) then
			if string.find( msg, trig ) then
				talked = (Produce( replace, "%[USER%]", user.sName))
				end	
			end
		end
	end
	
	-- Restart the timer each time someone is talking on the main chat, if bot is allowed to talk --
	if Talk() then
		StopTimer()
		StartTimer()
		if w.quiet then
			talked=Produce( s.idle.answers, "%[USER%]", user.sName)
			SetWait(false)	
		elseif 	(w.morn) then
			talked=Produce( s.idle.morninganswers, "%[USER%]", user.sName)
			SetWait(false,false)
		elseif w.even then 
			talked=Produce( s.idle.eveninganswers, "%[USER%]", user.sName)
			SetWait(false,false,false)
		end
		
	end

	if talked and not(w.silence) and not ParseCommands( user, string.sub(data,1, -2)) then
		SendToAll( user.sName, msg)
		SendToAll( bot, talked )
		return 1
	end
end


function OnTimer()
	local h, trig = tonumber(os.date("%H")), nil
	-- Idle trigs, for the morning, and the evening :o) --
	if h == 7 then
		SendToAll( bot, Produce(s.idle.morning) )
		SetWait(false,true,false)
		StartTimer()
		trig = true
	elseif h == 19 then
		SendToAll( bot, Produce(s.idle.evening) )
		SetWait(false,false,true)
		StartTimer()
		trig = true
	end

	-- Others idle trigs --
	if not trig then
		SendToAll( bot, Produce(s.idle.questions))
		SetWait(true)
	end
end

function Produce( val, what, with )
	if what then
		if type(val) == "table" then
			return string.gsub( val[math.random(1,table.getn(val))], what, with )
		end
		return string.gsub( val, what, with )
	end
	return val[math.random(1,table.getn(val))]
end

function SetWait( q, m, e )
	w.quiet = q --quiet
	w.morn  = m --morning
	w.even  = e --evening
end--------------------------------------------------------------------------------

*Post edited* bot was sending responce before the msg of the user , fixed, hopefully !!
*Post edited* ptokax wasnt responding to inbuild commands !!
*Post edited* the bot wouldnt shut up !!
Ignorance is Bliss.

bastya_elvtars

Great, I have been looking for this a long time. Maybe you might wanna re-edit your post and turn off emotes, but anyway, great job, I love Senzi!  :D
Everything could have been anything else and it would have just as much meaning.

Dessamator

QuoteOriginally posted by bastya_elvtars
Great, I have been looking for this a long time. Maybe you might wanna re-edit your post and turn off emotes, but anyway, great job, I love Senzi!  :D

Done, (post edited) , and well i didnt do any of the hard work, herodes did, i just fixed, some minor bugs, :)
Ignorance is Bliss.

MichaelD

Thank you very much for this one. :)

Dessamator

Ignorance is Bliss.

Jerry

Hi guys,

It is possible to do, these my ideas into seNsi
 
I think these 3 things:

1. Add feature, that you can write more then one anwer for the trigs, eg.:    
["lol"]={
	"Yeah, [USER] that was funny,  Hahahaha.",
	"Hmm, ok that was funny, I think :)",
	"what! [USER]  why are you laughing?",
	"You shake when you laugh, like a bowl full of jelly",
	"hilarious!",
	"hehehehe",
	"hohohohoh"  
                         

2. give all seNsi's phrases from script to individual .txt files, so you can add phrases with command

3. the command to add phrase into script (for ex. +addphrase hello="Hi [USER]"?

It is possible to do, please?

I think that script would be nice to have with that features.
It would be more simple to write triggs for all OPs and not only for one man (Admin), who running PtokaX (script) on his PC :)

Thank you in advance for answer!!

    Jerry

Dessamator

#6
Yes, indeed its possible, ive been thinking of adding it for a long time, but ive been kinda lazy, if someone else doesnt do it, i'll try it.
Ignorance is Bliss.

Jerry

OK, Thanks Dessamator  :))  :]

Dessamator

#8
--[[
	Thks to Ptaczek for his Trickerbot.lua
	Thks to Skrollster, for the math.random synthax
	Thks to MatrixX for some help, too...
	And thks to the others, for their help... ;o)
----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
	seNsi: the 'clever' bot :p
	Description:
	- Each 20 math.min, bot is talking alone, with math.random questions...
	- If someone speaks again on main chat, there is a math.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)
----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
	- heavily touched by Herodes :: 28/3/2005 ( 16.08 compliant too )
	- many optimizations .. couldn't count them .. just enjoy..
	- some fixes by Dessamator
	- added trigs for all events by Dessamator 
         - user commands added
--]]
-- Script Settings--
bot = {
	["name"] = "SenSi",
	["email"] = "petsagouris@hotmail.com",
	["desc"] = "I am the cleverest bot around ...",
}
Interval = 60 -- every how many minutes ?
Rclickon = true -- right click --> true/false
-- Script Settings end--


--trig tables--
s = {}
s.trigs = {}

s.idle ={} -- don't touch this line pls .. if you do don't blame it on me ..
s.idle.morning = {}
s.idle.evening = {}
s.idle.questions = {}
s.idle.answers = {}
s.idle.morninganswers = {}
s.idle.eveninganswers = {}

---trigs end ---
fTrigs = "trigs.txt" -- file containing the trigs

OpConnected = function (user)
	if user.bUserCommand and Rclickon then
		user:SendData("$UserCommand 1 3 ChatBot\\Gag the bot $<%[mynick]> !shutup|")
		user:SendData("$UserCommand 1 3 ChatBot\\Activate bot $<%[mynick]> !talk|")
		user:SendData("$UserCommand 1 3 ChatBot\\Add trig responce $<%[mynick]> !addresponce %[line:trig name] %[line:responce]|")
		user:SendData("$UserCommand 1 3 ChatBot\\Add idle trig responce $<%[mynick]> !idletrig %[line:trig name] %[line:responce]|")
		user:SendData("$UserCommand 1 3 ChatBot\\Del a trig $<%[mynick]> !deltrig %[line:Trig name] %[line:trig number eg.: 1]|")
		user:SendData("$UserCommand 1 3 ChatBot\\Show trig $<%[mynick]> !showtrig %[line:Trig Type(trig or idle)]|")
	end
end

function Main()
	if io.open(fTrigs,"r") then dofile(fTrigs) end -- load file
	talk = true
	--frmHub:RegBot(bot.name, 1, bot.desc, bot.email)
	bot = bot.name
	w = { ["quiet"] = false,["morn"] = false,["even"] = false,["silence"]=false, }
	SetTimer(Interval*60000)
	StartTimer()
end

function ParseCommands(user, data, pm_start)
	local findstr = (pm_start or "").."%b<>%s+[!#?+](%S+)"
	local _,_, cmd = string.find ( data, findstr )
	local ___,_____,trig = string.find(data,"%b<>%s+%S+%s+(%S+)")
	local b,e,responce = string.find(data,"%b<>%s+%S+%s+%S+%s+(.*)")

local function verify(table,value)
	for i,v in table do 
		if i == value then
			return true
		end
	end
end		
	if cmd then
tCmd={
	["shutup"]=function()
		Talk(false)
		SendToAll(bot, "away")
		StopTimer()
		w.silence =true
	end,
	["talk"]=function()
		Talk(true)
		SetWait(false,false,false)
		w.silence =false
		StartTimer()
		SendToAll(bot, "Back")
		
	end,
	["addresponce"] = function()
		local temp
		if trig and responce then
			if verify(s.trigs,trig) then
				table.insert(s.trigs[trig],responce)
				user:SendData(bot,"Responce added !")
			else
				s.trigs[trig] = {}
				table.insert(s.trigs[trig],responce)
				user:SendData(bot,"New Trig & responce added !")
			end
		elseif not trig  then
			user:SendData(bot,"no trig specified")
		elseif not responce then
			user:SendData(bot,"no responce specified")
		end
	end,
	["idletrig"] = function()
		if trig and responce then
			if verify(s.idle,trig) then
				table.insert(s.idle[trig],responce)
				user:SendData(bot,"Done, Trigger added for idle "..trig)
			else
				user:SendData(bot,"the ' "..trig.." ' table doesnt in idle trigs , use !showtrig idle, to see which ones are available!")
			end
		else 
			user:SendData(bot,"No Trig/responce specified")
		end
	end, 
	["deltrig"] = function()
		if type(tonumber(responce)) == "number" and verify(s.idle,trig) then
			if verify(s.idle[trig],tonumber(responce)) then
				table.remove(s.idle[trig], responce)
				user:SendData(bot,"Idle Trig removed")
			else
				user:SendData(bot,"That Idle Trig Responce doesnt exist")
			end
			
		elseif trig then
			if verify(s.trigs,trig) then
				s.trigs[trig] = nil
				user:SendData(bot,"Trig removed")
			else
				user:SendData(bot,"That Trig Responce doesnt exist")
			end
		else
			user:SendData(bot,"Syntax Error, Correct Syntax is : !deltrig  , or !deltrig ")
		end
	end,
	["showtrig"] = function()
	local temp=" The info u Requested :\r\n\t"
		if trig == "idle" then
			for i,v in s.idle do
				temp = temp.."Trig table :"..i.."\r\n\t"
			end
		elseif trig =="trig" then
			for i,v in s.trigs do 
				temp= temp.."Trigger : "..i
				for index,stuff in v do
					temp= temp.."  "..index.." -  Responce :"..stuff.."\r\n\t"
				end
			end
		end		
	user:SendData(bot,temp)
	end,
	
}
		if tCmd[cmd] then
			return "cmd",tCmd[cmd]()
		else
			return cmd
		end
	end
end

function Talk(b)
	if b then talk = b end
	return talk
end

function ToArrival(user, data)
	if (string.sub(data, 1, string.len(bot)+5 ) == "$To: "..bot ) then
		if user.bOperator then
			if ParseCommands(user, string.sub(data,1, -2), "%$") then
				return 1
			end
		end
	end
end

-- Main Chat events --
function ChatArrival(user, data)
	if  user.bOperator and ParseCommands( user, string.sub(data,1, -2))=="cmd" then return 1 end
	local _,_,msg = string.find( data, "%b<>%s*(.*)|")
	local talked = nil
	msg = string.lower(msg)
	for trig, replace in s.trigs do
		if ( w.silence == false) then
			if string.find( msg, trig) then
				talked = (Produce( (s.trigs[trig]), "%[USER%]", user.sName))	
			end
		end
	end
	
	-- Restart the timer each time someone is talking on the main chat, if bot is allowed to talk --
	if Talk() then
		StopTimer()
		StartTimer()
		if w.quiet then
			talked=Produce( s.idle.answers, "%[USER%]", user.sName)
			SetWait(false)	
		elseif 	(w.morn) then
			talked=Produce( s.idle.morninganswers, "%[USER%]", user.sName)
			SetWait(false,false)
		elseif w.even then 
			talked=Produce( s.idle.eveninganswers, "%[USER%]", user.sName)
			SetWait(false,false,false)
		end
		
	end

	if talked and not(w.silence) and not ParseCommands( user, string.sub(data,1, -2)) then
		SendToAll( user.sName, msg)
		SendToAll( bot, talked )
		return 1
	end
end


function OnTimer()
	local h, trig = tonumber(os.date("%H")), nil
	-- Idle trigs, for the morning, and the evening :o) --
	if h == 7 then
		SendToAll( bot, Produce(s.idle.morning) )
		SetWait(false,true,false)
		StartTimer()
		trig = true
	elseif h == 19 then
		SendToAll( bot, Produce(s.idle.evening) )
		SetWait(false,false,true)
		StartTimer()
		trig = true
	end

	-- Others idle trigs --
	if not trig then
		SendToAll( bot, Produce(s.idle.questions))
		SetWait(true)
	end
end

function Produce( val, what, with )
	if table.getn(val)>0 then
		if what then
			if type(val) == "table" then
				return string.gsub( val[math.random(1,table.getn(val))], what, with )
			end
			return string.gsub( val, what, with )
		end
		return val[math.random(1,table.getn(val))]
	else
		return false
	end
end

function SetWait( q, m, e )
	w.quiet = q --quiet
	w.morn  = m --morning
	w.even  = e --evening
end--------------------------------------------------------------------------------

function OnExit()
SaveToFile(fTrigs,s, "s")
end


-- Save tables in a file --
function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");

        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");

        sTab = sTab or "";
        sTmp = ""

        sTmp = sTmp..sTab..sTableName.." = {\n"

        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end

                sTmp = sTmp..",\n"
        end

        sTmp = sTmp..sTab.."}"
        return sTmp
end

function SaveToFile(file , table , tablename)
	local handle = io.open(file,"w+")
        handle:write(Serialize(table, tablename))
	handle:flush()
        handle:close()
end

Post Edited, fixed small bug !
Ignorance is Bliss.

Jerry

Thank you very much Dessamator!!!!  

P.S.
It is possible to do all others texts:  
s.idle.questions 

s.idle.answers 

s.idle.morninganswers 

s.idle.morning 

s.idle.evening 

s.idle.eveninganswers

as the trigs -> into seperate text files with command to add / remove this answers ?

Thank you very much in advance!!!

Dessamator

Done !

i thought u'd ask for that(or someone else would), i did it in advance ,

post edited!
Ignorance is Bliss.

Wizzi

Damn nice   could you make some rightclick commands build in

would be easyer to use that way


thanks  :)

Honey

Hi guys,

If I want add trig to idle trigs, the script didn't do anything :(
and in the PtokaX is this:
[17:58] Syntax ...\scripts\SeNsi.lua:237: bad argument #1 to `next' (table expected, got nil)

Line 237:
if  next(s.idle[trig]) then

What is wrong, please?

Thank you in advance!

Dessamator

u probably tried to add a trig in a table  that didnt exist, either way, ill debug it asap
Ignorance is Bliss.

chettedeboeuf

Thank you dessamator

Dessamator

#15
QuoteOriginally posted by Honey
Hi guys,

If I want add trig to idle trigs, the script didn't do anything :(
and in the PtokaX is this:
[17:58] Syntax ...\scripts\SeNsi.lua:237: bad argument #1 to `next' (table expected, got nil)

Line 237:
if  next(s.idle[trig]) then

What is wrong, please?

Thank you in advance!

fixed !
QuoteOriginally posted by chettedeboeuf

   Thank you dessamator

ur welcome

QuoteOriginally posted by Wizzi
Damn nice   could you make some rightclick commands build in

would be easyer to use that way


thanks  :)
done
Ignorance is Bliss.

Honey

QuoteOriginally posted by Dessamator
fixed !

Thanks!



I'm really very sorry  X(  ;(

But I find perhaps another problem (bug):

[22:42] Syntax ...scripts\SeNsi.lua:386: invalid pattern capture

Line 386:
if string.find( msg, trig) then

Thanks in advance for help!  :))

Dessamator

#17
hmm, i remember that bug somewhat, try the following:
1. Backup ur trigs
2. Stop the script
3. Delete trigs.txt
4. Start the script
5. add ur trigs again

P.S. I changed the script a bit, it should avoid some bugs :)
Ignorance is Bliss.

Wizzi


Dessamator

Ignorance is Bliss.

chettedeboeuf

I've a problem with the script :
when I enter a trig and a responce by right click, I've not the real responce :

Trig : lol
Responce : Ha Ha Ha

When someone types 'lol' on the central chat, responce is 'Ha'

Trig : bonjour
Responce : Salut ? toi

When someone types 'bonjour' on the central chat, responce is 'Salut'


Thank you dessamator and sorry for my poor english

Dessamator

QuoteOriginally posted by chettedeboeuf
I've a problem with the script :
when I enter a trig and a responce by right click, I've not the real responce :

Trig : lol
Responce : Ha Ha Ha

When someone types 'lol' on the central chat, responce is 'Ha'

Trig : bonjour
Responce : Salut ? toi

When someone types 'bonjour' on the central chat, responce is 'Salut'


Thank you dessamator and sorry for my poor english

fixed
Ignorance is Bliss.

chettedeboeuf

Thank you dessamator

SMF spam blocked by CleanTalk