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

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

View File

@ -22,7 +22,7 @@ function PLUGIN.action(msg)
local message, res = HTTP.request(url)
if res ~= 200 then
message = 'Connection error.'
message = locale.conn_err
end
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/')
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
local jdat = JSON.decode(jstr)
@ -29,7 +29,7 @@ function PLUGIN.action(msg)
arg1 = string.upper(string.sub(input, 1, 3))
arg2 = string.sub(input, 5)
if not tonumber(arg2) then
return send_msg(msg, 'Invalid argument.')
return send_msg(msg, locale.inv_arg)
end
end
@ -43,7 +43,7 @@ function PLUGIN.action(msg)
if url then
jstr, b = HTTPS.request(url)
else
return send_msg(msg, 'Error: Currency not found.')
return send_msg(msg, locale.noresults)
end
jdat = JSON.decode(jstr)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(random_url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
local jdat = JSON.decode(jstr)
result_url = jdat.data.image_url
@ -39,7 +39,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(search_url .. input)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
local jdat = JSON.decode(jstr)
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))
else
send_msg(msg, 'Invalid number.')
send_msg(msg, locale.inv_arg)
end

View File

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

View File

@ -12,7 +12,7 @@ PLUGIN.triggers = {
'^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)
@ -24,24 +24,20 @@ function PLUGIN.action(msg) -- I WISH LUA HAD PROPER REGEX SUPPORT
end
end
if input:match('thanks,? '..bot.first_name) or input:match('thank you,? '..bot.first_name) then
return send_message(msg.chat.id, 'No problem, ' .. msg.from.first_name .. '!')
end
interactions = {
[locale.responses.hello] = locale.hello,
[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
return send_message(msg.chat.id, 'Hi, ' .. msg.from.first_name .. '!')
end
if input:match('bye,? '..bot.first_name) or input:match('later,? '..bot.first_name) then
return send_message(msg.chat.id, 'Bye-bye, ' .. msg.from.first_name .. '!')
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')
for k,v in pairs(interactions) do
for key,val in pairs(v) do
if input:match(val..',? '..bot.first_name) then
return send_message(msg.chat.id, k..', '..msg.from.first_name..'!')
end
end
end
-- 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_jstr, res = HTTP.request(dex_url)
if res ~= 200 then
return send_msg(msg, 'Pokemon not found..')
return send_msg(msg, locale.noresults)
end
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_jstr, res = HTTP.request(desc_url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
local desc_jdat = JSON.decode(desc_jstr)

View File

@ -4,7 +4,8 @@ PLUGIN.triggers = {
['¯\\_(ツ)_/¯'] = '/shrug$',
['( ͡° ͜ʖ ͡°)'] = '/lenny$',
['(╯°□°)╯︵ ┻━┻'] = '/flip$',
[' o'] = '/homo$'
[' o'] = '/homo$',
['ಠ_ಠ'] = '/look$'
}
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 jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
jdat = JSON.decode(jstr)
if #jdat.data.children == 0 then
return send_msg(msg, 'Subreddit not found.')
return send_msg(msg, locale.noresults)
end
else
@ -36,11 +36,11 @@ function PLUGIN.action(msg)
local url = 'http://www.reddit.com/search.json?q=' .. URL.escape(input)
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
jdat = JSON.decode(jstr)
if #jdat.data.children == 0 then
return send_msg(msg, 'No results found.')
return send_msg(msg, locale.noresults)
end
end
@ -50,7 +50,7 @@ function PLUGIN.action(msg)
url = 'https://www.reddit.com/.json'
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
jdat = JSON.decode(jstr)

View File

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

View File

@ -21,13 +21,13 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
local jdat = JSON.decode(jstr)
if jdat.result_type == "no_results" then
return send_msg(msg, 'No results found.')
return send_msg(msg, locale.noresults)
end
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)
if not coords then
local message = 'Error: \"' .. input .. '\" not found.'
return send_msg(msg, message)
return send_msg(msg, locale.noresults)
end
local url = 'http://api.openweathermap.org/data/2.5/weather?lat=' .. coords.lat .. '&lon=' .. coords.lon
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, 'Connection error.')
return send_msg(msg, locale.conn_err)
end
local jdat = JSON.decode(jstr)

View File

@ -1,7 +1,7 @@
local PLUGIN = {}
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.
]]

View File

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