Skeleton of project - database loading
This commit is contained in:
32
bot/db/db_model.py
Normal file
32
bot/db/db_model.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from sqlitedict import SqliteDict
|
||||
from bot.common import bot
|
||||
from bot.config import DB_CHAT, DB
|
||||
from aiogram.types import InputFile, InputMediaDocument
|
||||
from aiogram.utils.exceptions import MessageToEditNotFound
|
||||
import time
|
||||
from .meta import DBMeta
|
||||
|
||||
|
||||
class DBTables:
|
||||
tables = ['config', 'cooldown']
|
||||
config = "config"
|
||||
cooldown = "cooldown"
|
||||
|
||||
|
||||
class DBDict(SqliteDict):
|
||||
async def write(self):
|
||||
try:
|
||||
DBMeta()[DBMeta.update_time] = time.time_ns()
|
||||
await bot.edit_message_media(media=InputMediaDocument(InputFile(DB)),
|
||||
chat_id=DB_CHAT, message_id=DBMeta()[DBMeta.message_id])
|
||||
await bot.edit_message_caption(
|
||||
caption=DBMeta(), chat_id=DB_CHAT, message_id=DBMeta()[DBMeta.message_id]
|
||||
)
|
||||
except MessageToEditNotFound:
|
||||
DBMeta()[DBMeta.update_time] = time.time_ns()
|
||||
self['db_message_id'] = (await bot.send_document(chat_id=DB_CHAT, document=InputFile(DB),
|
||||
disable_notification=True)).message_id
|
||||
DBMeta()[DBMeta.message_id] = self['db_message_id']
|
||||
await bot.edit_message_caption(
|
||||
caption=DBMeta(), chat_id=DB_CHAT, message_id=self.get('db_message_id')
|
||||
)
|
||||
Reference in New Issue
Block a user