Admin and start handlers work. Added testing txt2img from first bot version (will be replaced soon)
This commit is contained in:
@@ -1 +1,8 @@
|
||||
pass
|
||||
from bot.common import dp, bot
|
||||
from .start import *
|
||||
from .all_messages import *
|
||||
|
||||
|
||||
def register():
|
||||
dp.register_message_handler(all_messages.sync_db_filter, lambda *_: not hasattr(bot, 'cloudmeta_message_text'))
|
||||
dp.register_message_handler(start.start_command, commands='start')
|
||||
|
||||
7
bot/handlers/initialize/all_messages.py
Normal file
7
bot/handlers/initialize/all_messages.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from aiogram.types import Message
|
||||
from bot.db.pull_db import pull
|
||||
|
||||
|
||||
async def sync_db_filter(message: Message):
|
||||
await pull()
|
||||
await message.reply(f'🔄️ Bot database synchronised. If you tried to run a command, run it again')
|
||||
@@ -1,7 +0,0 @@
|
||||
from bot.common import dp
|
||||
from bot.db.pull_db import pull
|
||||
|
||||
|
||||
@dp.message_handler()
|
||||
async def pull_db_if_new(_):
|
||||
await pull()
|
||||
23
bot/handlers/initialize/start.py
Normal file
23
bot/handlers/initialize/start.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from aiogram import types
|
||||
from bot.db import db, DBTables
|
||||
from bot.config import ADMIN
|
||||
from bot.utils.cooldown import throttle
|
||||
|
||||
|
||||
@throttle(10)
|
||||
async def start_command(message: types.Message):
|
||||
if message.from_id == ADMIN:
|
||||
await message.reply(f'👋 Hello, {message.from_user.username}. You are admin of this instance, '
|
||||
f'so we will check config for you now')
|
||||
if not isinstance(db[DBTables.config].get('admins'), list):
|
||||
db[DBTables.config]['admins'] = list()
|
||||
if ADMIN not in db[DBTables.config].get('admins'):
|
||||
admins_ = db[DBTables.config].get('admins')
|
||||
admins_.append(ADMIN)
|
||||
db[DBTables.config]['admins'] = admins_
|
||||
await db[DBTables.config].write()
|
||||
await message.reply(f'✅ Added {message.from_user.username} to admins. You can add other admins, '
|
||||
f'check bot settings menu')
|
||||
return
|
||||
|
||||
await message.reply(f'👋 Hello, {message.from_user.username}. Use /help to see available commands.')
|
||||
Reference in New Issue
Block a user