Record points in the command.
This commit is contained in:
+16
-4
@@ -7,6 +7,7 @@ from discord import TextInputStyle
|
||||
from nextcord.ext import commands
|
||||
|
||||
from config import DakinyConfig
|
||||
from utils import record_event_host, record_event_participation
|
||||
|
||||
|
||||
class RecordCog(commands.Cog, name="Record Commands"):
|
||||
@@ -70,7 +71,7 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
||||
|
||||
await interaction.response.send_message(
|
||||
"Fill out event details and select all members who participated!",
|
||||
view=EventView(name, self.bot.config),
|
||||
view=EventView(name, self.bot.config, host.id),
|
||||
ephemeral=True,
|
||||
embed=embed,
|
||||
)
|
||||
@@ -84,11 +85,12 @@ class EventView(nextcord.ui.View):
|
||||
Also contains a UserSelect object to pick discord members.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str, config: DakinyConfig):
|
||||
def __init__(self, name: str, config: DakinyConfig, host_id: int):
|
||||
super().__init__()
|
||||
|
||||
self.name: str = name
|
||||
self.config: DakinyConfig = config
|
||||
self.host_id: int = host_id
|
||||
|
||||
self.event_participants = ParticipantSelect()
|
||||
|
||||
@@ -130,8 +132,18 @@ class EventView(nextcord.ui.View):
|
||||
await interaction.response.edit_message(
|
||||
content="Event has been submitted.", view=None, embed=None
|
||||
)
|
||||
# TODO send point information to database. Probably will make functions to do the separate
|
||||
# things. Want to try turning the embed into a dict.
|
||||
|
||||
discord_users: list[str] = [
|
||||
str(user.id) for user in self.event_participants.values.members
|
||||
]
|
||||
non_discord_users: list[str] = (
|
||||
interaction.message.embeds[0].fields[1].value.split("\n")
|
||||
)
|
||||
|
||||
record_event_participation(self.config, discord_users, True)
|
||||
record_event_participation(self.config, non_discord_users, False)
|
||||
record_event_host(self.config, self.host_id)
|
||||
|
||||
self.stop()
|
||||
|
||||
|
||||
|
||||
@@ -357,22 +357,21 @@ def record_event_participation(config: DakinyConfig, users: list[str], is_member
|
||||
session.commit()
|
||||
|
||||
|
||||
def record_event_host(config: DakinyConfig, user: str, is_member: bool):
|
||||
def record_event_host(config: DakinyConfig, user: int):
|
||||
"""
|
||||
Adds host points to the given user. Checks if they don't exist in order to make a new entry, otherwise adds points
|
||||
to the existing value.
|
||||
|
||||
Args:
|
||||
config (DakinyConfig): Dakiny config for getting points
|
||||
user (str): User that hosted.
|
||||
is_member (bool): whether the user is a discord member or not
|
||||
user (int): Id of user that hosted.
|
||||
"""
|
||||
cycle = get_current_cycle(config)
|
||||
host_point_value = config.params.event_host_points
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(ParticipationPoints)
|
||||
.where(ParticipationPoints.UserId == user)
|
||||
.where(ParticipationPoints.UserId == str(user))
|
||||
.where(ParticipationPoints.Cycle == cycle)
|
||||
)
|
||||
|
||||
@@ -380,8 +379,8 @@ def record_event_host(config: DakinyConfig, user: str, is_member: bool):
|
||||
if points is None:
|
||||
new_points = ParticipationPoints(
|
||||
Cycle=cycle,
|
||||
UserId=user,
|
||||
DiscordMember=is_member,
|
||||
UserId=str(user),
|
||||
DiscordMember=True,
|
||||
Points=host_point_value,
|
||||
)
|
||||
session.add(new_points)
|
||||
|
||||
Reference in New Issue
Block a user