Merge Upstream
This commit is contained in:
commit
65b339c773
@ -61,7 +61,7 @@ Sende /hilfe, um zu starten
|
|||||||
max_reminders_private = 50
|
max_reminders_private = 50
|
||||||
},
|
},
|
||||||
|
|
||||||
chatter = {
|
cleverbot = {
|
||||||
cleverbot_api = 'https://brawlbot.tk/apis/chatter-bot-api/cleverbot.php?text=',
|
cleverbot_api = 'https://brawlbot.tk/apis/chatter-bot-api/cleverbot.php?text=',
|
||||||
connection = 'Ich möchte jetzt nicht reden...',
|
connection = 'Ich möchte jetzt nicht reden...',
|
||||||
response = 'Ich weiß nicht, was ich dazu sagen soll...'
|
response = 'Ich weiß nicht, was ich dazu sagen soll...'
|
||||||
|
@ -5,19 +5,8 @@
|
|||||||
See the "Bindings" section of README.md for usage information.
|
See the "Bindings" section of README.md for usage information.
|
||||||
|
|
||||||
Copyright 2016 topkecleon <drew@otou.to>
|
Copyright 2016 topkecleon <drew@otou.to>
|
||||||
|
Modified by Brawl345 <https://github.com/Brawl345>
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This code is licensed under the GNU AGPLv3. See /LICENSE for details.
|
||||||
under the terms of the GNU Affero General Public License version 3 as
|
|
||||||
published by the Free Software Foundation.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program; if not, write to the Free Software Foundation,
|
|
||||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local bindings = {}
|
local bindings = {}
|
||||||
@ -26,7 +15,7 @@ local https = require('ssl.https')
|
|||||||
https.TIMEOUT = 10
|
https.TIMEOUT = 10
|
||||||
local json = require('dkjson')
|
local json = require('dkjson')
|
||||||
local ltn12 = require('ltn12')
|
local ltn12 = require('ltn12')
|
||||||
local mp_encode = require('multipart-post').encode
|
local mp = require('multipart-post')
|
||||||
|
|
||||||
function bindings.init(token)
|
function bindings.init(token)
|
||||||
bindings.BASE_URL = 'https://api.telegram.org/bot' .. token .. '/'
|
bindings.BASE_URL = 'https://api.telegram.org/bot' .. token .. '/'
|
||||||
@ -65,7 +54,7 @@ function bindings.request(method, parameters, file)
|
|||||||
parameters = {''}
|
parameters = {''}
|
||||||
end
|
end
|
||||||
local response = {}
|
local response = {}
|
||||||
local body, boundary = mp_encode(parameters)
|
local body, boundary = mp.encode(parameters)
|
||||||
local success, code = https.request{
|
local success, code = https.request{
|
||||||
url = bindings.BASE_URL .. method,
|
url = bindings.BASE_URL .. method,
|
||||||
method = 'POST',
|
method = 'POST',
|
||||||
@ -86,8 +75,9 @@ function bindings.request(method, parameters, file)
|
|||||||
return false, false
|
return false, false
|
||||||
elseif result.ok then
|
elseif result.ok then
|
||||||
return result
|
return result
|
||||||
else
|
elseif result.description == 'Method not found' then
|
||||||
assert(result.description ~= 'Method not found', method .. ': Method not found.')
|
error(method .. ': Method not found.')
|
||||||
|
else
|
||||||
return false, result
|
return false, result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
15
miku/bot.lua
15
miku/bot.lua
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
local bot = {}
|
local bot = {}
|
||||||
|
|
||||||
bot.version = '160908'
|
bot.version = '161005'
|
||||||
|
|
||||||
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.
|
||||||
assert(config.bot_api_key, 'Dein Bot-Token ist nicht in der Config gesetzt!')
|
assert(config.bot_api_key, 'Dein Bot-Token ist nicht in der Config gesetzt!')
|
||||||
@ -39,6 +39,16 @@ function bot:init(config) -- The function run when the bot is started or reloade
|
|||||||
if not self.database then
|
if not self.database then
|
||||||
self.database = utilities.load_data(self.info.username..'.db')
|
self.database = utilities.load_data(self.info.username..'.db')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Migration code 2.2.7 -> 2.3
|
||||||
|
-- "database.reminders" -> "database.remind"
|
||||||
|
if self.database.version ~= '2.3' then
|
||||||
|
self.database.remind = self.database.reminders
|
||||||
|
self.database.reminders = nil
|
||||||
|
end
|
||||||
|
-- End migration code.
|
||||||
|
|
||||||
|
self.database.version = bot.version
|
||||||
|
|
||||||
self.plugins = {} -- Load plugins.
|
self.plugins = {} -- Load plugins.
|
||||||
enabled_plugins = load_plugins()
|
enabled_plugins = load_plugins()
|
||||||
@ -75,7 +85,7 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
|
|||||||
print(bot:print_msg(msg))
|
print(bot:print_msg(msg))
|
||||||
|
|
||||||
-- Support deep linking.
|
-- Support deep linking.
|
||||||
if msg.text:match('^'..config.cmd_pat..'start .+') then
|
if msg.text:match('^/start .+') then
|
||||||
msg.text = config.cmd_pat .. utilities.input(msg.text)
|
msg.text = config.cmd_pat .. utilities.input(msg.text)
|
||||||
msg.text_lower = msg.text:lower()
|
msg.text_lower = msg.text:lower()
|
||||||
end
|
end
|
||||||
@ -368,6 +378,7 @@ function match_plugins(self, msg, config, plugin)
|
|||||||
end)
|
end)
|
||||||
if not success then
|
if not success then
|
||||||
utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config.log_chat)
|
utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config.log_chat)
|
||||||
|
msg = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- if one pattern matches, end
|
-- if one pattern matches, end
|
||||||
|
@ -6,7 +6,7 @@ function cleverbot:init(config)
|
|||||||
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
|
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
|
||||||
"^[Mm][Ii][Kk][Uu], (.+)$"
|
"^[Mm][Ii][Kk][Uu], (.+)$"
|
||||||
}
|
}
|
||||||
cleverbot.url = config.chatter.cleverbot_api
|
cleverbot.url = config.cleverbot.cleverbot_api
|
||||||
end
|
end
|
||||||
|
|
||||||
cleverbot.command = 'cbot <Text>'
|
cleverbot.command = 'cbot <Text>'
|
||||||
@ -16,13 +16,13 @@ function cleverbot:action(msg, config, matches)
|
|||||||
local text = matches[1]
|
local text = matches[1]
|
||||||
local query, code = https.request(cleverbot.url..URL.escape(text))
|
local query, code = https.request(cleverbot.url..URL.escape(text))
|
||||||
if code ~= 200 then
|
if code ~= 200 then
|
||||||
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
|
utilities.send_reply(msg, config.cleverbot.connection)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local data = json.decode(query)
|
local data = json.decode(query)
|
||||||
if not data.clever then
|
if not data.clever then
|
||||||
utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...')
|
utilities.send_reply(msg, config.cleverbot.response)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ function gImages:cache_result(results, text)
|
|||||||
cache_data('gImages', string.lower(text), cache, 1209600, 'set')
|
cache_data('gImages', string.lower(text), cache, 1209600, 'set')
|
||||||
end
|
end
|
||||||
|
|
||||||
function gImages:send_image(msg, input)
|
function gImages:send_image(msg, input, config)
|
||||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||||
|
|
||||||
local hash = 'telegram:cache:gImages'
|
local hash = 'telegram:cache:gImages'
|
||||||
@ -147,7 +147,7 @@ function gImages:callback(callback, msg, self, config, input)
|
|||||||
else
|
else
|
||||||
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
||||||
end
|
end
|
||||||
gImages:send_image(msg, input)
|
gImages:send_image(msg, input, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gImages:action(msg, config, matches)
|
function gImages:action(msg, config, matches)
|
||||||
@ -167,7 +167,7 @@ function gImages:action(msg, config, matches)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
gImages:send_image(msg, input)
|
gImages:send_image(msg, input, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
return gImages
|
return gImages
|
@ -75,7 +75,7 @@ function gImages_nsfw:cache_result(results, text)
|
|||||||
cache_data('gImages_nsfw', string.lower(text), cache, 1209600, 'set')
|
cache_data('gImages_nsfw', string.lower(text), cache, 1209600, 'set')
|
||||||
end
|
end
|
||||||
|
|
||||||
function gImages_nsfw:send_image(msg, input)
|
function gImages_nsfw:send_image(msg, input, config)
|
||||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||||
|
|
||||||
local hash = 'telegram:cache:gImages_nsfw'
|
local hash = 'telegram:cache:gImages_nsfw'
|
||||||
@ -147,7 +147,7 @@ function gImages_nsfw:callback(callback, msg, self, config, input)
|
|||||||
else
|
else
|
||||||
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
||||||
end
|
end
|
||||||
gImages_nsfw:send_image(msg, input)
|
gImages_nsfw:send_image(msg, input, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gImages_nsfw:action(msg, config, matches)
|
function gImages_nsfw:action(msg, config, matches)
|
||||||
@ -167,7 +167,7 @@ function gImages_nsfw:action(msg, config, matches)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
gImages_nsfw:send_image(msg, input)
|
gImages_nsfw:send_image(msg, input, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
return gImages_nsfw
|
return gImages_nsfw
|
@ -3,14 +3,19 @@ local remind = {}
|
|||||||
remind.command = 'remind <Länge> <Nachricht>'
|
remind.command = 'remind <Länge> <Nachricht>'
|
||||||
|
|
||||||
function remind:init(config)
|
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.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('remind', true).table
|
||||||
remind.doc = [[*
|
remind.doc = [[*
|
||||||
]]..config.cmd_pat..[[remind* _<Länge>_ _<Nachricht>_
|
]]..config.cmd_pat..[[remind* _<Länge>_ _<Nachricht>_
|
||||||
Erinnert dich in der angegeben Länge in Minuten an eine 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.]]
|
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
|
end
|
||||||
|
|
||||||
function remind:action(msg, config)
|
function remind:action(msg, config)
|
||||||
@ -49,10 +54,10 @@ function remind:action(msg, config)
|
|||||||
|
|
||||||
local chat_id_str = tostring(msg.chat.id)
|
local chat_id_str = tostring(msg.chat.id)
|
||||||
local output
|
local output
|
||||||
self.database.reminders[chat_id_str] = self.database.reminders[chat_id_str] or {}
|
self.database.remind[chat_id_str] = self.database.remind[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
|
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.'
|
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.'
|
output = 'Sorry, diese Gruppe kann keine Erinnerungen mehr hinzufügen.'
|
||||||
else
|
else
|
||||||
-- Put together the reminder with the expiration, message, and message to reply to.
|
-- Put together the reminder with the expiration, message, and message to reply to.
|
||||||
@ -61,7 +66,7 @@ function remind:action(msg, config)
|
|||||||
time = timestamp,
|
time = timestamp,
|
||||||
message = message
|
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')
|
local human_readable_time = convert_timestamp(timestamp, '%H:%M:%S')
|
||||||
output = 'Ich werde dich um *'..human_readable_time..' Uhr* erinnern.'
|
output = 'Ich werde dich um *'..human_readable_time..' Uhr* erinnern.'
|
||||||
end
|
end
|
||||||
@ -71,14 +76,14 @@ end
|
|||||||
function remind:cron(config)
|
function remind:cron(config)
|
||||||
local time = os.time()
|
local time = os.time()
|
||||||
-- Iterate over the group entries in the reminders database.
|
-- 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.
|
-- Iterate over each reminder.
|
||||||
for k, reminder in pairs(group) do
|
for k, reminder in pairs(group) do
|
||||||
-- If the reminder is past-due, send it and nullify it.
|
-- If the reminder is past-due, send it and nullify it.
|
||||||
-- Otherwise, add it to the replacement table.
|
-- Otherwise, add it to the replacement table.
|
||||||
if time > reminder.time then
|
if time > reminder.time then
|
||||||
local output = '*ERINNERUNG:*\n"' .. utilities.md_escape(reminder.message) .. '"'
|
local output = '<b>ERINNERUNG:</b>\n"'..utilities.html_escape(reminder.message)..'"'
|
||||||
local res = utilities.send_message(chat_id, output, true, nil, true)
|
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 the message fails to send, save it for later (if enabled in config).
|
||||||
if res or not config.remind.persist then
|
if res or not config.remind.persist then
|
||||||
group[k] = nil
|
group[k] = nil
|
||||||
|
@ -164,7 +164,7 @@ function youtube_dl:action(msg, config, matches)
|
|||||||
else
|
else
|
||||||
pretty_format = video.pretty_format..' ('..pretty_size..')'
|
pretty_format = video.pretty_format..' ('..pretty_size..')'
|
||||||
end
|
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
|
callback_buttons[#callback_buttons+1] = button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,22 +4,9 @@
|
|||||||
|
|
||||||
Copyright 2016 topkecleon <drew@otou.to>
|
Copyright 2016 topkecleon <drew@otou.to>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This code is licensed under the GNU AGPLv3. See /LICENSE for details.
|
||||||
under the terms of the GNU Affero General Public License version 3 as
|
|
||||||
published by the Free Software Foundation.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program; if not, write to the Free Software Foundation,
|
|
||||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local utilities = {}
|
|
||||||
|
|
||||||
utf8 = require('lua-utf8')
|
utf8 = require('lua-utf8')
|
||||||
ltn12 = require('ltn12')
|
ltn12 = require('ltn12')
|
||||||
http = require('socket.http')
|
http = require('socket.http')
|
||||||
@ -37,6 +24,8 @@ require('/miku/encoding')
|
|||||||
http.TIMEOUT = 10
|
http.TIMEOUT = 10
|
||||||
https.TIMEOUT = 10
|
https.TIMEOUT = 10
|
||||||
|
|
||||||
|
local utilities = {}
|
||||||
|
|
||||||
-- For the sake of ease to new contributors and familiarity to old contributors,
|
-- For the sake of ease to new contributors and familiarity to old contributors,
|
||||||
-- we'll provide a couple of aliases to real bindings here.
|
-- we'll provide a couple of aliases to real bindings here.
|
||||||
function utilities.send_message(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown, reply_markup)
|
function utilities.send_message(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown, reply_markup)
|
||||||
@ -462,7 +451,7 @@ end
|
|||||||
-- Get the number of values in a key/value table.
|
-- Get the number of values in a key/value table.
|
||||||
function utilities.table_size(tab)
|
function utilities.table_size(tab)
|
||||||
local i = 0
|
local i = 0
|
||||||
for _,_ in pairs(tab) do
|
for _ in pairs(tab) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
return i
|
return i
|
||||||
|
Reference in New Issue
Block a user