From 66a0ddf5e15b5cdc1b27f832fcb58b6e83ec9e47 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Tue, 8 Sep 2020 15:59:38 -0700 Subject: [PATCH 01/23] membersteal --- adminutils/adminutils.py | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 63cad507..e61ad115 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -188,7 +188,7 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): await ctx.tick() @emoji.command(name="message", aliases=["steal"]) - async def emote_steal(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): + async def message_steal(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): """ Add an emoji from a specified message Use double quotes if role name has spaces @@ -234,6 +234,51 @@ async def emote_steal(self, ctx, name: str, message_id: discord.Message, *roles: except discord.HTTPException as e: await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) + @emoji.command(name="member", aliases=["user"]) + async def member_steal(self, ctx, name: str, member: discord.Member, *roles: discord.Role): + """ + Add an emoji from a specified member's status + Use double quotes if role name has spaces + + Examples: + `[p]emoji member Example @PhenoM4n4n` + `[p]emoji message RoleBased 462364255128256513 EmojiRole` + """ + emoji = None + if member.activity: + if member.activity.emoji: + if member.activity.emoji.is_custom_emoji(): + emoji = member.activity.emoji + if not emoji: + await ctx.send(chat.error(_("This user does not have a custom emoji in their status."))) + return + async with self.session.get(str(emoji.url)) as r: + data = await r.read() + try: + await ctx.guild.create_custom_emoji( + name=name, + image=data, + roles=roles, + reason=get_audit_reason( + ctx.author, + _("Restricted to roles: {}").format( + ", ".join([f"{role.name}" for role in roles]) + ) + if roles + else None, + ), + ) + await ctx.tick() + except discord.InvalidArgument: + await ctx.send( + _( + "This image type is not supported anymore or Discord returned incorrect data. Try again later." + ) + ) + return + except discord.HTTPException as e: + await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) + @emoji.command(name="rename") async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: discord.Role): """Rename emoji and restrict to certain roles From 566f990ce1cd9381b8d17feca6aeb6a6deacdb5c Mon Sep 17 00:00:00 2001 From: phenom4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Thu, 10 Sep 2020 18:53:59 -0700 Subject: [PATCH 02/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index e61ad115..ff76c203 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -188,7 +188,7 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): await ctx.tick() @emoji.command(name="message", aliases=["steal"]) - async def message_steal(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): + async def emoji_steal_message(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): """ Add an emoji from a specified message Use double quotes if role name has spaces From 84e65f19cb2d54a817767ee89361d2192cc20dab Mon Sep 17 00:00:00 2001 From: phenom4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Thu, 10 Sep 2020 18:54:07 -0700 Subject: [PATCH 03/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index ff76c203..bb3894e1 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -235,7 +235,7 @@ async def emoji_steal_message(self, ctx, name: str, message_id: discord.Message, await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) @emoji.command(name="member", aliases=["user"]) - async def member_steal(self, ctx, name: str, member: discord.Member, *roles: discord.Role): + async def emoji_steal_activity(self, ctx, name: str, member: discord.Member, *roles: discord.Role): """ Add an emoji from a specified member's status Use double quotes if role name has spaces From 35f2854f95207e2be37cf2179335c8398057d945 Mon Sep 17 00:00:00 2001 From: phenom4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Thu, 10 Sep 2020 18:54:15 -0700 Subject: [PATCH 04/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index bb3894e1..f963e509 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -241,8 +241,8 @@ async def emoji_steal_activity(self, ctx, name: str, member: discord.Member, *ro Use double quotes if role name has spaces Examples: - `[p]emoji member Example @PhenoM4n4n` - `[p]emoji message RoleBased 462364255128256513 EmojiRole` + `[p]emoji member Example DiscordUser#0000` + `[p]emoji member RoleBased 162379234070467641 EmojiRole` """ emoji = None if member.activity: From 41ca0e339b03b16061cd527226544102e17b2c05 Mon Sep 17 00:00:00 2001 From: phenom4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Thu, 10 Sep 2020 18:54:23 -0700 Subject: [PATCH 05/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index f963e509..7aee09c0 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -245,9 +245,7 @@ async def emoji_steal_activity(self, ctx, name: str, member: discord.Member, *ro `[p]emoji member RoleBased 162379234070467641 EmojiRole` """ emoji = None - if member.activity: - if member.activity.emoji: - if member.activity.emoji.is_custom_emoji(): + if member.activity and member.activity.emoji and member.activity.emoji.is_custom_emoji(): emoji = member.activity.emoji if not emoji: await ctx.send(chat.error(_("This user does not have a custom emoji in their status."))) From 671921a61e2f00909d4c59a2db22b3490af1bee5 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Fri, 11 Sep 2020 19:27:23 -0700 Subject: [PATCH 06/23] steal --- adminutils/adminutils.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index e61ad115..97fd55ab 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -1,7 +1,7 @@ import re from asyncio import TimeoutError as AsyncTimeoutError from random import choice -from typing import Optional +from typing import Optional, Union import aiohttp import discord @@ -187,6 +187,29 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): else: await ctx.tick() + @emoji.command(name="steal", aliases=["member", "message"]) + async def emoji_steal(self, ctx, name: str, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], *roles: discord.Role): + """ + Add an emoji from either a member's status, a message, or an emoji from another server. + Use double quotes if role name has spaces + """ + if isinstance(id, Union[discord.Emoji, discord.PartialEmoji]): + async with self.session.get(id.url) as r: + data = await r.read() + elif isinstance(id, discord.Message): + emoji = EMOJI_RE.search(message_id.content) + if not emoji: + await ctx.send(chat.error(_("No emojis found specified message."))) + return + url = ( + "https://cdn.discordapp.com/emojis/" + f"{emoji.group(3)}.{'gif' if emoji.group(2) else 'png'}?v=1" + ) + async with self.session.get(url) as r: + data = await r.read() + elif isinstance(id, discord.member): + + @emoji.command(name="message", aliases=["steal"]) async def message_steal(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): """ From d42a9c7c5b2ed3fb76c651c840f9d17a2bc460ab Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Fri, 11 Sep 2020 20:20:06 -0700 Subject: [PATCH 07/23] emoji stealin' --- adminutils/adminutils.py | 100 ++++++++++----------------------------- 1 file changed, 25 insertions(+), 75 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index e401e405..e8680ec3 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -188,18 +188,25 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): await ctx.tick() @emoji.command(name="steal", aliases=["member", "message"]) - async def emoji_steal(self, ctx, name: str, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], *roles: discord.Role): + async def emoji_steal(self, ctx, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], name: Optional[str], *roles: discord.Role): """ Add an emoji from either a member's status, a message, or an emoji from another server. + A name must be passed if you would like to lock the emoji to roles. Use double quotes if role name has spaces + Examples: + `[p]emoji steal 236598364265634245` + `[p]emoji steal @user peepoDance` + `[p]emoji steal :thonk: thonk emojiRole` """ - if isinstance(id, Union[discord.Emoji, discord.PartialEmoji]): - async with self.session.get(id.url) as r: + if isinstance(id, (discord.Emoji, discord.PartialEmoji)): + async with self.session.get(str(id.url)) as r: data = await r.read() + if not name: + name = id.name elif isinstance(id, discord.Message): - emoji = EMOJI_RE.search(message_id.content) + emoji = EMOJI_RE.search(id.content) if not emoji: - await ctx.send(chat.error(_("No emojis found specified message."))) + await ctx.send(chat.error(_("No emojis found in the specified message."))) return url = ( "https://cdn.discordapp.com/emojis/" @@ -207,77 +214,19 @@ async def emoji_steal(self, ctx, name: str, id: Union[discord.Message, discord.M ) async with self.session.get(url) as r: data = await r.read() - elif isinstance(id, discord.member): - - - @emoji.command(name="message", aliases=["steal"]) - async def emoji_steal_message(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): - """ - Add an emoji from a specified message - Use double quotes if role name has spaces - - Examples: - `[p]emoji message Example 162379234070467641` - `[p]emoji message RoleBased 162379234070467641 EmojiRole` - """ - # TrusyJaid NotSoBot converter - # https://github.com/TrustyJAID/Trusty-cogs/blob/a3e931bc6227645007b37c3f4f524c9fc9859686/notsobot/converter.py#L30-L36 - emoji = EMOJI_RE.search(message_id.content) - if not emoji: - await ctx.send(chat.error(_("No emojis found specified message."))) - return - url = ( - "https://cdn.discordapp.com/emojis/" - f"{emoji.group(3)}.{'gif' if emoji.group(2) else 'png'}?v=1" - ) - async with self.session.get(url) as r: - data = await r.read() - try: - await ctx.guild.create_custom_emoji( - name=name, - image=data, - roles=roles, - reason=get_audit_reason( - ctx.author, - _("Restricted to roles: {}").format( - ", ".join([f"{role.name}" for role in roles]) - ) - if roles - else None, - ), - ) - await ctx.tick() - except discord.InvalidArgument: - await ctx.send( - _( - "This image type is not supported anymore or Discord returned incorrect data. Try again later." - ) - ) - return - except discord.HTTPException as e: - await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) - - @emoji.command(name="member", aliases=["user"]) - async def emoji_steal_activity(self, ctx, name: str, member: discord.Member, *roles: discord.Role): - """ - Add an emoji from a specified member's status - Use double quotes if role name has spaces - - Examples: - `[p]emoji member Example DiscordUser#0000` - `[p]emoji member RoleBased 162379234070467641 EmojiRole` - """ - emoji = None - if member.activity and member.activity.emoji and member.activity.emoji.is_custom_emoji(): - emoji = member.activity.emoji - if not emoji: - await ctx.send(chat.error(_("This user does not have a custom emoji in their status."))) - return - async with self.session.get(str(emoji.url)) as r: - data = await r.read() + elif isinstance(id, discord.Member): + emoji = None + if id.activity and id.activity.emoji and id.activity.emoji.is_custom_emoji(): + emoji = id.activity.emoji + if not emoji: + await ctx.send(chat.error(_("This user does not have a custom emoji in their status."))) + return + async with self.session.get(str(emoji.url)) as r: + data = await r.read() + name = emoji.name try: - await ctx.guild.create_custom_emoji( - name=name, + e = await ctx.guild.create_custom_emoji( + name=name if name else "stolen_emoji", image=data, roles=roles, reason=get_audit_reason( @@ -289,6 +238,7 @@ async def emoji_steal_activity(self, ctx, name: str, member: discord.Member, *ro else None, ), ) + await ctx.send(_(f"{e} created with the name `{e.name}`.")) await ctx.tick() except discord.InvalidArgument: await ctx.send( From 8927d33e3ca08ebd87f18d7da2c7902dfd464ae9 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Fri, 11 Sep 2020 20:23:09 -0700 Subject: [PATCH 08/23] newline --- adminutils/adminutils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index e8680ec3..15f8a70f 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -191,6 +191,7 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): async def emoji_steal(self, ctx, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], name: Optional[str], *roles: discord.Role): """ Add an emoji from either a member's status, a message, or an emoji from another server. + a A name must be passed if you would like to lock the emoji to roles. Use double quotes if role name has spaces Examples: From 5c0d490719b8f6ff2839aba4fe4f19e909b274be Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Fri, 11 Sep 2020 20:24:33 -0700 Subject: [PATCH 09/23] oops --- adminutils/adminutils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 15f8a70f..32239fa6 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -191,9 +191,10 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): async def emoji_steal(self, ctx, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], name: Optional[str], *roles: discord.Role): """ Add an emoji from either a member's status, a message, or an emoji from another server. - a + A name must be passed if you would like to lock the emoji to roles. Use double quotes if role name has spaces + Examples: `[p]emoji steal 236598364265634245` `[p]emoji steal @user peepoDance` From a1fde5802ae2685bbacd379d4e98b996a32d19bf Mon Sep 17 00:00:00 2001 From: phenom4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Sat, 12 Sep 2020 00:52:50 -0700 Subject: [PATCH 10/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 32239fa6..8533d269 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -197,7 +197,7 @@ async def emoji_steal(self, ctx, id: Union[discord.Message, discord.Member, disc Examples: `[p]emoji steal 236598364265634245` - `[p]emoji steal @user peepoDance` + `[p]emoji import Username#0000 peepoDance` `[p]emoji steal :thonk: thonk emojiRole` """ if isinstance(id, (discord.Emoji, discord.PartialEmoji)): From f75250b0f310d6f92abfb9aac7abe5b776364547 Mon Sep 17 00:00:00 2001 From: phenom4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Sat, 12 Sep 2020 00:53:04 -0700 Subject: [PATCH 11/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 8533d269..25ff31a2 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -187,8 +187,8 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): else: await ctx.tick() - @emoji.command(name="steal", aliases=["member", "message"]) - async def emoji_steal(self, ctx, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], name: Optional[str], *roles: discord.Role): + @emoji.command(name="import") + async def emoji_import(self, ctx, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], name: Optional[str], *roles: discord.Role): """ Add an emoji from either a member's status, a message, or an emoji from another server. From 966b89fe8e67fb5cdcdee12add115fbed5237b4a Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sat, 12 Sep 2020 00:58:46 -0700 Subject: [PATCH 12/23] emoji import --- adminutils/adminutils.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 25ff31a2..34708d55 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -167,7 +167,7 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): await ctx.send(chat.error(_("Unable to get emoji from provided url: {}").format(e))) return try: - await ctx.guild.create_custom_emoji( + e = await ctx.guild.create_custom_emoji( name=name, image=data, roles=roles, @@ -185,14 +185,14 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): except discord.HTTPException as e: await ctx.send(chat.error(_("An error occured on adding an emoji: {}").format(e))) else: + await ctx.send(_(f"{e} created with the name `{e.name}`.")) await ctx.tick() @emoji.command(name="import") - async def emoji_import(self, ctx, id: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], name: Optional[str], *roles: discord.Role): + async def emoji_import(self, ctx, name: str, location: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], *roles: discord.Role): """ Add an emoji from either a member's status, a message, or an emoji from another server. - A name must be passed if you would like to lock the emoji to roles. Use double quotes if role name has spaces Examples: @@ -200,13 +200,13 @@ async def emoji_import(self, ctx, id: Union[discord.Message, discord.Member, dis `[p]emoji import Username#0000 peepoDance` `[p]emoji steal :thonk: thonk emojiRole` """ - if isinstance(id, (discord.Emoji, discord.PartialEmoji)): - async with self.session.get(str(id.url)) as r: + if isinstance(location, (discord.Emoji, discord.PartialEmoji)): + async with self.session.get(str(location.url)) as r: data = await r.read() if not name: - name = id.name - elif isinstance(id, discord.Message): - emoji = EMOJI_RE.search(id.content) + name = location.name + elif isinstance(location, discord.Message): + emoji = EMOJI_RE.search(location.content) if not emoji: await ctx.send(chat.error(_("No emojis found in the specified message."))) return @@ -216,10 +216,10 @@ async def emoji_import(self, ctx, id: Union[discord.Message, discord.Member, dis ) async with self.session.get(url) as r: data = await r.read() - elif isinstance(id, discord.Member): + elif isinstance(location, discord.Member): emoji = None - if id.activity and id.activity.emoji and id.activity.emoji.is_custom_emoji(): - emoji = id.activity.emoji + if location.activity and location.activity.emoji and location.activity.emoji.is_custom_emoji(): + emoji = location.activity.emoji if not emoji: await ctx.send(chat.error(_("This user does not have a custom emoji in their status."))) return @@ -227,7 +227,7 @@ async def emoji_import(self, ctx, id: Union[discord.Message, discord.Member, dis data = await r.read() name = emoji.name try: - e = await ctx.guild.create_custom_emoji( + em = await ctx.guild.create_custom_emoji( name=name if name else "stolen_emoji", image=data, roles=roles, @@ -240,7 +240,7 @@ async def emoji_import(self, ctx, id: Union[discord.Message, discord.Member, dis else None, ), ) - await ctx.send(_(f"{e} created with the name `{e.name}`.")) + await ctx.send(_(f"{em} created with the name `{em.name}`.")) await ctx.tick() except discord.InvalidArgument: await ctx.send( @@ -267,7 +267,7 @@ async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: disco await ctx.send_help() return try: - await emoji.edit( + em = await emoji.edit( name=name, roles=roles, reason=get_audit_reason( @@ -281,6 +281,7 @@ async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: disco ) except discord.Forbidden: await ctx.send(chat.error(_("I can't edit this emoji"))) + await ctx.send(_(f"{em} edited to `{em.name}`.")) await ctx.tick() @emoji.command(name="remove") From cc2e0da64ac518f9a6381d165ee256e1ba576b68 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sat, 12 Sep 2020 18:30:59 -0700 Subject: [PATCH 13/23] updates --- adminutils/adminutils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 34708d55..6f7cface 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -196,9 +196,9 @@ async def emoji_import(self, ctx, name: str, location: Union[discord.Message, di Use double quotes if role name has spaces Examples: - `[p]emoji steal 236598364265634245` + `[p]emoji import 236598364265634245` `[p]emoji import Username#0000 peepoDance` - `[p]emoji steal :thonk: thonk emojiRole` + `[p]emoji import :thonk: thonk emojiRole` """ if isinstance(location, (discord.Emoji, discord.PartialEmoji)): async with self.session.get(str(location.url)) as r: @@ -228,7 +228,7 @@ async def emoji_import(self, ctx, name: str, location: Union[discord.Message, di name = emoji.name try: em = await ctx.guild.create_custom_emoji( - name=name if name else "stolen_emoji", + name=name, image=data, roles=roles, reason=get_audit_reason( From 54e2e985c3b7e821795a6ac98f5d6a7beebb9dc2 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sun, 13 Sep 2020 00:26:28 -0700 Subject: [PATCH 14/23] try except else --- adminutils/adminutils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 6f7cface..3473d46a 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -240,8 +240,6 @@ async def emoji_import(self, ctx, name: str, location: Union[discord.Message, di else None, ), ) - await ctx.send(_(f"{em} created with the name `{em.name}`.")) - await ctx.tick() except discord.InvalidArgument: await ctx.send( _( @@ -251,6 +249,9 @@ async def emoji_import(self, ctx, name: str, location: Union[discord.Message, di return except discord.HTTPException as e: await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) + else: + await ctx.send(_(f"{em} created with the name `{em.name}`.")) + await ctx.tick() @emoji.command(name="rename") async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: discord.Role): @@ -281,7 +282,8 @@ async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: disco ) except discord.Forbidden: await ctx.send(chat.error(_("I can't edit this emoji"))) - await ctx.send(_(f"{em} edited to `{em.name}`.")) + else: + await ctx.send(_(f"{em} edited to `{em.name}`.")) await ctx.tick() @emoji.command(name="remove") From 65a9b34a2bb27b3cd2426f80aa50b202b0fe4ded Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sun, 13 Sep 2020 00:34:54 -0700 Subject: [PATCH 15/23] black --- adminutils/adminutils.py | 24 ++++++++++++++++++------ datautils/datautils.py | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 3473d46a..5fe561af 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -189,12 +189,18 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): await ctx.tick() @emoji.command(name="import") - async def emoji_import(self, ctx, name: str, location: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], *roles: discord.Role): + async def emoji_import( + self, + ctx, + name: str, + location: Union[discord.Message, discord.Member, discord.Emoji, discord.PartialEmoji], + *roles: discord.Role, + ): """ Add an emoji from either a member's status, a message, or an emoji from another server. - + Use double quotes if role name has spaces - + Examples: `[p]emoji import 236598364265634245` `[p]emoji import Username#0000 peepoDance` @@ -218,10 +224,16 @@ async def emoji_import(self, ctx, name: str, location: Union[discord.Message, di data = await r.read() elif isinstance(location, discord.Member): emoji = None - if location.activity and location.activity.emoji and location.activity.emoji.is_custom_emoji(): - emoji = location.activity.emoji + if ( + location.activity + and location.activity.emoji + and location.activity.emoji.is_custom_emoji() + ): + emoji = location.activity.emoji if not emoji: - await ctx.send(chat.error(_("This user does not have a custom emoji in their status."))) + await ctx.send( + chat.error(_("This user does not have a custom emoji in their status.")) + ) return async with self.session.get(str(emoji.url)) as r: data = await r.read() diff --git a/datautils/datautils.py b/datautils/datautils.py index 5d3d1e7c..77896f23 100644 --- a/datautils/datautils.py +++ b/datautils/datautils.py @@ -750,7 +750,7 @@ async def emoji_embed(self, ctx, emoji: Union[discord.Emoji, discord.PartialEmoj em.add_field( name=_("Roles"), value=chat.escape("\n".join([x.name for x in emoji.roles]), formatting=True), - inline=False + inline=False, ) elif isinstance(emoji, discord.PartialEmoji): em.add_field( From 0f389dfe5a025c3d4b9168fe52084140aacdfed1 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sat, 19 Sep 2020 23:24:45 -0700 Subject: [PATCH 16/23] name --- adminutils/adminutils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 5fe561af..d4d5ff83 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -209,8 +209,6 @@ async def emoji_import( if isinstance(location, (discord.Emoji, discord.PartialEmoji)): async with self.session.get(str(location.url)) as r: data = await r.read() - if not name: - name = location.name elif isinstance(location, discord.Message): emoji = EMOJI_RE.search(location.content) if not emoji: @@ -237,7 +235,6 @@ async def emoji_import( return async with self.session.get(str(emoji.url)) as r: data = await r.read() - name = emoji.name try: em = await ctx.guild.create_custom_emoji( name=name, From ef8774fd45327ff9cb99c3fbef7eabe0a8aac283 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Fri, 9 Oct 2020 23:58:02 -0700 Subject: [PATCH 17/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index c9b51ece..a384757d 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -206,9 +206,9 @@ async def emoji_import( Use double quotes if role name has spaces Examples: - `[p]emoji import 236598364265634245` - `[p]emoji import Username#0000 peepoDance` - `[p]emoji import :thonk: thonk emojiRole` + `[p]emoji import SomeonesEmoji 236598364265634245` + `[p]emoji import peepoStolenDance Username#0000` + `[p]emoji import thonk :thonk: emojiRole` """ if isinstance(location, (discord.Emoji, discord.PartialEmoji)): async with self.session.get(str(location.url)) as r: From 390fb4c1eb2de96df17d8a35e469f0e1ba2289a6 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sat, 10 Oct 2020 00:03:11 -0700 Subject: [PATCH 18/23] roles message --- adminutils/adminutils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index c9b51ece..7aef7ce3 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -189,7 +189,7 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): except discord.HTTPException as e: await ctx.send(chat.error(_("An error occured on adding an emoji: {}").format(e))) else: - await ctx.send(_(f"{e} created with the name `{e.name}`.")) + await ctx.send(_("{em} created with the name `{em.name}`.".format(em=e))) await ctx.tick() @emoji.command(name="import") @@ -213,6 +213,8 @@ async def emoji_import( if isinstance(location, (discord.Emoji, discord.PartialEmoji)): async with self.session.get(str(location.url)) as r: data = await r.read() + if name == "_": + name = location.name elif isinstance(location, discord.Message): emoji = EMOJI_RE.search(location.content) if not emoji: @@ -239,6 +241,8 @@ async def emoji_import( return async with self.session.get(str(emoji.url)) as r: data = await r.read() + if name == "_": + name = location.name try: em = await ctx.guild.create_custom_emoji( name=name, @@ -247,7 +251,7 @@ async def emoji_import( reason=get_audit_reason( ctx.author, _("Restricted to roles: {}").format( - ", ".join([f"{role.name}" for role in roles]) + ", ".join([role.name for role in roles]) ) if roles else None, @@ -263,7 +267,9 @@ async def emoji_import( except discord.HTTPException as e: await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) else: - await ctx.send(_(f"{em} created with the name `{em.name}`.")) + msg = _("{em} created with the name `{em.name}`".format(em=em)) + msg += _(" and locked to the roles {}.".format(chat.humanize_list(role.name for role in roles)) if roles else ".") + await ctx.send(msg) await ctx.tick() @emoji.command(name="rename") @@ -296,7 +302,7 @@ async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: disco except discord.Forbidden: await ctx.send(chat.error(_("I can't edit this emoji"))) else: - await ctx.send(_(f"{em} edited to `{em.name}`.")) + await ctx.send(_("{em} created with the name `{em.name}`.".format(em=em))) await ctx.tick() @emoji.command(name="remove") From 9d7f6add9502ef0b4e0e5727cfdfdbbe06e6ef40 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Sat, 10 Oct 2020 00:09:54 -0700 Subject: [PATCH 19/23] . --- adminutils/adminutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 86d81daf..b46d6295 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -242,7 +242,7 @@ async def emoji_import( async with self.session.get(str(emoji.url)) as r: data = await r.read() if name == "_": - name = location.name + name = emoji.name try: em = await ctx.guild.create_custom_emoji( name=name, From e5c136ff11b2f03c38c64299140a2b5b31f610fd Mon Sep 17 00:00:00 2001 From: Fixator10 Date: Sat, 10 Oct 2020 11:23:12 +0400 Subject: [PATCH 20/23] add support of original emoji name on import from message --- adminutils/adminutils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index b46d6295..b4e6c216 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -18,7 +18,7 @@ _ = Translator("AdminUtils", __file__) -EMOJI_RE = re.compile(r"(<(a)?:[a-zA-Z0-9_]+:([0-9]+)>)") +EMOJI_RE = re.compile(r"(<(a)?:([a-zA-Z0-9_]+):([0-9]+)>)") @cog_i18n(_) @@ -203,7 +203,8 @@ async def emoji_import( """ Add an emoji from either a member's status, a message, or an emoji from another server. - Use double quotes if role name has spaces + Use double quotes if role name has spaces. + Use `_` as name to preserve original emoji name. Examples: `[p]emoji import SomeonesEmoji 236598364265634245` @@ -222,8 +223,10 @@ async def emoji_import( return url = ( "https://cdn.discordapp.com/emojis/" - f"{emoji.group(3)}.{'gif' if emoji.group(2) else 'png'}?v=1" + f"{emoji.group(4)}.{'gif' if emoji.group(2) else 'png'}?v=1" ) + if name == "_": + name = emoji.group(3) async with self.session.get(url) as r: data = await r.read() elif isinstance(location, discord.Member): From c2763e666c0d5fd7921d8c7cd70edceaaa2f31d2 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:48:49 -0700 Subject: [PATCH 21/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index b4e6c216..6ab1c296 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -271,7 +271,7 @@ async def emoji_import( await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e))) else: msg = _("{em} created with the name `{em.name}`".format(em=em)) - msg += _(" and locked to the roles {}.".format(chat.humanize_list(role.name for role in roles)) if roles else ".") + msg += _(" and locked to the roles {}.".format(chat.humanize_list([role.name for role in roles])) if roles else ".") await ctx.send(msg) await ctx.tick() From 9f070781ebe9bff550724a2a015dede40314fd82 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:49:07 -0700 Subject: [PATCH 22/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 6ab1c296..514308ca 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -305,7 +305,9 @@ async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: disco except discord.Forbidden: await ctx.send(chat.error(_("I can't edit this emoji"))) else: - await ctx.send(_("{em} created with the name `{em.name}`.".format(em=em))) + msg = _("{em} name changed to `{em.name}`".format(em=em)) + msg += _(" and locked to the roles {}.".format(chat.humanize_list([role.name for role in roles])) if roles else ".") + await ctx.send(msg) await ctx.tick() @emoji.command(name="remove") From fe2b4119aa0f5ec6765d84129ccb6e440ae76e76 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n <61065078+phenom4n4n@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:49:26 -0700 Subject: [PATCH 23/23] Update adminutils/adminutils.py Co-authored-by: Fixator10 --- adminutils/adminutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adminutils/adminutils.py b/adminutils/adminutils.py index 514308ca..e99f1364 100644 --- a/adminutils/adminutils.py +++ b/adminutils/adminutils.py @@ -189,7 +189,9 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role): except discord.HTTPException as e: await ctx.send(chat.error(_("An error occured on adding an emoji: {}").format(e))) else: - await ctx.send(_("{em} created with the name `{em.name}`.".format(em=e))) + msg = _("{em} created with the name `{em.name}`".format(em=em)) + msg += _(" and locked to the roles {}.".format(chat.humanize_list([role.name for role in roles])) if roles else ".") + await ctx.send(msg) await ctx.tick() @emoji.command(name="import")