Adding Cleaner and fixing bugs

This commit is contained in:
Rafael Vargas
2022-03-26 14:45:27 -04:00
parent 362ec02fe4
commit f30513f710
15 changed files with 115 additions and 184 deletions

32
Utils/Cleaner.py Normal file
View File

@@ -0,0 +1,32 @@
from typing import List
from discord.ext.commands import Context
from discord import Client, Message, Embed
from Config.Singleton import Singleton
class Cleaner(Singleton):
def __init__(self, bot: Client = None) -> None:
if not super().created:
self.__bot = bot
self.__clean_str = 'Uploader:'
def set_bot(self, bot: Client) -> None:
self.__bot = bot
async def clean_messages(self, ctx: Context, quant: int) -> None:
if self.__bot is None:
return
last_messages: List[Message] = await ctx.channel.history(limit=quant).flatten()
for message in last_messages:
try:
if message.author == self.__bot.user:
if len(message.embeds) > 0:
embed: Embed = message.embeds[0]
if len(embed.fields) > 0:
if embed.fields[0].name == self.__clean_str:
await message.delete()
except Exception as e:
print(f'DEVELOPER NOTE -> Error cleaning messages {e}')
continue

View File

@@ -34,7 +34,6 @@ def format_time(duration) -> str:
def is_url(string) -> bool:
"""Verify if a string is a url"""
regex = re.compile(
"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")