Added get whitelist command

This commit is contained in:
BarsTiger
2023-05-06 15:06:56 +03:00
parent 892fd3841f
commit f3c372fa8f
3 changed files with 17 additions and 3 deletions

View File

@@ -12,4 +12,5 @@ def register():
dp.register_message_handler(aliases.remove_admin, commands='rmadmin') dp.register_message_handler(aliases.remove_admin, commands='rmadmin')
dp.register_message_handler(aliases.add_whitelist, commands='addwhitelist') dp.register_message_handler(aliases.add_whitelist, commands='addwhitelist')
dp.register_message_handler(aliases.remove_whitelist, commands='rmwhitelist') dp.register_message_handler(aliases.remove_whitelist, commands='rmwhitelist')
dp.register_message_handler(aliases.get_whitelist, commands='getwhitelist')
dp.register_message_handler(tools.hash_command, commands='hash') dp.register_message_handler(tools.hash_command, commands='hash')

View File

@@ -23,6 +23,7 @@ async def set_endpoint(message: types.Message, is_command: bool = True):
await message.reply("✅ New url set") await message.reply("✅ New url set")
@throttle(5) @throttle(5)
async def add_whitelist(message: types.Message, is_command: bool = True): async def add_whitelist(message: types.Message, is_command: bool = True):
if message.from_id != ADMIN: if message.from_id != ADMIN:
@@ -57,6 +58,7 @@ async def add_whitelist(message: types.Message, is_command: bool = True):
await message.reply("✅ Added whitelist") await message.reply("✅ Added whitelist")
@throttle(5) @throttle(5)
async def remove_whitelist(message: types.Message, is_command: bool = True): async def remove_whitelist(message: types.Message, is_command: bool = True):
if message.from_id != ADMIN: if message.from_id != ADMIN:
@@ -64,7 +66,7 @@ async def remove_whitelist(message: types.Message, is_command: bool = True):
return return
if not (message.get_args() if is_command else message.text).isdecimal() and not \ if not (message.get_args() if is_command else message.text).isdecimal() and not \
hasattr(message.reply_to_message, 'text') and (message.chat.id >= 0: hasattr(message.reply_to_message, 'text') and (message.chat.id) >= 0:
await message.reply('❌ Put whitelist ID to command arguments or answer to users message') await message.reply('❌ Put whitelist ID to command arguments or answer to users message')
return return
elif not (message.get_args() if is_command else message.text).isdecimal() and not \ elif not (message.get_args() if is_command else message.text).isdecimal() and not \
@@ -92,6 +94,16 @@ async def remove_whitelist(message: types.Message, is_command: bool = True):
await message.reply("✅ Removed whitelist") await message.reply("✅ Removed whitelist")
@throttle(5)
async def get_whitelist(message: types.Message, is_command: bool = True):
if message.from_id != ADMIN:
await message.reply('❌ You are not permitted to do that. It is only for main admin')
return
await message.reply(f"✅ Whitelisted ids: {db[DBTables.config].get('whitelist')}"
if db[DBTables.config].get('whitelist') else
'❌ Whitelist is disabled. Everyone can use the bot. Add someone to whitelist to enable it')
@throttle(5) @throttle(5)
async def add_admin(message: types.Message, is_command: bool = True): async def add_admin(message: types.Message, is_command: bool = True):

View File

@@ -18,6 +18,7 @@ help_data = {
'setendpoint': '(admin) Set StableDiffusion API endpoint', 'setendpoint': '(admin) Set StableDiffusion API endpoint',
'addadmin': '(admin) Add new admin - reply to message or type user ID', 'addadmin': '(admin) Add new admin - reply to message or type user ID',
'rmadmin': '(admin) Remove admin - reply to message or type user ID', 'rmadmin': '(admin) Remove admin - reply to message or type user ID',
'addwhitelist': '(admin) Add new whitelist - reply to message or type user ID', 'addwhitelist': '(admin) Add to whitelist - reply to message or type user ID',
'rmwhitelist': '(admin) Remove whitelist - reply to message or type user ID' 'rmwhitelist': '(admin) Remove from whitelist - reply to message or type user ID',
'getwhitelist': '(admin) Get current whitelist and check if it is enabled'
} }