コード例 #1
0
    async def list(self, context, image_type='all'):
        """A list of all emotes on this server.

		The list shows each emote and its raw form.

		If "animated" is provided, only show animated emotes.
		If "static" is provided, only show static emotes.
		If “all” is provided, show all emotes.
		"""
        emotes = sorted(filter(image_type, context.guild.emojis),
                        key=lambda e: e.name.lower())

        processed = []
        for emote in emotes:
            raw = str(emote).replace(':', r'\:')
            processed.append(f'{emote} {raw}')

        paginator = ListPaginator(context, processed)
        self.paginators.add(paginator)
        await paginator.begin()
コード例 #2
0
ファイル: emote.py プロジェクト: saucylegs/EmoteManager
    async def identify(self, context, url, look_for="all"):
        """Displays names and URLs of all the emotes used in a message or reacted to a message.

		url: The URL of the message you would like to identify the emotes of. Message must be from this server, unless you are running this command in DM.

		If "message" is provided, then only emotes within the linked message will be returned.
		If "reaction" is provided, then only reactions to the linked message will be returned.
		If "all" is provided, then both will be returned. (default)
		"""
        url_match = re.findall(
            "^https://[a-z]*.?discord.com/channels/([0-9]{18})/([0-9]{18})/([0-9]{18})$",
            url)
        if url_match:
            if (not context.guild) or (url_match[0][0] == str(
                    context.guild.id)):
                try:
                    url_channel = self.bot.get_channel(int(url_match[0][1]))
                    url_message = await url_channel.fetch_message(
                        int(url_match[0][2]))
                except:
                    await context.send(
                        f'{utils.SUCCESS_EMOJIS[False]} I cannot access this message.'
                    )
                else:
                    results = []
                    if (look_for == "message") or (look_for == "all"):
                        em_match = re.findall(
                            "<(a)?:([A-z0-9-_]{2,32}):([0-9]{18})>",
                            url_message.content)
                        if em_match:
                            emotes_in = []
                            for i in em_match:
                                # Removing duplicate list items
                                if i not in emotes_in:
                                    emotes_in.append(i)
                            for emote in emotes_in:
                                if emote[0]:
                                    results.append(
                                        f":{emote[1]}: https://cdn.discordapp.com/emojis/{emote[2]}.gif"
                                    )
                                else:
                                    results.append(
                                        f":{emote[1]}:\nhttps://cdn.discordapp.com/emojis/{emote[2]}.png"
                                    )
                    if (look_for == "reaction") or (look_for == "all"):
                        if url_message.reactions:
                            for reaction in url_message.reactions:
                                if reaction.custom_emoji:
                                    results.append(
                                        f"(reaction) :{reaction.emoji.name}: {reaction.emoji.url}"
                                    )
                                else:
                                    results.append(
                                        f"(reaction) {reaction.emoji} (Unicode emoji)"
                                    )
                    if results == []:
                        await context.send(
                            "I did not see any emotes in this message.")
                    else:
                        paginator = ListPaginator(context, results)
                        self.paginators.add(paginator)
                        await paginator.begin()
            else:
                await context.send(
                    f'{utils.SUCCESS_EMOJIS[False]} You are only allowed to specify a message from within this server.'
                )
        else:
            await context.send(
                f"{utils.SUCCESS_EMOJIS[False]} You did not specify a valid URL. You can get a message's URL by right clicking on it and selecting 'Copy Message Link'."
            )