Ejemplo n.º 1
0
 async def has_access(self, user, tag=None, *tags):
     tags = [tag] + list(tags)
     if has_perm('mhadmin', user,
                 self.bot) or user.id in self.bot.owner_ids:
         return True
     for gtag in tags:
         for utag in await self.config.user(user).allowed_tags():
             if utag == "ALL":
                 return True
             if utag == gtag or utag == gtag.split(" ")[0]:
                 return True
     return False
Ejemplo n.º 2
0
 async def mh_s_add(self, ctx, *, tag):
     """Subscribe to a tag"""
     async with self.config.user(ctx.author).subscriptions() as subs:
         if tag in subs:
             return await ctx.send("You're already subscribed to that tag.")
         if has_perm('mhadmin', ctx.author, self.bot) and tag not in await self.api.get_tags():
             if not await get_user_confirmation(ctx, f"Are you sure you want to subscribe"
                                                     f" to currently non-existant tag `{tag}`?"):
                 return await ctx.react_quietly("\N{CROSS MARK}")
         elif not has_perm('mhadmin', ctx.author, self.bot) \
                 and tag not in await self.config.user(ctx.author).allowed_tags() \
                 and 'ALL' not in self.config.user(ctx.author).allowed_tags():
             return await send_cancellation_message(ctx, f"You cannot subscribe to tag `{tag}` as you don't"
                                                         f" have permission to view it. Contact a bot admin"
                                                         f" if you think this is an issue.")
         await self.check_subscriptions()
         async with self.config.seen() as seen:
             for game in await self.api.get_all_games(tag=tag):
                 seen[game['platformGameId']] = len(game['assets'])
         subs[tag] = {'date': time.time()}
     await ctx.tick()
Ejemplo n.º 3
0
    async def mh_q_all(self, ctx, limit: Optional[int], *, tag):
        """Get a list of the most recent `limit` games with the provided tag

        If limit is left blank, all games are sent.
        """
        allowed_tags = await self.config.user(ctx.author).allowed_tags()
        if not (has_perm('mhadmin', ctx.author, self.bot) or tag in allowed_tags or 'ALL' in allowed_tags):
            return await ctx.send(f"You do not have permission to query the tag `{tag}`.")
        games = sorted(await self.api.get_all_games(tag=tag), key=lambda g: isoparse(g['createdAt']), reverse=True)
        ret = [await self.format_game(game, ctx.author) for game in games[:limit][::-1]]
        if not ret:
            return await ctx.send(f"There are no games with tag `{tag}`."
                                  f" Make sure the tag is valid and correctly cased.")
        for page in pagify('\n\n'.join(ret), delims=['\n\n']):
            await ctx.send(page)
Ejemplo n.º 4
0
    async def mh_q_new(self, ctx, limit: Optional[int], *, tag):
        """Get only games that aren't on the wiki yet"""
        allowed_tags = await self.config.user(ctx.author).allowed_tags()
        if not (has_perm('mhadmin', ctx.author, self.bot) or tag in allowed_tags or 'ALL' in allowed_tags):
            return await ctx.send(f"You do not have permission to query the tag `{tag}`.")
        games = sorted(await self.api.get_all_games(tag=tag), key=lambda g: isoparse(g['createdAt']), reverse=True)
        if not games:
            return await ctx.send(f"There are no games with tag `{tag}`."
                                  f" Make sure the tag is valid and correctly cased.")

        site = await login_if_possible(ctx, self.bot, 'lol')
        games = await self.filter_new(site, games)
        ret = [await self.format_game(game, ctx.author) for game in games[:limit][::-1]]

        if not ret:
            return await ctx.send(f"There are no new games with tag `{tag}`.")

        for page in pagify('\n\n'.join(ret), delims=['\n\n']):
            await ctx.send(page)
Ejemplo n.º 5
0
async def is_editor(ctx) -> bool:
    GAMHCOG = ctx.bot.get_cog("BayesGAMH")
    return (ctx.author.id in ctx.bot.owner_ids
            or has_perm('mhadmin', ctx.author, ctx.bot)
            or await GAMHCOG.config.user(ctx.author).allowed_tags())