- Service-Nachrichten funktionieren nun anders und nicht mehr über Pre-Processoren (wie bei v1 des Bots) -> höhere Perfomance!
- leave_group und entergroup in service_leave_group bzw. service_entergroup umbenannt - Git zeigt die Umbenennung von leave_group nicht an!? - Games: Fix für Pattern - Utilites: Zwei neue Funktionen: is_service_msg() und service_modify_msg(), das erste prüft, ob es sich um eine Service-Message handelt, das zweite modifiziert msg.text und msg.text_lower entsprechend
This commit is contained in:
parent
39529785e0
commit
206c06937a
@ -93,6 +93,10 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
|
||||
end
|
||||
msg = pre_process_msg(self, msg, config)
|
||||
|
||||
if is_service_msg(msg) then
|
||||
msg = service_modify_msg(msg)
|
||||
end
|
||||
|
||||
for _, plugin in ipairs(self.plugins) do
|
||||
match_plugins(self, msg, config, plugin)
|
||||
end
|
||||
|
@ -5,9 +5,7 @@ local xml = require("xml")
|
||||
games.command = 'game <Spiel>'
|
||||
|
||||
function games:init(config)
|
||||
games.triggers = {
|
||||
"^/game (.+)$"
|
||||
}
|
||||
games.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('game', true).table
|
||||
games.doc = [[*
|
||||
]]..config.cmd_pat..[[game*_ <Spiel>_: Sendet Infos zum Spiel]]
|
||||
end
|
||||
@ -129,8 +127,17 @@ function games:send_game_data(game_id, self, msg)
|
||||
end
|
||||
|
||||
|
||||
function games:action(msg, config, matches)
|
||||
local game = URL.escape(matches[1])
|
||||
function games:action(msg, config)
|
||||
local game = utilities.input(msg.text)
|
||||
if not game then
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
game = msg.reply_to_message.text
|
||||
else
|
||||
utilities.send_message(self, msg.chat.id, fun.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local game_id = games:get_game_id(game)
|
||||
if not game_id then
|
||||
utilities.send_reply(self, msg, 'Spiel nicht gefunden!')
|
||||
|
@ -1,49 +0,0 @@
|
||||
local leave_group = {}
|
||||
|
||||
leave_group.triggers = {
|
||||
'/nil'
|
||||
}
|
||||
|
||||
local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you
|
||||
|
||||
function leave_group:check_for_admin(msg, self, config)
|
||||
local result = bindings.request(self, 'getChatMember', {
|
||||
chat_id = msg.chat.id,
|
||||
user_id = config.admin
|
||||
} )
|
||||
if not result.ok then
|
||||
print('Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...')
|
||||
return false
|
||||
end
|
||||
if result.result.status ~= "member" and result.result.status ~= "administrator" and result.result.status ~= "creator" then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function leave_group:pre_process(msg, self, config)
|
||||
if msg.group_chat_created or msg.new_chat_member then
|
||||
local admin_in_group = leave_group:check_for_admin(msg, self, config)
|
||||
if not admin_in_group then
|
||||
print('Admin ist nicht in der Gruppe, verlasse sie deshalb...')
|
||||
utilities.send_reply(self, msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!')
|
||||
local result = bindings.request(self, 'leaveChat', {
|
||||
chat_id = msg.chat.id
|
||||
} )
|
||||
local chat_name = msg.chat.title
|
||||
local chat_id = msg.chat.id
|
||||
local from = msg.from.name
|
||||
local from_id = msg.from.id
|
||||
if report_to_admin then
|
||||
utilities.send_message(self, config.admin, '#WARNUNG: Bot wurde in fremde Gruppe hinzugefügt:\nGruppenname: '..chat_name..' ('..chat_id..')\nHinzugefügt von: '..from..' ('..from_id..')')
|
||||
end
|
||||
end
|
||||
end
|
||||
return msg
|
||||
end
|
||||
|
||||
function leave_group:action(msg)
|
||||
end
|
||||
|
||||
return leave_group
|
@ -1,7 +1,8 @@
|
||||
local entergroup = {}
|
||||
|
||||
entergroup.triggers = {
|
||||
'/nil'
|
||||
'^//tgservice (new_chat_member)$',
|
||||
'^//tgservice (left_chat_member)$'
|
||||
}
|
||||
|
||||
function entergroup:chat_new_user(msg, self)
|
||||
@ -38,17 +39,14 @@ function entergroup:chat_del_user(msg, self)
|
||||
utilities.send_reply(self, msg, text, true)
|
||||
end
|
||||
|
||||
function entergroup:pre_process(msg, self)
|
||||
if msg.new_chat_member then
|
||||
function entergroup:action(msg, config, matches)
|
||||
if not is_service_msg(msg) then return end -- Bad attempt at trolling!
|
||||
|
||||
if matches[1] == 'new_chat_member' then
|
||||
entergroup:chat_new_user(msg, self)
|
||||
elseif msg.left_chat_member then
|
||||
elseif matches[1] == 'left_chat_member'then
|
||||
entergroup:chat_del_user(msg, self)
|
||||
end
|
||||
|
||||
return msg
|
||||
end
|
||||
|
||||
function entergroup:action(msg)
|
||||
end
|
||||
|
||||
return entergroup
|
45
otouto/plugins/service_leave_group.lua
Normal file
45
otouto/plugins/service_leave_group.lua
Normal file
@ -0,0 +1,45 @@
|
||||
local leave_group = {}
|
||||
|
||||
leave_group.triggers = {
|
||||
'^//tgservice group_chat_created$',
|
||||
'^//tgservice supergroup_chat_created$'
|
||||
}
|
||||
|
||||
local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you
|
||||
|
||||
function leave_group:check_for_admin(msg, self, config)
|
||||
local result = bindings.request(self, 'getChatMember', {
|
||||
chat_id = msg.chat.id,
|
||||
user_id = config.admin
|
||||
} )
|
||||
if not result.ok then
|
||||
print('Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...')
|
||||
return false
|
||||
end
|
||||
if result.result.status ~= "member" and result.result.status ~= "administrator" and result.result.status ~= "creator" then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function leave_group:action(msg)
|
||||
if not is_service_msg(msg) then return end -- Bad attempt at trolling!
|
||||
local admin_in_group = leave_group:check_for_admin(msg, self, config)
|
||||
if not admin_in_group then
|
||||
print('Admin ist nicht in der Gruppe, verlasse sie deshalb...')
|
||||
utilities.send_reply(self, msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!')
|
||||
local result = bindings.request(self, 'leaveChat', {
|
||||
chat_id = msg.chat.id
|
||||
} )
|
||||
local chat_name = msg.chat.title
|
||||
local chat_id = msg.chat.id
|
||||
local from = msg.from.name
|
||||
local from_id = msg.from.id
|
||||
if report_to_admin then
|
||||
utilities.send_message(self, config.admin, '#WARNUNG: Bot wurde in fremde Gruppe hinzugefügt:\nGruppenname: '..chat_name..' ('..chat_id..')\nHinzugefügt von: '..from..' ('..from_id..')')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return leave_group
|
@ -80,9 +80,9 @@ end
|
||||
|
||||
function stats:pre_process(msg, self)
|
||||
-- Ignore service msg
|
||||
if msg.service then -- check how Bot API handles service msgs, will update this
|
||||
if is_service_msg(msg) then
|
||||
print('Service message')
|
||||
return
|
||||
return msg
|
||||
end
|
||||
|
||||
if msg.left_chat_member then
|
||||
|
@ -631,6 +631,62 @@ function is_sudo(msg, config)
|
||||
return var
|
||||
end
|
||||
|
||||
function service_modify_msg(msg)
|
||||
if msg.new_chat_member then
|
||||
msg.text = '//tgservice new_chat_member'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.left_chat_member then
|
||||
msg.text = '//tgservice left_chat_member'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.new_chat_title then
|
||||
msg.text = '//tgservice new_chat_title'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.new_chat_photo then
|
||||
msg.text = '//tgservice new_chat_photo'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.group_chat_created then
|
||||
msg.text = '//tgservice group_chat_created'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.supergroup_chat_created then
|
||||
msg.text = '//tgservice supergroup_chat_created'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.channel_chat_created then
|
||||
msg.text = '//tgservice channel_chat_created'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.migrate_to_chat_id then
|
||||
msg.text = '//tgservice migrate_to_chat_id'
|
||||
msg.text_lower = msg.text
|
||||
elseif msg.migrate_from_chat_id then
|
||||
msg.text = '//tgservice migrate_from_chat_id'
|
||||
msg.text_lower = msg.text
|
||||
end
|
||||
return msg
|
||||
end
|
||||
|
||||
function is_service_msg(msg)
|
||||
local var = false
|
||||
if msg.new_chat_member then
|
||||
var = true
|
||||
elseif msg.left_chat_member then
|
||||
var = true
|
||||
elseif msg.new_chat_title then
|
||||
var = true
|
||||
elseif msg.new_chat_photo then
|
||||
var = true
|
||||
elseif msg.group_chat_created then
|
||||
var = true
|
||||
elseif msg.supergroup_chat_created then
|
||||
var = true
|
||||
elseif msg.channel_chat_created then
|
||||
var = true
|
||||
elseif msg.migrate_to_chat_id then
|
||||
var = true
|
||||
elseif msg.migrate_from_chat_id then
|
||||
var = true
|
||||
end
|
||||
return var
|
||||
end
|
||||
|
||||
function post_petition(url, arguments, headers)
|
||||
local url, h = string.gsub(url, "http://", "")
|
||||
local url, hs = string.gsub(url, "https://", "")
|
||||
|
Reference in New Issue
Block a user