Setting model, /status command for pinging host
This commit is contained in:
@@ -11,6 +11,8 @@ help_data = {
|
||||
'setsampler': 'Set StableDiffusion sampler',
|
||||
'setscale': 'Set CFG Scale (prompt stringency)',
|
||||
'setfaces': 'Set restore faces mode',
|
||||
'status': 'Ping API endpoint host',
|
||||
'setmodel': '(global) Sets StableDiffusion model for all users. Can be used only once an hour',
|
||||
'setendpoint': '(admin) Set StableDiffusion API endpoint',
|
||||
'addadmin': '(admin) Add new admin - reply to message or type user ID',
|
||||
'rmadmin': '(admin) Remove admin - reply to message or type user ID'
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
from aiogram.types import Message
|
||||
from bot.db.pull_db import pull
|
||||
|
||||
|
||||
async def sync_db_filter(message: Message):
|
||||
from bot.db.pull_db import pull
|
||||
from bot.modules.api.ping import ping
|
||||
await pull()
|
||||
if message.is_command():
|
||||
await message.reply(f'🔄️ Bot database synchronised because of restart. '
|
||||
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')
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from bot.common import dp
|
||||
from .txt2img import generate_command
|
||||
from .set_model import set_model_command
|
||||
from .status import get_status
|
||||
from .set_settings import (
|
||||
set_height_command, set_negative_prompt_command, set_size_command, set_steps_command, set_width_command,
|
||||
set_prompt_command, set_sampler_command, set_cfg_scale_command, set_restore_faces_command
|
||||
@@ -17,3 +19,5 @@ def register():
|
||||
dp.register_message_handler(set_settings.set_sampler_command, commands='setsampler')
|
||||
dp.register_message_handler(set_settings.set_cfg_scale_command, commands='setscale')
|
||||
dp.register_message_handler(set_settings.set_restore_faces_command, commands='setfaces')
|
||||
dp.register_message_handler(set_model.set_model_command, commands='setmodel')
|
||||
dp.register_message_handler(status.get_status, commands='status')
|
||||
|
||||
37
bot/handlers/txt2img/set_model.py
Normal file
37
bot/handlers/txt2img/set_model.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from aiogram import types
|
||||
from bot.db import db, DBTables
|
||||
from bot.utils.cooldown import throttle
|
||||
from bot.keyboards.set_model import get_set_model_keyboard
|
||||
from bot.keyboards.exception import get_exception_keyboard
|
||||
from bot.utils.trace_exception import PrettyException
|
||||
from bot.modules.api.models import get_models
|
||||
from aiohttp import ClientConnectorError
|
||||
|
||||
|
||||
@throttle(cooldown=60*60, admin_ids=db[DBTables.config].get('admins'), by_id=False)
|
||||
async def set_model_command(message: types.Message):
|
||||
temp_message = await message.reply('⏳ Getting models...')
|
||||
try:
|
||||
models = await get_models()
|
||||
if models is not None and len(models) > 0:
|
||||
db[DBTables.config]['models'] = models
|
||||
else:
|
||||
await temp_message.delete()
|
||||
await message.reply('❌ No models available')
|
||||
return
|
||||
|
||||
await temp_message.delete()
|
||||
await message.reply("🪄 You can choose model from available:", reply_markup=get_set_model_keyboard(0))
|
||||
|
||||
except ClientConnectorError:
|
||||
await message.reply('❌ Error! Maybe, StableDiffusion API endpoint is incorrect '
|
||||
'or turned off')
|
||||
await temp_message.delete()
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
exception_id = f'{message.message_thread_id}-{message.message_id}'
|
||||
db[DBTables.exceptions][exception_id] = PrettyException(e)
|
||||
await message.reply('❌ Error happened while processing your request', parse_mode='html',
|
||||
reply_markup=get_exception_keyboard(exception_id))
|
||||
return
|
||||
20
bot/handlers/txt2img/status.py
Normal file
20
bot/handlers/txt2img/status.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from aiogram import types
|
||||
from bot.db import db, DBTables
|
||||
from bot.utils.cooldown import throttle
|
||||
from bot.modules.api.ping import ping
|
||||
|
||||
|
||||
@throttle(cooldown=5, admin_ids=db[DBTables.config].get('admins'))
|
||||
async def get_status(message: types.Message):
|
||||
temp_message = await message.reply('⏳ Sending request...')
|
||||
try:
|
||||
if await ping():
|
||||
await message.reply('💚 Endpoint is UP')
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
except Exception as e:
|
||||
assert e
|
||||
await message.reply('💔 Endpoint is probably DOWN or incorrect')
|
||||
|
||||
await temp_message.delete()
|
||||
Reference in New Issue
Block a user