remove debug

This commit is contained in:
Josh Fraser 2020-02-24 18:13:27 -08:00
parent c922bed060
commit a2d419d29c

19
bot.py
View File

@ -16,11 +16,9 @@ import os
from model import User, Message, MessageHide, UserBan, session from model import User, Message, MessageHide, UserBan, session
from time import strftime from time import strftime
import re import re
import json
import unidecode import unidecode
from mwt import MWT from mwt import MWT
from googletrans import Translator from googletrans import Translator
from textblob import TextBlob
class TelegramMonitorBot: class TelegramMonitorBot:
@ -28,12 +26,12 @@ class TelegramMonitorBot:
def __init__(self): def __init__(self):
self.debug = ( self.debug = (
(os.environ.get('DEBUG') is not None) and (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? # Are admins exempt from having messages checked?
self.admin_exempt = ( self.admin_exempt = (
(os.environ.get('ADMIN_EXEMPT') is not None) and (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): if (self.debug):
print("🔵 debug:", self.debug) print("🔵 debug:", self.debug)
@ -285,7 +283,6 @@ class TelegramMonitorBot:
print("👮‍♂️ Skipping checks. User is admin: {}".format(user.id)) print("👮‍♂️ Skipping checks. User is admin: {}".format(user.id))
else: else:
# Security checks # Security checks
print(json.dumps(update))
self.attachment_check(bot, update) self.attachment_check(bot, update)
self.security_check_username(bot, update) self.security_check_username(bot, update)
self.security_check_message(bot, update) self.security_check_message(bot, update)
@ -306,26 +303,20 @@ 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):
try: try:
s = session() s = session()
language_code = english_message = "" language_code = english_message = ""
polarity = subjectivity = 0.0
try: try:
# translate to English & log the original language
translator = Translator() translator = Translator()
translated = translator.translate(user_message) translated = translator.translate(user_message)
language_code = translated.src language_code = translated.src
english_message = translated.text 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: except Exception as e:
print(e.message) print(e.message)
msg1 = Message(user_id=user_id, message=user_message, chat_id=chat_id, msg1 = Message(user_id=user_id, message=user_message,
language_code=language_code, english_message=english_message, polarity=polarity, chat_id=chat_id, language_code=language_code, english_message=english_message)
subjectivity=subjectivity)
s.add(msg1) s.add(msg1)
s.commit() s.commit()
s.close() s.close()