-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
41 lines (32 loc) · 1.01 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from aiotg import Bot, Chat
from db import KekDB
from typing import List
class QuoteManager(object):
def __init__(self):
"""
Load and preprocess quotes from db
"""
self.db = KekDB()
db_quotes = self.db.get_quotes_sync()
self.quotes: List[dict] = list(filter(any, map(self.preprocess_quote, db_quotes)))
def preprocess_quote(self, db_quote: dict) -> dict:
"""
Check quotes from db, apply some default values, throw incorrect quotes
"""
pass
class HistoryLogger(object):
db = KekDB()
@staticmethod
def log(chat: Chat):
"""
Prepare message and write it to db
"""
chat_id = chat.id
message = chat.message
text = chat.message.get('text')
sticker = chat.message.get('sticker')
timestamp = chat.message['date']
# anonymize
message.pop('from')
message.pop('chat')
HistoryLogger.db.log_history(chat_id, message, text, sticker, timestamp)