clean app.py
This commit is contained in:
parent
9e40377104
commit
c7e3ee2ba8
22
app.py
22
app.py
|
@ -24,19 +24,15 @@ 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'):
|
from utils.notify_start import notify_started_bot, database_is_empty
|
||||||
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)
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
await notify_started_bot(bot)
|
||||||
|
|
||||||
from utils.default_commands import set_default_commands
|
from utils.default_commands import set_default_commands
|
||||||
await set_default_commands(dp)
|
await set_default_commands(dp)
|
||||||
|
|
||||||
|
@ -58,7 +54,7 @@ async def on_shutdown(dp):
|
||||||
await dp.storage.wait_closed()
|
await dp.storage.wait_closed()
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
||||||
if config.USE_WEBHOOK:
|
if config.USE_WEBHOOK:
|
||||||
executor.start_webhook(
|
executor.start_webhook(
|
||||||
dispatcher=dp,
|
dispatcher=dp,
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
import config
|
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):
|
async def notify_started_bot(bot):
|
||||||
await bot.send_message(config.second_group_id,"Bot successfully launched!")
|
await bot.send_message(config.second_group_id,"Bot successfully launched!")
|
||||||
|
|
Reference in New Issue