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
def test_find_address(self): os.environ['BANANO'] = 'true' self.assertEqual( RegexUtil.find_address_match( 'sdasdasban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdadasd' ), 'ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse') with self.assertRaises(AddressAmbiguousException): RegexUtil.find_address_match( 'sdasdban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdasd ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse sban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse' ) with self.assertRaises(AddressMissingException): RegexUtil.find_address_match('sdadsd') del os.environ['BANANO'] self.assertEqual( RegexUtil.find_address_match( 'sdasdasnano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdadasd' ), 'nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse' ) with self.assertRaises(AddressAmbiguousException): RegexUtil.find_address_match( 'sdasdnano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdasd nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse snano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse' ) with self.assertRaises(AddressMissingException): RegexUtil.find_address_match('sdadsd') # XRB self.assertEqual( RegexUtil.find_address_match( 'sdasdasxrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdadasd' ), 'xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse') with self.assertRaises(AddressAmbiguousException): RegexUtil.find_address_match( 'sdasdxrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdasd xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse sxrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse' ) with self.assertRaises(AddressMissingException): RegexUtil.find_address_match('sdadsd')