Exemplo n.º 1
0
    async def ufw_cmd(self, ctx: Context):
        msg = ctx.message

        try:
            addresses = RegexUtil.find_address_matches(msg.content)
        except AddressMissingException:
            await Messages.add_x_reaction(msg)
            await Messages.send_error_dm(msg.author, "No valid addresses in your ufw command")
            return

        address_list = await Account.filter(address__in=addresses).prefetch_related('user').all()
        if len(address_list) < 1:
            await Messages.add_x_reaction(msg)
            await Messages.send_error_dm(msg.author, "No users found with specified addresses.")
            return

        for acct in address_list:
            response = f"Last known name: {acct.user.name}```{acct.user.id}```"
            response += f"```{acct.address}```"
            if Env.banano():
                response += f"https://creeper.banano.cc/explorer/account/{acct.address}\n"
            else:
                response += f"https://nanocrawler.cc/explorer/account/{acct.address}\n"

        embed = discord.Embed(colour=0xFBDD11 if Env.banano() else discord.Colour.green())
        embed.set_author(name="UFW Result", icon_url="https://github.com/bbedward/Graham_Nano_Tip_Bot/raw/master/assets/banano_logo.png" if Env.banano() else "https://i.imgur.com/7QFgoqT.png")
        embed.description = response

        await msg.author.send(embed=embed)
Exemplo n.º 2
0
 async def ufw(self, request: web.Request):
     """Return user info for specified wallet addresses
       e.g. http://server/wfu/ban_16n5c7qozokx661rneikh6e3mf978mc46qqjen7a51pwzood155bwrha6sfj+ban_37z6omyukgpgttq7bdagweaxdrdm5wjy7tdm97ggtkobdetme3bmhfayjowj"""
     if 'wallet' not in request.match_info:
         return web.HTTPBadRequest(reason="wallet is required")
     try:
         addresses = RegexUtil.find_address_matches(
             request.match_info['wallet'])
     except AddressMissingException:
         return web.HTTPBadRequest(reason="bad address specified")
     accounts = await Account.filter(address__in=addresses
                                     ).prefetch_related('user').all()
     if accounts is None:
         return web.json_response(data={'error': 'user(s) not found'},
                                  dumps=json.dumps)
     resp = []
     for account in accounts:
         resp.append({
             'user_id':
             account.user.id,
             'user_last_known_name':
             account.user.name,
             'address':
             account.address,
             'created_ts_utc':
             self.format_js_iso(account.user.created_at)
         })
     return web.json_response(data=resp, dumps=json.dumps)
Exemplo n.º 3
0
    def test_find_addresses(self):
        # Multiple addresses
        os.environ['BANANO'] = 'true'
        self.assertEqual(
            RegexUtil.find_address_matches(
                'sdasdasban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdadasd'
            ), [
                'ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ])
        self.assertEqual(
            RegexUtil.find_address_matches(
                'sdasdban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdasd ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse sban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ), [
                'ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse',
                'ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse',
                'ban_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ])
        with self.assertRaises(AddressMissingException):
            RegexUtil.find_address_matches('sdadsd')

        del os.environ['BANANO']
        self.assertEqual(
            RegexUtil.find_address_matches(
                'sdasdasnano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdadasd'
            ), [
                'nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ])
        self.assertEqual(
            RegexUtil.find_address_matches(
                'sdasdnano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdasd nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse snano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ), [
                'nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse',
                'nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse',
                'nano_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ])
        with self.assertRaises(AddressMissingException):
            RegexUtil.find_address_matches('sdadsd')
        # XRB
        self.assertEqual(
            RegexUtil.find_address_matches(
                'sdasdasxrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdadasd'
            ), [
                'xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ])
        self.assertEqual(
            RegexUtil.find_address_matches(
                'sdasdxrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48oksesdasd xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse sxrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ), [
                'xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse',
                'xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse',
                'xrb_3jb1fp4diu79wggp7e171jdpxp95auji4moste6gmc55pptwerfjqu48okse'
            ])
        with self.assertRaises(AddressMissingException):
            RegexUtil.find_address_matches('sdadsd')