Skip to content
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
wants to merge 36 commits into
base: V3
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
66a0ddf
membersteal
Sep 8, 2020
566f990
Update adminutils/adminutils.py
phenom4n4n Sep 11, 2020
84e65f1
Update adminutils/adminutils.py
phenom4n4n Sep 11, 2020
35f2854
Update adminutils/adminutils.py
phenom4n4n Sep 11, 2020
41ca0e3
Update adminutils/adminutils.py
phenom4n4n Sep 11, 2020
671921a
steal
Sep 12, 2020
14becd7
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
Sep 12, 2020
d42a9c7
emoji stealin'
Sep 12, 2020
8927d33
newline
Sep 12, 2020
5c0d490
oops
Sep 12, 2020
a1fde58
Update adminutils/adminutils.py
phenom4n4n Sep 12, 2020
f75250b
Update adminutils/adminutils.py
phenom4n4n Sep 12, 2020
966b89f
emoji import
Sep 12, 2020
670dd32
Merge branch 'V3' into emoji_steal
fixator10 Sep 12, 2020
cc2e0da
updates
Sep 13, 2020
2bcd500
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
Sep 13, 2020
54e2e98
try except else
Sep 13, 2020
e5997ce
Merge branch 'V3' into emoji_steal
fixator10 Sep 13, 2020
65a9b34
black
Sep 13, 2020
b2415bb
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
Sep 13, 2020
e1afcd5
Merge branch 'V3' into emoji_steal
fixator10 Sep 16, 2020
df83bc1
Merge branch 'V3' into emoji_steal
fixator10 Sep 16, 2020
2906731
Merge branch 'V3' into emoji_steal
fixator10 Sep 17, 2020
0f389df
name
Sep 20, 2020
fc5080e
Merge branch 'V3' into emoji_steal
fixator10 Oct 10, 2020
6968133
Merge branch 'V3' into emoji_steal
fixator10 Oct 10, 2020
ef8774f
Update adminutils/adminutils.py
phenom4n4n Oct 10, 2020
390fb4c
roles message
Oct 10, 2020
8069ffa
Merge branch 'emoji_steal' of https://github.com/phenom4n4n/Fixator10…
Oct 10, 2020
9d7f6ad
.
Oct 10, 2020
e5c136f
add support of original emoji name on import from message
fixator10 Oct 10, 2020
c2763e6
Update adminutils/adminutils.py
phenom4n4n Oct 10, 2020
9f07078
Update adminutils/adminutils.py
phenom4n4n Oct 10, 2020
fe2b411
Update adminutils/adminutils.py
phenom4n4n Oct 10, 2020
f0eeb16
Merge branch 'V3' into emoji_steal
fixator10 Nov 7, 2020
88bcd45
Merge branch 'V3' into emoji_steal
fixator10 Dec 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 68 additions & 25 deletions adminutils/adminutils.py
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
Expand All @@ -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(_)
Expand Down Expand Up @@ -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,
Expand All @@ -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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = _("{em} created with the name `{em.name}`".format(em=em))
msg = _("{em} created with the name `{em.name}`".format(em=e))

NameError: name 'em' is not defined

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(
_(
Expand All @@ -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):
Expand All @@ -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(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like emoji.edit doesnt return anything, you need to re-get emoji, e.g. via em = bot.get_emoji(emoji.id)

https://discordpy.readthedocs.io/en/stable/api.html#discord.Emoji.edit

name=name,
roles=roles,
reason=get_audit_reason(
Expand All @@ -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")
Expand Down