Adding and removing admins

This commit is contained in:
BarsTiger
2023-03-02 20:23:01 +02:00
parent 17f00689a5
commit 8e3e6929d8
3 changed files with 65 additions and 1 deletions

View File

@@ -7,4 +7,6 @@ from .tools import *
def register(): def register():
dp.register_message_handler(set_endpoint, commands='setendpoint') dp.register_message_handler(set_endpoint, commands='setendpoint')
dp.register_message_handler(reset.resetqueue, commands='resetqueue') dp.register_message_handler(reset.resetqueue, commands='resetqueue')
dp.register_message_handler(aliases.add_admin, commands='addadmin')
dp.register_message_handler(aliases.remove_admin, commands='rmadmin')
dp.register_message_handler(tools.hash_command, commands='hash') dp.register_message_handler(tools.hash_command, commands='hash')

View File

@@ -21,3 +21,63 @@ async def set_endpoint(message: types.Message):
await db[DBTables.config].write() await db[DBTables.config].write()
await message.reply("✅ New url set") await message.reply("✅ New url set")
@throttle(5)
async def add_admin(message: types.Message):
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'):
await message.reply('❌ Put new admin ID to command arguments or answer to users message')
return
elif not message.get_args().isdecimal():
ID = message.reply_to_message.from_id
elif not hasattr(message.reply_to_message, 'text'):
ID = int(message.get_args())
if not isinstance(db[DBTables.config].get('admins'), list):
db[DBTables.config]['admins'] = list()
if ID not in db[DBTables.config].get('admins'):
admins_ = db[DBTables.config].get('admins')
admins_.append(ID)
db[DBTables.config]['admins'] = admins_
else:
await message.reply('❌ This admin is added already')
return
await db[DBTables.config].write()
await message.reply("✅ Added admin")
@throttle(5)
async def remove_admin(message: types.Message):
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'):
await message.reply('❌ Put admin ID to command arguments or answer to users message')
return
elif not message.get_args().isdecimal():
ID = message.reply_to_message.from_id
elif not hasattr(message.reply_to_message, 'text'):
ID = int(message.get_args())
if not isinstance(db[DBTables.config].get('admins'), list):
db[DBTables.config]['admins'] = list()
if ID not in db[DBTables.config].get('admins'):
await message.reply('❌ This admin is not added')
return
else:
admins_ = db[DBTables.config].get('admins')
admins_.remove(ID)
db[DBTables.config]['admins'] = admins_
await db[DBTables.config].write()
await message.reply("✅ Removed admin")

View File

@@ -11,5 +11,7 @@ help_data = {
'setsampler': 'Set StableDiffusion sampler', 'setsampler': 'Set StableDiffusion sampler',
'setscale': 'Set CFG Scale (prompt stringency)', 'setscale': 'Set CFG Scale (prompt stringency)',
'setfaces': 'Set restore faces mode', 'setfaces': 'Set restore faces mode',
'setendpoint': '(admin) Set StableDiffusion API endpoint' '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'
} }