Adding and removing admins
This commit is contained in:
@@ -7,4 +7,6 @@ from .tools import *
|
||||
def register():
|
||||
dp.register_message_handler(set_endpoint, commands='setendpoint')
|
||||
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')
|
||||
|
||||
@@ -21,3 +21,63 @@ async def set_endpoint(message: types.Message):
|
||||
await db[DBTables.config].write()
|
||||
|
||||
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")
|
||||
|
||||
@@ -11,5 +11,7 @@ help_data = {
|
||||
'setsampler': 'Set StableDiffusion sampler',
|
||||
'setscale': 'Set CFG Scale (prompt stringency)',
|
||||
'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'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user