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
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
def test_find_send_amounts(self): self.assertEqual(RegexUtil.find_send_amounts('Hello 1.23 World'), 1.23) with self.assertRaises(AmountMissingException): RegexUtil.find_send_amounts('Hello World') with self.assertRaises(AmountAmbiguousException): RegexUtil.find_send_amounts('Hello 1.23 4.56 World')