config, locale in lua

personality.lua -> interactions.lua
innumerable improvements
This commit is contained in:
topkecleon
2015-07-15 02:15:23 -04:00
parent 42cda22ab6
commit a1a4978a1b
30 changed files with 289 additions and 303 deletions

View File

@ -13,7 +13,7 @@ PLUGIN.triggers = {
function PLUGIN.action(msg)
local message = [[
This is ]] .. bot.first_name .. [[: a plugin-wielding, multi-purpose Telegram bot.
I am ]] .. bot.first_name .. [[: a plugin-wielding, multi-purpose Telegram bot.
Use /help for a list of commands.
Based on otouto v]] .. VERSION .. [[ by @topkecleon.
@ -21,7 +21,7 @@ function PLUGIN.action(msg)
topkecleon.github.io/otouto
]] -- Please do not remove this message.
send_msg(msg, message)
send_message(msg.chat.id, message, true)
end

View File

@ -10,7 +10,7 @@ function PLUGIN.action(msg)
local input = get_input(msg.text)
local message = locale.inv_arg
local message = config.locale.errors.argument
local sudo = 0
for i,v in ipairs(config.admins) do
@ -24,7 +24,10 @@ function PLUGIN.action(msg)
elseif string.lower(first_word(input)) == 'run' then
local output = string.sub(input, 5)
local output = get_input(input)
if not output then
return send_msg(msg, config.locale.errors.argument)
end
local output = io.popen(output)
message = output:read('*all')
output:close()

View File

@ -18,11 +18,11 @@ function PLUGIN.action(msg)
return send_msg(msg, PLUGIN.doc)
end
local url = 'http://api.biblia.com/v1/bible/content/KJV.txt?key=' .. config.BIBLIA_API_KEY .. '&passage=' .. URL.escape(input)
local url = 'http://api.biblia.com/v1/bible/content/KJV.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
local message, res = HTTP.request(url)
if res ~= 200 then
message = locale.conn_err
message = config.locale.errors.connection
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
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, locale.inv_arg)
return send_msg(msg, config.locale.errors.argument)
end
end
@ -43,7 +43,7 @@ function PLUGIN.action(msg)
if url then
jstr, b = HTTPS.request(url)
else
return send_msg(msg, locale.noresults)
return send_msg(msg, config.locale.errors.results)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
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, locale.inv_arg)
return send_msg(msg, config.locale.errors.argument)
end
else
return send_msg(msg, locale.inv_arg)
return send_msg(msg, config.locale.errors.argument)
end
if tonumber(rolls) == 1 then
@ -44,11 +44,11 @@ function PLUGIN.action(msg)
elseif tonumber(rolls) > 1 then
results = rolls .. 'D' .. range .. ':\n'
else
return send_msg(msg, locale.inv_arg)
return send_msg(msg, config.locale.errors.syntax)
end
if tonumber(range) < 2 then
return send_msg(msg, locale.inv_arg)
return send_msg(msg, config.locale.errors.syntax)
end
if tonumber(rolls) > 100 or tonumber(range) > 100000 then

View File

@ -30,7 +30,12 @@ function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
if msg.reply_to_message then
msg = msg.reply_to_message
input = msg.text
else
return send_msg(msg, PLUGIN.doc)
end
end
url = url .. '&q=' .. URL.escape(input)
@ -38,14 +43,14 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url)
if res ~= 200 then
send_msg(msg, locale.conn_err)
send_msg(msg, config.locale.errors.connection)
return
end
local jdat = JSON.decode(jstr)
if #jdat.responseData.results < 1 then
send_msg(msg, locale.noresults)
send_msg(msg, config.locale.errors.results)
return
end

View File

@ -13,20 +13,25 @@ function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
if msg.reply_to_message then
msg = msg.reply_to_message
input = msg.text
else
return send_msg(msg, PLUGIN.doc)
end
end
local url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input)
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
if jdat.status ~= 'OK' then
local message = locale.noresults
local message = config.locale.errors.results
return send_msg(msg, message)
end

View File

