From 7df93078ef671e918bb9fa559726ef5489dd758d Mon Sep 17 00:00:00 2001 From: Sydney Date: Thu, 28 Dec 2023 17:56:24 -0500 Subject: [PATCH] Make the cog work --- personalroles/__init__.py | 4 +- personalroles/discord_new_features.py | 69 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 personalroles/discord_new_features.py diff --git a/personalroles/__init__.py b/personalroles/__init__.py index 72aa995..1944c4a 100644 --- a/personalroles/__init__.py +++ b/personalroles/__init__.py @@ -22,5 +22,5 @@ __red_end_user_data_statement__ = "This will store what a user's custom role is if they have one." -def setup(bot): - bot.add_cog(PersonalRoles(bot)) +async def setup(bot): + await bot.add_cog(PersonalRoles(bot)) diff --git a/personalroles/discord_new_features.py b/personalroles/discord_new_features.py new file mode 100644 index 0000000..10a3566 --- /dev/null +++ b/personalroles/discord_new_features.py @@ -0,0 +1,69 @@ +# Personal Roles - Adds automated personal roles to discord +# Copyright (C) 2023 brandons209 +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +####################################### +# This file is forked from brandons209's PersonalRoles cog. +# Original Source can be found at: +# https://github.com/brandons209/Red-bot-Cogs/tree/66bf686eec363a729c3dc21e979903b56bd05312/personalroles +####################################### + +# NOTE: this file contains backports or unintroduced features of next versions of dpy (as for 1.7.3) +# TODO: nuke this file when Red is changed its version to support required features +# from @fixator10 +from discord import Role +from discord.http import Route +from discord.utils import _bytes_to_base64_data + + +async def edit_role_icon(bot, role: Role, reason=None, **fields): + """|coro| + + Changes specified role's icon + + Parameters + ----------- + role: :class:`discord.Role` + A role to edit + icon: :class:`bytes` + A :term:`py:bytes-like object` representing the image to upload. + unicode_emoji: :class:`str` + A unicode emoji to set + reason: Optional[:class:`str`] + The reason for editing this role. Shows up on the audit log. + + Raises + ------- + Forbidden + You do not have permissions to change the role. + HTTPException + Editing the role failed. + InvalidArgument + Wrong image format passed for ``icon``. + :param bot: + """ + if "unicode_emoji" in fields: + fields["icon"] = None + else: + try: + icon_bytes = fields["icon"] + except KeyError: + pass + else: + if icon_bytes is not None: + fields["icon"] = _bytes_to_base64_data(icon_bytes) + else: + fields["icon"] = None + + r = Route("PATCH", "/guilds/{guild_id}/roles/{role_id}", guild_id=role.guild.id, role_id=role.id) + await bot.http.request(r, json=fields, reason=reason)