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" "#ssss"
}, },
hooks={ hooks={
"highfive.lua" "highfive.lua",
"ai.lua"
}, },
cmds={ cmds={
"reload.lua"
}, },
timers={ timers={
"highfive.lua" "highfive.lua"
}, },
debug=false,
autojoin=true, autojoin=true,
prefix=":", prefix=":",
username="yuki", 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 = {...} tArgs = {...}
local nick, chan, message = tArgs[1],tArgs[2],tArgs[3] 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 message:find("o/") ~= nil or message:find("\\o") ~= nil then
if nick ~= "Shocky" then if nick ~= "Shocky" then
if _G.leftHanging[2] == false then if _G.leftHanging[2] == false then

View File

@ -20,7 +20,7 @@ function loadconfig()
local s,f = pcall(load,c) local s,f = pcall(load,c)
fo:close() fo:close()
if s then if s then
table.insert(hooks,f) table.insert(hooks,#hooks+1,f)
print("Hook "..v.." loaded") print("Hook "..v.." loaded")
else else
print("Hook "..v.." failed to load:") print("Hook "..v.." failed to load:")
@ -105,8 +105,10 @@ end
leftHanging = {0,false} leftHanging = {0,false}
function parsemsg(nick,chan,message) function parsemsg(nick,chan,message)
for k,v in ipairs(hooks) do for k,v in pairs(hooks) do
v(nick,chan,message) print("Running hook "..k)
local fail,errors = pcall(v,nick,chan,message)
if not fail then print(errors) end
end end
if string.find(message,config.prefix) == 1 then if string.find(message,config.prefix) == 1 then
local command = message:sub(2) .. " " local command = message:sub(2) .. " "
@ -152,7 +154,8 @@ function parsemsg(nick,chan,message)
print("Killed by "..nick) print("Killed by "..nick)
end end
elseif cmds[tCommand[1]] ~= nil then 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 end
end end
@ -215,7 +218,8 @@ function main()
pcall(parse,line) pcall(parse,line)
end end
for k,v in ipairs(timers) do for k,v in ipairs(timers) do
v(line) local fail, errors = pcall(v,line)
if not fail then print(errors) end
end end
if line == nil then line = "" end if line == nil then line = "" end
until string.find(line,"ERROR :Closing link:") ~= nil until string.find(line,"ERROR :Closing link:") ~= nil