Added an AI module, works mostly.

This commit is contained in:
Izaya 2016-01-13 00:55:44 +11:00
parent 8a2f380146
commit b978594993
6 changed files with 65 additions and 7 deletions

7
ai.lua Normal file
View File

@ -0,0 +1,7 @@
{{
{"I'm a real person, I swear!"},
{"are","you","bot"}
},{
{"Thisisalsoatest"},
{"1234","9999"}
}}

View File

@ -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",

Binary file not shown.

45
hooks/ai.lua Normal file
View File

@ -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

View File

@ -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

View File

@ -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