From 66b6da88ad9f0811b852ad02405379f0fdceee1d Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Sat, 11 Mar 2023 23:13:55 +0200 Subject: [PATCH] `config` command now works fully --- bot/callbacks/common.py | 5 +-- bot/callbacks/config/__init__.py | 23 +++++++++- bot/callbacks/config/admin_settings.py | 51 +++++++++++++++++++++ bot/callbacks/config/global_settings.py | 41 +++++++++++++++++ bot/callbacks/config/prompt_settings.py | 47 +++++++++++++++++++ bot/callbacks/factories/common.py | 4 -- bot/callbacks/factories/config.py | 5 +-- bot/callbacks/register.py | 4 +- bot/db/db.py | 1 + bot/db/db_model.py | 3 +- bot/handlers/admin/aliases.py | 25 ++++++----- bot/handlers/admin/reset.py | 5 ++- bot/handlers/initialize/__init__.py | 3 ++ bot/handlers/initialize/all_messages.py | 15 +++++++ bot/handlers/txt2img/set_settings.py | 60 ++++++++++++------------- bot/keyboards/config.py | 56 ++++++++++++++++++++--- bot/keyboards/set_model.py | 3 +- bot/modules/api/objects/action.py | 9 ++++ 18 files changed, 297 insertions(+), 63 deletions(-) create mode 100644 bot/callbacks/config/admin_settings.py create mode 100644 bot/callbacks/config/global_settings.py create mode 100644 bot/callbacks/config/prompt_settings.py delete mode 100644 bot/callbacks/factories/common.py create mode 100644 bot/modules/api/objects/action.py diff --git a/bot/callbacks/common.py b/bot/callbacks/common.py index 9fba9e1..b24fe47 100644 --- a/bot/callbacks/common.py +++ b/bot/callbacks/common.py @@ -1,6 +1,5 @@ from bot.common import dp -from bot.callbacks.factories.common import close_keyboard_data -from aiogram import types +from aiogram import types, filters from bot.utils.private_keyboard import other_user @@ -12,4 +11,4 @@ async def on_close_keyboard(call: types.CallbackQuery): def register(): - dp.register_callback_query_handler(on_close_keyboard, close_keyboard_data.filter()) + dp.register_callback_query_handler(on_close_keyboard, filters.Text("close_keyboard")) diff --git a/bot/callbacks/config/__init__.py b/bot/callbacks/config/__init__.py index 2ae2839..7b58079 100644 --- a/bot/callbacks/config/__init__.py +++ b/bot/callbacks/config/__init__.py @@ -1 +1,22 @@ -pass +from bot.common import dp +from bot.keyboards.config import get_config_keyboard +from bot.utils.private_keyboard import other_user +from aiogram import types, filters +from .prompt_settings import register +from .global_settings import register +from .admin_settings import register + + +async def back_to_config(call: types.CallbackQuery): + if await other_user(call): + return + + await call.message.edit_text("⚙️ Configuration:") + await call.message.edit_reply_markup(get_config_keyboard(call.from_user.id)) + + +def register(): + prompt_settings.register() + global_settings.register() + admin_settings.register() + dp.register_callback_query_handler(back_to_config, filters.Text('config_back')) diff --git a/bot/callbacks/config/admin_settings.py b/bot/callbacks/config/admin_settings.py new file mode 100644 index 0000000..c8f3b53 --- /dev/null +++ b/bot/callbacks/config/admin_settings.py @@ -0,0 +1,51 @@ +from bot.common import dp +from ..factories import config as config_factory +from bot.utils.private_keyboard import other_user +from bot.modules.api.objects.action import Action +from bot.db import db, DBTables +from aiogram import types, filters + + +async def on_admin_settings_kb_open(call: types.CallbackQuery): + from bot.keyboards.config import get_admin_settings_keyboard + if await other_user(call): + return + + await call.message.edit_text("⚙️ Administrative configuration", reply_markup=get_admin_settings_keyboard()) + + +async def on_admin_settings_set(call: types.CallbackQuery, callback_data: dict): + overload = callback_data['setting'] + if await other_user(call): + return + + db[DBTables.actions][call.from_user.id] = Action( + chat_id=call.message.chat.id, + action_module='config.admin_settings', + action='on_admin_settings_action', + overload=overload + ) + + await call.message.edit_text( + f"⚒️ Type id or answer to message of this user to {'add' if 'add' in overload else 'remove'} admin: " + if 'aliases' in overload and 'admin' in overload and ('add' in overload or 'remove' in overload) + else f"⚒️ Type new endpoint address: " if "aliases.set_endpoint" in overload + else f"⚒️ Type \"reset\" if you REALLY want to reset queue: " if "reset.resetqueue" in overload + else f"❌ Not found...", + reply_markup=types.InlineKeyboardMarkup().add(types.InlineKeyboardButton( + "👈 Back", + callback_data="admin_settings_kb") + ) + ) + + +async def on_admin_settings_action(message: types.Message, overload): + assert message + from bot.handlers import admin + assert admin + await eval(f"admin.{overload}(message, is_command=False)") + + +def register(): + dp.register_callback_query_handler(on_admin_settings_set, config_factory.admin_settings_data.filter()) + dp.register_callback_query_handler(on_admin_settings_kb_open, filters.Text("admin_settings_kb")) diff --git a/bot/callbacks/config/global_settings.py b/bot/callbacks/config/global_settings.py new file mode 100644 index 0000000..fcc9750 --- /dev/null +++ b/bot/callbacks/config/global_settings.py @@ -0,0 +1,41 @@ +from bot.common import dp +from bot.utils.private_keyboard import other_user +from bot.db import db, DBTables +from aiogram import types, filters +from bot.utils.errorable_command import wrap_exception +from bot.utils.cooldown import throttle + + +async def on_global_settings_kb_open(call: types.CallbackQuery): + from bot.keyboards.config import get_global_settings_keyboard + if await other_user(call): + return + + await call.message.edit_text("⚙️ Global configuration", reply_markup=get_global_settings_keyboard()) + + +@wrap_exception() +@throttle(cooldown=60*60, admin_ids=db[DBTables.config].get('admins'), by_id=False) +async def on_set_model(call: types.CallbackQuery): + from bot.keyboards.set_model import get_set_model_keyboard + from bot.modules.api.models import get_models + + if await other_user(call): + return + + models = await get_models() + if models is not None and len(models) > 0: + db[DBTables.config]['models'] = models + else: + await call.answer('❌ No models available', show_alert=True) + return + + await call.message.edit_text("🪄 You can choose model from available:", + reply_markup=get_set_model_keyboard(0).add( + types.InlineKeyboardButton("👈 Back", callback_data="global_settings_kb") + )) + + +def register(): + dp.register_callback_query_handler(on_set_model, filters.Text("global_settings_set_model")) + dp.register_callback_query_handler(on_global_settings_kb_open, filters.Text("global_settings_kb")) diff --git a/bot/callbacks/config/prompt_settings.py b/bot/callbacks/config/prompt_settings.py new file mode 100644 index 0000000..6d93a4f --- /dev/null +++ b/bot/callbacks/config/prompt_settings.py @@ -0,0 +1,47 @@ +from bot.common import dp +from ..factories import config as config_factory +from bot.utils.private_keyboard import other_user +from bot.modules.api.objects.action import Action +from bot.db import db, DBTables +from aiogram import types, filters + + +async def on_prompt_settings_kb_open(call: types.CallbackQuery): + from bot.keyboards.config import get_prompt_settings_keyboard + if await other_user(call): + return + + await call.message.edit_text("⚙️ Prompt configuration", reply_markup=get_prompt_settings_keyboard()) + + +async def on_prompt_settings_set(call: types.CallbackQuery, callback_data: dict): + overload = callback_data['setting'] + if await other_user(call): + return + + db[DBTables.actions][call.from_user.id] = Action( + chat_id=call.message.chat.id, + action_module='config.prompt_settings', + action='on_prompt_settings_action', + overload=overload + ) + + await call.message.edit_text( + f"⚒️ Type new {overload} value in this chat: ", + reply_markup=types.InlineKeyboardMarkup().add(types.InlineKeyboardButton( + "👈 Back", + callback_data="prompt_settings_kb") + ) + ) + + +async def on_prompt_settings_action(message: types.Message, overload): + assert message + from bot.handlers.txt2img import set_settings + assert set_settings + await eval(f"set_settings.set_{overload}_command(message, is_command=False)") + + +def register(): + dp.register_callback_query_handler(on_prompt_settings_set, config_factory.prompt_settings_data.filter()) + dp.register_callback_query_handler(on_prompt_settings_kb_open, filters.Text("prompt_settings_kb")) diff --git a/bot/callbacks/factories/common.py b/bot/callbacks/factories/common.py deleted file mode 100644 index d399fcb..0000000 --- a/bot/callbacks/factories/common.py +++ /dev/null @@ -1,4 +0,0 @@ -from aiogram.utils.callback_data import CallbackData - - -close_keyboard_data = CallbackData("close_keyboard") diff --git a/bot/callbacks/factories/config.py b/bot/callbacks/factories/config.py index dd8014e..e76a885 100644 --- a/bot/callbacks/factories/config.py +++ b/bot/callbacks/factories/config.py @@ -1,6 +1,5 @@ from aiogram.utils.callback_data import CallbackData -prompt_settings_data = CallbackData("prompt_settings") -global_settings_data = CallbackData("global_settings") -admin_settings_data = CallbackData("admin_settings") +prompt_settings_data = CallbackData("prompt_settings_set", "setting") +admin_settings_data = CallbackData("admin_settings_set", "setting") diff --git a/bot/callbacks/register.py b/bot/callbacks/register.py index d5169c6..5ea3184 100644 --- a/bot/callbacks/register.py +++ b/bot/callbacks/register.py @@ -6,12 +6,14 @@ def register_callbacks(): exception, image_info, set_model, - common + common, + config ) exception.register() image_info.register() set_model.register() common.register() + config.register() print('[gray]All callbacks registered[/]') diff --git a/bot/db/db.py b/bot/db/db.py index 7f6381b..17e8633 100644 --- a/bot/db/db.py +++ b/bot/db/db.py @@ -12,5 +12,6 @@ db = { 'exceptions': DBDict(DB, autocommit=True, tablename='exceptions'), 'queue': DBDict(DB, autocommit=True, tablename='queue'), 'generated': DBDict(DB, autocommit=True, tablename='generated'), + 'actions': DBDict(DB, autocommit=True, tablename='actions'), 'prompts': DBDict(DB, autocommit=True, tablename='prompts') } diff --git a/bot/db/db_model.py b/bot/db/db_model.py index 970a0e1..4407f0a 100644 --- a/bot/db/db_model.py +++ b/bot/db/db_model.py @@ -8,12 +8,13 @@ from .meta import DBMeta class DBTables: - tables = ['config', 'cooldown', 'exceptions', 'queue', 'generated', 'prompts'] + tables = ['config', 'cooldown', 'exceptions', 'queue', 'generated', 'actions', 'prompts'] config = "config" cooldown = "cooldown" exceptions = "exceptions" queue = "queue" generated = "generated" + actions = "actions" prompts = "prompts" diff --git a/bot/handlers/admin/aliases.py b/bot/handlers/admin/aliases.py index c44180c..b6d47aa 100644 --- a/bot/handlers/admin/aliases.py +++ b/bot/handlers/admin/aliases.py @@ -6,17 +6,18 @@ from bot.utils.cooldown import throttle @throttle(5) -async def set_endpoint(message: types.Message): +async def set_endpoint(message: types.Message, is_command: bool = True): if message.from_id not in db[DBTables.config].get('admins') and message.from_id != ADMIN: await message.reply('❌ You are not permitted to do that. ' 'It is only for this bot instance maintainers and admins') return - if not message.get_args() or not validators.url(message.get_args()): + if not (message.get_args() if is_command else message.text) or not \ + validators.url((message.get_args() if is_command else message.text)): await message.reply("❌ Specify correct url for endpoint") return - db[DBTables.config]['endpoint'] = encrypt(message.get_args()) + db[DBTables.config]['endpoint'] = encrypt((message.get_args() if is_command else message.text)) await db[DBTables.config].write() @@ -24,18 +25,19 @@ async def set_endpoint(message: types.Message): @throttle(5) -async def add_admin(message: types.Message): +async def add_admin(message: types.Message, is_command: bool = True): if message.from_id != ADMIN: await message.reply('❌ You are not permitted to do that. It is only for main admin') return - if not message.get_args().isdecimal() and not hasattr(message.reply_to_message, 'text'): + if not (message.get_args() if is_command else message.text).isdecimal() and not \ + hasattr(message.reply_to_message, 'text'): await message.reply('❌ Put new admin ID to command arguments or answer to users message') return - elif not message.get_args().isdecimal(): + elif not (message.get_args() if is_command else message.text).isdecimal(): ID = message.reply_to_message.from_id elif not hasattr(message.reply_to_message, 'text'): - ID = int(message.get_args()) + ID = int((message.get_args() if is_command else message.text)) if not isinstance(db[DBTables.config].get('admins'), list): db[DBTables.config]['admins'] = list() @@ -54,18 +56,19 @@ async def add_admin(message: types.Message): @throttle(5) -async def remove_admin(message: types.Message): +async def remove_admin(message: types.Message, is_command: bool = True): if message.from_id != ADMIN: await message.reply('❌ You are not permitted to do that. It is only for main admin') return - if not message.get_args().isdecimal() and not hasattr(message.reply_to_message, 'text'): + if not (message.get_args() if is_command else message.text).isdecimal() and not \ + hasattr(message.reply_to_message, 'text'): await message.reply('❌ Put admin ID to command arguments or answer to users message') return - elif not message.get_args().isdecimal(): + elif not (message.get_args() if is_command else message.text).isdecimal(): ID = message.reply_to_message.from_id elif not hasattr(message.reply_to_message, 'text'): - ID = int(message.get_args()) + ID = int((message.get_args() if is_command else message.text)) if not isinstance(db[DBTables.config].get('admins'), list): db[DBTables.config]['admins'] = list() diff --git a/bot/handlers/admin/reset.py b/bot/handlers/admin/reset.py index 076a209..843ee22 100644 --- a/bot/handlers/admin/reset.py +++ b/bot/handlers/admin/reset.py @@ -5,12 +5,15 @@ from bot.utils.cooldown import throttle @throttle(5) -async def resetqueue(message: types.Message): +async def resetqueue(message: types.Message, is_command: bool = True): if message.from_id not in db[DBTables.config].get('admins') and message.from_id != ADMIN: await message.reply('❌ You are not permitted to do that. ' 'It is only for this bot instance maintainers and admins') return + if is_command and message.text.lower() != 'reset': + return + db[DBTables.queue]['n'] = 0 await db[DBTables.config].write() diff --git a/bot/handlers/initialize/__init__.py b/bot/handlers/initialize/__init__.py index acb0de8..0450951 100644 --- a/bot/handlers/initialize/__init__.py +++ b/bot/handlers/initialize/__init__.py @@ -1,8 +1,11 @@ from bot.common import dp, bot from .start import * from .all_messages import * +from bot.db import db, DBTables def register(): dp.register_message_handler(all_messages.sync_db_filter, lambda *_: not hasattr(bot, 'cloudmeta_message_text')) + dp.register_message_handler(all_messages.on_action_message, + lambda message: str(message.from_id) in list(db[DBTables.actions].keys())) dp.register_message_handler(start.start_command, commands='start') diff --git a/bot/handlers/initialize/all_messages.py b/bot/handlers/initialize/all_messages.py index 16a8aa3..2753497 100644 --- a/bot/handlers/initialize/all_messages.py +++ b/bot/handlers/initialize/all_messages.py @@ -1,4 +1,6 @@ from aiogram.types import Message +from bot.db import db, DBTables +from bot.modules.api.objects.action import Action async def sync_db_filter(message: Message): @@ -10,3 +12,16 @@ async def sync_db_filter(message: Message): f'If you tried to run a command, run it again') if not await ping(): await message.reply('⚠️ Warning: StableDiffusion server is turned off or api endpoint is incorrect') + + +async def on_action_message(message: Message): + action: Action = db[DBTables.actions].get(message.from_id) + if not action: + return + if action.chat_id != message.chat.id: + return + del db[DBTables.actions][message.from_id] + + import bot.callbacks + assert bot.callbacks + await eval(f"bot.callbacks.{action.action_module}.{action.action}(message, '{action.overload}')") diff --git a/bot/handlers/txt2img/set_settings.py b/bot/handlers/txt2img/set_settings.py index 5c8dfa2..7f778ae 100644 --- a/bot/handlers/txt2img/set_settings.py +++ b/bot/handlers/txt2img/set_settings.py @@ -6,9 +6,9 @@ from bot.utils.errorable_command import wrap_exception @wrap_exception(custom_loading=True) -async def _set_property(message: types.Message, prop: str, value=None): +async def _set_property(message: types.Message, prop: str, value=None, is_command: bool = True): temp_message = await message.reply(f"⏳ Setting {prop}...") - if not message.get_args(): + if not message.get_args() and is_command: await temp_message.edit_text("😶‍🌫️ Specify arguments for this command. Check /help") return @@ -20,9 +20,9 @@ async def _set_property(message: types.Message, prop: str, value=None): f"jacket, outdoors, streets", parse_mode='HTML') return elif prompt is None: - prompt = Prompt(message.get_args(), creator=message.from_id) + prompt = Prompt((message.get_args() if is_command else message.text), creator=message.from_id) - prompt.__setattr__(prop, message.get_args() if value is None else value) + prompt.__setattr__(prop, (message.get_args() if is_command else message.text) if value is None else value) prompt.creator = message.from_id db[DBTables.prompts][message.from_id] = prompt @@ -33,19 +33,19 @@ async def _set_property(message: types.Message, prop: str, value=None): @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_prompt_command(message: types.Message): - await _set_property(message, 'prompt') +async def set_prompt_command(message: types.Message, is_command: bool = True): + await _set_property(message, 'prompt', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_negative_prompt_command(message: types.Message): - await _set_property(message, 'negative_prompt') +async def set_negative_prompt_command(message: types.Message, is_command: bool = True): + await _set_property(message, 'negative_prompt', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_steps_command(message: types.Message): +async def set_steps_command(message: types.Message, is_command: bool = True): try: - _ = int(message.get_args()) + _ = int((message.get_args() if is_command else message.text)) except Exception as e: assert e await message.reply('❌ Specify number as argument') @@ -55,25 +55,25 @@ async def set_steps_command(message: types.Message): await message.reply('❌ Specify number <= 30') return - await _set_property(message, 'steps') + await _set_property(message, 'steps', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_cfg_scale_command(message: types.Message): +async def set_cfg_scale_command(message: types.Message, is_command: bool = True): try: - _ = int(message.get_args()) + _ = int((message.get_args() if is_command else message.text)) except Exception as e: assert e await message.reply('❌ Specify number as argument') return - await _set_property(message, 'cfg_scale') + await _set_property(message, 'cfg_scale', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_width_command(message: types.Message): +async def set_width_command(message: types.Message, is_command: bool = True): try: - _ = int(message.get_args()) + _ = int((message.get_args() if is_command else message.text)) except Exception as e: assert e await message.reply('❌ Specify number as argument') @@ -83,13 +83,13 @@ async def set_width_command(message: types.Message): await message.reply('❌ Specify number <= 768') return - await _set_property(message, 'width') + await _set_property(message, 'width', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_height_command(message: types.Message): +async def set_height_command(message: types.Message, is_command: bool = True): try: - _ = int(message.get_args()) + _ = int((message.get_args() if is_command else message.text)) except Exception as e: assert e await message.reply('❌ Specify number as argument') @@ -99,40 +99,40 @@ async def set_height_command(message: types.Message): await message.reply('❌ Specify number <= 768') return - await _set_property(message, 'height') + await _set_property(message, 'height', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_restore_faces_command(message: types.Message): +async def set_restore_faces_command(message: types.Message, is_command: bool = True): try: - _ = bool(message.get_args()) + _ = bool((message.get_args() if is_command else message.text)) except Exception as e: assert e await message.reply('❌ Specify boolean True/False as argument', parse_mode='HTML') return - await _set_property(message, 'restore_faces') + await _set_property(message, 'restore_faces', is_command=is_command) @wrap_exception() @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_sampler_command(message: types.Message): +async def set_sampler_command(message: types.Message, is_command: bool = True): from bot.modules.api.samplers import get_samplers - if message.get_args() not in (samplers := await get_samplers()): + if (message.get_args() if is_command else message.text) not in (samplers := await get_samplers()): await message.reply( f'❌ You can use only {", ".join(f"{x}" for x in samplers)}', parse_mode='HTML' ) return - await _set_property(message, 'sampler') + await _set_property(message, 'sampler', is_command=is_command) @throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins')) -async def set_size_command(message: types.Message): +async def set_size_command(message: types.Message, is_command: bool = True): try: - hxw = message.get_args().split('x') + hxw = (message.get_args() if is_command else message.text).split('x') height = int(hxw[0]) width = int(hxw[1]) except Exception as e: @@ -145,5 +145,5 @@ async def set_size_command(message: types.Message): await message.reply('❌ Specify numbers <= 768') return - await _set_property(message, 'height', height) - await _set_property(message, 'width', width) + await _set_property(message, 'height', height, is_command=is_command) + await _set_property(message, 'width', width, is_command=is_command) diff --git a/bot/keyboards/config.py b/bot/keyboards/config.py index eaf3da9..2504d82 100644 --- a/bot/keyboards/config.py +++ b/bot/keyboards/config.py @@ -1,22 +1,66 @@ from aiogram import types from bot.db import db, DBTables -from bot.callbacks.factories.config import (prompt_settings_data, global_settings_data, admin_settings_data) -from bot.callbacks.factories.common import close_keyboard_data +from bot.callbacks.factories.config import prompt_settings_data, admin_settings_data def get_config_keyboard(user_id: int) -> types.InlineKeyboardMarkup: buttons = [ - types.InlineKeyboardButton("Prompt settings", callback_data=prompt_settings_data.new()), - types.InlineKeyboardButton("Global settings", callback_data=global_settings_data.new()) + types.InlineKeyboardButton("Prompt settings", callback_data="prompt_settings_kb"), + types.InlineKeyboardButton("Global settings", callback_data="global_settings_kb") ] if user_id in db[DBTables.config].get('admins'): buttons.append( - types.InlineKeyboardButton("Admin settings", callback_data=admin_settings_data.new()) + types.InlineKeyboardButton("Admin settings", callback_data="admin_settings_kb") ) buttons.append( - types.InlineKeyboardButton("🔻 Close", callback_data=close_keyboard_data.new()) + types.InlineKeyboardButton("🔻 Close", callback_data="close_keyboard") ) keyboard = types.InlineKeyboardMarkup(row_width=1) keyboard.add(*buttons) return keyboard + + +def get_prompt_settings_keyboard() -> types.InlineKeyboardMarkup: + buttons = [ + types.InlineKeyboardButton("Prompt", callback_data=prompt_settings_data.new("prompt")), + types.InlineKeyboardButton("Negative prompt", callback_data=prompt_settings_data.new("negative_prompt")), + types.InlineKeyboardButton("Steps count", callback_data=prompt_settings_data.new("steps")), + types.InlineKeyboardButton("CFG Scale (model creativity)", callback_data=prompt_settings_data.new("cfg_scale")), + types.InlineKeyboardButton("Size", callback_data=prompt_settings_data.new("size")), + types.InlineKeyboardButton("Restore faces", callback_data=prompt_settings_data.new("restore_faces")), + types.InlineKeyboardButton("Sampler", callback_data=prompt_settings_data.new("sampler")), + types.InlineKeyboardButton("👈 Back", callback_data="config_back"), + types.InlineKeyboardButton("🔻 Close", callback_data="close_keyboard") + ] + + keyboard = types.InlineKeyboardMarkup(row_width=1) + keyboard.add(*buttons) + return keyboard + + +def get_global_settings_keyboard() -> types.InlineKeyboardMarkup: + buttons = [ + types.InlineKeyboardButton("Set model", callback_data="global_settings_set_model"), + types.InlineKeyboardButton("👈 Back", callback_data="config_back"), + types.InlineKeyboardButton("🔻 Close", callback_data="close_keyboard") + ] + + keyboard = types.InlineKeyboardMarkup(row_width=1) + keyboard.add(*buttons) + return keyboard + + +def get_admin_settings_keyboard() -> types.InlineKeyboardMarkup: + buttons = [ + types.InlineKeyboardButton("Add admin", callback_data=admin_settings_data.new("aliases.add_admin")), + types.InlineKeyboardButton("Remove admin", callback_data=admin_settings_data.new("aliases.remove_admin")), + types.InlineKeyboardButton("Set API endpoint", callback_data=admin_settings_data.new("aliases.set_endpoint")), + types.InlineKeyboardButton("Reset generation queue", callback_data=admin_settings_data.new("reset.resetqueue")), + types.InlineKeyboardButton("👈 Back", callback_data="config_back"), + types.InlineKeyboardButton("🔻 Close", callback_data="close_keyboard") + ] + + keyboard = types.InlineKeyboardMarkup(row_width=1) + keyboard.add(*buttons) + return keyboard diff --git a/bot/keyboards/set_model.py b/bot/keyboards/set_model.py index e43a355..d0e308d 100644 --- a/bot/keyboards/set_model.py +++ b/bot/keyboards/set_model.py @@ -1,7 +1,6 @@ from aiogram import types from bot.db import db, DBTables from bot.callbacks.factories.set_model import set_model_page, set_model -from bot.callbacks.factories.common import close_keyboard_data def get_set_model_keyboard(page: int) -> types.InlineKeyboardMarkup: @@ -30,7 +29,7 @@ def get_set_model_keyboard(page: int) -> types.InlineKeyboardMarkup: keyboard.add(*models_buttons) keyboard.add( - types.InlineKeyboardButton("🔻 Cancel", callback_data=close_keyboard_data.new()) + types.InlineKeyboardButton("🔻 Cancel", callback_data="close_keyboard") ) return keyboard diff --git a/bot/modules/api/objects/action.py b/bot/modules/api/objects/action.py new file mode 100644 index 0000000..812ffd9 --- /dev/null +++ b/bot/modules/api/objects/action.py @@ -0,0 +1,9 @@ +import dataclasses + + +@dataclasses.dataclass +class Action: + chat_id: int + action_module: str + action: str + overload: str = None