config command now works fully
This commit is contained in:
@@ -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"))
|
||||
|
||||
@@ -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'))
|
||||
|
||||
51
bot/callbacks/config/admin_settings.py
Normal file
51
bot/callbacks/config/admin_settings.py
Normal file
@@ -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"))
|
||||
41
bot/callbacks/config/global_settings.py
Normal file
41
bot/callbacks/config/global_settings.py
Normal file
@@ -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"))
|
||||
47
bot/callbacks/config/prompt_settings.py
Normal file
47
bot/callbacks/config/prompt_settings.py
Normal file
@@ -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"))
|
||||
@@ -1,4 +0,0 @@
|
||||
from aiogram.utils.callback_data import CallbackData
|
||||
|
||||
|
||||
close_keyboard_data = CallbackData("close_keyboard")
|
||||
@@ -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")
|
||||
|
||||
@@ -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[/]')
|
||||
|
||||
Reference in New Issue
Block a user