Add view points command.
This commit is contained in:
+59
-2
@@ -3,11 +3,18 @@ Commands for viewing information in the database.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
|
import pandas as pd
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
from numpy import indices
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
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"):
|
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.
|
Default constructor for ViewCog class. Does nothing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@nextcord.slash_command()
|
@nextcord.slash_command(guild_ids=[1000247361639030804])
|
||||||
async def view(self, interaction: nextcord.Interaction):
|
async def view(self, interaction: nextcord.Interaction):
|
||||||
"""
|
"""
|
||||||
Parent slash command for set. Never called.
|
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.")
|
@view.subcommand(description="Show all possible presence choices.")
|
||||||
async def presences(
|
async def presences(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ python-dotenv==1.0.0
|
|||||||
pytz==2022.7.1
|
pytz==2022.7.1
|
||||||
hydra-core==1.3.2
|
hydra-core==1.3.2
|
||||||
sqlalchemy<2.0
|
sqlalchemy<2.0
|
||||||
|
pandas>=1.5.2
|
||||||
Reference in New Issue
Block a user