Check if database is empty and remind user
This commit is contained in:
parent
2d56564e3c
commit
e95551a795
15
app.py
15
app.py
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
import logging
|
||||
from aiogram import executor
|
||||
from database import build
|
||||
|
||||
# from database import build
|
||||
from database import db, Member, Restriction
|
||||
|
||||
from load import dp, bot
|
||||
import filters
|
||||
|
@ -24,6 +24,16 @@ 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")
|
||||
|
||||
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")
|
||||
|
||||
from utils.notify_start import notify_started_bot
|
||||
await notify_started_bot(bot)
|
||||
|
||||
|
@ -43,7 +53,6 @@ async def on_shutdown(dp):
|
|||
await dp.storage.wait_closed()
|
||||
|
||||
def main() -> None:
|
||||
build()
|
||||
|
||||
if config.USE_WEBHOOK:
|
||||
executor.start_webhook(
|
||||
|
|
12
database.py
12
database.py
|
@ -61,7 +61,6 @@ class Member(Model):
|
|||
database = db
|
||||
|
||||
class Restriction(Model):
|
||||
# TODO: not forget rename all operation to action
|
||||
action = CharField()
|
||||
|
||||
from_user = ForeignKeyField(Member, lazy_load=True)
|
||||
|
@ -83,5 +82,12 @@ class Restriction(Model):
|
|||
db_table = "auditlog"
|
||||
database = db
|
||||
|
||||
def build() -> None:
|
||||
db.create_tables([Member,Restriction])
|
||||
# if not db.get_columns('members'):
|
||||
# db.create_tables([Member,Restriction])
|
||||
# logging.warning("Members table is empty, you need get data(run !reload)")
|
||||
#
|
||||
# if Member.select().count() == 0:
|
||||
# logging.warning("Members table is empty, you need get data(run !reload)")
|
||||
|
||||
# def build() -> None:
|
||||
# db.create_tables([Member,Restriction])
|
||||
|
|
|
@ -15,9 +15,8 @@ class AvaibleRolesFilter(BoundFilter):
|
|||
member = Member.search(Member.user_id,message.from_user.id)
|
||||
|
||||
if (member is None):
|
||||
return False
|
||||
|
||||
# member = database.search_single_member(Member.user_id,message.from_user.id)
|
||||
await message.answer("Something wrong: user not found in database(u should run !reload)")
|
||||
return
|
||||
|
||||
if (member.role == "owner"):
|
||||
return True
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import config
|
||||
|
||||
async def notify_started_bot(bot):
|
||||
await bot.send_message(config.second_group_id,"Bot started!")
|
||||
await bot.send_message(config.second_group_id,"Bot successfully launched!")
|
||||
|
|
Reference in New Issue