much improved personality.lua interactions

partial localization support
This commit is contained in:
topkecleon 2015-07-11 04:31:29 -04:00
parent 294ca0319a
commit 42cda22ab6
26 changed files with 153 additions and 114 deletions

View File

@ -172,6 +172,8 @@ Add your bot API key, and other API keys if desirable.
The plugins which require API keys that are not provided are disabled by default. The plugins which require API keys that are not provided are disabled by default.
The provided Giphy key is the public test key, and is subject to rate limitaton. The provided Giphy key is the public test key, and is subject to rate limitaton.
The "fortune.lua" plugin requires the fortune program to be installed on the host computer.
TIME_OFFSET is the time difference, in seconds, between your system clock. It is sometimes necessary for accurate output of the time plugin. Default at 0 (duh). TIME_OFFSET is the time difference, in seconds, between your system clock. It is sometimes necessary for accurate output of the time plugin. Default at 0 (duh).
"admins" table includes the ID numbers, as integers, of any privileged users. These will have access to the admin plugin and any addition privileged commands. "admins" table includes the ID numbers, as integers, of any privileged users. These will have access to the admin plugin and any addition privileged commands.

10
bot.lua
View File

@ -31,9 +31,13 @@ function bot_init()
print('\nLoading configuration...') print('\nLoading configuration...')
local jstr = io.open('config.json') local j = io.open('config.json')
local jstr = jstr:read('*all') local j = j:read('*all')
config = JSON.decode(jstr) config = JSON.decode(j)
local j = io.open('loc/'..config.LOCALE..'.json')
local j = j:read('*all')
locale = JSON.decode(j)
print(#config.plugins .. ' plugins enabled.') print(#config.plugins .. ' plugins enabled.')
require('bindings') require('bindings')

View File

@ -3,6 +3,7 @@
"BIBLIA_API_KEY": "", "BIBLIA_API_KEY": "",
"GIPHY_API_KEY": "dc6zaTOxFJmzC", "GIPHY_API_KEY": "dc6zaTOxFJmzC",
"TIME_OFFSET": 0, "TIME_OFFSET": 0,
"LOCALE": "en_US",
"admins": [ "admins": [
0 0
], ],

View File

@ -1,47 +0,0 @@
{
"BOT_API_KEY": "",
"BIBLIA_API_KEY": "",
"GIPHY_API_KEY": "dc6zaTOxFJmzC",
"TIME_OFFSET": 0,
"admins": [
0
],
"plugins": [
"about.lua",
"8ball.lua",
"admin.lua",
"bandersnatch.lua",
"btc.lua",
"calc.lua",
"chatter.lua",
"commit.lua",
"dice.lua",
"dogify.lua",
"echo.lua",
"fortune.lua",
"gImages.lua",
"giphy.lua",
"gMaps.lua",
"gSearch.lua",
"hackernews.lua",
"help.lua",
"hex.lua",
"imdb.lua",
"personality.lua",
"pokedex.lua",
"pun.lua",
"reaction.lua",
"reddit.lua",
"remind.lua",
"slap.lua",
"time.lua",
"urbandictionary.lua",
"weather.lua",
"whoami.lua",
"xkcd.lua"
],
"people": {
"55994550": "topkecleon",
}
}

40
loc/en_US.json Normal file
View File

@ -0,0 +1,40 @@
{
"hello": [
"hello",
"hey",
"hi",
"good morning",
"good day",
"good afternoon",
"good evening"
],
"goodbye": [
"bye",
"later",
"see ya",
"good night"
],
"thankyou": [
"thanks",
"thank you"
],
"love": [
"love you"
],
"hate": [
"hate you",
"screw you",
"fuck you",
"go away"
],
"responses": {
"hello": "Hi",
"goodbye": "Bye-bye",
"thankyou": "No problem",
"love": "You, too",
"hate": "Screw you"
},
"conn_err": "Connection error.",
"noresults": "No results found.",
"inv_arg": "Invalid argument."
}

46
loc/weeb.json Normal file
View File

@ -0,0 +1,46 @@
{
"hello": [
"hello",
"hey",
"hi",
"good morning",
"good day",
"good afternoon",
"good evening",
"ohayou?",
"kon?'?nichiwa",
"konbanwa"
],
"goodbye": [
"bye",
"later",
"see ya",
"good night",
"sayou?nara",
"oyasumi"
],
"thankyou": [
"thanks",
"thank you",
"arigatou?"
],
"love": [
"love you"
],
"hate": [
"hate you",
"screw you",
"fuck you",
"go away"
],
"responses": {
"hello": "Hi",
"goodbye": "Bye-bye",
"thankyou": "No problem",
"love": "You, too",
"hate": "Screw you"
},
"conn_err": "Connection error.",
"noresults": "No results found.",
"inv_arg": "Invalid argument."
}

View File

@ -6,9 +6,11 @@ PLUGIN.triggers = {
function PLUGIN.action(msg) function PLUGIN.action(msg)
if msg.date < os.time() - 1 then return end
local input = get_input(msg.text) local input = get_input(msg.text)
local message = 'Command not found.' local message = locale.inv_arg
local sudo = 0 local sudo = 0
for i,v in ipairs(config.admins) do for i,v in ipairs(config.admins) do

View File

@ -22,7 +22,7 @@ function PLUGIN.action(msg)
local message, res = HTTP.request(url) local message, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
message = 'Connection error.' message = locale.conn_err
end end
send_msg(msg, message) send_msg(msg, message)

View File

@ -19,7 +19,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTPS.request('https://api.bitcoinaverage.com/ticker/global/') local jstr, res = HTTPS.request('https://api.bitcoinaverage.com/ticker/global/')
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
@ -29,7 +29,7 @@ function PLUGIN.action(msg)
arg1 = string.upper(string.sub(input, 1, 3)) arg1 = string.upper(string.sub(input, 1, 3))
arg2 = string.sub(input, 5) arg2 = string.sub(input, 5)
if not tonumber(arg2) then if not tonumber(arg2) then
return send_msg(msg, 'Invalid argument.') return send_msg(msg, locale.inv_arg)
end end
end end
@ -43,7 +43,7 @@ function PLUGIN.action(msg)
if url then if url then
jstr, b = HTTPS.request(url) jstr, b = HTTPS.request(url)
else else
return send_msg(msg, 'Error: Currency not found.') return send_msg(msg, locale.noresults)
end end
jdat = JSON.decode(jstr) jdat = JSON.decode(jstr)

View File

@ -20,7 +20,7 @@ function PLUGIN.action(msg)
local message, res = HTTP.request(url) local message, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
send_msg(msg, message) send_msg(msg, message)

View File

@ -33,10 +33,10 @@ function PLUGIN.action(msg)
end end
range = string.sub(input, dloc+1) range = string.sub(input, dloc+1)
if not tonumber(rolls) or not tonumber(range) then if not tonumber(rolls) or not tonumber(range) then
return send_msg(msg, 'Invalid syntax.') return send_msg(msg, locale.inv_arg)
end end
else else
return send_msg(msg, 'Invalid syntax.') return send_msg(msg, locale.inv_arg)
end end
if tonumber(rolls) == 1 then if tonumber(rolls) == 1 then
@ -44,19 +44,15 @@ function PLUGIN.action(msg)
elseif tonumber(rolls) > 1 then elseif tonumber(rolls) > 1 then
results = rolls .. 'D' .. range .. ':\n' results = rolls .. 'D' .. range .. ':\n'
else else
return send_msg(msg, 'Invalid syntax.') return send_msg(msg, locale.inv_arg)
end end
if tonumber(range) < 2 then if tonumber(range) < 2 then
return send_msg(msg, 'Invalid syntax.') return send_msg(msg, locale.inv_arg)
end end
if tonumber(rolls) > 100 then if tonumber(rolls) > 100 or tonumber(range) > 100000 then
return send_msg(msg, 'Maximum dice is 100.') return send_msg(msg, 'Max 100D100000')
end
if tonumber(range) > 100000 then
return send_msg(msg, 'Maximum range is 100000.')
end end
for i = 1, tonumber(rolls) do for i = 1, tonumber(rolls) do

View File

@ -38,14 +38,14 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
send_msg(msg, 'Connection error.') send_msg(msg, locale.conn_err)
return return
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
if #jdat.responseData.results < 1 then if #jdat.responseData.results < 1 then
send_msg(msg, 'No results found.') send_msg(msg, locale.noresults)
return return
end end

View File

@ -20,13 +20,13 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
if jdat.status ~= 'OK' then if jdat.status ~= 'OK' then
local message = 'Error: \"' .. input .. '\" not found.' local message = locale.noresults
return send_msg(msg, message) return send_msg(msg, message)
end end

View File

@ -33,13 +33,13 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
if #jdat.responseData.results < 1 then if #jdat.responseData.results < 1 then
return send_msg(msg, 'No results found.') return send_msg(msg, locale.noresults)
end end
message = '' message = ''

View File

@ -30,7 +30,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(random_url) local jstr, res = HTTP.request(random_url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
result_url = jdat.data.image_url result_url = jdat.data.image_url
@ -39,7 +39,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(search_url .. input) local jstr, res = HTTP.request(search_url .. input)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
result_url = jdat.data[math.random(#jdat.data)].images.original.url result_url = jdat.data[math.random(#jdat.data)].images.original.url

View File

@ -20,7 +20,7 @@ function PLUGIN.action(msg)
send_msg(msg, string.format('%x', input)) send_msg(msg, string.format('%x', input))
else else
send_msg(msg, 'Invalid number.') send_msg(msg, locale.inv_arg)
end end

View File

@ -21,7 +21,7 @@ function PLUGIN.action(msg)
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Error connecting to server.') return send_msg(msg, locale.conn_err)
end end
if jdat.Response ~= 'True' then if jdat.Response ~= 'True' then

View File

@ -12,7 +12,7 @@ PLUGIN.triggers = {
'^i\'m back%p?$' '^i\'m back%p?$'
} }
function PLUGIN.action(msg) -- I WISH LUA HAD PROPER REGEX SUPPORT function PLUGIN.action(msg)
local input = string.lower(msg.text) local input = string.lower(msg.text)
@ -24,24 +24,20 @@ function PLUGIN.action(msg) -- I WISH LUA HAD PROPER REGEX SUPPORT
end end
end end
if input:match('thanks,? '..bot.first_name) or input:match('thank you,? '..bot.first_name) then interactions = {
return send_message(msg.chat.id, 'No problem, ' .. msg.from.first_name .. '!') [locale.responses.hello] = locale.hello,
end [locale.responses.goodbye] = locale.goodbye,
[locale.responses.thankyou] = locale.thankyou,
[locale.responses.love] = locale.love,
[locale.responses.hate] = locale.hate
}
if input:match('hello,? '..bot.first_name) or input:match('hey,? '..bot.first_name) or input:match('hi,? '..bot.first_name) then for k,v in pairs(interactions) do
return send_message(msg.chat.id, 'Hi, ' .. msg.from.first_name .. '!') for key,val in pairs(v) do
end if input:match(val..',? '..bot.first_name) then
return send_message(msg.chat.id, k..', '..msg.from.first_name..'!')
if input:match('bye,? '..bot.first_name) or input:match('later,? '..bot.first_name) then end
return send_message(msg.chat.id, 'Bye-bye, ' .. msg.from.first_name .. '!') end
end
if input:match('i hate you,? '..bot.first_name) or input:match('screw you,? '..bot.first_name) or input:match('fuck you,? '..bot.first_name) then
return send_msg(msg, '; _ ;')
end
if string.match(input, 'i love you,? '..bot.first_name) then
return send_msg(msg, '<3')
end end
-- msg.text = '@' .. bot.username .. ', ' .. msg.text:gsub(bot.first_name, '') -- msg.text = '@' .. bot.username .. ', ' .. msg.text:gsub(bot.first_name, '')

View File

@ -23,7 +23,7 @@ function PLUGIN.action(msg)
local dex_url = base_url .. '/api/v1/pokemon/' .. input local dex_url = base_url .. '/api/v1/pokemon/' .. input
local dex_jstr, res = HTTP.request(dex_url) local dex_jstr, res = HTTP.request(dex_url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Pokemon not found..') return send_msg(msg, locale.noresults)
end end
local dex_jdat = JSON.decode(dex_jstr) local dex_jdat = JSON.decode(dex_jstr)
@ -31,7 +31,7 @@ function PLUGIN.action(msg)
local desc_url = base_url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri local desc_url = base_url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri
local desc_jstr, res = HTTP.request(desc_url) local desc_jstr, res = HTTP.request(desc_url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local desc_jdat = JSON.decode(desc_jstr) local desc_jdat = JSON.decode(desc_jstr)

View File

@ -4,7 +4,8 @@ PLUGIN.triggers = {
['¯\\_(ツ)_/¯'] = '/shrug$', ['¯\\_(ツ)_/¯'] = '/shrug$',
['( ͡° ͜ʖ ͡°)'] = '/lenny$', ['( ͡° ͜ʖ ͡°)'] = '/lenny$',
['(╯°□°)╯︵ ┻━┻'] = '/flip$', ['(╯°□°)╯︵ ┻━┻'] = '/flip$',
[' o'] = '/homo$' [' o'] = '/homo$',
['ಠ_ಠ'] = '/look$'
} }
function PLUGIN.action(msg) function PLUGIN.action(msg)

View File

@ -24,11 +24,11 @@ function PLUGIN.action(msg)
local url = 'http://www.reddit.com/' .. first_word(input) .. '/.json' local url = 'http://www.reddit.com/' .. first_word(input) .. '/.json'
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
jdat = JSON.decode(jstr) jdat = JSON.decode(jstr)
if #jdat.data.children == 0 then if #jdat.data.children == 0 then
return send_msg(msg, 'Subreddit not found.') return send_msg(msg, locale.noresults)
end end
else else
@ -36,11 +36,11 @@ function PLUGIN.action(msg)
local url = 'http://www.reddit.com/search.json?q=' .. URL.escape(input) local url = 'http://www.reddit.com/search.json?q=' .. URL.escape(input)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
jdat = JSON.decode(jstr) jdat = JSON.decode(jstr)
if #jdat.data.children == 0 then if #jdat.data.children == 0 then
return send_msg(msg, 'No results found.') return send_msg(msg, locale.noresults)
end end
end end
@ -50,7 +50,7 @@ function PLUGIN.action(msg)
url = 'https://www.reddit.com/.json' url = 'https://www.reddit.com/.json'
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
jdat = JSON.decode(jstr) jdat = JSON.decode(jstr)

View File

@ -20,14 +20,13 @@ function PLUGIN.action(msg)
coords = get_coords(input) coords = get_coords(input)
if not coords then if not coords then
local message = 'Error: \"' .. input .. '\" not found.' return send_msg(msg, locale.noresults)
return send_msg(msg, message)
end end
local url = 'http://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '&timestamp='..os.time() local url = 'http://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '&timestamp='..os.time()
local jstr, res = HTTPS.request(url) local jstr, res = HTTPS.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)

View File

@ -21,13 +21,13 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
if jdat.result_type == "no_results" then if jdat.result_type == "no_results" then
return send_msg(msg, 'No results found.') return send_msg(msg, locale.noresults)
end end
message = '"' .. jdat.list[1].word .. '"\n' .. trim_string(jdat.list[1].definition) message = '"' .. jdat.list[1].word .. '"\n' .. trim_string(jdat.list[1].definition)

View File

@ -19,14 +19,13 @@ function PLUGIN.action(msg)
coords = get_coords(input) coords = get_coords(input)
if not coords then if not coords then
local message = 'Error: \"' .. input .. '\" not found.' return send_msg(msg, locale.noresults)
return send_msg(msg, message)
end end
local url = 'http://api.openweathermap.org/data/2.5/weather?lat=' .. coords.lat .. '&lon=' .. coords.lon local url = 'http://api.openweathermap.org/data/2.5/weather?lat=' .. coords.lat .. '&lon=' .. coords.lon
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)

View File

@ -1,7 +1,7 @@
local PLUGIN = {} local PLUGIN = {}
PLUGIN.doc = [[ PLUGIN.doc = [[
/who /whoami
Get the user ID for yourself and the group. Use it in a reply to get info for the sender of the original message. Get the user ID for yourself and the group. Use it in a reply to get info for the sender of the original message.
]] ]]

View File

@ -15,7 +15,7 @@ function PLUGIN.action(msg)
local url = 'http://xkcd.com/info.0.json' local url = 'http://xkcd.com/info.0.json'
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local latest = JSON.decode(jstr).num local latest = JSON.decode(jstr).num
@ -24,7 +24,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
print('here') print('here')
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
url = JSON.decode(jstr).responseData.results[1].url .. 'info.0.json' url = JSON.decode(jstr).responseData.results[1].url .. 'info.0.json'
else else
@ -34,7 +34,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
return send_msg(msg, 'Connection error.') return send_msg(msg, locale.conn_err)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)