Пример #1
0
    async def cog_before_invoke(self, ctx: Context):
        ctx.error = False
        msg = ctx.message
        # See if user exists in DB
        user = await User.get_user(msg.author)
        if user is None:
            ctx.error = True
            await Messages.send_error_dm(
                msg.author,
                f"You should create an account with me first, send me `{config.Config.instance().command_prefix}help` to get started."
            )
            return
        elif user.frozen:
            ctx.error = True
            await Messages.send_error_dm(
                msg.author,
                f"Your account is frozen. Contact an admin if you need further assistance."
            )
            return
        ctx.user = user
        # Update name if applicable
        await user.update_name(msg.author.name)

        # Special checks for tipfavorites
        if ctx.command.name == 'tipfavorites_cmd':
            # Check admins
            ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
            ctx.admin = False
            author: discord.Member = msg.author
            for role in author.roles:
                if role.id in config.Config.instance().get_admin_roles():
                    ctx.admin = True
                    break
            # Check paused
            if await RedisDB.instance().is_paused():
                ctx.error = True
                await Messages.send_error_dm(
                    msg.author,
                    f"Transaction activity is currently suspended. I'll be back online soon!"
                )
                return
            # See if amount meets tip_minimum requirement
            try:
                send_amount = RegexUtil.find_float(msg.content)
                if send_amount < Constants.TIP_MINIMUM:
                    raise AmountMissingException(
                        f"Tip amount is too low, minimum is {Constants.TIP_MINIMUM}"
                    )
                elif Validators.too_many_decimals(send_amount):
                    await Messages.send_error_dm(
                        ctx.message.author,
                        f"You are only allowed to use {Env.precision_digits()} digits after the decimal."
                    )
                    ctx.error = True
                    return
            except AmountMissingException:
                ctx.error = True

                await Messages.send_usage_dm(msg.author, TIPFAVORITES_INFO)
            ctx.send_amount = send_amount
Пример #2
0
 async def cog_before_invoke(self, ctx: Context):
     ctx.error = False
     # Remove duplicate mentions
     ctx.message.mentions = set(ctx.message.mentions)
     # Only allow giveaway commands in public channels
     msg = ctx.message
     if ChannelUtil.is_private(msg.channel) and ctx.command.name not in [
             'ticketstatus_cmd', 'ticket_cmd'
     ]:
         ctx.error = True
         await Messages.send_error_dm(
             msg.author,
             "You need to use giveaway commands in a public channel")
         return
     else:
         # Determine if user is admin
         ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
         if not ctx.god:
             ctx.admin = False
             for g in self.bot.guilds:
                 member = g.get_member(msg.author.id)
                 if member is not None:
                     for role in member.roles:
                         if role.id in config.Config.instance(
                         ).get_admin_roles():
                             ctx.admin = True
                             break
                 if ctx.admin:
                     break
         else:
             ctx.admin = True
     if ctx.command.name not in 'giveaway_stats_cmd':
         # See if user exists in DB
         user = await User.get_user(msg.author)
         if user is None:
             ctx.error = True
             await Messages.send_error_dm(
                 msg.author,
                 f"You should create an account with me first, send me `{config.Config.instance().command_prefix}help` to get started."
             )
             return
         elif user.frozen:
             ctx.error = True
             await Messages.send_error_dm(
                 msg.author,
                 f"Your account is frozen. Contact an admin if you need further assistance."
             )
             return
         # Update name, if applicable
         await user.update_name(msg.author.name)
         ctx.user = user
