diff --git a/.gitignore b/.gitignore index 9bb7a64..e3cbc6b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/cogs/moderation.py b/cogs/moderation.py index 2c83e15..33121b4 100644 --- a/cogs/moderation.py +++ b/cogs/moderation.py @@ -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: diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 0000000..af34e47 --- /dev/null +++ b/utils/README.md @@ -0,0 +1,3 @@ +# Embed + +This code was given to me by `MystciMia#9718` on the [Revolt.py Revolt Server](https://rvlt.gg/hBWWYqmk). diff --git a/utils/embed.py b/utils/embed.py new file mode 100644 index 0000000..470557c --- /dev/null +++ b/utils/embed.py @@ -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 `_ + + 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