log chat IDs
This commit is contained in:
parent
5e6f9b4eba
commit
b1a57bb917
10
bot.py
10
bot.py
@ -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()
|
||||
|
3
model.py
3
model.py
@ -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())
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user