Merge Upstream
This commit is contained in:
commit
ae033a3788
29
miku/bot.lua
29
miku/bot.lua
@ -86,12 +86,6 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
|
||||
msg.text_lower = msg.text:lower()
|
||||
end
|
||||
|
||||
if is_channel_disabled(msg)then
|
||||
if not is_sudo(msg, config) or msg.text ~= "/channel enable" then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
msg = pre_process_msg(self, msg, config)
|
||||
if not msg then return end -- deleted by banning
|
||||
|
||||
@ -109,12 +103,13 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
-- vardump(msg)
|
||||
-- vardump(callback)
|
||||
|
||||
if msg.date < os.time() - 1800 then -- Do not process old messages.
|
||||
utilities.answer_callback_query(callback, 'Nachricht älter als eine halbe Stunde, bitte sende den Befehl selbst noch einmal.', true)
|
||||
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(':') or not callback.data:find('@'..self.info.username..' ') then
|
||||
if not callback.data:find(':') then
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Parameter.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -152,7 +147,6 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
end
|
||||
end
|
||||
|
||||
callback.data = string.gsub(callback.data, '@'..self.info.username..' ', "")
|
||||
local called_plugin = callback.data:match('(.*):.*')
|
||||
local param = callback.data:sub(callback.data:find(':')+1)
|
||||
|
||||
@ -164,7 +158,13 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
local plugin = self.plugins[n]
|
||||
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
|
||||
plugin:callback(callback, msg, self, config, param)
|
||||
if plugin.callback then
|
||||
plugin:callback(callback, msg, self, config, param)
|
||||
return
|
||||
else
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Plugin unterstützt keine Callbacks.')
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -190,9 +190,7 @@ function bot:process_inline_query(inline_query, config) -- When an inline query
|
||||
if not is_whitelisted then abort_inline_query(inline_query) return end
|
||||
end
|
||||
|
||||
if inline_query.query:match('"') then
|
||||
inline_query.query = inline_query.query:gsub('"', '\\"')
|
||||
end
|
||||
inline_query.query = inline_query.query:gsub('"', '\\"')
|
||||
|
||||
if string.len(inline_query.query) > 200 then
|
||||
abort_inline_query(inline_query)
|
||||
@ -220,7 +218,7 @@ function bot:run(config)
|
||||
local v = res.result[n]
|
||||
self.last_update = v.update_id
|
||||
if v.inline_query then
|
||||
bot.process_inline_query(self, v.inline_query, config)
|
||||
bot.process_inline_query(self, v.inline_query, config)
|
||||
elseif v.callback_query then
|
||||
bot.on_callback_receive(self, v.callback_query, v.callback_query.message, config)
|
||||
elseif v.message then
|
||||
@ -414,7 +412,6 @@ function create_plugin_set()
|
||||
'creds',
|
||||
'echo',
|
||||
'banhammer',
|
||||
'channels',
|
||||
'plugins',
|
||||
'settings',
|
||||
'help'
|
||||
|
@ -1,67 +0,0 @@
|
||||
local channels = {}
|
||||
|
||||
channels.command = 'channel <nur für Superuser>'
|
||||
|
||||
function channels:init(config)
|
||||
channels.triggers = {
|
||||
"^/[Cc][Hh][Aa][Nn][Nn][Ee][Ll] (enable)",
|
||||
"^/[Cc][Hh][Aa][Nn][Nn][Ee][Ll] (disable)"
|
||||
}
|
||||
channels.doc = [[*
|
||||
]]..config.cmd_pat..[[channel* _<enable>_/_<disable>_: Aktiviert/deaktiviert den Bot im Chat]]
|
||||
end
|
||||
|
||||
function channels:enable_channel(msg)
|
||||
local hash = 'chat:'..msg.chat.id..':disabled'
|
||||
local disabled = redis:get(hash)
|
||||
if disabled then
|
||||
print('Setting redis variable '..hash..' to false')
|
||||
redis:set(hash, false)
|
||||
return 'Channel aktiviert'
|
||||
else
|
||||
return 'Channel ist nicht deaktiviert!'
|
||||
end
|
||||
end
|
||||
|
||||
function channels:disable_channel(msg)
|
||||
local hash = 'chat:'..msg.chat.id..':disabled'
|
||||
local disabled = redis:get(hash)
|
||||
if disabled ~= "true" then
|
||||
print('Setting redis variable '..hash..' to true')
|
||||
redis:set(hash, true)
|
||||
return 'Channel deaktiviert'
|
||||
else
|
||||
return 'Channel ist bereits deaktiviert!'
|
||||
end
|
||||
end
|
||||
|
||||
function channels:pre_process(msg, config)
|
||||
-- If is sudo can reeanble the channel
|
||||
if is_sudo(msg, config) then
|
||||
if msg.text == "/channel enable" then
|
||||
channels:enable_channel(msg)
|
||||
end
|
||||
end
|
||||
|
||||
return msg
|
||||
end
|
||||
|
||||
function channels:action(msg, config, matches)
|
||||
if not is_sudo(msg, config) then
|
||||
utilities.send_reply(msg, config.errors.sudo, true)
|
||||
return
|
||||
end
|
||||
|
||||
-- Enable a channel
|
||||
if matches[1] == 'enable' then
|
||||
utilities.send_reply(msg, channels:enable_channel(msg))
|
||||
return
|
||||
end
|
||||
-- Disable a channel
|
||||
if matches[1] == 'disable' then
|
||||
utilities.send_reply(msg, channels:disable_channel(msg))
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return channels
|
@ -107,13 +107,13 @@ function gImages:callback(callback, msg, self, config, input)
|
||||
end
|
||||
|
||||
if mimetype == 'image/gif' then
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..input..'"}]]}')
|
||||
else
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..input..'"}]]}')
|
||||
end
|
||||
|
||||
if not result then
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..input..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -236,13 +236,13 @@ function gImages:action(msg, config, matches)
|
||||
end
|
||||
|
||||
if mimetype == 'image/gif' then
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
|
||||
else
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
|
||||
end
|
||||
|
||||
if not result then
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -107,13 +107,13 @@ function gImages_nsfw:callback(callback, msg, self, config, input)
|
||||
end
|
||||
|
||||
if mimetype == 'image/gif' then
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}')
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..input..'"}]]}')
|
||||
else
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}')
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..input..'"}]]}')
|
||||
end
|
||||
|
||||
if not result then
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}')
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages_nsfw:'..input..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -236,13 +236,13 @@ function gImages_nsfw:action(msg, config, matches)
|
||||
end
|
||||
|
||||
if mimetype == 'image/gif' then
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}')
|
||||
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
|
||||
else
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}')
|
||||
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
|
||||
end
|
||||
|
||||
if not result then
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}')
|
||||
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,8 @@ function twitter:action(msg, config, matches)
|
||||
end
|
||||
|
||||
local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. id.. ".json"
|
||||
local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url)
|
||||
local get_params = {tweet_mode = 'extended'}
|
||||
local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, get_params)
|
||||
local response = json.decode(response_body)
|
||||
|
||||
local full_name = response.user.name
|
||||
@ -60,7 +61,7 @@ function twitter:action(msg, config, matches)
|
||||
verified = ''
|
||||
end
|
||||
local header = '<b>Tweet von '..full_name..'</b> (<a href="https://twitter.com/'..user_name..'">@' ..user_name..'</a>'..verified..'):'
|
||||
local text = response.text
|
||||
local text = response.full_text
|
||||
|
||||
-- favorites & retweets
|
||||
if response.retweet_count == 0 then
|
||||
@ -116,7 +117,7 @@ function twitter:action(msg, config, matches)
|
||||
|
||||
-- quoted tweet
|
||||
if response.quoted_status then
|
||||
local quoted_text = response.quoted_status.text
|
||||
local quoted_text = response.quoted_status.full_text
|
||||
local quoted_name = response.quoted_status.user.name
|
||||
local quoted_screen_name = response.quoted_status.user.screen_name
|
||||
if response.quoted_status.user.verified then
|
||||
@ -124,6 +125,27 @@ function twitter:action(msg, config, matches)
|
||||
else
|
||||
quoted_verified = ''
|
||||
end
|
||||
|
||||
-- replace short URLs for quoted tweets
|
||||
if response.quoted_status.entities.urls then
|
||||
for k, v in pairs(response.quoted_status.entities.urls) do
|
||||
local short = v.url
|
||||
local long = v.expanded_url
|
||||
local long = long:gsub('%%', '%%%%')
|
||||
quoted_text = quoted_text:gsub(short, long)
|
||||
end
|
||||
end
|
||||
|
||||
-- same for media
|
||||
if response.quoted_status.entities.media then
|
||||
for k, v in pairs(response.quoted_status.entities.media) do
|
||||
local short = v.url
|
||||
local long = v.media_url_https
|
||||
local long = long:gsub('%%', '%%%%')
|
||||
quoted_text = quoted_text:gsub(short, long)
|
||||
end
|
||||
end
|
||||
|
||||
quote = '<b>Als Antwort auf '..quoted_name..'</b> (<a href="https://twitter.com/'..quoted_screen_name..'">@' ..quoted_screen_name..'</a>'..quoted_verified..'):\n'..quoted_text
|
||||
text = text..'\n\n'..quote..'\n'
|
||||
end
|
||||
|
@ -1016,23 +1016,10 @@ function table.contains(table, element)
|
||||
return false
|
||||
end
|
||||
|
||||
-- Checks if bot was disabled on specific chat
|
||||
function is_channel_disabled(msg)
|
||||
local hash = 'chat:'..msg.chat.id..':disabled'
|
||||
local disabled = redis:get(hash)
|
||||
|
||||
if not disabled or disabled == "false" then
|
||||
return false
|
||||
end
|
||||
|
||||
return disabled
|
||||
end
|
||||
|
||||
-- Converts a gross string back into proper UTF-8.
|
||||
-- Useful for fixing improper encoding caused by bad JSON escaping.
|
||||
function utilities.fix_utf8(str)
|
||||
return string.char(utf8.codepoint(str, 1, -1))
|
||||
end
|
||||
|
||||
|
||||
return utilities
|
Reference in New Issue
Block a user