Пример #3
0
    async def cog_before_invoke(self, ctx: Context):
        ctx.error = False
        # Only allow tip commands in public channels
        msg = ctx.message
        if ChannelUtil.is_private(
                msg.channel) and ctx.command.name != 'blocks_cmd':
            await Messages.send_error_dm(
                msg.author,
                "You can only view statistics in a server, not via DM.")
            ctx.error = True
            return
        else:
            # Determine if user is admin
            ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
            if not ctx.god:
                ctx.admin = False
                for g in self.bot.guilds:
                    member = g.get_member(msg.author.id)
                    if member is not None:
                        for role in member.roles:
                            if role.id in config.Config.instance(
                            ).get_admin_roles():
                                ctx.admin = True
                                break
                    if ctx.admin:
                        break
            else:
                ctx.admin = True

        # Can't spam stats commands
        if msg.channel.id in config.Config.instance().get_no_spam_channels():
            ctx.error = True
            await Messages.send_error_dm(
                msg.author, "I can't post stats in that channel.")
            return

        if ctx.command.name in ['tipstats_cmd']:
            # Make sure user exists in DB
            user = await User.get_user(msg.author)
            if user is None:
                ctx.error = True
                await Messages.send_error_dm(
                    msg.author,
                    f"You should create an account with me first, send me `{config.Config.instance().command_prefix}help` to get started."
                )
                return
            # Update name, if applicable
            await user.update_name(msg.author.name)
            ctx.user = user
Пример #4
0
 async def cog_before_invoke(self, ctx: Context):
     ctx.error = False
     # Only allow tip commands in public channels
     msg = ctx.message
     # Determine if user is admin
     ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
     if not ctx.god:
         ctx.admin = False
         for g in self.bot.guilds:
             member = g.get_member(msg.author.id)
             if member is not None:
                 for role in member.roles:
                     if role.id in config.Config.instance().get_admin_roles():
                         ctx.admin = True
                         break
             if ctx.admin:
                 break
     else:
         ctx.admin = True
Пример #5
0
    async def cog_before_invoke(self, ctx: Context):
        ctx.error = False
        msg = ctx.message
        # Restrict all commands to admins only
        ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
        if not ctx.god:
            ctx.admin = False
            for g in self.bot.guilds:
                member = g.get_member(msg.author.id)
                if member is not None:
                    for role in member.roles:
                        if role.id in config.Config.instance().get_admin_roles():
                            ctx.admin = True
                            break
                if ctx.admin:
                    break
        else:
            ctx.admin = True

        if not ctx.admin:
            ctx.error = True
Пример #6
0
    async def cog_before_invoke(self, ctx: Context):
        ctx.error = False
        msg = ctx.message
        if ChannelUtil.is_private(ctx.message.channel):
            ctx.error = True
            return
        else:
            # Check admins
            ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
            ctx.admin = False
            author: discord.Member = msg.author
            for role in author.roles:
                if role.id in config.Config.instance().get_admin_roles():
                    ctx.admin = True
                    break

        # Check paused
        if await RedisDB.instance().is_paused():
            ctx.error = True
            await Messages.send_error_dm(
                msg.author,
                f"Transaction activity is currently suspended. I'll be back online soon!"
            )
            return

        # Check anti-spam
        if not ctx.god and await RedisDB.instance().exists(
                f"rainspam{msg.author.id}"):
            ctx.error = True
            await Messages.add_timer_reaction(msg)
            await Messages.send_basic_dm(
                msg.author, "You can only rain once every 5 minutes")
            return

        # Parse some info
        try:
            ctx.send_amount = RegexUtil.find_send_amounts(msg.content)
            if Validators.too_many_decimals(ctx.send_amount):
                await Messages.add_x_reaction(msg)
                await Messages.send_error_dm(
                    msg.author,
                    f"You are only allowed to use {Env.precision_digits()} digits after the decimal."
                )
                ctx.error = True
                return
            elif ctx.send_amount < config.Config.instance().get_rain_minimum():
                ctx.error = True
                await Messages.add_x_reaction(msg)
                await Messages.send_usage_dm(msg.author, RAIN_INFO)
                return
            # See if user exists in DB
            user = await User.get_user(msg.author)
            if user is None:
                await Messages.add_x_reaction(msg)
                await Messages.send_error_dm(
                    msg.author,
                    f"You should create an account with me first, send me `{config.Config.instance().command_prefix}help` to get started."
                )
                ctx.error = True
                return
            elif user.frozen:
                ctx.error = True
                await Messages.add_x_reaction(msg)
                await Messages.send_error_dm(
                    msg.author,
                    f"Your account is frozen. Contact an admin if you need further assistance."
                )
                return
            # Update name, if applicable
            await user.update_name(msg.author.name)
            ctx.user = user
        except AmountMissingException:
            await Messages.add_x_reaction(msg)
            await Messages.send_usage_dm(msg.author, RAIN_INFO)
            ctx.error = True
            return
        except AmountAmbiguousException:
            await Messages.add_x_reaction(msg)
            await Messages.send_error_dm(
                msg.author, "You can only specify 1 amount to send")
            ctx.error = True
            return
