Пример #1
0
 async def buttonctrl(cls,
                      reaction: discord.Reaction,
                      user: discord.User,
                      pgr: pager.Pager,
                      *,
                      double: int = 5):
     emj = reaction.emoji
     try:
         if emj == '⏪':
             if double == 0:
                 pgr.go_first(exc=True)
             else:
                 pgr.minus(double, exc=True)
         elif emj == '⏩':
             if double == 0:
                 pgr.go_end(exc=True)
             else:
                 pgr.plus(double, exc=True)
         elif emj == '◀':
             pgr.prev(exc=True)
         elif emj == '▶':
             pgr.next(exc=True)
         elif emj == '⏹':
             return reaction.message.clear_reactions()
     except StopIteration:
         await reaction.remove(user)
         return
     else:
         return reaction.remove(user)
Пример #2
0
 def check(reaction: Reaction, user):
     if reaction.message.id == message.id and user.id != self.user.id:
         asyncio.ensure_future(reaction.remove(user))
     if user != target or reaction.message.id != message.id:
         return False
     return emotes is None or len(emotes) == 0 or str(
         reaction.emoji) in [str(e) for e in emotes]
Пример #3
0
    async def on_reaction_add(self, reaction: discord.Reaction,
                              user: discord.Member):
        member = conn.execute(
            "SELECT * FROM members WHERE main_account_id == ? AND id = ? AND member_enabled = 1",
            [user.id, reaction.message.author.id],
        ).fetchone()

        # Check for correct user
        if member is not None:
            # Delete React
            if type(reaction.emoji) is str:
                if (emoji.demojize(reaction.emoji)
                        or "") == ":cross_mark:":  # Discord name: x
                    await reaction.message.delete()

                # Edit React
                if (emoji.demojize(reaction.emoji)
                        or "") == ":memo:":  # Discord name: pencil
                    self.edit_session.append(user.id)
                    embed = discord.Embed(
                        description=
                        f"You are now editing a [message]({reaction.message.jump_url})\nYour next message will replace it's contents.",
                        color=discord.Color.orange(),
                    )
                    embed.set_footer(text='Type "cancel" to cancel edit')
                    instructions = await reaction.message.channel.send(
                        f"{user.mention}", embed=embed)

                    try:

                        # Wait 30 seconds for new message
                        message = await self.bot.wait_for(
                            "message",
                            check=lambda message: message.author.id == member[
                                "main_account_id"],
                            timeout=30,
                        )

                        # On new message, do all the things
                        # If message isn't "cancel" then momentarily switch bot tokens and edit the message
                        if message.content.lower() != "cancel":
                            while await helper.edit_as(
                                    reaction.message, message.content,
                                    member["token"]) is False:
                                await reset()
                        # Delete instructions and edit message with main bot (again, low-level is easier without ctx)
                        await instructions.delete()
                        # bot.http.delete_message(instructions.channel.id, instructions.id),
                        await message.delete()
                        # bot.http.delete_message(message.channel.id, message.id),
                        await reaction.remove(user)

                    # On timeout, delete instructions and reaction
                    except asyncio.TimeoutError:
                        # Delete instructions with main bot
                        await asyncio.gather(instructions.delete(),
                                             reaction.remove(user))

                    self.edit_session.remove(user.id)
Пример #4
0
    def check(self, reaction: discord.Reaction, user: discord.Member):
        if self.op.id != user.id or reaction.message.id != self.message.id:
            return False

        emoji = reaction.emoji

        if emoji != "◀️" and emoji != "▶️":
            return False

        asyncio.get_running_loop().create_task(reaction.remove(user))

        if emoji == "◀️" and self.page > 0:
            self.page += -1
        elif emoji == "▶️" and self.page < self.total_pages:
            self.page += 1
        else:
            return False
        return True