Move notification chat to end of function

...So if notification channel is not set up right, it doesn't stop blocking from happening.
This commit is contained in:
Stan James 2018-06-28 11:54:17 -06:00
parent 7874dbfbfe
commit 68aa8b85b8

16
bot.py
View File

@ -79,8 +79,6 @@ class TelegramMonitorBot:
if self.debug: if self.debug:
update.message.reply_text(log_message) update.message.reply_text(log_message)
print(log_message) print(log_message)
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text="🤖:" + log_message)
# Ban the user # Ban the user
self.ban_user(update) self.ban_user(update)
# Log in database # Log in database
@ -91,6 +89,8 @@ class TelegramMonitorBot:
s.add(userBan) s.add(userBan)
s.commit() s.commit()
s.close() s.close()
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
if self.name_ban_re and self.name_ban_re.search(update.message.from_user.username or ''): if self.name_ban_re and self.name_ban_re.search(update.message.from_user.username or ''):
# Logging # Logging
@ -98,8 +98,6 @@ class TelegramMonitorBot:
if self.debug: if self.debug:
update.message.reply_text(log_message) update.message.reply_text(log_message)
print(log_message) print(log_message)
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
# Ban the user # Ban the user
self.ban_user(update) self.ban_user(update)
# Log in database # Log in database
@ -110,6 +108,8 @@ class TelegramMonitorBot:
s.add(userBan) s.add(userBan)
s.commit() s.commit()
s.close() s.close()
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
def security_check_message(self, bot, update): def security_check_message(self, bot, update):
@ -126,8 +126,6 @@ class TelegramMonitorBot:
if self.debug: if self.debug:
update.message.reply_text(log_message) update.message.reply_text(log_message)
print(log_message) print(log_message)
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
# Any message that causes a ban gets deleted # Any message that causes a ban gets deleted
update.message.delete() update.message.delete()
# Ban the user # Ban the user
@ -140,6 +138,8 @@ class TelegramMonitorBot:
s.add(userBan) s.add(userBan)
s.commit() s.commit()
s.close() s.close()
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
elif self.message_hide_re and self.message_hide_re.search(message): elif self.message_hide_re and self.message_hide_re.search(message):
# Logging # Logging
@ -147,8 +147,6 @@ class TelegramMonitorBot:
if self.debug: if self.debug:
update.message.reply_text(log_message) update.message.reply_text(log_message)
print(log_message) print(log_message)
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
# Delete the message # Delete the message
update.message.delete() update.message.delete()
# Log in database # Log in database
@ -159,6 +157,8 @@ class TelegramMonitorBot:
s.add(messageHide) s.add(messageHide)
s.commit() s.commit()
s.close() s.close()
# Notify channel
bot.sendMessage(chat_id=self.notify_chat, text=log_message)
def logger(self, bot, update): def logger(self, bot, update):