@ -7,6 +7,7 @@ PLUGIN.doc = [[
PLUGIN.triggers = {
'^/g ',
'^/g$',
'^/google',
'^/gnsfw'
}
@ -25,7 +26,12 @@ function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
if msg.reply_to_message then
msg = msg.reply_to_message
input = msg.text
else
return send_msg(msg, PLUGIN.doc)
end
end
url = url .. '&q=' .. URL.escape(input)
@ -33,13 +39,13 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
if #jdat.responseData.results < 1 then
return send_msg(msg, locale.noresults)
return send_msg(msg, config.locale.errors.results)
end
message = ''

View File

@ -12,8 +12,8 @@ PLUGIN.triggers = {
function PLUGIN.action(msg)
local search_url = 'http://api.giphy.com/v1/gifs/search?limit=10&api_key=' .. config.GIPHY_API_KEY
local random_url = 'http://tv.giphy.com/v1/gifs/random?api_key=' .. config.GIPHY_API_KEY
local search_url = 'http://api.giphy.com/v1/gifs/search?limit=10&api_key=' .. config.giphy_api_key
local random_url = 'http://tv.giphy.com/v1/gifs/random?api_key=' .. config.giphy_api_key
local result_url = ''
if string.match(msg.text, '^/giphynsfw') then
@ -30,7 +30,7 @@ function PLUGIN.action(msg)
local jstr, res = HTTP.request(random_url)
if res ~= 200 then
return send_msg(msg, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
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, locale.inv_arg)
send_msg(msg, config.locale.errors.argument)
end

View File

@ -13,7 +13,12 @@ function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
if msg.reply_to_message then
msg = msg.reply_to_message
input = msg.text
else
return send_msg(msg, PLUGIN.doc)
end
end
local url = 'http://www.imdbapi.com/?t=' .. URL.escape(input)
@ -21,7 +26,7 @@ function PLUGIN.action(msg)
local jdat = JSON.decode(jstr)
if res ~= 200 then
return send_msg(msg, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
if jdat.Response ~= 'True' then

View File

@ -7,6 +7,7 @@ local PLUGIN = {}
PLUGIN.triggers = {
bot.first_name .. '%p?$',
'@' .. bot.username .. '%p?$',
'^tadaima%p?$',
'^i\'m home%p?$',
'^i\'m back%p?$'
@ -18,31 +19,20 @@ function PLUGIN.action(msg)
if config.people[tostring(msg.from.id)] then msg.from.first_name = config.people[tostring(msg.from.id)] end
for i = 2, #PLUGIN.triggers do
for i = 3, #PLUGIN.triggers do
if string.match(input, PLUGIN.triggers[i]) then
return send_message(msg.chat.id, 'Welcome back, ' .. msg.from.first_name .. '!')
end
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
}
for k,v in pairs(interactions) do
for k,v in pairs(config.locale.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..'!')
return send_message(msg.chat.id, k:gsub('#NAME', msg.from.first_name))
end
end
end
-- msg.text = '@' .. bot.username .. ', ' .. msg.text:gsub(bot.first_name, '')
-- on_msg_receive(msg)
end
return PLUGIN

18
plugins/lmgtfy.lua Normal file
View File

@ -0,0 +1,18 @@
local PLUGIN = {}
PLUGIN.triggers = {
'^/lmgtfy'
}
function PLUGIN.action(msg)
if not msg.reply_to_message then return end
msg = msg.reply_to_message
local message = 'http://lmgtfy.com/?q=' .. URL.escape(msg.text)
send_msg(msg, message)
end
return PLUGIN

View File

@ -12,7 +12,7 @@ PLUGIN.triggers = {
function PLUGIN.action(msg)
local input = get_input(msg.text)
local input = get_input(msg.text:lower())
if not input then
return send_msg(msg, PLUGIN.doc)
end
@ -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, locale.noresults)
return send_msg(msg, config.locale.errors.results)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
local desc_jdat = JSON.decode(desc_jstr)

View File

@ -12,16 +12,18 @@ function PLUGIN.action(msg)
local message = string.lower(msg.text)
if msg.reply_to_message then
msg = msg.reply_to_message
end
for k,v in pairs(PLUGIN.triggers) do
if string.match(message, v) then
return send_msg(msg, k)
message = k
end
end
if msg.reply_to_message then
send_msg(msg.reply_to_message, message)
else
send_message(msg.chat.id, message)
end
end
return PLUGIN

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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
jdat = JSON.decode(jstr)
if #jdat.data.children == 0 then
return send_msg(msg, locale.noresults)
return send_msg(msg, config.locale.errors.results)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
jdat = JSON.decode(jstr)
if #jdat.data.children == 0 then
return send_msg(msg, locale.noresults)
return send_msg(msg, config.locale.errors.results)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
jdat = JSON.decode(jstr)

View File

@ -1,4 +1,4 @@
-- TIME_OFFSET is the number of seconds necessary to correct your system clock to UTC.
-- time_offset is the number of seconds necessary to correct your system clock to UTC.
local PLUGIN = {}
@ -18,22 +18,28 @@ function PLUGIN.action(msg)
return send_msg(msg, PLUGIN.doc)
end
coords = get_coords(input)
local coords = get_coords(input)
if not coords then
return send_msg(msg, locale.noresults)
return send_msg(msg, config.locale.errors.results)
end
local url = 'http://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '&timestamp='..os.time()
local url = 'https://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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
local timestamp = os.time() + jdat.rawOffset + jdat.dstOffset + config.TIME_OFFSET
timestamp = os.date("%H:%M on %A, %B %d.", timestamp)
local timeloc = (string.gsub((string.sub(jdat.timeZoneId, string.find(jdat.timeZoneId, '/')+1)), '_', ' '))
local message = "The time in " .. timeloc .. " is " .. timestamp
local timestamp = os.time() + jdat.rawOffset + jdat.dstOffset + config.time_offset
local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600
if utcoff == math.abs(utcoff) then
utcoff = '+' .. utcoff
end
local message = os.date('%I:%M %p\n', timestamp) .. os.date('%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')'
send_msg(msg, message)

View File

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

View File

@ -19,13 +19,13 @@ function PLUGIN.action(msg)
coords = get_coords(input)
if not coords then
return send_msg(msg, locale.noresults)
return send_msg(msg, config.locale.errors.results)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)

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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
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, locale.conn_err)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)