Пример #1
0
 async def remove(self, ctx, subject=None, id: int = None):
     """Remove review from DB. User is just allowed to remove his own review
     For admin it is possible to use 'id' as subject shorcut and delete review by its ID
     """
     if not await self.check_member(ctx):
         return
     if subject is None:
         if utils.is_bot_admin(ctx):
             await ctx.send(messages.review_remove_format_admin)
         else:
             await ctx.send(messages.review_remove_format)
     elif subject == "id":
         if utils.is_bot_admin(ctx):
             if id is None:
                 await ctx.send(messages.review_remove_id_format)
             else:
                 review_repo.remove(id)
                 await ctx.send(messages.review_remove_success)
         else:
             await ctx.send(utils.fill_message("insufficient_rights", user=ctx.author.id))
     else:
         subject = subject.lower()
         if self.rev.remove(str(ctx.message.author.id), subject):
             await ctx.send(messages.review_remove_success)
         else:
             await ctx.send(messages.review_remove_error)
Пример #2
0
 async def remove(self, inter: disnake.ApplicationCommandInteraction, subject: str = None, id: int = None):
     """Remove review from DB. User is just allowed to remove his own review
     For admin it is possible to use 'id' as subject shortcut and delete review by its ID
     """
     if id is not None:
         if utils.is_bot_admin(inter):
             self.repo.remove(id)
             await inter.send(Messages.review_remove_success)
             return
     elif subject is not None:
         subject = subject.lower()
         if self.manager.remove(str(inter.author.id), subject):
             await inter.send(Messages.review_remove_success)
             return
     await inter.send(Messages.review_remove_error)
Пример #3
0
    async def proposal_remove(self, ctx, proposal_nums: commands.Greedy[int],
                              *, reason):
        """Remove one or more proposals (and renumber subsequent ones accordingly).

        You must be an admin or the owner of a proposal to remove it.

        proposal_nums -- A list of proposal numbers to remove
        reason -- Justification for removal (applies to all proposals removed)
        """
        if not proposal_nums:
            await invoke_command_help(ctx)
            return
        game = get_game(ctx)
        for n in proposal_nums:
            # Make sure proposal exists and make sure that the user has
            # permission to remove it.
            if not ((game.get_proposal(n)['author'] == ctx.author.id
                     and game.get_proposal(n)['timestamp'] <
                     datetime.utcnow().timestamp() + 60 * 60 * 6)
                    or is_bot_admin(ctx.author)):
                raise UserInputError(
                    f"You don't have permission to remove proposal #{n}.")
        proposal_amount = 'ALL' if proposal_nums == 'all' else len(
            proposal_nums)
        proposal_pluralized = f"proposal{'s' * (len(proposal_nums) != 1)}"
        m = await ctx.send(embed=make_embed(
            color=colors.EMBED_ASK,
            title=f"Remove {proposal_amount} {proposal_pluralized}?",
            description="Are you sure? This cannot be undone."))
        response = await react_yes_no(ctx, m)
        await m.edit(embed=make_embed(
            color=YES_NO_EMBED_COLORS[response],
            title=f"Proposal removal {YES_NO_HUMAN_RESULT[response]}"))
        if response == 'y':
            game = get_game(ctx)
            await game.remove_proposal(ctx.author,
                                       *proposal_nums,
                                       reason=reason,
                                       m=m)
            await game.wait_delete_if_illegal(ctx.message, m)
Пример #4
0
    async def callback(self, inter: disnake.MessageInteraction):
        """React to user selecting cog(s)."""
        await inter.response.defer()
        if utils.is_bot_admin(inter):
            unloaded = self.create_cog_lists()

            for cog in self.unloadable_cogs:
                if cog in self.values:
                    await inter.send(utils.fill_message("cog_not_unloadable", cog=cog))
                    self.options = self.create_select()
                    self.values.remove(cog)

            if not self.reload:
                for cog in self.values:
                    if cog in unloaded:
                        try:
                            self.bot.load_extension(f"cogs.{cog}")
                            print(utils.fill_message("cog_loaded", cog=cog))
                        except Exception as e:
                            await inter.send(f"Loading error\n`{e}`")
                    else:
                        try:
                            self.bot.unload_extension(f"cogs.{cog}")
                            print(utils.fill_message("cog_unloaded", cog=cog))
                        except Exception as e:
                            await inter.send(f"Unloading error\n`{e}`")
            else:
                for cog in self.values:
                    try:
                        self.bot.reload_extension(f"cogs.{cog}")
                        print(utils.fill_message("cog_reloaded", cog=cog))
                        await inter.channel.send(utils.fill_message("cog_reloaded", cog=cog))
                    except Exception as e:
                        await inter.send(f"Reloading error\n`{e}`")

            self.options = self.create_select()
            await self.msg.edit(embed=self.create_embed(inter.author.colour), view=self._view)
        else:
            await inter.send(utils.fill_message("insufficient_rights", user=inter.author.id), ephemeral=True)