log chat IDs

This commit is contained in:
Josh Fraser 2020-01-24 17:51:34 -08:00
parent 5e6f9b4eba
commit b1a57bb917
2 changed files with 8 additions and 5 deletions

10
bot.py
View File

@ -242,7 +242,8 @@ class TelegramMonitorBot:
return
if self.id_exists(user.id):
self.log_message(user.id, update.message.text)
self.log_message(user.id, update.message.text,
update.message.chat_id)
else:
add_user_success = self.add_user(
user.id,
@ -251,7 +252,8 @@ class TelegramMonitorBot:
user.username)
if add_user_success:
self.log_message(user.id, update.message.text)
self.log_message(
user.id, update.message.text, update.message.chat_id)
print("User added: {}".format(user.id))
else:
print("Something went wrong adding the user {}".format(user.id), file=sys.stderr)
@ -301,10 +303,10 @@ class TelegramMonitorBot:
return bool_set
def log_message(self, user_id, user_message):
def log_message(self, user_id, user_message, chat_id):
try:
s = session()
msg1 = Message(user_id=user_id, message=user_message)
msg1 = Message(user_id=user_id, message=user_message, chat_id=chat_id)
s.add(msg1)
s.commit()
s.close()

View File

@ -1,4 +1,4 @@
from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func
from sqlalchemy import Column, DateTime, BigInteger, String, Integer, ForeignKey, func
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
import os
@ -27,6 +27,7 @@ class Message(Base):
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False)
message = Column(String)
chat_id = Column(BigInteger)
time = Column(DateTime, default=func.now())