minor improvements
This commit is contained in:
parent
e04abca769
commit
c94c8e3b4d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
plugins/administration.lua
|
plugins/administration.lua
|
||||||
|
plugins/CUSTOM.lua
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
-- bindings.lua
|
||||||
|
-- Bindings for the Telegram bot API.
|
||||||
|
-- https://core.telegram.org/bots/api
|
||||||
|
|
||||||
|
assert(HTTPS)
|
||||||
|
assert(JSON)
|
||||||
|
|
||||||
local BASE_URL = 'https://api.telegram.org/bot' .. config.bot_api_key
|
local BASE_URL = 'https://api.telegram.org/bot' .. config.bot_api_key
|
||||||
|
|
||||||
if not config.bot_api_key then
|
if not config.bot_api_key then
|
||||||
|
@ -15,7 +15,7 @@ return {
|
|||||||
admin_name = 'John Smith',
|
admin_name = 'John Smith',
|
||||||
log_chat = nil,
|
log_chat = nil,
|
||||||
about_text = [[
|
about_text = [[
|
||||||
I am otouto, the plugin-wielding, multi-purpose Telegram bot written by topkecleon.
|
I am otouto, the plugin-wielding, multi-purpose Telegram bot.
|
||||||
|
|
||||||
Send /help to get started.
|
Send /help to get started.
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ local action = function(msg)
|
|||||||
url = url .. '&date=' .. URL.escape(input)
|
url = url .. '&date=' .. URL.escape(input)
|
||||||
date = date .. input
|
date = date .. input
|
||||||
else
|
else
|
||||||
date = date .. os.date("%Y-%m-%d")
|
date = date .. os.date("%F")
|
||||||
end
|
end
|
||||||
|
|
||||||
date = date .. '*\n'
|
date = date .. '*\n'
|
||||||
@ -44,9 +44,8 @@ local action = function(msg)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--local weburl = 'http://apod.nasa.gov/apod/ap' .. date_url .. '.html'
|
local img_url = jdat.hdurl or jdat.url
|
||||||
--output = date .. '[' .. jdat.title .. '](' .. weburl .. ')\n'
|
output = date .. '[' .. jdat.title .. '](' .. img_url .. ')\n'
|
||||||
output = date .. '[' .. jdat.title .. '](' .. jdat.hdurl .. ')\n'
|
|
||||||
|
|
||||||
if jdat.copyright then
|
if jdat.copyright then
|
||||||
output = output .. 'Copyright: ' .. jdat.copyright
|
output = output .. 'Copyright: ' .. jdat.copyright
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
-- utilities.lua
|
-- utilities.lua
|
||||||
-- Functions shared among plugins.
|
-- Functions shared among plugins.
|
||||||
|
|
||||||
|
HTTP = require('socket.http')
|
||||||
|
HTTPS = require('ssl.https')
|
||||||
|
JSON = require('dkjson')
|
||||||
|
|
||||||
-- get the indexed word in a string
|
-- get the indexed word in a string
|
||||||
get_word = function(s, i)
|
get_word = function(s, i)
|
||||||
|
|
||||||
@ -152,4 +156,42 @@ handle_exception = function(err, message)
|
|||||||
print(output)
|
print(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Okay, this one I actually did copy from yagop.
|
||||||
|
-- https://github.com/yagop/telegram-bot/blob/master/bot/utils.lua
|
||||||
|
download_file = function(url, filename)
|
||||||
|
|
||||||
|
local respbody = {}
|
||||||
|
local options = {
|
||||||
|
url = url,
|
||||||
|
sink = ltn12.sink.table(respbody),
|
||||||
|
redirect = true
|
||||||
|
}
|
||||||
|
|
||||||
|
local response = nil
|
||||||
|
|
||||||
|
if url:match('^https') then
|
||||||
|
options.redirect = false
|
||||||
|
response = { HTTPS.request(options) }
|
||||||
|
else
|
||||||
|
response = { HTTP.request(options) }
|
||||||
|
end
|
||||||
|
|
||||||
|
local code = response[2]
|
||||||
|
local headers = response[3]
|
||||||
|
local status = response[4]
|
||||||
|
|
||||||
|
if code ~= 200 then return false end
|
||||||
|
|
||||||
|
filename = filename or os.time()
|
||||||
|
|
||||||
|
local file_path = '/tmp/'..filename
|
||||||
|
|
||||||
|
file = io.open(file_path, 'w+')
|
||||||
|
file:write(table.concat(respbody))
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
return file_path
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user