Skip to content

Commit

Permalink
fix(purge): add error handling on delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMissx committed Jan 1, 2024
1 parent 0a1a6f9 commit ab4d8c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions anjani/language/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ purges-help: |
× /purge | /prune : Deletes all messages until the replied to message.
purge-done: "`Purged {} messages in {} second(s)...`"
purge-error: "__Can't purge messages more than 2 days__"
purge-failed: "Can't delete message(s), {}"
#endregion
#region reporting
reporting-button: Reporting
Expand Down
1 change: 1 addition & 0 deletions anjani/language/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ purges-help: |
× /purge | /prune: Menghapus semua pesan hingga pesan yang dibalas /purge.
purge-done: "`{} pesan telah dihapus dalam {} detik...`"
purge-error: "__Mohon maaf tidak bisa menghapus pesan lebih dari 2 hari__"
purge-failed: "Tidak bisa menghapus pesan ini, {}"
#endregion
#region reporting
reporting-button: Laporan
Expand Down
8 changes: 6 additions & 2 deletions anjani/plugins/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ async def cmd_del(self, ctx: command.Context) -> Optional[str]:
if not reply_msg:
return await self.text(ctx.chat.id, "error-reply-to-message")

await self.bot.client.delete_messages(ctx.chat.id, [reply_msg.id, ctx.msg.id])
return None
try:
await self.bot.client.delete_messages(ctx.chat.id, [reply_msg.id, ctx.msg.id])
except MessageDeleteForbidden as e:
await ctx.respond(
await self.text(ctx.chat.id, "purge-failed", e.MESSAGE), delete_after=5
)

@command.filters(filters.can_delete, aliases=["prune"])
async def cmd_purge(self, ctx: command.Context) -> Optional[str]:
Expand Down

0 comments on commit ab4d8c7

Please sign in to comment.