General code cleanup.

Soon: More phrases to respond with.
This commit is contained in:
Izaya 2016-01-13 01:41:25 +11:00
parent ca311aef1e
commit 3c3034de21
2 changed files with 13 additions and 13 deletions

View File

@ -1,22 +1,22 @@
nick,chan,message = ... nick,chan,message = ...
local serialization = require "serialization" local serialization = require "serialization"
lnick = "yukichan" lnick = "yukichan"
print(lnick,nick,chan,message) --print(lnick,nick,chan,message)
if string.find(message,lnick) ~= nil and nick ~= "Shocky" then if string.find(message,lnick) ~= nil and nick ~= "Shocky" then
print("Message addressed to AI!") -- print("Message addressed to AI!")
local f = io.open("./ai.lua","rb") local f = io.open("./ai.lua","rb")
if f ~= nil then if f ~= nil then
local content = f:read("*a") local content = f:read("*a")
f:close() f:close()
print(content) -- print(content)
print("Loaded AI file.") -- print("Loaded AI file.")
print(type(serialization.unserialize)) -- print(type(serialization.unserialize))
w,aitab = pcall(serialization.unserialize,content) w,aitab = pcall(serialization.unserialize,content)
print(w,aitab) -- print(w,aitab)
print("Decoded AI file.") -- print("Decoded AI file.")
local selection = 0 local selection = 0
local hscore = 0 local hscore = 0
print("Starting interpretation.") -- print("Starting interpretation.")
for k,v in ipairs(aitab) do for k,v in ipairs(aitab) do
local count = 0 local count = 0
for l,w in ipairs(v[2]) do for l,w in ipairs(v[2]) do
@ -25,21 +25,21 @@ if string.find(message,lnick) ~= nil and nick ~= "Shocky" then
if count > hscore then if count > hscore then
selection = k selection = k
hscore = count hscore = count
print(selection,hscore) -- print(selection,hscore)
end end
end end
if hscore == 0 then if hscore == 0 then
print("No high score, selecting a random response.") -- print("No high score, selecting a random response.")
selection = math.random(1,#aitab) selection = math.random(1,#aitab)
end end
print(selection) -- print(selection)
selstring = aitab[selection][1][1] selstring = aitab[selection][1][1]
if type(selstring) == "table" then if type(selstring) == "table" then
for k,v in pairs(selstring) do for k,v in pairs(selstring) do
print(k.."="..v) print(k.."="..v)
end end
end end
print(selstring) print("Selected response: " .. selstring)
sendchan(chan,selstring) sendchan(chan,selstring)
end end
end end

View File

@ -106,7 +106,7 @@ leftHanging = {0,false}
function parsemsg(nick,chan,message) function parsemsg(nick,chan,message)
for k,v in pairs(hooks) do for k,v in pairs(hooks) do
print("Running hook "..k) -- print("Running hook "..k)
local fail,errors = pcall(v,nick,chan,message) local fail,errors = pcall(v,nick,chan,message)
if not fail then print(errors) end if not fail then print(errors) end
end end