-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[adminutils] membersteal #47
Open
phenom4n4n
wants to merge
36
commits into
fixator10:V3
Choose a base branch
from
phenom4n4n:emoji_steal
base: V3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
66a0ddf
membersteal
566f990
Update adminutils/adminutils.py
phenom4n4n 84e65f1
Update adminutils/adminutils.py
phenom4n4n 35f2854
Update adminutils/adminutils.py
phenom4n4n 41ca0e3
Update adminutils/adminutils.py
phenom4n4n 671921a
steal
14becd7
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
d42a9c7
emoji stealin'
8927d33
newline
5c0d490
oops
a1fde58
Update adminutils/adminutils.py
phenom4n4n f75250b
Update adminutils/adminutils.py
phenom4n4n 966b89f
emoji import
670dd32
Merge branch 'V3' into emoji_steal
fixator10 cc2e0da
updates
2bcd500
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
54e2e98
try except else
e5997ce
Merge branch 'V3' into emoji_steal
fixator10 65a9b34
black
b2415bb
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
e1afcd5
Merge branch 'V3' into emoji_steal
fixator10 df83bc1
Merge branch 'V3' into emoji_steal
fixator10 2906731
Merge branch 'V3' into emoji_steal
fixator10 0f389df
name
fc5080e
Merge branch 'V3' into emoji_steal
fixator10 6968133
Merge branch 'V3' into emoji_steal
fixator10 ef8774f
Update adminutils/adminutils.py
phenom4n4n 390fb4c
roles message
8069ffa
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
9d7f6ad
.
e5c136f
add support of original emoji name on import from message
fixator10 c2763e6
Update adminutils/adminutils.py
phenom4n4n 9f07078
Update adminutils/adminutils.py
phenom4n4n fe2b411
Update adminutils/adminutils.py
phenom4n4n f0eeb16
Merge branch 'V3' into emoji_steal
fixator10 88bcd45
Merge branch 'V3' into emoji_steal
fixator10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
@@ -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(_) | ||
|
@@ -171,7 +171,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, | ||
|
@@ -189,45 +189,79 @@ 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: | ||
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="message", aliases=["steal"]) | ||
async def emote_steal(self, ctx, name: str, message_id: discord.Message, *roles: discord.Role): | ||
@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, | ||
): | ||
""" | ||
Add an emoji from a specified message | ||
Use double quotes if role name has spaces | ||
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 `_` as name to preserve original emoji name. | ||
|
||
Examples: | ||
`[p]emoji message Example 162379234070467641` | ||
`[p]emoji message RoleBased 162379234070467641 EmojiRole` | ||
`[p]emoji import SomeonesEmoji 236598364265634245` | ||
`[p]emoji import peepoStolenDance Username#0000` | ||
`[p]emoji import thonk :thonk: 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() | ||
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: | ||
await ctx.send(chat.error(_("No emojis found in the specified message."))) | ||
return | ||
url = ( | ||
"https://cdn.discordapp.com/emojis/" | ||
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): | ||
emoji = None | ||
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 | ||
async with self.session.get(str(emoji.url)) as r: | ||
data = await r.read() | ||
if name == "_": | ||
name = emoji.name | ||
try: | ||
await ctx.guild.create_custom_emoji( | ||
em = 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]) | ||
", ".join([role.name for role in roles]) | ||
) | ||
if roles | ||
else None, | ||
), | ||
) | ||
await ctx.tick() | ||
except discord.InvalidArgument: | ||
await ctx.send( | ||
_( | ||
|
@@ -237,6 +271,11 @@ async def emote_steal(self, ctx, name: str, message_id: discord.Message, *roles: | |
return | ||
except discord.HTTPException as e: | ||
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 ".") | ||
await ctx.send(msg) | ||
await ctx.tick() | ||
|
||
@emoji.command(name="rename") | ||
async def emoji_rename(self, ctx, emoji: discord.Emoji, name: str, *roles: discord.Role): | ||
|
@@ -253,7 +292,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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like https://discordpy.readthedocs.io/en/stable/api.html#discord.Emoji.edit |
||
name=name, | ||
roles=roles, | ||
reason=get_audit_reason( | ||
|
@@ -267,6 +306,10 @@ 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: | ||
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") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NameError: name 'em' is not defined