Rework point settings to combine clan and event points into same class for simplicity.

This commit is contained in:
2024-09-20 21:43:08 -04:00
parent a01503c2c3
commit 50d10f5168
3 changed files with 22 additions and 28 deletions
+14 -20
View File
@@ -19,15 +19,6 @@ class ChannelIds:
voting: int
@dataclass
class ClanPointSettings:
"""Class defines settings for Clan Points editable by Clan Council."""
points: int
verify: bool
weekly_limit: int
@dataclass
class Election:
"""Class defines relevant election dates."""
@@ -44,16 +35,6 @@ class Election:
voting_start: str
@dataclass
class EventSettings:
"""Class defines settings editable by Clan Council."""
host_points: int
participate_points: int
verify: bool
weekly_limit: int
@dataclass
class Params:
"""Class defines start parameters that shouldn't be changed."""
@@ -63,6 +44,19 @@ class Params:
guild_id: int
@dataclass
class PointSettings:
"""Class defines point settings editable by Clan Council."""
clan_points: int
clan_points_weekly_limit: int
events_weekly_limit: int
host_points: int
participate_points: int
verify_clan_points: bool
verify_events: bool
@dataclass
class RoleIds:
"""Class holds all role ids needed by bot."""
@@ -80,8 +74,8 @@ class DakinySettings(YAMLWizard):
channel_ids: ChannelIds
election_cycles: list[Election]
event_settings: EventSettings
params: Params
point_settings: PointSettings
role_ids: RoleIds
def save(self) -> None:
+6 -6
View File
@@ -119,14 +119,14 @@ class RecordCog(commands.Cog, name="Record Commands"):
elif recipient is not None: # noqa: RET505
record_event_points(
[str(recipient.id)],
settings.event_settings.participate_points,
settings.point_settings.participate_points,
is_member=True,
)
recipient_str = f"<@{recipient.id}>"
elif non_discord_recipient is not None:
record_event_points(
[non_discord_recipient],
settings.event_settings.participate_points,
settings.point_settings.participate_points,
is_member=False,
)
recipient_str = f'"{non_discord_recipient}"'
@@ -180,7 +180,7 @@ class EventView(nextcord.ui.View):
Removes view and embed from recording message.
Sends point information to database.
"""
if settings.event_settings.verify:
if settings.point_settings.verify_events:
verification_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.admin)
verification_view = EventVerification(
self.event_participants.values.members, interaction.message.embeds[0].fields[1].value, self.host_id
@@ -339,7 +339,7 @@ def process_event(discord_users: list[nextcord.Member], non_discord_users: str,
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not host_id]
record_event_points(
discord_users_list,
settings.event_settings.participate_points,
settings.point_settings.participate_points,
is_member=True,
)
@@ -347,8 +347,8 @@ def process_event(discord_users: list[nextcord.Member], non_discord_users: str,
non_discord_users_list: list[str] = non_discord_users.split("\n")
record_event_points(
non_discord_users_list,
settings.event_settings.participate_points,
settings.point_settings.participate_points,
is_member=False,
)
record_event_points([host_id], settings.event_settings.host_points, is_member=True)
record_event_points([host_id], settings.point_settings.host_points, is_member=True)
+2 -2
View File
@@ -309,7 +309,7 @@ def record_event_points(users: Sequence[str], add_points: int, *, is_member: boo
points = session.scalar(stmt)
if points is None:
add_points = get_allowed_points(session, settings.event_settings.weekly_limit, user, add_points)
add_points = get_allowed_points(session, settings.point_settings.events_weekly_limit, user, add_points)
new_points = EventPoints(
QuarterName=quarter_name,
UserId=user,
@@ -318,7 +318,7 @@ def record_event_points(users: Sequence[str], add_points: int, *, is_member: boo
)
session.add(new_points)
else:
add_points = get_allowed_points(session, settings.event_settings.weekly_limit, user, add_points)
add_points = get_allowed_points(session, settings.point_settings.events_weekly_limit, user, add_points)
points.Points += add_points
session.commit()