Exemple #1
0
    async def tierboard(self, ctx, type="V", sem="Z", year=""):
        """Board of suject based on average tier from reviews"""
        # TODO autochange sem based on week command?
        degree = None
        type = type.upper()
        if type == "HELP":
            await ctx.send(messages.tierboard_help)
            return
        sem = sem.upper()
        for role in ctx.author.roles:
            if "BIT" in role.name:
                degree = "BIT"
                if not year and type == "P":
                    if role.name == "4BIT+":
                        year = "3BIT"
                    elif role.name == "0BIT":
                        year = "1BIT"
                    else:
                        year = role.name
                break
            if "MIT" in role.name:
                degree = "MIT"
                if not year and type == "P":
                    year = ""
                    # TODO get programme from DB? or find all MIT P?
                break
        if not degree and not year:
            await ctx.send(messages.tierboard_missing_year)
            return
        board = review_repo.get_tierboard(type, sem, degree, year)
        output = ""
        cnt = 1
        for line in board:
            output += f"{cnt} - **{line.shortcut}**: {round(line.avg_tier, 1)}\n"
            cnt += 1
        embed = discord.Embed(title="Tierboard", description=output)
        embed.timestamp = datetime.datetime.now(tz=datetime.timezone.utc)
        embed.add_field(name="Semester", value=sem)
        embed.add_field(name="Typ", value=type)
        if year:
            degree = year
        embed.add_field(name="Program", value=degree)

        utils.add_author_footer(embed, ctx.author, additional_text=("?tierboard help",))
        await ctx.send(embed=embed)
Exemple #2
0
    async def tierboard(self, ctx, type="V", sem="Z", year=""):
        """Board of suject based on average tier from reviews"""
        # TODO autochange sem based on week command?
        degree = None
        type = type.upper()
        sem = sem.upper()
        if type == "HELP" or sem not in ['Z', 'L'] or type not in ['P', 'PVT', 'PVA', 'V']:
            await ctx.send(f"`{utils.get_command_signature(ctx)}`\n{messages.tierboard_help}")
            return

        for role in ctx.author.roles:
            if "BIT" in role.name:
                degree = "BIT"
                if not year and type == "P":
                    if role.name == "4BIT+":
                        year = "3BIT"
                    elif role.name == "0BIT":
                        year = "1BIT"
                    else:
                        year = role.name
                break
            if "MIT" in role.name:
                degree = "MIT"
                if not year and type == "P":
                    year = ""
                    # TODO get programme from DB? or find all MIT P?
                break
        if not degree and not year:
            await ctx.send(messages.tierboard_missing_year)
            return
        board = review_repo.get_tierboard(type, sem, degree, year)
        output = ""
        cnt = 1
        for line in board:
            output += f"{cnt} - **{line.shortcut}**: {round(line.avg_tier, 1)}\n"
            cnt += 1
        embed = discord.Embed(title="Tierboard", description=output)
        embed.timestamp = datetime.datetime.now(tz=datetime.timezone.utc)
        embed.add_field(name="Typ", value=type)
        embed.add_field(name="Semestr", value="Letní" if sem == "L" else "Zimní")
        if year:
            degree = year
        embed.add_field(name="Program", value=degree)

        utils.add_author_footer(embed, ctx.author, additional_text=("?tierboard help",))
        msg = await ctx.send(embed=embed)

        page_num = 0
        pages_total = review_repo.get_tierboard_page_count(type, sem, degree, year)

        if pages_total == 0:
            return

        await msg.add_reaction("⏪")
        await msg.add_reaction("◀")
        await msg.add_reaction("▶")

        while True:

            def check(reaction, user):
                return reaction.message.id == msg.id and not user.bot

            try:
                reaction, user = await self.bot.wait_for("reaction_add", check=check, timeout=300.0)
            except asyncio.TimeoutError:
                return
            emoji = str(reaction.emoji)
            if emoji in ["⏪", "◀", "▶"] and user.id == ctx.author.id:
                if emoji == "⏪":
                    page_num = 0
                elif emoji == "◀":
                    page_num -= 1
                    if page_num < 0:
                        page_num = pages_total - 1
                elif emoji == "▶":
                    page_num += 1
                    if page_num >= pages_total:
                        page_num = 0

                offset = page_num * 10
                board = review_repo.get_tierboard(type, sem, degree, year, offset)
                output = ""
                cnt = 1 + offset
                for line in board:
                    output += f"{cnt} - **{line.shortcut}**: {round(line.avg_tier, 1)}\n"
                    cnt += 1
                embed.description = output
                await msg.edit(embed=embed)
            try:
                await msg.remove_reaction(emoji, user)
            except discord.errors.Forbidden:
                pass