示例#1
0
 def test_purge_clears_expired_items(self):
     """ Test that calling _purge() removes expired items """
     ttl_dict = TTLOrderedDict(1, a=1, b=2)
     self.assertEqual(sorted(ttl_dict.keys()), sorted(['a', 'b']))
     time.sleep(2)
     ttl_dict._purge()
     self.assertEqual(len(ttl_dict), 0)
     self.assertEqual(list(ttl_dict.keys()), [])
示例#2
0
    def test_schedule_purge_multiple_run(self):
        """ Test that calling _purge() removes expired items """
        ttl_dict = TTLOrderedDict(1, a=1, b=2)
        ttl_dict.schedule_purge_job()
        self.assertEqual(sorted(ttl_dict.keys()), sorted(['a', 'b']))
        time.sleep(2)
        self.assertEqual(len(ttl_dict), 0)
        self.assertEqual(list(ttl_dict.keys()), [])

        ttl_dict['a'] = 1
        ttl_dict['b'] = 2
        self.assertEqual(sorted(ttl_dict.keys()), sorted(['a', 'b']))
        time.sleep(2)
        self.assertEqual(len(ttl_dict), 0)
        self.assertEqual(list(ttl_dict.keys()), [])
示例#3
0
class StalkCmds(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.stalkdict = TTLOrderedDict(default_ttl=60)

    @commands.command(aliases=['backgroundcheck', 'check', 'creep'])
    @commands.cooldown(60, 60)
    @permission_node(f'{__name__}.stalk')
    async def stalk(self, ctx, lookupName: str):
        """Fetch some incriminatory information on a player.

        Gets info such as UUID, past-names and avatar.
        """

        log.info(f'Stalking \"{lookupName}\"...')
        if lookupName in self.stalkdict.keys():
            mcU = self.stalkdict.get(lookupName)
            log.info(f'Retrieved data for \"{lookupName}\" from cache.')
        else:
            try:
                mcU = await MCUser.create(lookupName, self.bot.session)
                self.stalkdict[lookupName] = mcU
            except mojException as e:
                log.warning(e.message)
                reportCard = discord.Embed(title=e.message,
                                           type="rich",
                                           colour=discord.Colour.dark_red())
                await ctx.send(embed=reportCard)
                return
        reportCard = discord.Embed(title="__Subject: " + mcU.name + "__",
                                   url='http://mcbouncer.com/u/' + mcU.uuid,
                                   type='rich',
                                   color=0x0080c0)
        reportCard.set_author(
            name="Classified Report",
            url=f'https://google.com/search?q=minecraft%20"{mcU.name}"',
            icon_url='https://crafatar.com/avatars/' + mcU.uuid)
        reportCard.set_thumbnail(url='https://crafatar.com/renders/head/' +
                                 mcU.uuid + '?overlay')
        reportCard.add_field(name="Current Name:",
                             value="```\n" + mcU.name + "\n```")
        reportCard.add_field(name="UUID:", value="```\n" + mcU.uuid + "\n```")
        reportCard.add_field(
            name="Links!:",
            value=f"[MCBans](https://www.mcbans.com/player/{mcU.name}/)\n"
            f"[Statistic](https://minecraft-statistic.net/en/player/{mcU.name}.html)\n"
            f"[MCBouncer](http://mcbouncer.com/u/{mcU.uuid})\n"
            f'[Google](https://google.com/search?q=minecraft%20"{mcU.name}")')
        if mcU.demo:
            reportCard.add_field(name="__**DEMO ACCOUNT**__",
                                 value="Watch out for this!")
        if mcU.legacy:
            reportCard.add_field(name="*Legacy*",
                                 value="This guy is old-school!")
        if mcU.nameHistory is not None:
            pastNames = '\n'.join(mcU.nameHistory)
            reportCard.add_field(name="Past names:",
                                 value=f'```\n{pastNames}\n```')
        reportCard.set_footer(text="Report compiled by Agent Charfred")
        log.info('Sent Reportcard.')
        await ctx.send(embed=reportCard)