From 257a7eccd792274478c0a942eba23ecee45683d5 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Thu, 9 May 2024 23:27:06 -0400 Subject: [PATCH] Add view points command. --- cogs/commands/view.py | 61 +++++++++++++++++++++++++++++++++++++++++-- requirements.txt | 3 ++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/cogs/commands/view.py b/cogs/commands/view.py index ecb6f7f..a1ea1b1 100644 --- a/cogs/commands/view.py +++ b/cogs/commands/view.py @@ -3,11 +3,18 @@ Commands for viewing information in the database. """ import nextcord +import pandas as pd from nextcord.ext import commands +from numpy import indices from sqlalchemy import select from sqlalchemy.orm import Session -from database_setup.sql_data_classes import Presences, Votes, engine +from database_setup.sql_data_classes import ( + ParticipationPoints, + Presences, + Votes, + engine, +) class ViewCog(commands.Cog, name="View Commands"): @@ -20,12 +27,62 @@ class ViewCog(commands.Cog, name="View Commands"): Default constructor for ViewCog class. Does nothing. """ - @nextcord.slash_command() + @nextcord.slash_command(guild_ids=[1000247361639030804]) async def view(self, interaction: nextcord.Interaction): """ Parent slash command for set. Never called. """ + @view.subcommand(description="Show event points.") + async def event_points( + self, + interaction: nextcord.Interaction, + quarter_name: str = nextcord.SlashOption( + description="The quarter to view", + required=False, + ), + ): + # just in case + await interaction.response.defer(ephemeral=True) + + with Session(engine) as session: + if quarter_name: + df = pd.read_sql_query( + sql=session.query(ParticipationPoints) + .where(ParticipationPoints.Cycle == quarter_name) + .statement, + con=engine, + ) + else: + df = pd.read_sql_query( + sql=session.query(ParticipationPoints).statement, + con=engine, + ) + + cycles = df.groupby("Cycle") + + content = "" + for cycle in cycles.groups: + content += f"```{cycle}```\n" + group = cycles.get_group(cycle) + for row in group.itertuples(): + userid = row.UserId + points = row.Points + discord_member = row.DiscordMember + content += ( + f"<@{userid}>: {points}\n" + if discord_member + else f"{userid}: {points}\n" + ) + + if len(content) > 2000: + await interaction.followup.send( + "Message length is too long, please choose a quarter." + ) + return + + await interaction.followup.send(content=content, ephemeral=True) + @view.subcommand(description="Show all possible presence choices.") async def presences( self, diff --git a/requirements.txt b/requirements.txt index 3d5d68b..1c365c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ nextcord==2.4.2 python-dotenv==1.0.0 pytz==2022.7.1 hydra-core==1.3.2 -sqlalchemy<2.0 \ No newline at end of file +sqlalchemy<2.0 +pandas>=1.5.2 \ No newline at end of file