Skip to content

Commit

Permalink
Added Silent Pin and Silent Unpin
Browse files Browse the repository at this point in the history
  • Loading branch information
sppidy authored Feb 23, 2021
1 parent f541572 commit 5ff7922
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions plugins/admintools.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
• `{i}unpin (all) <reply to message>`
Unpin the message(s) in the chat.
• `{i}dpin <reply to message>`
Pin the message in the chat Silently.
• `{i}dunpin (all) <reply to message>`
Unpin the message(s) in the chat Silently.
• `{i}purge <reply to message>`
Purge all messages from the replied message.
Expand Down Expand Up @@ -277,7 +283,7 @@ async def kck(ult):
pattern="pin($| (.*))",
)
async def pin(msg):
x = await eor(msg, "`Processing...`")
x = await eor(msg, "`Wait...`")
if not msg.is_private:
# for pin(s) in private messages
await msg.get_chat()
Expand All @@ -295,9 +301,31 @@ async def pin(msg):
return await x.edit("`Hmm, I'm have no rights here...`")
except Exception as e:
return await x.edit(f"**ERROR:**`{str(e)}`")
await x.edit(f"`Pinned` [this message](https://t.me/c/{cht.id}/{xx})!")


await x.delete()

@ultroid_cmd(
pattern="dpin($| (.*))",
)
async def pin(msg):
if not msg.is_private:
# for pin(s) in private messages
await msg.get_chat()
cht = await ultroid_bot.get_entity(msg.chat_id)
xx = msg.reply_to_msg_id
if not msg.is_reply:
return await msg.edit("Reply to a message to pin it.")
ch = msg.pattern_match.group(1)
slnt = False
if ch == "loud":
slnt = True
try:
await ultroid_bot.pin_message(msg.chat_id, xx, notify=slnt)
except BadRequestError:
return await msg.edit("Hmm, I'm have no rights here...")
except Exception as e:
return await msg.edit(f"**ERROR:**{str(e)}")
await msg.delete()

@ultroid_cmd(
pattern="unpin($| (.*))",
)
Expand Down Expand Up @@ -328,6 +356,34 @@ async def unp(ult):
return await xx.edit(f"Either reply to a message, or, use `{hndlr}unpin all`")
await xx.edit("`Unpinned!`")

@ultroid_cmd(
pattern="dunpin($| (.*))",
)
async def unp(ult):
if not ult.is_private:
# for (un)pin(s) in private messages
await ult.get_chat()
ch = (ult.pattern_match.group(1)).strip()
msg = ult.reply_to_msg_id
if msg and not ch:
try:
await ultroid_bot.unpin_message(ult.chat_id, msg)
except BadRequestError:
return await ult.edit("`Hmm, I'm have no rights here...`")
except Exception as e:
return await ult.edit(f"**ERROR:**\n`{str(e)}`")
elif ch == "all":
try:
await ultroid_bot.unpin_message(ult.chat_id)
except BadRequestError:
return await ult.edit("`Hmm, I'm have no rights here...`")
except Exception as e:
return await ult.edit(f"**ERROR:**`{str(e)}`")
else:
return await ult.edit(f"Either reply to a message, or, use `{hndlr}unpin all`")
if not msg and ch != "all":
return await ult.edit(f"Either reply to a message, or, use `{hndlr}unpin all`")
await ult.delete()

@ultroid_cmd(
pattern="purge$",
Expand Down

0 comments on commit 5ff7922

Please sign in to comment.