Exemplo n.º 1
0
    async def on_reaction_add(self, reaction, user):
        if user == self.bot.user:
            return
        try:
            bannee = reaction.message.author
            banner = user
            if banner == bannee:
                return

            msg = reaction.message
            if reaction.emoji == "🙏":
                self.decrement_ban(bannee)
            elif reaction.emoji.id == BANNED:
                self.increment_ban(bannee)
            elif msg.author == self.bot.user:
                embed = msg.embeds[0]
                bannee_name = embed.fields[1].value.split("#")[0]
                bannee_disc = embed.fields[1].value.split("#")[1]
                bannee = dutils.get(msg.guild.members, name=bannee_name, discriminator=bannee_disc)
                og_banner = dutils.get(msg.guild.members,
                                       name=embed.fields[0].value.split("#")[0],
                                       discriminator=embed.fields[0].value.split("#")[1])
                if banner == bannee:
                    return
                if banner == og_banner:
                    return

                if embed.title == "Ban!":
                    embed_desc = BAN_MSG_TEMPLATE
                    green_tick_func = self.increment_ban
                    red_tick_func = self.decrement_ban
                elif embed.title == "Unban!":
                    embed_desc = UNBAN_MSG_TEMPLATE
                    green_tick_func = self.decrement_ban
                    red_tick_func = self.increment_ban
                
                if str(reaction.emoji) == '✅':
                    green_tick_func(bannee)
                elif str(reaction.emoji) == '❎':
                    red_tick_func(bannee)

                new_bans = db.get_bans({"u_id": bannee.id, "g_id": bannee.guild.id})[0]
                embed.description = embed_desc.format(bannee_name, new_bans)
                if msg in self.embed_edit_tasks:
                    self.embed_edit_tasks[msg].cancel()
                self.embed_edit_tasks[msg] = asyncio.create_task(self.edit_embed(msg, embed))
        except AttributeError:
            # The emoji was a unicode emoji, we don't care about it
            pass
        except IndexError:
            # Message did not contain any embeds
            pass
Exemplo n.º 2
0
    async def unban(self, ctx, user_mention):
        banner = ctx.message.author
        bannee = ctx.message.guild.get_member(int(user_mention.strip("<>@!")))
        
        if banner == bannee:
            return

        self.decrement_ban(bannee)
        ban_count = db.get_bans({"u_id": bannee.id, "g_id": bannee.guild.id})[0]

        ban_msg = await ctx.send(embed=create_ban_embed(banner, bannee, ban_count, ban=False))
        await ban_msg.add_reaction(self.bot.get_emoji('✅'))
        await ban_msg.add_reaction(self.bot.get_emoji('❎'))
Exemplo n.º 3
0
 def decrement_ban(self, bannee):
     cur_bans = db.get_bans({"u_id": bannee.id, "g_id": bannee.guild.id})[0]
     db.update_bans({"count": cur_bans - 1, "u_id": bannee.id, "g_id": bannee.guild.id})