async def convert(self, ctx, argument: str) -> PartialEmoji: # Convert an emoji ID. if argument.isdigit(): return PartialEmoji(id=int(argument), name=None, animated=False) # Convert from an emoji URL. url_match = EMOJI_URL_REGEX.search(argument) if url_match: return PartialEmoji( id=int(url_match.group("id")), name=None, animated=url_match.group("extension") == "png", ) # Convert an actual emoji. try: return await commands.PartialEmojiConverter().convert(ctx, argument) except commands.BadArgument: pass # Scan recently used custom emoji. if argument == "recent": return await self.recent(ctx) raise commands.BadArgument( "Invalid emoji. You can use an actual emoji or an emoji ID or URL. " "You can also specify `recent` to select a recently used emoji." )
def idc_emoji_or_just_string(val): match = re.match( r'<(?P<animated>a)?:(?P<name>[a-zA-Z0-9_]+):(?P<id>[0-9]+)>$', val) if match: return PartialEmoji(name=match.group("name"), id=match.group("id"), animated=bool(match.group("animated"))) return PartialEmoji(name=val.replace(':', ''), id=None, animated=False) # guess it's not animated
async def on_raw_reaction_add(self, emoji: discord.PartialEmoji, message_id: int, channel_id: int, user_id: int): """ Event handler for long term reaction watching. :param discord.PartialReactionEmoji emoji: :param int message_id: :param int channel_id: :param int user_id: :return: """ tracker = await self.config.srtracker() if str(message_id) not in tracker: return log_channel = self._get_channel_from_id(390927071553126402) # await log_channel.send("Message ID: "+str(message_id)+" was just reacted to") tracker = tracker[str(message_id)] guild = self.bot.get_guild(tracker["GUILDID"]) member = guild.get_member(user_id) if member.bot: return if tracker["MID"] != (await self._parseuser(guild, tracker["TID"], member.id)): message = (await self._get_message_from_id(guild, message_id)) await message.remove_reaction(emoji, member) return channel = guild.get_channel(channel_id) message = await channel.get_message(message_id) if emoji.is_custom_emoji(): emoji_id = emoji.id else: emoji_id = emoji.name wld = [(await self.config.win()), (await self.config.loss()), (await self.config.dispute())] if emoji_id not in wld: # Not sure if this works # It does await message.remove_reaction(emoji, member) return if emoji_id == wld[0]: await self._report_win() await log_channel.send("Message ID: " + str(message_id) + " was reporting a win") if emoji_id == wld[1]: await self._report_loss() await log_channel.send("Message ID: " + str(message_id) + " was reporting a loss") if emoji_id == wld[2]: await self._report_dispute(guild, tracker["TID"], tracker["MID"]) await log_channel.send("Message ID: " + str(message_id) + " was reporting a dispute")
async def convert(self, ctx, argument): try: return await super().convert(ctx, argument) except BadArgument: pass # noinspection PyProtectedMember return PartialEmoji.with_state(ctx.bot._connection, animated=False, name=argument, id=None)
async def check_add_role(self, emoji: discord.PartialEmoji, message_id: int, channel_id: int, user_id: int): message = self.get_from_message_cache(channel_id, message_id) if message is not None: guild = message.guild emoji_str = str(emoji.id) if emoji.is_custom_emoji() else emoji.name role = self.get_from_cache(guild.id, channel_id, message_id, emoji_str) member = guild.get_member(user_id) if member is not None and member != guild.me and role is not None: await self.add_role_queue(member, role, True, linked_roles=self.get_link(guild.id, channel_id, message_id))
def _payload_has_duckpond_emoji(self, emoji: discord.PartialEmoji) -> bool: """Test if the RawReactionActionEvent payload contains a duckpond emoji.""" if emoji.is_unicode_emoji(): # For unicode PartialEmojis, the `name` attribute is just the string # representation of the emoji. This is what the helper method # expects, as unicode emojis show up as just a `str` instance when # inspecting the reactions attached to a message. emoji = emoji.name return self._is_duck_emoji(emoji)
async def on_control_reaction_add(self, _, message: discord.Message, emoji: discord.PartialEmoji): if not message.embeds or message.author != self.bot.me or not emoji.is_unicode_emoji( ): return emoji = emoji.name embed = message.embeds[0] if 'MC Bot Help page' in embed.author.name: await self.switch_help_page(emoji, message)
async def steal_emoji(self, ctx, emoji: discord.PartialEmoji, name=None): """Copy an emoji to the server A new name can be provided, otherwise the name is copied Example: %emoji steal <:meowpuffyblush:876190347137548288> """ if not emoji.is_custom_emoji(): return await ctx.send(f'That is not a valid emoji') url = emoji.url emoji_name = name or emoji.name await self.create_emoji(ctx, emoji_name, url)
async def check_remove_role(self, emoji: discord.PartialEmoji, message_id: int, channel_id: int, user_id: int): message = self.get_from_message_cache(channel_id, message_id) if message is not None: guild = message.guild if user_id == guild.me.id: # Safeguard in case a mod removes the bot's reaction by accident await message.add_reaction(emoji) else: emoji_str = str(emoji.id) if emoji.is_custom_emoji() else emoji.name member = guild.get_member(user_id) role = self.get_from_cache(guild.id, channel_id, message_id, emoji_str) if role is not None: await self.add_role_queue(member, role, False)
def dumbEmojiFromPartial(e : PartialEmoji) -> dumbEmoji: """Construct a new dumbEmoji object from a given discord.PartialEmoji. :return: A dumbEmoji representing e :rtype: dumbEmoji """ if type(e) == dumbEmoji: return e if e.is_unicode_emoji(): return dumbEmoji(unicode=e.name) else: return dumbEmoji(id=e.id)
def _parse_emoji(component_tag: Element) -> Optional[EMOJI]: # Search for partial emoji attribute emoji = component_tag.get(ButtonKeys.EMOJI) if emoji is None: # Search for inner Emoji tag emoji_tag = component_tag.find(EMOJI_TAG) if emoji_tag is None: return None animated_raw: str = emoji_tag.get(EmojiKeys.ANIMATED) animated: bool = animated_raw and _parse_boolean(animated_raw) return PartialEmoji(name=emoji_tag.get(EmojiKeys.NAME), animated=animated, id=int(emoji_tag.get(EmojiKeys.ID)))
async def extract_emoji_from_messages(self, messages): parsed_emoji = set() for message in messages: for match in self.emoji_extraction_pattern.finditer( message.content): animated = bool(match.group(1)) name = match.group(2) emoji_id = int(match.group(3)) emoji = PartialEmoji.with_state(self.bot._connection, animated=animated, name=name, id=emoji_id) parsed_emoji.add(emoji) return parsed_emoji
async def set_emoji(self, ctx, emo: discord.PartialEmoji): context.new_guild_check(ctx.guild.id) if ctx.message.author.guild_permissions.administrator: if emo.is_custom_emoji(): context.guilds[ctx.guild.id].emoji = str(emo) await ctx.send("El nuevo emoji es " + str(context.guilds[ctx.guild.id].emoji)) await ctx.message.add_reaction( context.guilds[ctx.guild.id].emoji) context.save() else: await ctx.send("Solo lo puede ocupar un administrador") await ctx.message.add_reaction(context.guilds[ctx.guild.id].emoji)
def get_proficiency_by_emoji(emoji: PartialEmoji): global proficiency_emojis if proficiency_emojis is None: proficiency_emojis = { 0: '1️⃣', 1: '2️⃣', 2: '3️⃣', 3: '4️⃣' } if emoji.is_unicode_emoji(): for key in proficiency_emojis: if proficiency_emojis[key] == emoji.name: return key return None
async def check_remove_role( self, emoji: discord.PartialEmoji, message_id: int, channel_id: int, user_id: int ): message = self.get_from_message_cache(channel_id, message_id) if message is not None: guild = message.guild if ( user_id == guild.me.id ): # Safeguard in case a mod removes the bot's reaction by accident await message.add_reaction(emoji) else: emoji_str = str(emoji.id) if emoji.is_custom_emoji() else emoji.name member = guild.get_member(user_id) role = self.get_from_cache(guild.id, channel_id, message_id, emoji_str) if role is not None: await self.add_role_queue(member, role, False)
async def check_add_role( self, emoji: discord.PartialEmoji, message_id: int, channel_id: int, user_id: int ): message = self.get_from_message_cache(channel_id, message_id) if message is not None: guild = message.guild emoji_str = str(emoji.id) if emoji.is_custom_emoji() else emoji.name role = self.get_from_cache(guild.id, channel_id, message_id, emoji_str) member = guild.get_member(user_id) if member is not None and member != guild.me and role is not None: await self.add_role_queue( member, role, True, linked_roles=self.get_link(guild.id, channel_id, message_id), )
def is_emoji_equal( partial_emoji: discord.PartialEmoji, emoji: Union[str, discord.Emoji, discord.PartialEmoji], ): """ Utility to compare a partial emoji with any other kind of emoji """ if isinstance(emoji, discord.PartialEmoji): return partial_emoji == emoji if isinstance(emoji, discord.Emoji): if partial_emoji.is_unicode_emoji(): return False return emoji.id == partial_emoji.id return str(partial_emoji) == emoji
async def on_raw_reaction_add(self, emoji: discord.PartialEmoji, message_id: int, channel_id: int, user_id: int): """ Event handler for long term reaction watching. :param discord.PartialReactionEmoji emoji: :param int message_id: :param int channel_id: :param int user_id: :return: """ if emoji.is_custom_emoji(): emoji_id = emoji.id else: emoji_id = emoji.name has_reactrestrict, combos = await self.has_reactrestrict_combo( message_id) if not has_reactrestrict: return try: member = self._get_member(channel_id, user_id) except LookupError: return if member.bot: return if await self.bot.cog_disabled_in_guild(self, member.guild): return try: roles = [self._get_role(member.guild, c.role_id) for c in combos] except LookupError: return for apprrole in roles: if apprrole in member.roles: return message = await self._get_message_from_channel(channel_id, message_id) await message.remove_reaction(emoji, member)
def fromPartial(cls, e: PartialEmoji, rejectInvalid: bool = False) -> BasedEmoji: """Construct a new BasedEmoji object from a given discord.PartialEmoji. :param bool rejectInvalid: When true, an exception is guaranteed to raise if an invalid emoji is requested, regardless of raiseUnknownEmojis (Default False) :raise exceptions.UnrecognisedCustomEmoji: When rejectInvalid=True is present in kwargs, and a custom emoji is given that does not exist or the client cannot access. :return: A BasedEmoji representing e :rtype: BasedEmoji """ if isinstance(e, BasedEmoji): return e if e.is_unicode_emoji(): return BasedEmoji(unicode=e.name, rejectInvalid=rejectInvalid) else: return BasedEmoji(id=e.id, rejectInvalid=rejectInvalid)
async def create(self, *, guild, name, image: bytes, role_ids=(), reason=None): data = await self.request( 'POST', f'/guilds/{guild.id}/emojis', guild.id, json=dict(name=name, image=image_utils.image_to_base64_url(image), roles=role_ids), reason=reason, ) return PartialEmoji(animated=data.get('animated', False), name=data.get('name'), id=data.get('id'))
def reducer( emoji: Set[PartialEmoji], msg: discord.Message ) -> Set[PartialEmoji]: match = EMOJI_REGEX.search(msg.content) if not match: return emoji emoji_id = int(match.group("id")) # If the emoji used is already in the guild, ignore. if discord.utils.get(ctx.guild.emojis, id=emoji_id): return emoji new_emoji = PartialEmoji( animated=bool(match.group("animated")), name=match.group("name"), id=emoji_id, ) return emoji | set([new_emoji])
from discord import PartialEmoji battlenet = PartialEmoji(name="battlenet", id=679469162724196387) psn = PartialEmoji(name="psn", id=679468542541693128) xbl = PartialEmoji(name="xbl", id=679469487623503930) switch = PartialEmoji(name="nsw", id=752653766377078817) # emojis for custom nickname u_tank = "\N{SHIELD}" u_damage = "\N{CROSSED SWORDS}" u_support = "\N{HEAVY GREEK CROSS}" tank = PartialEmoji(name="tank", id=645784573141319722) damage = PartialEmoji(name="damage", id=645784543093325824) support = PartialEmoji(name="support", id=645784563322191902) sr = PartialEmoji(name="sr", id=639897739920146437) online = PartialEmoji(name="online", id=648186001361076243) dnd = PartialEmoji(name="dnd", id=648185968209428490) offline = PartialEmoji(name="offline", id=648185992360099865) bronze = PartialEmoji(name="bronze", id=632281015863214096) silver = PartialEmoji(name="silver", id=632281054211997718) gold = PartialEmoji(name="gold", id=632281064596832278) platinum = PartialEmoji(name="platinum", id=632281092875091998) diamond = PartialEmoji(name="diamon", id=632281105571119105) master = PartialEmoji(name="master", id=632281117394993163) grand_master = PartialEmoji(name="grandmaster", id=632281128966946826) check = "\N{WHITE HEAVY CHECK MARK}"
class RemovableMessage(ReactionMessage): EMOJIS: Tuple[PartialEmoji, ...] = (PartialEmoji(name="❌"), ) async def react_action(self, reacted_emoji: PartialEmoji) -> None: await self.message.delete()
from discord import PartialEmoji BLOB_SALUTE = PartialEmoji(animated=False, name="pinkblobsalute", id=544625129997598733) BLOB_THINK = PartialEmoji(animated=False, name="pinkblobthinks", id=511626506049683458) BLOB_TICK = PartialEmoji(animated=False, name="pinkblobyes", id=544628885153906698) BLOB_CROSS = PartialEmoji(animated=False, name="pinkblobdeny", id=544628885258633216) BLOB_PLSNO = PartialEmoji(animated=False, name="pinkblobplsno", id=511668250313097246) BLOB_WINK = PartialEmoji(animated=False, name="pinkblobwink", id=544628885023621126) BLOB_PARTY = PartialEmoji(animated=True, name="partyblob", id=561657508041588786) BLOB_O = PartialEmoji(animated=False, name="pinkbolb", id=511660130195210263) BLOB_THUMB = PartialEmoji(animated=False, name="pinkblobthumbsup", id=511649152669843477) BLOB_ARMSCROSSED = PartialEmoji(animated=False, name="pinkblobcrossedarms", id=512477512719400970) BLOB_ANGERY = PartialEmoji(animated=False,
class Emoji: online = PartialEmoji(name='online', id=659012420735467540) idle = PartialEmoji(name='idle', id=659012420672421888) dnd = PartialEmoji(name='dnd', id=659012419296952350) offline = PartialEmoji(name='offline', id=659012420273963008) tick = PartialEmoji(name='tick', id=688829439659737095) cross = PartialEmoji(name='cross', id=688829441123942416) discord = PartialEmoji(name='discord', id=626486432793493540) dpy = PartialEmoji(name='dpy', id=622794044547792926) python = PartialEmoji(name='python', id=622621989474926622) postgres = PartialEmoji(name='postgres', id=689210432031817750) text = PartialEmoji(name='textchannel', id=661376810214359041) voice = PartialEmoji(name='voicechannel', id=661376810650435624) loading = PartialEmoji(name='loading', id=661210169870516225, animated=True) eq = PartialEmoji(name='eq', id=688741356524404914, animated=True) cpu = PartialEmoji(name='cpu', id=622621524418887680) ram = PartialEmoji(name='ram', id=689212498544820301)
from discord import PartialEmoji # Feel free to add/change constants with caution for pre-existing constants! # pylint: disable=invalid-name TRANSPARENT_DARK = 0x36393E aLOADING = PartialEmoji(animated=True, name="loading", id=420942895638642699) CHECK = PartialEmoji(animated=False, name="check", id=474939098075758604) CROSS = PartialEmoji(animated=False, name="cross", id=474939098625474560)
from discord import PartialEmoji NEGEVCHARGE = PartialEmoji(animated=True, name="negevcharge", id=565233628246704139) AWORRY = PartialEmoji(animated=True, name="aworry", id=600845978840465425) ALBASPARKLE = PartialEmoji(animated=False, name="AlbaSparkle", id=600006042822377478) MIKASASNAPPED = PartialEmoji(animated=False, name="mikasapped", id=600004777056665631) MIKASASHOCK = PartialEmoji(animated=False, name="Mikasashock", id=60000559947173069) TRANSPARENT = PartialEmoji(animated=False, name="trans", id=600959039551307776) GUN = PartialEmoji(animated=True, name="fire0", id=594222734574223363) FIRE_ZERO = PartialEmoji(animated=True, name="fire1", id=594222779193229491) NUKE = PartialEmoji(animated=False, name="nuke", id=594229212328755232) EXPLOSION = PartialEmoji(animated=True, name="explosion", id=594231696241590322) RIGHT_POINT = PartialEmoji(animated=False, name="rightpoint", id=624200769620410378) LEFT_POINT = PartialEmoji(animated=False, name="leftpoint", id=624200756563804162) DRIGHT_POINT = PartialEmoji(animated=False,
async def emo(ctx, arg, meo: discord.PartialEmoji): print('Была введена строчка: ' + arg) arg = str.lower(arg) if meo.is_custom_emoji(): await ctx.channel.send('Ждите...') url_pic = str(meo.url) # Скачиваем изображение png with open('pic.png', 'wb') as handle: response = requests.get(url_pic, stream=True) if not response.ok: print(response) for block in response.iter_content(1024): if not block: break handle.write(block) # Открываем изображение "пиксель" pic = Image.open('pic.png') w_pic = pic.width # Ширина изображения "пикселя" h_pic = pic.height # Высота изображения "пикселя" width = (len(arg) - 1) * w_pic # Начальная ширина итогового изображения height = 0 # Начальная высота итогового изображения height_cells = 0 # Высота итогового изображения в "пикселях" # Определяем размер итогового изображения for el in arg: if el in dic.keys(): li2 = dic.get(el) width = width + (int(li2[0]) * w_pic) if height < int(li[1]) * h_pic: height = int(li2[1]) * h_pic height_cells = int(li2[1]) result = Image.new('RGBA', (width, height), (0, 0, 0, 0)) # Создаем итоговое пустое изображение # Собираем буквы в слова x_res = 0 y_res = 0 msg = await ctx.channel.send('Прогресс: 0%') co = 0 for el in arg: if el == '_': x_res = x_res + w_pic co = co + 1 else: if el in dic.keys(): li2 = dic.get(el) w_cells = int( li2[0]) # Ширина буквы в количестве "пикселей" h_cells = int( li2[1]) # Высота буквы в количестве "пикселей" w_letter = w_pic * w_cells # Ширина буквы в пикселях h_letter = h_pic * h_cells # Высота буквы в пикселях letter = Image.new( 'RGBA', (w_letter, h_letter), (0, 0, 0, 0)) # Создаем пустое изображение буквы x = 0 y = 0 n = 2 while n < w_cells * h_cells + 2: if int(li2[n]) == 1: letter.paste(pic, (x, y), pic) x = x + w_pic else: x = x + w_pic if (n - 1) % w_cells == 0: y = y + h_pic x = 0 n = n + 1 if h_cells < height_cells: razn = height_cells - h_cells y_res = y_res + razn * h_pic result.paste(letter, (x_res, y_res), letter) y_res = y_res - razn * h_pic else: result.paste(letter, (x_res, y_res), letter) x_res = x_res + w_letter + w_pic result.save('result.png') co = co + 1 loading = co * 100 / len(arg) await msg.edit(content='Прогресс: ' + str(loading) + '%') else: await ctx.channel.send('Недопустимый символ!') break else: await ctx.channel.send(file=discord.File('result.png') ) # Вывод результата
from discord import PartialEmoji KAZ_HAPPY = PartialEmoji(animated=False, name="kazukihappy", id=564090074480771086) ONE_POUT = PartialEmoji(animated=False, name="onoepout", id=564099210329194496) ARI_DERP = PartialEmoji(animated=False, name="arimuraderp", id=564105049379307530) YAM_SAD = PartialEmoji(animated=False, name="yamazoesad", id=564100708522131458) POPULAR = PartialEmoji(animated=False, name="popular", id=550253474370027521) HAND = PartialEmoji(animated=False, name="stophand", id=564114808220286976) FORWARD = PartialEmoji(animated=False, name="forward", id=564116143464382495) BACKWARDS = PartialEmoji(animated=False, name="backwards", id=564116143565045761) FESTIVE = PartialEmoji(animated=False, name="festive", id=566690416326475779)
# -*- coding: utf-8 -*- import asyncio import logging import re import discord from discord import PartialEmoji from discord.ext import commands from cog.misc import Misc from configuration import ConfigNode from utility import DictAccess ri_emoji = [ PartialEmoji(animated=False, name='🇦', id=None), PartialEmoji(animated=False, name='🇧', id=None), PartialEmoji(animated=False, name='🇨', id=None), PartialEmoji(animated=False, name='🇩', id=None), PartialEmoji(animated=False, name='🇪', id=None), PartialEmoji(animated=False, name='🇫', id=None), PartialEmoji(animated=False, name='🇬', id=None), PartialEmoji(animated=False, name='ðŸ‡', id=None), PartialEmoji(animated=False, name='🇮', id=None), PartialEmoji(animated=False, name='🇯', id=None), PartialEmoji(animated=False, name='🇰', id=None), PartialEmoji(animated=False, name='🇱', id=None), PartialEmoji(animated=False, name='🇲', id=None), PartialEmoji(animated=False, name='🇳', id=None), PartialEmoji(animated=False, name='🇴', id=None), PartialEmoji(animated=False, name='🇵', id=None),
class ConfirmationMessage(ReactionMessage): EMOJIS: Tuple[PartialEmoji, ...] = (PartialEmoji(name="✅"), PartialEmoji(name="❌")) async def react_action(self, reacted_emoji: PartialEmoji) -> bool: return reacted_emoji == self.EMOJIS[0]
from discord import PartialEmoji emoji_dict = { 'info': PartialEmoji(name="info", id=475570696345485332, animated=False), 'weapon': PartialEmoji(name="weapon", id=475570695523401739, animated=False), 'ring': PartialEmoji(name="ring", id=475570695577927680, animated=False), 'jewels': PartialEmoji(name="jewels", id=475570695422738432, animated=False), 'helmet': PartialEmoji(name="helmet", id=475570696437891092, animated=False), 'gloves': PartialEmoji(name="gloves", id=475570695179468801, animated=False), 'gems': PartialEmoji(name="gems", id=475571905978564608, animated=False), 'boots': PartialEmoji(name="boots", id=475570695980449797, animated=False), 'bodyarmour': PartialEmoji(name="bodyarmour", id=475570697083682826, animated=False), 'amulet': PartialEmoji(name="amulet", id=475570696643411978, animated=False), 'belt': PartialEmoji(name="belt", id=475570694772621315, animated=False), 'flask': PartialEmoji(name="flask", id=489892408893505567, animated=False) }