From b9785949937c9bc002fdc9e97883b8bd5c79799f Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Jan 2016 00:55:44 +1100 Subject: [PATCH] Added an AI module, works mostly. --- ai.lua | 7 +++++++ config.lua | 5 ++++- hooks/.highfive.lua.swp | Bin 12288 -> 0 bytes hooks/ai.lua | 45 ++++++++++++++++++++++++++++++++++++++++ hooks/highfive.lua | 1 - init.lua | 14 ++++++++----- 6 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 ai.lua delete mode 100644 hooks/.highfive.lua.swp create mode 100644 hooks/ai.lua diff --git a/ai.lua b/ai.lua new file mode 100644 index 0000000..effda60 --- /dev/null +++ b/ai.lua @@ -0,0 +1,7 @@ +{{ +{"I'm a real person, I swear!"}, +{"are","you","bot"} +},{ +{"Thisisalsoatest"}, +{"1234","9999"} +}} diff --git a/config.lua b/config.lua index 1048dc8..d16b76a 100644 --- a/config.lua +++ b/config.lua @@ -9,13 +9,16 @@ channels={ "#ssss" }, hooks={ -"highfive.lua" +"highfive.lua", +"ai.lua" }, cmds={ +"reload.lua" }, timers={ "highfive.lua" }, +debug=false, autojoin=true, prefix=":", username="yuki", diff --git a/hooks/.highfive.lua.swp b/hooks/.highfive.lua.swp deleted file mode 100644 index 5c67f3d2a463ccc460945729712109e0dba0dd15..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2F>ljA6vtl~m?%X>Yz&XNfC(@GCUBw&6vG90 zP8FW2s=QG33kUk@k~=2A1egF5U;<2l2`~XBzyz286JP>N;6Egw`T*b006bo##nb=) zv+w^OO8_58FG=@F>!fAUx3d5rNv}ySNK?{H(nZoQit&Z?ne>VDp7f6NmgM3a5;rEm z1egF5U;<2l2`~XBzyz4Ui6memq~D&-a~13Bk+J=T$Xa+AcXl$-#QhMhNwG+@#YeYg zs-t2<+1S_^Lwwc_Fj8r*r>JcoocsXiT1zK6=mEgWh{KVwMMK=pFwJbNN9a-@9ldrr zq-c`!&}cp!RZw5tcBhMBh{b5E{o3b8$#PkkJ>6&q&KS4@-$5}M>U+@!9r(UQ2fnB7 zL0=d3^(m@fI7ZGfhhUwZGo@Ki5y@KokXZW&9s@S4=?zdyQKNvWKq2Ly)jB5ss@OxW zN+yqwNAFNPNV48wBFdRVmz#|a?1sNK0+jE}#V(muyC?A32>UEs6Uv&s6FuHpY@%1( Z7{&SaYBwkco!MZm3;vGVU{cB{{00q+1bqMi diff --git a/hooks/ai.lua b/hooks/ai.lua new file mode 100644 index 0000000..03dd1c5 --- /dev/null +++ b/hooks/ai.lua @@ -0,0 +1,45 @@ +nick,chan,message = ... +local serialization = require "serialization" +lnick = "yukichan" +print(lnick,nick,chan,message) +if string.find(message,lnick) ~= nil and nick ~= "Shocky" then + print("Message addressed to AI!") + local f = io.open("./ai.lua","rb") + if f ~= nil then + local content = f:read("*a") + f:close() + print(content) + print("Loaded AI file.") + print(type(serialization.unserialize)) + w,aitab = pcall(serialization.unserialize,content) + print(w,aitab) + print("Decoded AI file.") + local selection = 0 + local hscore = 0 + print("Starting interpretation.") + for k,v in ipairs(aitab) do + local count = 0 + for l,w in ipairs(v[2]) do + if message:find(w) then count = count + 1 print ("yes") end + end + if count > hscore then + selection = k + hscore = count + print(selection,hscore) + end + end + if hscore == 0 then + print("No high score, selecting a random response.") + selection = math.random(1,#aitab) + end + print(selection) + selstring = aitab[selection][1][1] + if type(selstring) == "table" then + for k,v in pairs(selstring) do + print(k.."="..v) + end + end + print(selstring) + sendchan(chan,selstring) + end +end diff --git a/hooks/highfive.lua b/hooks/highfive.lua index 2b356fc..b98bad3 100644 --- a/hooks/highfive.lua +++ b/hooks/highfive.lua @@ -1,6 +1,5 @@ tArgs = {...} local nick, chan, message = tArgs[1],tArgs[2],tArgs[3] -print(nick,chan,message,nick == "Shocky") if message:find("o/") ~= nil or message:find("\\o") ~= nil then if nick ~= "Shocky" then if _G.leftHanging[2] == false then diff --git a/init.lua b/init.lua index 5ebeaba..ad0dbb4 100644 --- a/init.lua +++ b/init.lua @@ -20,7 +20,7 @@ function loadconfig() local s,f = pcall(load,c) fo:close() if s then - table.insert(hooks,f) + table.insert(hooks,#hooks+1,f) print("Hook "..v.." loaded") else print("Hook "..v.." failed to load:") @@ -105,8 +105,10 @@ end leftHanging = {0,false} function parsemsg(nick,chan,message) - for k,v in ipairs(hooks) do - v(nick,chan,message) + for k,v in pairs(hooks) do + print("Running hook "..k) + local fail,errors = pcall(v,nick,chan,message) + if not fail then print(errors) end end if string.find(message,config.prefix) == 1 then local command = message:sub(2) .. " " @@ -152,7 +154,8 @@ function parsemsg(nick,chan,message) print("Killed by "..nick) end elseif cmds[tCommand[1]] ~= nil then - pcall(cmds[tCommand[1]],nick,chan,tCommand,message) + local fail, errors = pcall(cmds[tCommand[1]],nick,chan,tCommand,message) + if not fail then print(errors) end end end end @@ -215,7 +218,8 @@ function main() pcall(parse,line) end for k,v in ipairs(timers) do - v(line) + local fail, errors = pcall(v,line) + if not fail then print(errors) end end if line == nil then line = "" end until string.find(line,"ERROR :Closing link:") ~= nil