Check if database is empty and remind user
This commit is contained in:
parent
2d56564e3c
commit
e95551a795
17
app.py
17
app.py
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import logging
|
import logging
|
||||||
from aiogram import executor
|
from aiogram import executor
|
||||||
from database import build
|
# from database import build
|
||||||
|
from database import db, Member, Restriction
|
||||||
|
|
||||||
from load import dp, bot
|
from load import dp, bot
|
||||||
import filters
|
import filters
|
||||||
|
@ -24,6 +24,16 @@ WEBHOOK_PATH = f'/bot{config.token}/'
|
||||||
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
|
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
|
||||||
|
|
||||||
async def on_startup(dp):
|
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
|
from utils.notify_start import notify_started_bot
|
||||||
await notify_started_bot(bot)
|
await notify_started_bot(bot)
|
||||||
|
|
||||||
|
@ -43,8 +53,7 @@ async def on_shutdown(dp):
|
||||||
await dp.storage.wait_closed()
|
await dp.storage.wait_closed()
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
build()
|
|
||||||
|
|
||||||
if config.USE_WEBHOOK:
|
if config.USE_WEBHOOK:
|
||||||
executor.start_webhook(
|
executor.start_webhook(
|
||||||
dispatcher=dp,
|
dispatcher=dp,
|
||||||
|
|
12
database.py
12
database.py
|
@ -61,7 +61,6 @@ class Member(Model):
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
class Restriction(Model):
|
class Restriction(Model):
|
||||||
# TODO: not forget rename all operation to action
|
|
||||||
action = CharField()
|
action = CharField()
|
||||||
|
|
||||||
from_user = ForeignKeyField(Member, lazy_load=True)
|
from_user = ForeignKeyField(Member, lazy_load=True)
|
||||||
|
@ -83,5 +82,12 @@ class Restriction(Model):
|
||||||
db_table = "auditlog"
|
db_table = "auditlog"
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
def build() -> None:
|
# if not db.get_columns('members'):
|
||||||
db.create_tables([Member,Restriction])
|
# 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)
|
member = Member.search(Member.user_id,message.from_user.id)
|
||||||
|
|
||||||
if (member is None):
|
if (member is None):
|
||||||
return False
|
await message.answer("Something wrong: user not found in database(u should run !reload)")
|
||||||
|
return
|
||||||
# member = database.search_single_member(Member.user_id,message.from_user.id)
|
|
||||||
|
|
||||||
if (member.role == "owner"):
|
if (member.role == "owner"):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import config
|
import config
|
||||||
|
|
||||||
async def notify_started_bot(bot):
|
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