Пример #7
0
 async def cog_before_invoke(self, ctx: Context):
     ctx.error = False
     # Remove duplicate mentions
     ctx.message.mentions = set(ctx.message.mentions)
     # Only allow tip commands in public channels
     msg = ctx.message
     if ChannelUtil.is_private(msg.channel):
         ctx.error = True
         return
     else:
         # Check admins
         ctx.god = msg.author.id in config.Config.instance().get_admin_ids()
         ctx.admin = False
         author: discord.Member = msg.author
         for role in author.roles:
             if role.id in config.Config.instance().get_admin_roles():
                 ctx.admin = True
                 break
     # Check paused
     if await RedisDB.instance().is_paused():
         ctx.error = True
         await Messages.send_error_dm(
             msg.author,
             f"Transaction activity is currently suspended. I'll be back online soon!"
         )
         return
     # See if user exists in DB
     user = await User.get_user(msg.author)
     if user is None:
         ctx.error = True
         await Messages.send_error_dm(
             msg.author,
             f"You should create an account with me first, send me `{config.Config.instance().command_prefix}help` to get started."
         )
         return
     elif user.frozen:
         ctx.error = True
         await Messages.send_error_dm(
             msg.author,
             f"Your account is frozen. Contact an admin if you need further assistance."
         )
         return
     # Update name, if applicable
     await user.update_name(msg.author.name)
     ctx.user = user
     # See if amount meets tip_minimum requirement
     try:
         send_amount = RegexUtil.find_float(msg.content)
         if ctx.command.name == 'tiprandom_cmd' and send_amount < Constants.TIPRANDOM_MINIMUM:
             raise AmountMissingException(
                 f"Tip random amount is too low, minimum is {Constants.TIPRANDOM_MINIMUM}"
             )
         elif ctx.command.name != 'tiprandom_cmd' and ctx.command.name != 'burn' and send_amount < Constants.TIP_MINIMUM:
             raise AmountMissingException(
                 f"Tip amount is too low, minimum is {Constants.TIP_MINIMUM}"
             )
         elif ctx.command.name == 'burn' and send_amount < 1.0:
             raise AmountMissingException(f"Come on, burn at least 1 BAN")
         elif Validators.too_many_decimals(send_amount):
             await Messages.send_error_dm(
                 ctx.message.author,
                 f"You are only allowed to use {Env.precision_digits()} digits after the decimal."
             )
             ctx.error = True
             return
     except AmountMissingException:
         ctx.error = True
         if ctx.command.name == 'tip_cmd':
             await Messages.send_usage_dm(msg.author, TIP_INFO)
         elif ctx.command.name == 'tipsplit_cmd':
             await Messages.send_usage_dm(msg.author, TIPSPLIT_INFO)
         elif ctx.command.name == 'tiprandom_cmd':
             await Messages.send_usage_dm(msg.author, TIPRANDOM_INFO)
         elif ctx.command.name == 'burn':
             await Messages.send_basic_dm(
                 msg.author, 'Come on, burn at least 1 ya cheap skate')
         return
     ctx.send_amount = send_amount