Merge Upstream

This commit is contained in:
2016-10-05 17:32:02 +02:00
9 changed files with 49 additions and 54 deletions

View File

@ -6,7 +6,7 @@ function cleverbot:init(config)
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
"^[Mm][Ii][Kk][Uu], (.+)$"
}
cleverbot.url = config.chatter.cleverbot_api
cleverbot.url = config.cleverbot.cleverbot_api
end
cleverbot.command = 'cbot <Text>'
@ -16,13 +16,13 @@ function cleverbot:action(msg, config, matches)
local text = matches[1]
local query, code = https.request(cleverbot.url..URL.escape(text))
if code ~= 200 then
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
utilities.send_reply(msg, config.cleverbot.connection)
return
end
local data = json.decode(query)
if not data.clever then
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
utilities.send_reply(msg, config.cleverbot.response)
return
end

View File

@ -75,7 +75,7 @@ function gImages:cache_result(results, text)
cache_data('gImages', string.lower(text), cache, 1209600, 'set')
end
function gImages:send_image(msg, input)
function gImages:send_image(msg, input, config)
utilities.send_typing(msg.chat.id, 'upload_photo')
local hash = 'telegram:cache:gImages'
@ -147,7 +147,7 @@ function gImages:callback(callback, msg, self, config, input)
else
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
end
gImages:send_image(msg, input)
gImages:send_image(msg, input, config)
end
function gImages:action(msg, config, matches)
@ -167,7 +167,7 @@ function gImages:action(msg, config, matches)
return
end
gImages:send_image(msg, input)
gImages:send_image(msg, input, config)
end
return gImages

View File

@ -75,7 +75,7 @@ function gImages_nsfw:cache_result(results, text)
cache_data('gImages_nsfw', string.lower(text), cache, 1209600, 'set')
end
function gImages_nsfw:send_image(msg, input)
function gImages_nsfw:send_image(msg, input, config)
utilities.send_typing(msg.chat.id, 'upload_photo')
local hash = 'telegram:cache:gImages_nsfw'
@ -147,7 +147,7 @@ function gImages_nsfw:callback(callback, msg, self, config, input)
else
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
end
gImages_nsfw:send_image(msg, input)
gImages_nsfw:send_image(msg, input, config)
end
function gImages_nsfw:action(msg, config, matches)
@ -167,7 +167,7 @@ function gImages_nsfw:action(msg, config, matches)
return
end
gImages_nsfw:send_image(msg, input)
gImages_nsfw:send_image(msg, input, config)
end
return gImages_nsfw

View File

@ -3,14 +3,19 @@ local remind = {}
remind.command = 'remind <Länge> <Nachricht>'
function remind:init(config)
self.database.reminders = self.database.reminders or {}
self.database.remind = self.database.remind or {}
remind.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('remind', true).table
remind.doc = [[*
]]..config.cmd_pat..[[remind* _<Länge>_ _<Nachricht>_
Erinnert dich in der angegeben Länge in Minuten an eine Nachricht.
Die maximale Länge einer Erinnerung beträgt %s Buchstaben, die maximale Zeit beträgt %s Minuten, die maximale Anzahl an Erinnerung für eine Gruppe ist %s und für private Chats %s.]]
remind.doc = remind.doc:format(config.remind.max_length, config.remind.max_duration, config.remind.max_reminders_group, config.remind.max_reminders_private)
remind.doc = remind.doc:format(
config.remind.max_length,
config.remind.max_duration,
config.remind.max_reminders_group,
config.remind.max_reminders_private
)
end
function remind:action(msg, config)
@ -49,10 +54,10 @@ function remind:action(msg, config)
local chat_id_str = tostring(msg.chat.id)
local output
self.database.reminders[chat_id_str] = self.database.reminders[chat_id_str] or {}
if msg.chat.type == 'private' and utilities.table_size(self.database.reminders[chat_id_str]) >= config.remind.max_reminders_private then
self.database.remind[chat_id_str] = self.database.remind[chat_id_str] or {}
if msg.chat.type == 'private' and utilities.table_size(self.database.remind[chat_id_str]) >= config.remind.max_reminders_private then
output = 'Sorry, du kannst keine Erinnerungen mehr hinzufügen.'
elseif msg.chat.type ~= 'private' and utilities.table_size(self.database.reminders[chat_id_str]) >= config.remind.max_reminders_group then
elseif msg.chat.type ~= 'private' and utilities.table_size(self.database.remind[chat_id_str]) >= config.remind.max_reminders_group then
output = 'Sorry, diese Gruppe kann keine Erinnerungen mehr hinzufügen.'
else
-- Put together the reminder with the expiration, message, and message to reply to.
@ -61,7 +66,7 @@ function remind:action(msg, config)
time = timestamp,
message = message
}
table.insert(self.database.reminders[chat_id_str], reminder)
table.insert(self.database.remind[chat_id_str], reminder)
local human_readable_time = convert_timestamp(timestamp, '%H:%M:%S')
output = 'Ich werde dich um *'..human_readable_time..' Uhr* erinnern.'
end
@ -71,14 +76,14 @@ end
function remind:cron(config)
local time = os.time()
-- Iterate over the group entries in the reminders database.
for chat_id, group in pairs(self.database.reminders) do
for chat_id, group in pairs(self.database.remind) do
-- Iterate over each reminder.
for k, reminder in pairs(group) do
-- If the reminder is past-due, send it and nullify it.
-- Otherwise, add it to the replacement table.
if time > reminder.time then
local output = '*ERINNERUNG:*\n"' .. utilities.md_escape(reminder.message) .. '"'
local res = utilities.send_message(chat_id, output, true, nil, true)
local output = '<b>ERINNERUNG:</b>\n"'..utilities.html_escape(reminder.message)..'"'
local res = utilities.send_message(chat_id, output, true, nil, 'HTML')
-- If the message fails to send, save it for later (if enabled in config).
if res or not config.remind.persist then
group[k] = nil

View File

@ -164,7 +164,7 @@ function youtube_dl:action(msg, config, matches)
else
pretty_format = video.pretty_format..' ('..pretty_size..')'
end
local button = '{"text":"'..pretty_format..'","callback_data":"@'..self.info.username..' youtube_dl:'..id..'@'..format..'"}'
local button = '{"text":"'..pretty_format..'","callback_data":"youtube_dl:'..id..'@'..format..'"}'
callback_buttons[#callback_buttons+1] = button
end