Skip to content

Commit

Permalink
Update extra.py
Browse files Browse the repository at this point in the history
Added
Delete messages via phrase
  • Loading branch information
ufoptg authored Jan 25, 2024
1 parent 82c1fe7 commit 9b3ef6b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions plugins/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
__doc__ = get_help("extra")

import asyncio
import logging
import os

from telethon import errors, events, functions
from telethon.errors import FloodWaitError
from telethon.tl.types import PeerChannel, PeerUser

from . import get_string, ultroid_cmd
from . import *


@ultroid_cmd(
Expand Down Expand Up @@ -83,3 +90,33 @@ async def _(e):
)
else:
await e.try_delete()


@ultroid_cmd(
pattern="delmsgs",
)
async def delete_messages(event):
# Get the search phrase from the command
search_phrase = event.raw_text.split(" ", 1)[1]

# Get the chat ID of the group
chat_id = event.chat_id

# Get the messages in the chat
async for message in nimbus_bot.iter_messages(chat_id):
if message.text and search_phrase.lower() in message.text.lower():
try:
await nimbus_bot.delete_messages(chat_id, message)
except FloodWaitError as e:
# If a FloodWaitError occurs, wait for the specified time
# before retrying
wait_time = e.seconds + 5
logger.warning(
f"FloodWaitError occurred. Waiting for {wait_time} seconds.")
await asyncio.sleep(wait_time)
continue

# Reply to the command with a confirmation message
await event.reply(f"Messages containing the phrase '{search_phrase}' deleted.")
logger.info(
f"Deleted messages containing the phrase '{search_phrase}' in chat {chat_id}")

0 comments on commit 9b3ef6b

Please sign in to comment.