From 9bb0a85751b93de4a1b9e26cdb5200ee42bddfd2 Mon Sep 17 00:00:00 2001 From: Josh Fraser Date: Mon, 24 Feb 2020 18:04:26 -0800 Subject: [PATCH 1/3] temporary debug --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index 6303b98..ad1f3af 100644 --- a/bot.py +++ b/bot.py @@ -283,6 +283,7 @@ class TelegramMonitorBot: print("👮‍♂️ Skipping checks. User is admin: {}".format(user.id)) else: # Security checks + print(json.dumps(update)) self.attachment_check(bot, update) self.security_check_username(bot, update) self.security_check_message(bot, update) From c922bed0608d86ea071cdaf723c6874331065f39 Mon Sep 17 00:00:00 2001 From: Josh Fraser Date: Mon, 24 Feb 2020 18:09:16 -0800 Subject: [PATCH 2/3] quick prototype --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index d5a6e1d..1bbf27d 100644 --- a/bot.py +++ b/bot.py @@ -16,6 +16,7 @@ import os from model import User, Message, MessageHide, UserBan, session from time import strftime import re +import json import unidecode from mwt import MWT from googletrans import Translator From a2d419d29c7cc3f8a347275ad1764ce3904b301f Mon Sep 17 00:00:00 2001 From: Josh Fraser Date: Mon, 24 Feb 2020 18:13:27 -0800 Subject: [PATCH 3/3] remove debug --- bot.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/bot.py b/bot.py index 1bbf27d..6303b98 100644 --- a/bot.py +++ b/bot.py @@ -16,11 +16,9 @@ import os from model import User, Message, MessageHide, UserBan, session from time import strftime import re -import json import unidecode from mwt import MWT from googletrans import Translator -from textblob import TextBlob class TelegramMonitorBot: @@ -28,12 +26,12 @@ class TelegramMonitorBot: def __init__(self): self.debug = ( (os.environ.get('DEBUG') is not None) and - (os.environ.get('DEBUG').lower() != "false")) + (os.environ.get('DEBUG').upper() != "false")) # Are admins exempt from having messages checked? self.admin_exempt = ( (os.environ.get('ADMIN_EXEMPT') is not None) and - (os.environ.get('ADMIN_EXEMPT').lower() != "false")) + (os.environ.get('ADMIN_EXEMPT').upper() != "false")) if (self.debug): print("🔵 debug:", self.debug) @@ -285,7 +283,6 @@ class TelegramMonitorBot: print("👮‍♂️ Skipping checks. User is admin: {}".format(user.id)) else: # Security checks - print(json.dumps(update)) self.attachment_check(bot, update) self.security_check_username(bot, update) self.security_check_message(bot, update) @@ -306,26 +303,20 @@ class TelegramMonitorBot: return bool_set + def log_message(self, user_id, user_message, chat_id): try: s = session() language_code = english_message = "" - polarity = subjectivity = 0.0 try: - # translate to English & log the original language translator = Translator() translated = translator.translate(user_message) language_code = translated.src english_message = translated.text - # run basic sentiment analysis on the translated English string - analysis = TextBlob(english_message) - polarity = analysis.sentiment.polarity - subjectivity = analysis.sentiment.subjectivity except Exception as e: print(e.message) - msg1 = Message(user_id=user_id, message=user_message, chat_id=chat_id, - language_code=language_code, english_message=english_message, polarity=polarity, - subjectivity=subjectivity) + msg1 = Message(user_id=user_id, message=user_message, + chat_id=chat_id, language_code=language_code, english_message=english_message) s.add(msg1) s.commit() s.close()