- Time: Inline-Query + Umstrukturierung
- Einige Plugins: matches vergessen
This commit is contained in:
parent
545894d970
commit
8b5413808b
@ -3,7 +3,7 @@ local bot = {}
|
|||||||
bindings = require('otouto.bindings')
|
bindings = require('otouto.bindings')
|
||||||
utilities = require('otouto.utilities')
|
utilities = require('otouto.utilities')
|
||||||
|
|
||||||
bot.version = '2.2.5.1'
|
bot.version = '2.2.5.1b'
|
||||||
|
|
||||||
function bot:init(config) -- The function run when the bot is started or reloaded.
|
function bot:init(config) -- The function run when the bot is started or reloaded.
|
||||||
cred_data = load_cred()
|
cred_data = load_cred()
|
||||||
|
@ -19,7 +19,7 @@ function gMaps:get_staticmap(area, lat, lon)
|
|||||||
return file
|
return file
|
||||||
end
|
end
|
||||||
|
|
||||||
function gMaps:inline_callback(inline_query, config)
|
function gMaps:inline_callback(inline_query, config, matches)
|
||||||
local place = matches[1]
|
local place = matches[1]
|
||||||
local coords = utilities.get_coords(place, config)
|
local coords = utilities.get_coords(place, config)
|
||||||
if type(coords) == 'string' then utilities.answer_inline_query(self, inline_query) return end
|
if type(coords) == 'string' then utilities.answer_inline_query(self, inline_query) return end
|
||||||
|
@ -21,7 +21,7 @@ function gps:init(config)
|
|||||||
]]..config.cmd_pat..[[gps* _<Breitengrad>_,_<Längengrad>_: Sendet Karte mit diesen Koordinaten]]
|
]]..config.cmd_pat..[[gps* _<Breitengrad>_,_<Längengrad>_: Sendet Karte mit diesen Koordinaten]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function gps:inline_callback(inline_query, config)
|
function gps:inline_callback(inline_query, config, matches)
|
||||||
local lat = matches[1]
|
local lat = matches[1]
|
||||||
local lon = matches[2]
|
local lon = matches[2]
|
||||||
|
|
||||||
|
@ -6,14 +6,19 @@ local help = {}
|
|||||||
local help_text
|
local help_text
|
||||||
|
|
||||||
function help:init(config)
|
function help:init(config)
|
||||||
help.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('hilfe', true):t('help', true).table
|
help.triggers = {
|
||||||
|
"^/hilfe (.+)",
|
||||||
|
"^/help (.+)",
|
||||||
|
"^/(hilfe)_(.+)",
|
||||||
|
"^/hilfe"
|
||||||
|
}
|
||||||
help.inline_triggers = {
|
help.inline_triggers = {
|
||||||
"^hilfe (.+)",
|
"^hilfe (.+)",
|
||||||
"^help (.+)"
|
"^help (.+)"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function help:inline_callback(inline_query, config)
|
function help:inline_callback(inline_query, config, matches)
|
||||||
local query = matches[1]
|
local query = matches[1]
|
||||||
|
|
||||||
for _,plugin in ipairs(self.plugins) do
|
for _,plugin in ipairs(self.plugins) do
|
||||||
@ -23,38 +28,43 @@ function help:inline_callback(inline_query, config)
|
|||||||
local doc = doc:gsub('\\n', '\\\n')
|
local doc = doc:gsub('\\n', '\\\n')
|
||||||
local chosen_plugin = utilities.get_word(plugin.command, 1)
|
local chosen_plugin = utilities.get_word(plugin.command, 1)
|
||||||
local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Hilfe für '..chosen_plugin..'","description":"Hilfe für das Plugin \\"'..chosen_plugin..'\\" wird gepostet.","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/help/hilfe.jpg","input_message_content":{"message_text":"'..doc..'","parse_mode":"Markdown"}}]'
|
local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Hilfe für '..chosen_plugin..'","description":"Hilfe für das Plugin \\"'..chosen_plugin..'\\" wird gepostet.","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/help/hilfe.jpg","input_message_content":{"message_text":"'..doc..'","parse_mode":"Markdown"}}]'
|
||||||
local results, err = utilities.answer_inline_query(self, inline_query, results, 600)
|
utilities.answer_inline_query(self, inline_query, results, 600, nil, nil, 'Hilfe anzeigen', 'hilfe_'..chosen_plugin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
utilities.answer_inline_query(self, inline_query)
|
utilities.answer_inline_query(self, inline_query)
|
||||||
end
|
end
|
||||||
|
|
||||||
function help:action(msg, config)
|
function help:action(msg, config, matches)
|
||||||
local commandlist = {}
|
if matches[2] then
|
||||||
help_text = '*Verfügbare Befehle:*\n• '..config.cmd_pat
|
input = matches[2]
|
||||||
|
elseif matches[1] ~= '/hilfe' then
|
||||||
|
input = matches[1]
|
||||||
|
else
|
||||||
|
input = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Attempts to send the help message via PM.
|
||||||
|
-- If msg is from a group, it tells the group whether the PM was successful.
|
||||||
|
if not input then
|
||||||
|
local commandlist = {}
|
||||||
|
local help_text = '*Verfügbare Befehle:*\n• '..config.cmd_pat
|
||||||
for _,plugin in ipairs(self.plugins) do
|
for _,plugin in ipairs(self.plugins) do
|
||||||
if plugin.command then
|
if plugin.command then
|
||||||
|
|
||||||
table.insert(commandlist, plugin.command)
|
table.insert(commandlist, plugin.command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(commandlist, 'hilfe [Befehl]')
|
table.insert(commandlist, 'hilfe [Befehl]')
|
||||||
table.sort(commandlist)
|
table.sort(commandlist)
|
||||||
help_text = help_text .. table.concat(commandlist, '\n• '..config.cmd_pat) .. '\nParameter: <benötigt> [optional]'
|
local help_text = help_text .. table.concat(commandlist, '\n• '..config.cmd_pat) .. '\nParameter: <benötigt> [optional]'
|
||||||
|
local help_text = help_text:gsub('%[', '\\[')
|
||||||
|
|
||||||
help_text = help_text:gsub('%[', '\\[')
|
|
||||||
local input = utilities.input(msg.text_lower)
|
|
||||||
|
|
||||||
-- Attempts to send the help message via PM.
|
|
||||||
-- If msg is from a group, it tells the group whether the PM was successful.
|
|
||||||
if not input then
|
|
||||||
local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true)
|
local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true)
|
||||||
if not res then
|
if not res then
|
||||||
utilities.send_reply(self, msg, 'Bitte schreibe mir zuerst [privat](http://telegram.me/' .. self.info.username .. '?start=help) für eine Hilfe.', true)
|
utilities.send_reply(self, msg, 'Bitte schreibe mir zuerst [privat](http://telegram.me/' .. self.info.username .. '?start=help) für eine Hilfe.', true)
|
||||||
elseif msg.chat.type ~= 'private' then
|
elseif msg.chat.type ~= 'private' then
|
||||||
utilities.send_reply(self, msg, 'Ich habe dir die Hilfe per PN gesendet!.')
|
utilities.send_reply(self, msg, 'Ich habe dir die Hilfe privat gesendet!.')
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -4,6 +4,10 @@ time.command = 'time <Ort>'
|
|||||||
|
|
||||||
function time:init(config)
|
function time:init(config)
|
||||||
time.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('time', true).table
|
time.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('time', true).table
|
||||||
|
time.inline_triggers = {
|
||||||
|
"^time (.+)",
|
||||||
|
"^time"
|
||||||
|
}
|
||||||
time.doc = [[*
|
time.doc = [[*
|
||||||
]]..config.cmd_pat..[[time*: Aktuelle Zeit in Deutschland
|
]]..config.cmd_pat..[[time*: Aktuelle Zeit in Deutschland
|
||||||
*]]..config.cmd_pat..[[time* _<Ort>_: Gibt Zeit an diesem Ort aus]]
|
*]]..config.cmd_pat..[[time* _<Ort>_: Gibt Zeit an diesem Ort aus]]
|
||||||
@ -45,6 +49,47 @@ function time:localize(output)
|
|||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function time:get_time(coords)
|
||||||
|
local now = os.time()
|
||||||
|
local utc = os.time(os.date("!*t", now))
|
||||||
|
|
||||||
|
local url = 'https://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '×tamp='..utc..'&language=de'
|
||||||
|
local jstr, res = https.request(url)
|
||||||
|
if res ~= 200 then return nil end
|
||||||
|
|
||||||
|
local jdat = json.decode(jstr)
|
||||||
|
local place = string.gsub(jdat.timeZoneId, '_', ' ' )
|
||||||
|
local place = time:localize(place)
|
||||||
|
local timezoneid = '*'..place..'*'
|
||||||
|
local timestamp = now + jdat.rawOffset + jdat.dstOffset
|
||||||
|
local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600
|
||||||
|
if utcoff == math.abs(utcoff) then
|
||||||
|
utcoff = '+'.. utilities.pretty_float(utcoff)
|
||||||
|
else
|
||||||
|
utcoff = utilities.pretty_float(utcoff)
|
||||||
|
end
|
||||||
|
-- "%A, %d. %B %Y, %H:%M:%S Uhr"
|
||||||
|
local time_there = os.date('!%A, %d. %B %Y, %H:%M:%S Uhr',timestamp)
|
||||||
|
local output = timezoneid..':\n'..time_there
|
||||||
|
|
||||||
|
return output..'\n_'..jdat.timeZoneName .. ' (UTC' .. utcoff .. ')_', place, time_there
|
||||||
|
end
|
||||||
|
|
||||||
|
function time:inline_callback(inline_query, config, matches)
|
||||||
|
if matches[1] == 'time' then
|
||||||
|
local desc_time = os.date("%A, %d. %B %Y, %H:%M:%S Uhr")
|
||||||
|
local cur_time = time:localize(os.date("%A, %d. %B %Y, *%H:%M:%S Uhr*"))
|
||||||
|
results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Europa/Berlin","description":"'..desc_time..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/time/clock.jpg","input_message_content":{"message_text":"'..cur_time..'","parse_mode":"Markdown"}}]'
|
||||||
|
else
|
||||||
|
local coords = utilities.get_coords(matches[1], config)
|
||||||
|
if type(coords) == 'string' then utilities.answer_inline_query(self, inline_query) return end
|
||||||
|
local output, place, desc_time = time:get_time(coords)
|
||||||
|
if not output then utilities.answer_inline_query(self, inline_query) return end
|
||||||
|
results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..place..'","description":"'..desc_time..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/time/clock.jpg","input_message_content":{"message_text":"'..output..'","parse_mode":"Markdown"}}]'
|
||||||
|
end
|
||||||
|
utilities.answer_inline_query(self, inline_query, results, 1)
|
||||||
|
end
|
||||||
|
|
||||||
function time:action(msg, config)
|
function time:action(msg, config)
|
||||||
local input = utilities.input(msg.text)
|
local input = utilities.input(msg.text)
|
||||||
if not input then
|
if not input then
|
||||||
@ -58,31 +103,8 @@ function time:action(msg, config)
|
|||||||
utilities.send_reply(self, msg, coords)
|
utilities.send_reply(self, msg, coords)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local output = time:get_time(coords)
|
||||||
local now = os.time()
|
if not output then utilities.send_reply(self, msg, config.errors.connection) return end
|
||||||
local utc = os.time(os.date("!*t", now))
|
|
||||||
|
|
||||||
local url = 'https://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '×tamp='..utc..'&language=de'
|
|
||||||
local jstr, res = https.request(url)
|
|
||||||
if res ~= 200 then
|
|
||||||
utilities.send_reply(self, msg, config.errors.connection)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local jdat = json.decode(jstr)
|
|
||||||
local timezoneid = '*'..string.gsub(jdat.timeZoneId, '_', ' ' )..'*'
|
|
||||||
local timestamp = now + jdat.rawOffset + jdat.dstOffset
|
|
||||||
local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600
|
|
||||||
if utcoff == math.abs(utcoff) then
|
|
||||||
utcoff = '+'.. utilities.pretty_float(utcoff)
|
|
||||||
else
|
|
||||||
utcoff = utilities.pretty_float(utcoff)
|
|
||||||
end
|
|
||||||
-- "%A, %d. %B %Y, %H:%M:%S Uhr"
|
|
||||||
local output = timezoneid..':\n'..os.date('!%A, %d. %B %Y, %H:%M:%S Uhr',timestamp)
|
|
||||||
local output = time:localize(output)
|
|
||||||
|
|
||||||
local output = output..'\n_'..jdat.timeZoneName .. ' (UTC' .. utcoff .. ')_'
|
|
||||||
|
|
||||||
utilities.send_reply(self, msg, output, true)
|
utilities.send_reply(self, msg, output, true)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user