Merge Upstream
This commit is contained in:
commit
7e43a5dc8b
61
miku/bot.lua
61
miku/bot.lua
@ -113,11 +113,6 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
|||||||
-- vardump(msg)
|
-- vardump(msg)
|
||||||
-- vardump(callback)
|
-- vardump(callback)
|
||||||
|
|
||||||
if msg.date < os.time() - 3600 then -- Do not process old messages.
|
|
||||||
utilities.answer_callback_query(callback, 'Nachricht älter als eine Stunde, bitte sende den Befehl selbst noch einmal.', true)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not callback.data:find(':') then
|
if not callback.data:find(':') then
|
||||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Parameter.')
|
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Parameter.')
|
||||||
return
|
return
|
||||||
@ -125,36 +120,40 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
|||||||
|
|
||||||
-- Check if user is blocked
|
-- Check if user is blocked
|
||||||
local user_id = callback.from.id
|
local user_id = callback.from.id
|
||||||
local chat_id = msg.chat.id
|
|
||||||
if redis:get('blocked:'..user_id) then
|
if redis:get('blocked:'..user_id) then
|
||||||
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if user is banned
|
-- Check if user is banned, not working for Callbacks from InlineQuerys!
|
||||||
local banned = redis:get('banned:'..chat_id..':'..user_id)
|
if msg then
|
||||||
if banned then
|
local chat_id = msg.chat.id
|
||||||
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
local banned = redis:get('banned:'..chat_id..':'..user_id)
|
||||||
return
|
if banned then
|
||||||
end
|
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Check if whitelist is enabled and user/chat is whitelisted
|
-- Check if whitelist is enabled and user/chat is whitelisted
|
||||||
local whitelist = redis:get('whitelist:enabled')
|
local whitelist = redis:get('whitelist:enabled')
|
||||||
if whitelist and not is_sudo(callback, config) then
|
if whitelist and not is_sudo(callback, config) then
|
||||||
local hash = 'whitelist:user#id'..user_id
|
local hash = 'whitelist:user#id'..user_id
|
||||||
local allowed = redis:get(hash) or false
|
local allowed = redis:get(hash) or false
|
||||||
if not allowed then
|
if not allowed then
|
||||||
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
||||||
local allowed = redis:get('whitelist:chat#id'.. chat_id)
|
local allowed = redis:get('whitelist:chat#id'.. chat_id)
|
||||||
if not allowed then
|
if not allowed then
|
||||||
|
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
else
|
||||||
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
|
||||||
utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true)
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
msg = utilities.enrich_message(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local called_plugin = callback.data:match('(.*):.*')
|
local called_plugin = callback.data:match('(.*):.*')
|
||||||
@ -162,12 +161,18 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
|||||||
|
|
||||||
print('Callback Query "'..param..'" für Plugin "'..called_plugin..'" ausgelöst von '..callback.from.first_name..' ('..callback.from.id..')')
|
print('Callback Query "'..param..'" für Plugin "'..called_plugin..'" ausgelöst von '..callback.from.first_name..' ('..callback.from.id..')')
|
||||||
|
|
||||||
msg = utilities.enrich_message(msg)
|
|
||||||
|
|
||||||
for n=1, #self.plugins do
|
for n=1, #self.plugins do
|
||||||
local plugin = self.plugins[n]
|
local plugin = self.plugins[n]
|
||||||
if plugin.name == called_plugin then
|
if plugin.name == called_plugin then
|
||||||
if is_plugin_disabled_on_chat(plugin.name, msg) then utilities.answer_callback_query(callback, 'Plugin wurde in diesem Chat deaktiviert.') return end
|
|
||||||
|
-- Check if plugin is disabled on this chat
|
||||||
|
if msg then
|
||||||
|
if is_plugin_disabled_on_chat(plugin.name, msg) then
|
||||||
|
utilities.answer_callback_query(callback, 'Plugin wurde in diesem Chat deaktiviert.')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if plugin.callback then
|
if plugin.callback then
|
||||||
plugin:callback(callback, msg, self, config, param)
|
plugin:callback(callback, msg, self, config, param)
|
||||||
return
|
return
|
||||||
|
@ -23,8 +23,8 @@ function cats:init(config)
|
|||||||
*]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]]
|
*]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
|
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
|
||||||
|
local BASE_URL = 'http://thecatapi.com/api/images/get'
|
||||||
|
|
||||||
function cats:inline_callback(inline_query, config, matches)
|
function cats:inline_callback(inline_query, config, matches)
|
||||||
if matches[1] == 'gif' then
|
if matches[1] == 'gif' then
|
||||||
@ -59,15 +59,53 @@ function cats:inline_callback(inline_query, config, matches)
|
|||||||
utilities.answer_inline_query(inline_query, results, 30)
|
utilities.answer_inline_query(inline_query, results, 30)
|
||||||
end
|
end
|
||||||
|
|
||||||
function cats:action(msg, config, matches)
|
function cats:get_cat(gif)
|
||||||
if matches[1] == 'gif' then
|
if gif then
|
||||||
local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey
|
local url = BASE_URL..'?type=gif&apikey='..apikey
|
||||||
local file = download_to_file(url, 'miau.gif')
|
file = download_to_file(url, 'miau.gif')
|
||||||
utilities.send_document(msg.chat.id, file, nil, msg.message_id)
|
|
||||||
else
|
else
|
||||||
local url = 'http://thecatapi.com/api/images/get?type=jpg,png&apikey='..apikey
|
local url = BASE_URL..'?type=jpg,png&apikey='..apikey
|
||||||
local file = download_to_file(url, 'miau.png')
|
file = download_to_file(url, 'miau.png')
|
||||||
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
|
end
|
||||||
|
return file
|
||||||
|
end
|
||||||
|
|
||||||
|
function cats:callback(callback, msg, self, config, input)
|
||||||
|
utilities.answer_callback_query(callback, 'Miau!')
|
||||||
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||||
|
if string.isempty(input) then
|
||||||
|
local file = cats:get_cat()
|
||||||
|
if not file then
|
||||||
|
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
|
||||||
|
else
|
||||||
|
local file = cats:get_cat(true)
|
||||||
|
if not file then
|
||||||
|
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function cats:action(msg, config, matches)
|
||||||
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||||
|
if matches[1] == 'gif' then
|
||||||
|
local file = cats:get_cat(true)
|
||||||
|
if not file then
|
||||||
|
utilities.send_reply(msg, config.errors.connection)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
|
||||||
|
else
|
||||||
|
local file = cats:get_cat()
|
||||||
|
if not file then
|
||||||
|
utilities.send_reply(msg, config.errors.connection)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user