added embed custom class (thanks MysticMia)

This commit is contained in:
SeaswimmerTheFsh 2023-06-21 17:03:29 -04:00
parent 5a514f86f6
commit 6a28033d52
4 changed files with 80 additions and 1 deletions

2
.gitignore vendored
View file

@ -158,4 +158,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/launch.json
.vscode

View file

@ -36,6 +36,17 @@ class Moderation(commands.Cog):
database.close()
print(f"MySQL Row Inserted!\n{moderation_id}, {moderation_type}, {target_id}, {duration}, {reason}, 0")
def add_field(self, name = None, value = None):
if name is None and value is None:
raise ValueError("A 'name' or 'value' must be given")
self.description = "\n" if self.description else ""
if value is None:
self.description += f"### {name}"
elif name is None:
self.description += f"{value}"
else:
self.description += f"### {name}\n{value}"
@commands.command(name="timeout", aliases=["mute"])
async def timeout(self, ctx: commands.Context, target: commands.MemberConverter, duration: str, *, reason: str):
try:

3
utils/README.md Normal file
View file

@ -0,0 +1,3 @@
# Embed
This code was given to me by `MystciMia#9718` on the [Revolt.py Revolt Server](https://rvlt.gg/hBWWYqmk).

65
utils/embed.py Normal file
View file

@ -0,0 +1,65 @@
import revolt
class CustomEmbed(revolt.SendableEmbed):
def __init__(self, *args, **kwargs):
"""
Represents an embed that can be sent in a message, you will never receive this, you will receive :class:`Embed`.
Attributes
-----------
title: Optional[:class:`str`]
The title of the embed
description: Optional[:class:`str`]
The description of the embed
media: Optional[:class:`str`]
The file inside the embed, this is the ID of the file, you can use :meth:`Client.upload_file` to get an ID.
icon_url: Optional[:class:`str`]
The url of the icon url
colour: Optional[:class:`str`]
The embed's accent colour, this is any valid `CSS color <https://developer.mozilla.org/en-US/docs/Web/CSS/color_value>`_
url: Optional[:class:`str`]
URL for hyperlinking the embed's title
"""
if "color" in kwargs:
kwargs["colour"] = kwargs["color"]
del kwargs["color"]
super().__init__(*args, **kwargs)
self.footer: str | None = None
def add_field(self, name = None, value = None, inline = None):
if name is None and value is None:
raise ValueError("A 'name' or 'value' must be given")
if self.description == None:
self.description = ""
else:
self.description += "\n"
if value is None:
self.description += f"### {name}"
elif name is None:
self.description += f"{value}"
else:
self.description += f"### {name}\n{value}"
def set_footer(self, text):
self.footer = text
def to_dict(self):
if self.footer is not None:
if self.description == None:
self.description = ""
else:
self.description += "\n\n"
self.description += f"##### {self.footer}"
return super().to_dict()
def copy(self):
deepcopy = CustomEmbed(title=self.title, description=self.description, colour=self.colour)
deepcopy.set_footer(self.footer)
return deepcopy