Обновить dorontools.py
This commit is contained in:
@@ -75,80 +75,6 @@ class JsonAsDict():
|
|||||||
data = _json.load(file)
|
data = _json.load(file)
|
||||||
return key in data
|
return key in data
|
||||||
|
|
||||||
class PyrogramLogger():
|
|
||||||
def __init__(self, conn):
|
|
||||||
self.conn = conn
|
|
||||||
self.cursor = conn.cursor()
|
|
||||||
self.cursor.execute('''
|
|
||||||
CREATE TABLE IF NOT EXISTS msgs (
|
|
||||||
id SERIAL PRIMARY KEY,
|
|
||||||
datetime TEXT,
|
|
||||||
chatid BIGINT,
|
|
||||||
chattitle TEXT,
|
|
||||||
msgid BIGINT,
|
|
||||||
userid BIGINT,
|
|
||||||
firstname TEXT,
|
|
||||||
lastname TEXT,
|
|
||||||
username TEXT,
|
|
||||||
text TEXT
|
|
||||||
)
|
|
||||||
''')
|
|
||||||
conn.commit()
|
|
||||||
|
|
||||||
def log(self, message):
|
|
||||||
msg = _json.loads(str(message))
|
|
||||||
# try:
|
|
||||||
title = msg['chat'].get('title')
|
|
||||||
if title == None:
|
|
||||||
title = msg['chat'].get('first_name')
|
|
||||||
|
|
||||||
userid = None
|
|
||||||
firstname = None
|
|
||||||
lastname = None
|
|
||||||
username = None
|
|
||||||
if msg.get('from_user') != None:
|
|
||||||
userid = msg['from_user']['id']
|
|
||||||
firstname = msg['from_user']['first_name']
|
|
||||||
lastname = msg['from_user'].get('last_name')
|
|
||||||
username = msg['from_user'].get('username')
|
|
||||||
|
|
||||||
text = msg.get('text')
|
|
||||||
if text == None:
|
|
||||||
text = msg.get('caption')
|
|
||||||
|
|
||||||
self.cursor.execute('INSERT INTO msgs (datetime, chatid, chattitle, msgid, userid, firstname, lastname, username, text) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)',
|
|
||||||
(msg.get('date'),
|
|
||||||
msg['chat']['id'],
|
|
||||||
title,
|
|
||||||
msg['id'],
|
|
||||||
userid,
|
|
||||||
firstname,
|
|
||||||
lastname,
|
|
||||||
username,
|
|
||||||
text))
|
|
||||||
self.conn.commit()
|
|
||||||
# except Exception as e:
|
|
||||||
# filename = f'{e}.json'
|
|
||||||
# with open(filename, 'w', encoding='utf-8') as file:
|
|
||||||
# _json.dump(msg, file, indent=4)
|
|
||||||
# print(filename, 'saved')
|
|
||||||
|
|
||||||
def logredacted(self, message):
|
|
||||||
self.cursor.execute("SELECT text FROM msgs WHERE chatid = %s AND msgid = %s", (message.chat.id, message.id))
|
|
||||||
oldtext = self.cursor.fetchall()
|
|
||||||
if oldtext != [] and message.text:
|
|
||||||
oldtext = oldtext[0][0]
|
|
||||||
self.cursor.execute("UPDATE msgs SET text = %s WHERE chatid = %s AND msgid = %s", (oldtext + '\n\nREDACTED TO\n\n' + message.text, message.chat.id, message.id))
|
|
||||||
self.conn.commit()
|
|
||||||
|
|
||||||
def logdeleted(self, message):
|
|
||||||
self.cursor.execute("SELECT text FROM msgs WHERE msgid = " + str(message.id))
|
|
||||||
oldtext = self.cursor.fetchall()
|
|
||||||
if oldtext != []:
|
|
||||||
oldtext = oldtext[0][0]
|
|
||||||
self.cursor.execute("UPDATE msgs SET text = %s WHERE msgid = %s", (oldtext + '\n\nDELETED', message.id))
|
|
||||||
self.conn.commit()
|
|
||||||
|
|
||||||
class TelebotLogger():
|
class TelebotLogger():
|
||||||
def __init__(self, conn):
|
def __init__(self, conn):
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
|
|||||||
Reference in New Issue
Block a user