clean app.py

This commit is contained in:
hok7z 2023-01-13 10:22:32 +02:00
parent 9e40377104
commit c7e3ee2ba8
2 changed files with 21 additions and 13 deletions

14
app.py
View File

@ -24,17 +24,13 @@ WEBHOOK_PATH = f'/bot{config.token}/'
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
async def on_startup(dp):
if not db.get_columns('members'):
db.create_tables([Member,Restriction])
logging.warning("Member table is empty")
await bot.send_message(config.second_group_id, "First launch successful!")
await bot.send_message(config.second_group_id, "Member table is empty, run: `!reload`",parse_mode="Markdown")
from utils.notify_start import notify_started_bot, database_is_empty
elif Member.select().count() == 0:
await bot.send_message(config.second_group_id, "Member table is empty, run `!reload`",parse_mode="Markdown")
logging.warning("Member table is empty")
DATABASE_EMPTY = database_is_empty()
if DATABASE_EMPTY:
await bot.send_message(config.second_group_id,
"Member table is empty, run: `!reload`",parse_mode="Markdown")
from utils.notify_start import notify_started_bot
await notify_started_bot(bot)
from utils.default_commands import set_default_commands

View File

@ -1,4 +1,16 @@
import config
from database import Member, Restriction
from database import db
def database_is_empty():
if not db.get_columns("members"):
db.create_tables([Member, Restriction])
return True
elif not Member.select().count():
return True
return False
async def notify_started_bot(bot):
await bot.send_message(config.second_group_id,"Bot successfully launched!")