allow gifs(telegram Documents with mime_type of video/mp4)
This commit is contained in:
parent
9bc388a036
commit
fd2f50135b
21
bot.py
21
bot.py
@ -73,6 +73,11 @@ class TelegramMonitorBot:
|
|||||||
re.IGNORECASE | re.VERBOSE)
|
re.IGNORECASE | re.VERBOSE)
|
||||||
if self.name_ban_patterns else None)
|
if self.name_ban_patterns else None)
|
||||||
|
|
||||||
|
# Mime type document check
|
||||||
|
# NOTE: All gifs appear to be converted to video/mp4
|
||||||
|
mime_types = os.environ.get('ALLOWED_MIME_TYPES', 'video/mp4')
|
||||||
|
self.allowed_mime_types = set(map(lambda s: s.strip(), mime_types.split(',')))
|
||||||
|
|
||||||
|
|
||||||
@MWT(timeout=60*60)
|
@MWT(timeout=60*60)
|
||||||
def get_admin_ids(self, bot, chat_id):
|
def get_admin_ids(self, bot, chat_id):
|
||||||
@ -210,6 +215,10 @@ class TelegramMonitorBot:
|
|||||||
update.message.voice):
|
update.message.voice):
|
||||||
# Logging
|
# Logging
|
||||||
if update.message.document:
|
if update.message.document:
|
||||||
|
# GIFs are documents and allowed
|
||||||
|
mime_type = update.message.document.mime_type
|
||||||
|
if mime_type and mime_type in self.allowed_mime_types:
|
||||||
|
return
|
||||||
log_message = "❌ HIDE DOCUMENT: {}".format(update.message.document.__dict__)
|
log_message = "❌ HIDE DOCUMENT: {}".format(update.message.document.__dict__)
|
||||||
else:
|
else:
|
||||||
log_message = "❌ HIDE NON-DOCUMENT ATTACHMENT"
|
log_message = "❌ HIDE NON-DOCUMENT ATTACHMENT"
|
||||||
@ -289,7 +298,7 @@ class TelegramMonitorBot:
|
|||||||
self.security_check_message(bot, update)
|
self.security_check_message(bot, update)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error: {}".format(e))
|
print("Error[292]: {}".format(e))
|
||||||
print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e)
|
print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e)
|
||||||
|
|
||||||
# DB queries
|
# DB queries
|
||||||
@ -305,6 +314,10 @@ class TelegramMonitorBot:
|
|||||||
return bool_set
|
return bool_set
|
||||||
|
|
||||||
def log_message(self, user_id, user_message, chat_id):
|
def log_message(self, user_id, user_message, chat_id):
|
||||||
|
|
||||||
|
if user_message is None:
|
||||||
|
user_message = "[NO MESSAGE]"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = session()
|
s = session()
|
||||||
language_code = english_message = ""
|
language_code = english_message = ""
|
||||||
@ -320,7 +333,7 @@ class TelegramMonitorBot:
|
|||||||
polarity = analysis.sentiment.polarity
|
polarity = analysis.sentiment.polarity
|
||||||
subjectivity = analysis.sentiment.subjectivity
|
subjectivity = analysis.sentiment.subjectivity
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e.message)
|
print(str(e))
|
||||||
msg1 = Message(user_id=user_id, message=user_message, chat_id=chat_id,
|
msg1 = Message(user_id=user_id, message=user_message, chat_id=chat_id,
|
||||||
language_code=language_code, english_message=english_message, polarity=polarity,
|
language_code=language_code, english_message=english_message, polarity=polarity,
|
||||||
subjectivity=subjectivity)
|
subjectivity=subjectivity)
|
||||||
@ -328,7 +341,7 @@ class TelegramMonitorBot:
|
|||||||
s.commit()
|
s.commit()
|
||||||
s.close()
|
s.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error: {}".format(e))
|
print("Error logging message: {}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def add_user(self, user_id, first_name, last_name, username):
|
def add_user(self, user_id, first_name, last_name, username):
|
||||||
@ -344,7 +357,7 @@ class TelegramMonitorBot:
|
|||||||
s.close()
|
s.close()
|
||||||
return self.id_exists(user_id)
|
return self.id_exists(user_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error: {}".format(e))
|
print("Error[347]: {}".format(e))
|
||||||
|
|
||||||
|
|
||||||
def error(self, bot, update, error):
|
def error(self, bot, update, error):
|
||||||
|
Loading…
Reference in New Issue
Block a user