From 75f6404e94b75c35fc461d622ac0c64bb2ce361d Mon Sep 17 00:00:00 2001 From: seel2304 <37144504+seel2304@users.noreply.github.com> Date: Wed, 3 May 2023 17:09:25 +0000 Subject: [PATCH] Fixed changing models. Changed cooldown for changing models to 30m --- bot/handlers/txt2img/set_model.py | 4 ++-- bot/modules/api/models.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bot/handlers/txt2img/set_model.py b/bot/handlers/txt2img/set_model.py index ddb31e3..75248fe 100644 --- a/bot/handlers/txt2img/set_model.py +++ b/bot/handlers/txt2img/set_model.py @@ -1,5 +1,5 @@ from aiogram import types -from bot.db import db, DBTables +from bot.db import db, DBTables, decrypt from bot.utils.cooldown import throttle from bot.keyboards.set_model import get_set_model_keyboard from bot.modules.api.models import get_models @@ -7,7 +7,7 @@ from bot.utils.errorable_command import wrap_exception @wrap_exception() -@throttle(cooldown=60*60, admin_ids=db[DBTables.config].get('admins'), by_id=False) +@throttle(cooldown=30*60, admin_ids=db[DBTables.config].get('admins'), by_id=False) async def set_model_command(message: types.Message): models = await get_models() if models is not None and len(models) > 0: diff --git a/bot/modules/api/models.py b/bot/modules/api/models.py index 77fba92..9000950 100644 --- a/bot/modules/api/models.py +++ b/bot/modules/api/models.py @@ -1,14 +1,16 @@ import aiohttp +import json from bot.db import db, DBTables, decrypt async def get_models() -> list | None: endpoint = decrypt(db[DBTables.config].get('endpoint')) async with aiohttp.ClientSession() as session: - r = await session.get(endpoint + "/sdapi/v1/sd-models") + r = await session.get(endpoint + '/sdapi/v1/sd-models') if r.status != 200: return None - return [x["title"] for x in await r.json()] + json_data = await r.json() + return [x["title"] for x in json_data] async def set_model(model_name: str):