config command now works fully
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from bot.common import dp
|
from bot.common import dp
|
||||||
from bot.callbacks.factories.common import close_keyboard_data
|
from aiogram import types, filters
|
||||||
from aiogram import types
|
|
||||||
from bot.utils.private_keyboard import other_user
|
from bot.utils.private_keyboard import other_user
|
||||||
|
|
||||||
|
|
||||||
@@ -12,4 +11,4 @@ async def on_close_keyboard(call: types.CallbackQuery):
|
|||||||
|
|
||||||
|
|
||||||
def register():
|
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
|
from aiogram.utils.callback_data import CallbackData
|
||||||
|
|
||||||
|
|
||||||
prompt_settings_data = CallbackData("prompt_settings")
|
prompt_settings_data = CallbackData("prompt_settings_set", "setting")
|
||||||
global_settings_data = CallbackData("global_settings")
|
admin_settings_data = CallbackData("admin_settings_set", "setting")
|
||||||
admin_settings_data = CallbackData("admin_settings")
|
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ def register_callbacks():
|
|||||||
exception,
|
exception,
|
||||||
image_info,
|
image_info,
|
||||||
set_model,
|
set_model,
|
||||||
common
|
common,
|
||||||
|
config
|
||||||
)
|
)
|
||||||
|
|
||||||
exception.register()
|
exception.register()
|
||||||
image_info.register()
|
image_info.register()
|
||||||
set_model.register()
|
set_model.register()
|
||||||
common.register()
|
common.register()
|
||||||
|
config.register()
|
||||||
|
|
||||||
print('[gray]All callbacks registered[/]')
|
print('[gray]All callbacks registered[/]')
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ db = {
|
|||||||
'exceptions': DBDict(DB, autocommit=True, tablename='exceptions'),
|
'exceptions': DBDict(DB, autocommit=True, tablename='exceptions'),
|
||||||
'queue': DBDict(DB, autocommit=True, tablename='queue'),
|
'queue': DBDict(DB, autocommit=True, tablename='queue'),
|
||||||
'generated': DBDict(DB, autocommit=True, tablename='generated'),
|
'generated': DBDict(DB, autocommit=True, tablename='generated'),
|
||||||
|
'actions': DBDict(DB, autocommit=True, tablename='actions'),
|
||||||
'prompts': DBDict(DB, autocommit=True, tablename='prompts')
|
'prompts': DBDict(DB, autocommit=True, tablename='prompts')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ from .meta import DBMeta
|
|||||||
|
|
||||||
|
|
||||||
class DBTables:
|
class DBTables:
|
||||||
tables = ['config', 'cooldown', 'exceptions', 'queue', 'generated', 'prompts']
|
tables = ['config', 'cooldown', 'exceptions', 'queue', 'generated', 'actions', 'prompts']
|
||||||
config = "config"
|
config = "config"
|
||||||
cooldown = "cooldown"
|
cooldown = "cooldown"
|
||||||
exceptions = "exceptions"
|
exceptions = "exceptions"
|
||||||
queue = "queue"
|
queue = "queue"
|
||||||
generated = "generated"
|
generated = "generated"
|
||||||
|
actions = "actions"
|
||||||
prompts = "prompts"
|
prompts = "prompts"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,18 @@ from bot.utils.cooldown import throttle
|
|||||||
|
|
||||||
|
|
||||||
@throttle(5)
|
@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:
|
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. '
|
await message.reply('❌ You are not permitted to do that. '
|
||||||
'It is only for this bot instance maintainers and admins')
|
'It is only for this bot instance maintainers and admins')
|
||||||
return
|
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")
|
await message.reply("❌ Specify correct url for endpoint")
|
||||||
return
|
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()
|
await db[DBTables.config].write()
|
||||||
|
|
||||||
@@ -24,18 +25,19 @@ async def set_endpoint(message: types.Message):
|
|||||||
|
|
||||||
|
|
||||||
@throttle(5)
|
@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:
|
if message.from_id != ADMIN:
|
||||||
await message.reply('❌ You are not permitted to do that. It is only for main admin')
|
await message.reply('❌ You are not permitted to do that. It is only for main admin')
|
||||||
return
|
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')
|
await message.reply('❌ Put new admin ID to command arguments or answer to users message')
|
||||||
return
|
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
|
ID = message.reply_to_message.from_id
|
||||||
elif not hasattr(message.reply_to_message, 'text'):
|
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):
|
if not isinstance(db[DBTables.config].get('admins'), list):
|
||||||
db[DBTables.config]['admins'] = list()
|
db[DBTables.config]['admins'] = list()
|
||||||
@@ -54,18 +56,19 @@ async def add_admin(message: types.Message):
|
|||||||
|
|
||||||
|
|
||||||
@throttle(5)
|
@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:
|
if message.from_id != ADMIN:
|
||||||
await message.reply('❌ You are not permitted to do that. It is only for main admin')
|
await message.reply('❌ You are not permitted to do that. It is only for main admin')
|
||||||
return
|
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')
|
await message.reply('❌ Put admin ID to command arguments or answer to users message')
|
||||||
return
|
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
|
ID = message.reply_to_message.from_id
|
||||||
elif not hasattr(message.reply_to_message, 'text'):
|
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):
|
if not isinstance(db[DBTables.config].get('admins'), list):
|
||||||
db[DBTables.config]['admins'] = list()
|
db[DBTables.config]['admins'] = list()
|
||||||
|
|||||||
@@ -5,12 +5,15 @@ from bot.utils.cooldown import throttle
|
|||||||
|
|
||||||
|
|
||||||
@throttle(5)
|
@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:
|
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. '
|
await message.reply('❌ You are not permitted to do that. '
|
||||||
'It is only for this bot instance maintainers and admins')
|
'It is only for this bot instance maintainers and admins')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if is_command and message.text.lower() != 'reset':
|
||||||
|
return
|
||||||
|
|
||||||
db[DBTables.queue]['n'] = 0
|
db[DBTables.queue]['n'] = 0
|
||||||
|
|
||||||
await db[DBTables.config].write()
|
await db[DBTables.config].write()
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
from bot.common import dp, bot
|
from bot.common import dp, bot
|
||||||
from .start import *
|
from .start import *
|
||||||
from .all_messages import *
|
from .all_messages import *
|
||||||
|
from bot.db import db, DBTables
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
dp.register_message_handler(all_messages.sync_db_filter, lambda *_: not hasattr(bot, 'cloudmeta_message_text'))
|
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')
|
dp.register_message_handler(start.start_command, commands='start')
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
from aiogram.types import Message
|
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):
|
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')
|
f'If you tried to run a command, run it again')
|
||||||
if not await ping():
|
if not await ping():
|
||||||
await message.reply('⚠️ Warning: StableDiffusion server is turned off or api endpoint is incorrect')
|
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}')")
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ from bot.utils.errorable_command import wrap_exception
|
|||||||
|
|
||||||
|
|
||||||
@wrap_exception(custom_loading=True)
|
@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}...")
|
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")
|
await temp_message.edit_text("😶🌫️ Specify arguments for this command. Check /help")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -20,9 +20,9 @@ async def _set_property(message: types.Message, prop: str, value=None):
|
|||||||
f"jacket, outdoors, streets</code>", parse_mode='HTML')
|
f"jacket, outdoors, streets</code>", parse_mode='HTML')
|
||||||
return
|
return
|
||||||
elif prompt is None:
|
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
|
prompt.creator = message.from_id
|
||||||
db[DBTables.prompts][message.from_id] = prompt
|
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'))
|
@throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins'))
|
||||||
async def set_prompt_command(message: types.Message):
|
async def set_prompt_command(message: types.Message, is_command: bool = True):
|
||||||
await _set_property(message, 'prompt')
|
await _set_property(message, 'prompt', is_command=is_command)
|
||||||
|
|
||||||
|
|
||||||
@throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins'))
|
@throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins'))
|
||||||
async def set_negative_prompt_command(message: types.Message):
|
async def set_negative_prompt_command(message: types.Message, is_command: bool = True):
|
||||||
await _set_property(message, 'negative_prompt')
|
await _set_property(message, 'negative_prompt', is_command=is_command)
|
||||||
|
|
||||||
|
|
||||||
@throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins'))
|
@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:
|
try:
|
||||||
_ = int(message.get_args())
|
_ = int((message.get_args() if is_command else message.text))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e
|
assert e
|
||||||
await message.reply('❌ Specify number as argument')
|
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')
|
await message.reply('❌ Specify number <= 30')
|
||||||
return
|
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'))
|
@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:
|
try:
|
||||||
_ = int(message.get_args())
|
_ = int((message.get_args() if is_command else message.text))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e
|
assert e
|
||||||
await message.reply('❌ Specify number as argument')
|
await message.reply('❌ Specify number as argument')
|
||||||
return
|
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'))
|
@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:
|
try:
|
||||||
_ = int(message.get_args())
|
_ = int((message.get_args() if is_command else message.text))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e
|
assert e
|
||||||
await message.reply('❌ Specify number as argument')
|
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')
|
await message.reply('❌ Specify number <= 768')
|
||||||
return
|
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'))
|
@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:
|
try:
|
||||||
_ = int(message.get_args())
|
_ = int((message.get_args() if is_command else message.text))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e
|
assert e
|
||||||
await message.reply('❌ Specify number as argument')
|
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')
|
await message.reply('❌ Specify number <= 768')
|
||||||
return
|
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'))
|
@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:
|
try:
|
||||||
_ = bool(message.get_args())
|
_ = bool((message.get_args() if is_command else message.text))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e
|
assert e
|
||||||
await message.reply('❌ Specify boolean <code>True</code>/<code>False</code> as argument',
|
await message.reply('❌ Specify boolean <code>True</code>/<code>False</code> as argument',
|
||||||
parse_mode='HTML')
|
parse_mode='HTML')
|
||||||
return
|
return
|
||||||
|
|
||||||
await _set_property(message, 'restore_faces')
|
await _set_property(message, 'restore_faces', is_command=is_command)
|
||||||
|
|
||||||
|
|
||||||
@wrap_exception()
|
@wrap_exception()
|
||||||
@throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins'))
|
@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
|
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(
|
await message.reply(
|
||||||
f'❌ You can use only {", ".join(f"<code>{x}</code>" for x in samplers)}',
|
f'❌ You can use only {", ".join(f"<code>{x}</code>" for x in samplers)}',
|
||||||
parse_mode='HTML'
|
parse_mode='HTML'
|
||||||
)
|
)
|
||||||
return
|
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'))
|
@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:
|
try:
|
||||||
hxw = message.get_args().split('x')
|
hxw = (message.get_args() if is_command else message.text).split('x')
|
||||||
height = int(hxw[0])
|
height = int(hxw[0])
|
||||||
width = int(hxw[1])
|
width = int(hxw[1])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -145,5 +145,5 @@ async def set_size_command(message: types.Message):
|
|||||||
await message.reply('❌ Specify numbers <= 768')
|
await message.reply('❌ Specify numbers <= 768')
|
||||||
return
|
return
|
||||||
|
|
||||||
await _set_property(message, 'height', height)
|
await _set_property(message, 'height', height, is_command=is_command)
|
||||||
await _set_property(message, 'width', width)
|
await _set_property(message, 'width', width, is_command=is_command)
|
||||||
|
|||||||
@@ -1,22 +1,66 @@
|
|||||||
from aiogram import types
|
from aiogram import types
|
||||||
from bot.db import db, DBTables
|
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.config import prompt_settings_data, admin_settings_data
|
||||||
from bot.callbacks.factories.common import close_keyboard_data
|
|
||||||
|
|
||||||
|
|
||||||
def get_config_keyboard(user_id: int) -> types.InlineKeyboardMarkup:
|
def get_config_keyboard(user_id: int) -> types.InlineKeyboardMarkup:
|
||||||
buttons = [
|
buttons = [
|
||||||
types.InlineKeyboardButton("Prompt settings", callback_data=prompt_settings_data.new()),
|
types.InlineKeyboardButton("Prompt settings", callback_data="prompt_settings_kb"),
|
||||||
types.InlineKeyboardButton("Global settings", callback_data=global_settings_data.new())
|
types.InlineKeyboardButton("Global settings", callback_data="global_settings_kb")
|
||||||
]
|
]
|
||||||
if user_id in db[DBTables.config].get('admins'):
|
if user_id in db[DBTables.config].get('admins'):
|
||||||
buttons.append(
|
buttons.append(
|
||||||
types.InlineKeyboardButton("Admin settings", callback_data=admin_settings_data.new())
|
types.InlineKeyboardButton("Admin settings", callback_data="admin_settings_kb")
|
||||||
)
|
)
|
||||||
|
|
||||||
buttons.append(
|
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 = types.InlineKeyboardMarkup(row_width=1)
|
||||||
keyboard.add(*buttons)
|
keyboard.add(*buttons)
|
||||||
return keyboard
|
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
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from aiogram import types
|
from aiogram import types
|
||||||
from bot.db import db, DBTables
|
from bot.db import db, DBTables
|
||||||
from bot.callbacks.factories.set_model import set_model_page, set_model
|
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:
|
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(*models_buttons)
|
||||||
|
|
||||||
keyboard.add(
|
keyboard.add(
|
||||||
types.InlineKeyboardButton("🔻 Cancel", callback_data=close_keyboard_data.new())
|
types.InlineKeyboardButton("🔻 Cancel", callback_data="close_keyboard")
|
||||||
)
|
)
|
||||||
|
|
||||||
return keyboard
|
return keyboard
|
||||||
|
|||||||
9
bot/modules/api/objects/action.py
Normal file
9
bot/modules/api/objects/action.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import dataclasses
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class Action:
|
||||||
|
chat_id: int
|
||||||
|
action_module: str
|
||||||
|
action: str
|
||||||
|
overload: str = None
|
||||||
Reference in New Issue
Block a user