minor improvements
This commit is contained in:
parent
e04abca769
commit
c94c8e3b4d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
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
|
||||
|
||||
if not config.bot_api_key then
|
||||
|
@ -15,7 +15,7 @@ return {
|
||||
admin_name = 'John Smith',
|
||||
log_chat = nil,
|
||||
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.
|
||||
|
||||
|
@ -26,7 +26,7 @@ local action = function(msg)
|
||||
url = url .. '&date=' .. URL.escape(input)
|
||||
date = date .. input
|
||||
else
|
||||
date = date .. os.date("%Y-%m-%d")
|
||||
date = date .. os.date("%F")
|
||||
end
|
||||
|
||||
date = date .. '*\n'
|
||||
@ -44,9 +44,8 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
--local weburl = 'http://apod.nasa.gov/apod/ap' .. date_url .. '.html'
|
||||
--output = date .. '[' .. jdat.title .. '](' .. weburl .. ')\n'
|
||||
output = date .. '[' .. jdat.title .. '](' .. jdat.hdurl .. ')\n'
|
||||
local img_url = jdat.hdurl or jdat.url
|
||||
output = date .. '[' .. jdat.title .. '](' .. img_url .. ')\n'
|
||||
|
||||
if jdat.copyright then
|
||||
output = output .. 'Copyright: ' .. jdat.copyright
|
||||
|
@ -1,6 +1,10 @@
|
||||
-- utilities.lua
|
||||
-- Functions shared among plugins.
|
||||
|
||||
HTTP = require('socket.http')
|
||||
HTTPS = require('ssl.https')
|
||||
JSON = require('dkjson')
|
||||
|
||||
-- get the indexed word in a string
|
||||
get_word = function(s, i)
|
||||
|
||||
@ -152,4 +156,42 @@ handle_exception = function(err, message)
|
||||
print(output)
|
||||
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
|
||||
|
Reference in New Issue
Block a user