mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Adding Cleaner and fixing bugs
This commit is contained in:
32
Utils/Cleaner.py
Normal file
32
Utils/Cleaner.py
Normal 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
|
||||
@@ -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]))+")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user