Compare commits
6
Commits
v1.7.2
..
e34d847364
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e34d847364 | ||
|
|
50d10f5168 | ||
|
|
a01503c2c3 | ||
|
|
4c40a4c0e5 | ||
|
|
c3f25b6b54 | ||
|
|
e36b2425aa |
+14
-11
@@ -35,16 +35,6 @@ class Election:
|
|||||||
voting_start: str
|
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
|
@dataclass
|
||||||
class Params:
|
class Params:
|
||||||
"""Class defines start parameters that shouldn't be changed."""
|
"""Class defines start parameters that shouldn't be changed."""
|
||||||
@@ -54,6 +44,19 @@ class Params:
|
|||||||
guild_id: int
|
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
|
@dataclass
|
||||||
class RoleIds:
|
class RoleIds:
|
||||||
"""Class holds all role ids needed by bot."""
|
"""Class holds all role ids needed by bot."""
|
||||||
@@ -71,8 +74,8 @@ class DakinySettings(YAMLWizard):
|
|||||||
|
|
||||||
channel_ids: ChannelIds
|
channel_ids: ChannelIds
|
||||||
election_cycles: list[Election]
|
election_cycles: list[Election]
|
||||||
event_settings: EventSettings
|
|
||||||
params: Params
|
params: Params
|
||||||
|
point_settings: PointSettings
|
||||||
role_ids: RoleIds
|
role_ids: RoleIds
|
||||||
|
|
||||||
def save(self) -> None:
|
def save(self) -> None:
|
||||||
|
|||||||
@@ -119,14 +119,14 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
|||||||
elif recipient is not None: # noqa: RET505
|
elif recipient is not None: # noqa: RET505
|
||||||
record_event_points(
|
record_event_points(
|
||||||
[str(recipient.id)],
|
[str(recipient.id)],
|
||||||
settings.event_settings.participate_points,
|
settings.point_settings.participate_points,
|
||||||
is_member=True,
|
is_member=True,
|
||||||
)
|
)
|
||||||
recipient_str = f"<@{recipient.id}>"
|
recipient_str = f"<@{recipient.id}>"
|
||||||
elif non_discord_recipient is not None:
|
elif non_discord_recipient is not None:
|
||||||
record_event_points(
|
record_event_points(
|
||||||
[non_discord_recipient],
|
[non_discord_recipient],
|
||||||
settings.event_settings.participate_points,
|
settings.point_settings.participate_points,
|
||||||
is_member=False,
|
is_member=False,
|
||||||
)
|
)
|
||||||
recipient_str = f'"{non_discord_recipient}"'
|
recipient_str = f'"{non_discord_recipient}"'
|
||||||
@@ -180,7 +180,7 @@ class EventView(nextcord.ui.View):
|
|||||||
Removes view and embed from recording message.
|
Removes view and embed from recording message.
|
||||||
Sends point information to database.
|
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_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.admin)
|
||||||
verification_view = EventVerification(
|
verification_view = EventVerification(
|
||||||
self.event_participants.values.members, interaction.message.embeds[0].fields[1].value, self.host_id
|
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]
|
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not host_id]
|
||||||
record_event_points(
|
record_event_points(
|
||||||
discord_users_list,
|
discord_users_list,
|
||||||
settings.event_settings.participate_points,
|
settings.point_settings.participate_points,
|
||||||
is_member=True,
|
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")
|
non_discord_users_list: list[str] = non_discord_users.split("\n")
|
||||||
record_event_points(
|
record_event_points(
|
||||||
non_discord_users_list,
|
non_discord_users_list,
|
||||||
settings.event_settings.participate_points,
|
settings.point_settings.participate_points,
|
||||||
is_member=False,
|
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)
|
||||||
|
|||||||
+74
-16
@@ -144,10 +144,67 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
await interaction.response.send_message(f"Voting channel set to <#{channel_id}>.", ephemeral=True)
|
await interaction.response.send_message(f"Voting channel set to <#{channel_id}>.", ephemeral=True)
|
||||||
|
|
||||||
@settings.subcommand()
|
@settings.subcommand()
|
||||||
async def event_settings(self, interaction: nextcord.Interaction) -> None:
|
async def point_settings(self, interaction: nextcord.Interaction) -> None:
|
||||||
"""Subcommand parent. Never called."""
|
"""Subcommand parent. Never called."""
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Host Points value.")
|
@point_settings.subcommand(description="Sets Points value.")
|
||||||
|
async def clan_points(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
points: int = nextcord.SlashOption(
|
||||||
|
required=True, description="Number of Clan Points the recipient earns.", min_value=0
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets PointSettings.points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
points (int): Number of points to assign to PointSettings.points.
|
||||||
|
"""
|
||||||
|
settings.point_settings.clan_points = points
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Points set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets Event Weekly Limit value for Clan Points.")
|
||||||
|
async def clan_points_weekly_limit(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
points: int = nextcord.SlashOption(
|
||||||
|
required=True, description="Number of Clan Points a clan member can earn in a week.", min_value=0
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets DakinySettings event_settings.weekly_limit to the given number of points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
points (int): Number of points to set.
|
||||||
|
"""
|
||||||
|
settings.point_settings.clan_points_weekly_limit = points
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Clan Points Weekly Limit set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets Event Weekly Limit value.")
|
||||||
|
async def events_weekly_limit(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
points: int = nextcord.SlashOption(
|
||||||
|
required=True, description="Number of Event Points a clan member can earn in a week.", min_value=0
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets DakinySettings event_settings.weekly_limit to the given number of points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
points (int): Number of points to set.
|
||||||
|
"""
|
||||||
|
settings.point_settings.events_weekly_limit = points
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Event Weekly Limit set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets Event Host Points value.")
|
||||||
async def host_points(
|
async def host_points(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
@@ -162,11 +219,11 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
points (int): Number of points to set.
|
points (int): Number of points to set.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.host_points = points
|
settings.point_settings.host_points = points
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event Host Points set to {points}.", ephemeral=True)
|
await interaction.response.send_message(f"Event Host Points set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Participation Points value.")
|
@point_settings.subcommand(description="Sets Event Participation Points value.")
|
||||||
async def participate_points(
|
async def participate_points(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
@@ -183,12 +240,12 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
points (int): Number of points to set.
|
points (int): Number of points to set.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.participate_points = points
|
settings.point_settings.participate_points = points
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event Participation Points set to {points}.", ephemeral=True)
|
await interaction.response.send_message(f"Event Participation Points set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Participation Points value.")
|
@point_settings.subcommand(description="Sets whether to verify a clan point entry.")
|
||||||
async def verify(
|
async def verify_clan_points(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
do_verification: bool = nextcord.SlashOption( # noqa: FBT001
|
do_verification: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
@@ -203,28 +260,29 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
do_verification (bool): If the bot should verify events.
|
do_verification (bool): If the bot should verify events.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.verify = do_verification
|
settings.point_settings.verify_clan_points = do_verification
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event verification set to {do_verification}.", ephemeral=True)
|
await interaction.response.send_message(f"Event verification set to {do_verification}.", ephemeral=True)
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Weekly Limit value.")
|
@point_settings.subcommand(description="Sets whether an event.")
|
||||||
async def weekly_limit(
|
async def verify_events(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
points: int = nextcord.SlashOption(
|
do_verification: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
required=True, description="Number of Event Points a clan member can earn in a week.", min_value=0
|
required=True,
|
||||||
|
description="Whether an event should be verified or not.",
|
||||||
),
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Sets DakinySettings event_settings.weekly_limit to the given number of points.
|
Sets DakinySettings event_settings.verify to the given number of points.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
points (int): Number of points to set.
|
do_verification (bool): If the bot should verify events.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.weekly_limit = points
|
settings.point_settings.verify_events = do_verification
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event Weekly Limit set to {points}.", ephemeral=True)
|
await interaction.response.send_message(f"Event verification set to {do_verification}.", ephemeral=True)
|
||||||
|
|
||||||
@settings.subcommand()
|
@settings.subcommand()
|
||||||
async def role_ids(self, interaction: nextcord.Interaction) -> None:
|
async def role_ids(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
|||||||
@@ -59,4 +59,19 @@ CREATE TABLE EventPointsLimit (
|
|||||||
Points int unsigned DEFAULT 0,
|
Points int unsigned DEFAULT 0,
|
||||||
Week varchar(7) not null,
|
Week varchar(7) not null,
|
||||||
PRIMARY KEY (UserId, Week)
|
PRIMARY KEY (UserId, Week)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE ClanPoints (
|
||||||
|
QuarterName varchar(30) not null,
|
||||||
|
UserId varchar(32) not null,
|
||||||
|
DiscordMember boolean not null,
|
||||||
|
Points int unsigned DEFAULT 0,
|
||||||
|
PRIMARY KEY (QuarterName, UserId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE ClanPointsLimit (
|
||||||
|
UserId varchar(32) not null,
|
||||||
|
Points int unsigned DEFAULT 0,
|
||||||
|
Week varchar(7) not null,
|
||||||
|
PRIMARY KEY (UserId, Week)
|
||||||
);
|
);
|
||||||
@@ -10,11 +10,13 @@ Base = automap_base()
|
|||||||
Base.prepare(autoload_with=engine)
|
Base.prepare(autoload_with=engine)
|
||||||
|
|
||||||
# define the classes
|
# define the classes
|
||||||
|
ClanPoints = Base.classes.ClanPoints
|
||||||
|
ClanPointsLimit = Base.classes.ClanPointsLimit
|
||||||
CouncilMembers = Base.classes.CouncilMembers
|
CouncilMembers = Base.classes.CouncilMembers
|
||||||
ElectionInformation = Base.classes.ElectionInformation
|
ElectionInformation = Base.classes.ElectionInformation
|
||||||
|
EventPoints = Base.classes.EventPoints
|
||||||
EventPointsLimit = Base.classes.EventPointsLimit
|
EventPointsLimit = Base.classes.EventPointsLimit
|
||||||
Messages = Base.classes.Messages
|
Messages = Base.classes.Messages
|
||||||
EventPoints = Base.classes.EventPoints
|
|
||||||
Presences = Base.classes.Presences
|
Presences = Base.classes.Presences
|
||||||
UserBirthday = Base.classes.UserBirthday
|
UserBirthday = Base.classes.UserBirthday
|
||||||
Votes = Base.classes.Votes
|
Votes = Base.classes.Votes
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ def record_event_points(users: Sequence[str], add_points: int, *, is_member: boo
|
|||||||
|
|
||||||
points = session.scalar(stmt)
|
points = session.scalar(stmt)
|
||||||
if points is None:
|
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(
|
new_points = EventPoints(
|
||||||
QuarterName=quarter_name,
|
QuarterName=quarter_name,
|
||||||
UserId=user,
|
UserId=user,
|
||||||
@@ -318,7 +318,7 @@ def record_event_points(users: Sequence[str], add_points: int, *, is_member: boo
|
|||||||
)
|
)
|
||||||
session.add(new_points)
|
session.add(new_points)
|
||||||
else:
|
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
|
points.Points += add_points
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user