Skip to content

Commit

Permalink
added demote func + more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
K-E-N-W-A-Y committed Mar 29, 2020
1 parent cf5ccbe commit 84c16a6
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion userge/plugins/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
**Example:**
`.promote [username | userid] [custom_rank]`""")
`.promote [username | userid] or [reply to user]`""")

async def promote_usr(message: Message):
"""
Expand Down Expand Up @@ -55,3 +55,68 @@ async def promote_usr(message: Message):
else:
await message.edit(
text="`I don't have proper admin permission to do that ⚠`")

@userge.on_cmd("demote", about="""\
__use this to demote group members__
**Usage:**
`Remove admin rights from admin in the chat.`
[NOTE: Requires proper admin rights in the chat!!!]
**Example:**
`.demote [username | userid] or [reply to user]`""")

async def demote_usr(message: Message):
"""
this function can demote members in tg group
"""
chat_id = message.chat.id
get_chat = await userge.get_chat_member(message.chat.id, message.from_user.id)
demote_perm = get_chat.can_promote_members

await message.edit("`Trying to Demote User.. Hang on!`")

if demote_perm:

user_id = message.input_str

if user_id:
try:
await userge.promote_chat_member(chat_id, user_id,
can_change_info=False,
can_delete_messages=False,
can_restrict_members=False,
can_invite_users=False,
can_pin_messages=False)

await message.edit("**🛡 Demoted Successfully**", del_in=5)

except Exception as e:
await message.edit(
text=f"`something went wrong 🤔, do .help demoted for more info` \n **ERROR** {str(e)}")

else:

user_id = message.reply_to_message.from_user.id

try:
await userge.promote_chat_member(chat_id, user_id,
can_change_info=False,
can_delete_messages=False,
can_restrict_members=False,
can_invite_users=False,
can_pin_messages=False)

await message.edit("**🛡 Demoted Successfully**", del_in=5)

except Exception as e:
await message.edit(
text=f"`something went wrong 🤔, do .help demote for more info` \n **ERROR** {str(e)}")

else:
await message.edit(
text="`I don't have proper admin permission to do that ⚠`")

0 comments on commit 84c16a6

Please sign in to comment.