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
Example #2
0
 async def cog_before_invoke(self, ctx: Context):
     ctx.error = False
     msg = ctx.message
     # 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
     if ctx.command.name == 'send_cmd':
         try:
             ctx.send_amount = RegexUtil.find_send_amounts(msg.content)
             if Validators.too_many_decimals(ctx.send_amount):
                 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
         except AmountMissingException:
             await Messages.send_usage_dm(msg.author, SEND_INFO)
             ctx.error = True
             return
         except AmountAmbiguousException:
             await Messages.send_error_dm(msg.author, "You can only specify 1 amount to send")
             ctx.error = True
             return
     if ctx.command.name in ['send_cmd', 'sendmax_cmd']:
         # See if user exists in DB
         user = await User.get_user(msg.author)
         if user is None:
             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.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 they are spammin'
         withdraw_delay = await user.get_next_withdraw_s()
         if withdraw_delay > 0:
             await Messages.send_error_dm(msg.author, f"You need to wait {withdraw_delay}s before you can withdraw again")
             ctx.error = True
             return
         try:
             ctx.destination = RegexUtil.find_address_match(msg.content)
         except AddressMissingException:
             await Messages.send_usage_dm(msg.author, SEND_INFO)
             ctx.error = True
             return
         except AddressAmbiguousException:
             await Messages.send_error_dm(msg.author, "You can only specify 1 destination address")
             ctx.error = True
             return
         if not Validators.is_valid_address(ctx.destination):
             await Messages.send_error_dm(msg.author, "The destination address you specified is invalid")
             ctx.error = True
             return
Example #3
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
Example #4
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