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
|
return
|
||||||
|
|
||||||
if self.id_exists(user.id):
|
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:
|
else:
|
||||||
add_user_success = self.add_user(
|
add_user_success = self.add_user(
|
||||||
user.id,
|
user.id,
|
||||||
@ -251,7 +252,8 @@ class TelegramMonitorBot:
|
|||||||
user.username)
|
user.username)
|
||||||
|
|
||||||
if add_user_success:
|
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))
|
print("User added: {}".format(user.id))
|
||||||
else:
|
else:
|
||||||
print("Something went wrong adding the user {}".format(user.id), file=sys.stderr)
|
print("Something went wrong adding the user {}".format(user.id), file=sys.stderr)
|
||||||
@ -301,10 +303,10 @@ class TelegramMonitorBot:
|
|||||||
return bool_set
|
return bool_set
|
||||||
|
|
||||||
|
|
||||||
def log_message(self, user_id, user_message):
|
def log_message(self, user_id, user_message, chat_id):
|
||||||
try:
|
try:
|
||||||
s = session()
|
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.add(msg1)
|
||||||
s.commit()
|
s.commit()
|
||||||
s.close()
|
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.orm import relationship, backref
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
import os
|
import os
|
||||||
@ -27,6 +27,7 @@ class Message(Base):
|
|||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False)
|
user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False)
|
||||||
message = Column(String)
|
message = Column(String)
|
||||||
|
chat_id = Column(BigInteger)
|
||||||
time = Column(DateTime, default=func.now())
|
time = Column(DateTime, default=func.now())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user