Run ruff linter with autofixing.
This commit is contained in:
@@ -46,7 +46,6 @@ class ElectionCycle:
|
|||||||
config (DakinyConfig): The entire config object.
|
config (DakinyConfig): The entire config object.
|
||||||
guild (nextcord.Guild): The guild that this election is running in.
|
guild (nextcord.Guild): The guild that this election is running in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.config: DakinyConfig = config
|
self.config: DakinyConfig = config
|
||||||
self.cycle = cycle
|
self.cycle = cycle
|
||||||
self.election_cycle = self.config.election_cycles[self.cycle]
|
self.election_cycle = self.config.election_cycles[self.cycle]
|
||||||
@@ -69,8 +68,7 @@ class ElectionCycle:
|
|||||||
list[str]: A list of message contents in the correct order. Must be a string because the message is too
|
list[str]: A list of message contents in the correct order. Must be a string because the message is too
|
||||||
long.
|
long.
|
||||||
"""
|
"""
|
||||||
|
with open(f"{TEMPLATES_DIR}/election_announcement.txt", encoding="utf8") as file:
|
||||||
with open(f"{TEMPLATES_DIR}/election_announcement.txt", mode="r", encoding="utf8") as file:
|
|
||||||
message = file.read()
|
message = file.read()
|
||||||
|
|
||||||
next_election = get_datetime(
|
next_election = get_datetime(
|
||||||
@@ -98,8 +96,7 @@ class ElectionCycle:
|
|||||||
Returns:
|
Returns:
|
||||||
str: Message to send.
|
str: Message to send.
|
||||||
"""
|
"""
|
||||||
|
with open(f"{TEMPLATES_DIR}/highcouncil_election.txt", encoding="utf8") as file:
|
||||||
with open(f"{TEMPLATES_DIR}/highcouncil_election.txt", mode="r", encoding="utf8") as file:
|
|
||||||
message = file.read()
|
message = file.read()
|
||||||
|
|
||||||
return message.format(
|
return message.format(
|
||||||
@@ -117,8 +114,7 @@ class ElectionCycle:
|
|||||||
Returns:
|
Returns:
|
||||||
str: Message to send.
|
str: Message to send.
|
||||||
"""
|
"""
|
||||||
|
with open(f"{TEMPLATES_DIR}/highcouncil_vote.txt", encoding="utf8") as file:
|
||||||
with open(f"{TEMPLATES_DIR}/highcouncil_vote.txt", mode="r", encoding="utf8") as file:
|
|
||||||
message = file.read()
|
message = file.read()
|
||||||
|
|
||||||
return message.format(
|
return message.format(
|
||||||
@@ -133,8 +129,7 @@ class ElectionCycle:
|
|||||||
Returns:
|
Returns:
|
||||||
str: Message to send
|
str: Message to send
|
||||||
"""
|
"""
|
||||||
|
with open(f"{TEMPLATES_DIR}/vote_start.txt", encoding="utf8") as file:
|
||||||
with open(f"{TEMPLATES_DIR}/vote_start.txt", mode="r", encoding="utf8") as file:
|
|
||||||
message = file.read()
|
message = file.read()
|
||||||
vote_end: datetime = get_datetime(self.config.election_cycles[self.cycle].voting_end)
|
vote_end: datetime = get_datetime(self.config.election_cycles[self.cycle].voting_end)
|
||||||
|
|
||||||
@@ -226,7 +221,6 @@ class ElectionCycle:
|
|||||||
"""
|
"""
|
||||||
Performs required actions for when voting time has ended.
|
Performs required actions for when voting time has ended.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
message = self.build_highcouncil_election_announce()
|
message = self.build_highcouncil_election_announce()
|
||||||
council_elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
council_elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
||||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||||
@@ -278,7 +272,6 @@ class ElectionCycle:
|
|||||||
"""
|
"""
|
||||||
Performs required actions for when the highcouncil is elected.
|
Performs required actions for when the highcouncil is elected.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
message = self.build_highcouncil_vote_start()
|
message = self.build_highcouncil_vote_start()
|
||||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||||
await election_thread.send(message)
|
await election_thread.send(message)
|
||||||
@@ -303,7 +296,6 @@ class ElectionCycle:
|
|||||||
"""
|
"""
|
||||||
Marks the election as over.
|
Marks the election as over.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.election_over = True
|
self.election_over = True
|
||||||
|
|
||||||
elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
||||||
@@ -396,7 +388,6 @@ class ElectionCycle:
|
|||||||
Returns:
|
Returns:
|
||||||
ElectionInformation: The information from the database about the current election.
|
ElectionInformation: The information from the database about the current election.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation).where(
|
stmt = select(ElectionInformation).where(
|
||||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
||||||
@@ -407,7 +398,6 @@ class ElectionCycle:
|
|||||||
"""
|
"""
|
||||||
Sends a message to general chat reminder clan about election.
|
Sends a message to general chat reminder clan about election.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
general: nextcord.TextChannel = self.guild.get_channel(self.config.params.general_channel_id)
|
general: nextcord.TextChannel = self.guild.get_channel(self.config.params.general_channel_id)
|
||||||
|
|
||||||
message = f"Reminder to <@&{self.config.params.clan_member_role_id}>! Clan elections are happening! Head over "
|
message = f"Reminder to <@&{self.config.params.clan_member_role_id}>! Clan elections are happening! Head over "
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
@@ -29,9 +27,9 @@ class Commit(BaseModel):
|
|||||||
committer: Committer
|
committer: Committer
|
||||||
verification: None
|
verification: None
|
||||||
timestamp: str
|
timestamp: str
|
||||||
added: List[str]
|
added: list[str]
|
||||||
removed: List[str]
|
removed: list[str]
|
||||||
modified: List[str]
|
modified: list[str]
|
||||||
|
|
||||||
|
|
||||||
class HeadCommit(BaseModel):
|
class HeadCommit(BaseModel):
|
||||||
@@ -42,9 +40,9 @@ class HeadCommit(BaseModel):
|
|||||||
committer: Committer
|
committer: Committer
|
||||||
verification: None
|
verification: None
|
||||||
timestamp: str
|
timestamp: str
|
||||||
added: List[str]
|
added: list[str]
|
||||||
removed: List[str]
|
removed: list[str]
|
||||||
modified: List[str]
|
modified: list[str]
|
||||||
|
|
||||||
|
|
||||||
class Owner(BaseModel):
|
class Owner(BaseModel):
|
||||||
@@ -187,7 +185,7 @@ class GiteaWebhook(BaseModel):
|
|||||||
before: str
|
before: str
|
||||||
after: str
|
after: str
|
||||||
compare_url: str
|
compare_url: str
|
||||||
commits: List[Commit]
|
commits: list[Commit]
|
||||||
total_commits: int
|
total_commits: int
|
||||||
head_commit: HeadCommit
|
head_commit: HeadCommit
|
||||||
repository: Repository
|
repository: Repository
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ class NominateDMModal(nextcord.ui.Modal):
|
|||||||
interaction (Interaction): Interaction with user.
|
interaction (Interaction): Interaction with user.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
speech = decorate_dm_nomination(interaction.user.id, self.speech.value)
|
speech = decorate_dm_nomination(interaction.user.id, self.speech.value)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -116,7 +115,6 @@ class NominateCLModal(nextcord.ui.Modal):
|
|||||||
interaction (Interaction): Interaction with user.
|
interaction (Interaction): Interaction with user.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
speech = decorate_cl_nomination(interaction.user.id, self.speech.value)
|
speech = decorate_cl_nomination(interaction.user.id, self.speech.value)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -163,7 +161,6 @@ class NominateHighCouncilView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce council elect only
|
# enforce council elect only
|
||||||
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@@ -207,7 +204,6 @@ class NominateHighCouncilView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce council elect only
|
# enforce council elect only
|
||||||
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
interaction (Interaction): Interaction with user.
|
interaction (Interaction): Interaction with user.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
speech = decorate_nomination(interaction.user.id, self.speech.value)
|
speech = decorate_nomination(interaction.user.id, self.speech.value)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -102,7 +101,6 @@ class NominateView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce members only
|
# enforce members only
|
||||||
if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles:
|
if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
Contains various views to be used while voting for high council. Controls the logic when performing the vote.
|
Contains various views to be used while voting for high council. Controls the logic when performing the vote.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord import SelectOption
|
from nextcord import SelectOption
|
||||||
@@ -21,7 +20,7 @@ from utils import VoteType, build_highcouncil_votes_str, get_election_name
|
|||||||
|
|
||||||
|
|
||||||
class VoteSelect(nextcord.ui.StringSelect):
|
class VoteSelect(nextcord.ui.StringSelect):
|
||||||
def __init__(self, options: List["SelectOption"], config: DakinyConfig, election_type: str) -> None:
|
def __init__(self, options: list["SelectOption"], config: DakinyConfig, election_type: str) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
placeholder="Choose 1",
|
placeholder="Choose 1",
|
||||||
min_values=1,
|
min_values=1,
|
||||||
@@ -105,7 +104,6 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce council elect only
|
# enforce council elect only
|
||||||
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@@ -176,7 +174,6 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce council elect only
|
# enforce council elect only
|
||||||
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
Contains various views to be used while voting. Controls the logic when performing the vote.
|
Contains various views to be used while voting. Controls the logic when performing the vote.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord import SelectOption
|
from nextcord import SelectOption
|
||||||
@@ -21,7 +20,7 @@ from utils import VoteType, build_votes_str, get_election_name
|
|||||||
|
|
||||||
|
|
||||||
class VoteSelect(nextcord.ui.StringSelect):
|
class VoteSelect(nextcord.ui.StringSelect):
|
||||||
def __init__(self, options: List["SelectOption"], config: DakinyConfig) -> None:
|
def __init__(self, options: list["SelectOption"], config: DakinyConfig) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
placeholder="Choose 1",
|
placeholder="Choose 1",
|
||||||
min_values=1,
|
min_values=1,
|
||||||
@@ -98,7 +97,6 @@ class VoteView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce members only
|
# enforce members only
|
||||||
if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles:
|
if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
|||||||
Pulls from git and then calls method to update all the discord messages as described by the
|
Pulls from git and then calls method to update all the discord messages as described by the
|
||||||
files in the git repo.
|
files in the git repo.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get all modified/added files
|
# Get all modified/added files
|
||||||
modified_files: list[str] = [
|
modified_files: list[str] = [
|
||||||
file for list in [commit.modified + commit.added for commit in hook_info.commits] for file in list
|
file for list in [commit.modified + commit.added for commit in hook_info.commits] for file in list
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ def setup(bot: commands.Bot):
|
|||||||
"""
|
"""
|
||||||
Adds all command classes to bot.
|
Adds all command classes to bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
bot.add_cog(RecordCog(bot))
|
bot.add_cog(RecordCog(bot))
|
||||||
bot.add_cog(RefreshCog(bot))
|
bot.add_cog(RefreshCog(bot))
|
||||||
bot.add_cog(RemoveCog())
|
bot.add_cog(RemoveCog())
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
|||||||
name (str): Name of the event.
|
name (str): Name of the event.
|
||||||
host (nextcord.Member, optional): Alternative host to user using command.
|
host (nextcord.Member, optional): Alternative host to user using command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# check role
|
# check role
|
||||||
if interaction.guild.get_role(self.bot.config.params.event_host_role_id) not in interaction.user.roles:
|
if interaction.guild.get_role(self.bot.config.params.event_host_role_id) not in interaction.user.roles:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@@ -110,7 +109,6 @@ class EventView(nextcord.ui.View):
|
|||||||
Submits the event embed to the event channel. Removes view and embed from recording message.
|
Submits the event embed to the event channel. Removes view and embed from recording message.
|
||||||
Sends point information to database.
|
Sends point information to database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
discord_users = self.event_participants.values.members
|
discord_users = self.event_participants.values.members
|
||||||
if discord_users:
|
if discord_users:
|
||||||
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id]
|
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id]
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class RemoveCog(commands.Cog, name="Remove Commands"):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
presence (str): Is SlashOption. The presence to remove. Is the ID of the presence.
|
presence (str): Is SlashOption. The presence to remove. Is the ID of the presence.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
presence_id = int(presence_str)
|
presence_id = int(presence_str)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = delete(Presences).where(Presences.Id == presence_id)
|
stmt = delete(Presences).where(Presences.Id == presence_id)
|
||||||
@@ -60,7 +59,6 @@ class RemoveCog(commands.Cog, name="Remove Commands"):
|
|||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
presence_str (str): String to run autocomplete on.
|
presence_str (str): String to run autocomplete on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Presences)
|
stmt = select(Presences)
|
||||||
presences_dict: "dict[str,str]" = {pres.Presence: str(pres.Id) for pres in session.scalars(stmt)}
|
presences_dict: "dict[str,str]" = {pres.Presence: str(pres.Id) for pres in session.scalars(stmt)}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class RequestCog(commands.Cog, name="Request Commands"):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
presence (str): The presence to add.
|
presence (str): The presence to add.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
content = f'<@{interaction.user.id}> would like to add presence "{presence}."'
|
content = f'<@{interaction.user.id}> would like to add presence "{presence}."'
|
||||||
view = PresenceChange(presence)
|
view = PresenceChange(presence)
|
||||||
@@ -70,7 +69,6 @@ class RequestCog(commands.Cog, name="Request Commands"):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
new_username(str): The username to change to.
|
new_username(str): The username to change to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."'
|
content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."'
|
||||||
view = UsernameRequest(interaction.user.id, new_nickname)
|
view = UsernameRequest(interaction.user.id, new_nickname)
|
||||||
@@ -160,7 +158,6 @@ class PresenceChange(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused.
|
button (nextcord.ui.Button): Unused.
|
||||||
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
session.add(Presences(Presence=self.presence))
|
session.add(Presences(Presence=self.presence))
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class setCog(commands.Cog, name="Set Commands"):
|
|||||||
month (int, optional): The month a user was born. Is SlashOption.
|
month (int, optional): The month a user was born. Is SlashOption.
|
||||||
day (int, optional): The day a user was born. Is SlashOption.
|
day (int, optional): The day a user was born. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Must be deferred, apparently datetime takes a little bit on invalid dates.
|
# Must be deferred, apparently datetime takes a little bit on invalid dates.
|
||||||
await interaction.response.defer(ephemeral=True)
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): _description_
|
interaction (nextcord.Interaction): _description_
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = ElectionCycle(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Integration): User's interaction with the command.
|
interaction (nextcord.Integration): User's interaction with the command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# might take a while depending on number of presences
|
# might take a while depending on number of presences
|
||||||
await interaction.response.defer(ephemeral=True)
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
@@ -141,7 +140,6 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
interaction (nextcord.Interaction): User's interaction with the command.
|
interaction (nextcord.Interaction): User's interaction with the command.
|
||||||
election_name (str): Is SlashOption. The name of the election to view votes for.
|
election_name (str): Is SlashOption. The name of the election to view votes for.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == election_type)
|
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == election_type)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -170,7 +168,6 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
election_name (str): String to run autocomplete on.
|
election_name (str): String to run autocomplete on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Votes.ElectionCycle).distinct()
|
stmt = select(Votes.ElectionCycle).distinct()
|
||||||
elections = session.scalars(stmt)
|
elections = session.scalars(stmt)
|
||||||
@@ -194,7 +191,6 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
quarter_name (str): String to run autocomplete on.
|
quarter_name (str): String to run autocomplete on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ParticipationPoints.Cycle).distinct()
|
stmt = select(ParticipationPoints.Cycle).distinct()
|
||||||
quarters = session.scalars(stmt)
|
quarters = session.scalars(stmt)
|
||||||
|
|||||||
@@ -12,6 +12,5 @@ def setup(bot: commands.Bot):
|
|||||||
"""
|
"""
|
||||||
Adds functions to bot.
|
Adds functions to bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
bot.add_cog(BotPresence(bot))
|
bot.add_cog(BotPresence(bot))
|
||||||
bot.add_cog(DailyLoop(bot))
|
bot.add_cog(DailyLoop(bot))
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class BotPresence(commands.Cog, name="Bot Presence"):
|
|||||||
|
|
||||||
async def change_presence(self):
|
async def change_presence(self):
|
||||||
"""Randomly chooses a presence and updates bot's presence."""
|
"""Randomly chooses a presence and updates bot's presence."""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
presence = session.scalar(select(Presences.Presence).order_by(func.random()))
|
presence = session.scalar(select(Presences.Presence).order_by(func.random()))
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
an active election, runs the check_date() function for the election to perform actions. Finally checks if the
|
an active election, runs the check_date() function for the election to perform actions. Finally checks if the
|
||||||
election is over to delete the current election object.
|
election is over to delete the current election object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.current_election is None:
|
if self.current_election is None:
|
||||||
self.current_election = self.get_election_cycle()
|
self.current_election = self.get_election_cycle()
|
||||||
|
|
||||||
@@ -61,7 +60,6 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
"""
|
"""
|
||||||
Actions run before the loop starts. Want to wait for bot to be ready and get the current cycle.
|
Actions run before the loop starts. Want to wait for bot to be ready and get the current cycle.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await self.bot.wait_until_ready()
|
await self.bot.wait_until_ready()
|
||||||
|
|
||||||
# Bot needs to know guilds to get the current cycle.
|
# Bot needs to know guilds to get the current cycle.
|
||||||
@@ -75,7 +73,6 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
Returns:
|
Returns:
|
||||||
ElectionCycle: Current election cycle, None if there is no election happening.
|
ElectionCycle: Current election cycle, None if there is no election happening.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = get_current_election_cycle(config)
|
cycle = get_current_election_cycle(config)
|
||||||
|
|
||||||
@@ -108,7 +105,6 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
Loops through the guild's humans checking for joined_at dates that match today's date. Sends a message
|
Loops through the guild's humans checking for joined_at dates that match today's date. Sends a message
|
||||||
saying happy cakeday.
|
saying happy cakeday.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id)
|
guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id)
|
||||||
announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id)
|
announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id)
|
||||||
|
|||||||
@@ -38,6 +38,5 @@ async def birthday_action(message: nextcord.Message) -> None:
|
|||||||
Args:
|
Args:
|
||||||
message (nextcord.Message): The message to check for a birthday person.
|
message (nextcord.Message): The message to check for a birthday person.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if message.author.id in birthday_list or bool(set(message.raw_mentions) & set(birthday_list)):
|
if message.author.id in birthday_list or bool(set(message.raw_mentions) & set(birthday_list)):
|
||||||
await message.add_reaction("🎂")
|
await message.add_reaction("🎂")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ if not exists("database/dakiny.db"):
|
|||||||
with sqlite3.connect("database/dakiny.db") as con:
|
with sqlite3.connect("database/dakiny.db") as con:
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
|
||||||
with open("database_setup/database.sql", mode="r", encoding="utf-8") as file:
|
with open("database_setup/database.sql", encoding="utf-8") as file:
|
||||||
database_script = file.read()
|
database_script = file.read()
|
||||||
cur.executescript(database_script)
|
cur.executescript(database_script)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import nextcord
|
|||||||
from hydra.core.config_store import ConfigStore
|
from hydra.core.config_store import ConfigStore
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
import database_setup.create_database as create_database
|
|
||||||
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
||||||
from classes.nominate_views import NominateView
|
from classes.nominate_views import NominateView
|
||||||
from classes.voting_highcouncil_views import VoteHighcouncilView
|
from classes.voting_highcouncil_views import VoteHighcouncilView
|
||||||
from classes.voting_views import VoteView
|
from classes.voting_views import VoteView
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
from database_setup import create_database
|
||||||
|
|
||||||
cs = ConfigStore.instance()
|
cs = ConfigStore.instance()
|
||||||
cs.store(name="dakiny_config", node=DakinyConfig)
|
cs.store(name="dakiny_config", node=DakinyConfig)
|
||||||
|
|||||||
+4
-1
@@ -57,7 +57,7 @@ line-length = 120
|
|||||||
indent-width = 4
|
indent-width = 4
|
||||||
|
|
||||||
# Assume Python 3.8
|
# Assume Python 3.8
|
||||||
target-version = "py38"
|
target-version = "py311"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||||
@@ -91,6 +91,9 @@ unfixable = []
|
|||||||
# Allow unused variables when underscore-prefixed.
|
# Allow unused variables when underscore-prefixed.
|
||||||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||||
|
|
||||||
|
[tool.ruff.lint.pydocstyle]
|
||||||
|
convention = "google"
|
||||||
|
|
||||||
[tool.ruff.format]
|
[tool.ruff.format]
|
||||||
# Like Black, use double quotes for strings.
|
# Like Black, use double quotes for strings.
|
||||||
quote-style = "double"
|
quote-style = "double"
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ File contains util functions.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from collections.abc import Sequence
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from typing import Sequence
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from sqlalchemy import select, true, update
|
from sqlalchemy import select, true, update
|
||||||
@@ -63,7 +63,6 @@ def get_election_name(config: DakinyConfig) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: the name of the election cycle
|
str: the name of the election cycle
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cycle = get_current_election_cycle(config)
|
cycle = get_current_election_cycle(config)
|
||||||
current_cycle = config.election_cycles[cycle]
|
current_cycle = config.election_cycles[cycle]
|
||||||
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||||
@@ -79,7 +78,6 @@ def get_quarter_name(config: DakinyConfig) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: the name of the cycle.
|
str: the name of the cycle.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cycle = get_quarter_cycle(config)
|
cycle = get_quarter_cycle(config)
|
||||||
current_cycle = config.election_cycles[cycle]
|
current_cycle = config.election_cycles[cycle]
|
||||||
|
|
||||||
@@ -96,7 +94,6 @@ def get_current_election_cycle(config: DakinyConfig) -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: cycle index for active election. None for no active cycle
|
int: cycle index for active election. None for no active cycle
|
||||||
"""
|
"""
|
||||||
|
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
|
|
||||||
for cycle, election in enumerate(config.election_cycles):
|
for cycle, election in enumerate(config.election_cycles):
|
||||||
@@ -120,7 +117,6 @@ def get_quarter_cycle(config: DakinyConfig) -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: cycle index for current cycle.
|
int: cycle index for current cycle.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
for cycle, election in enumerate(config.election_cycles):
|
for cycle, election in enumerate(config.election_cycles):
|
||||||
if (
|
if (
|
||||||
@@ -143,7 +139,6 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: String that contains all nominees and their votes.
|
str: String that contains all nominees and their votes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
votes: dict[int, int] = {}
|
votes: dict[int, int] = {}
|
||||||
|
|
||||||
election_name = get_election_name(config)
|
election_name = get_election_name(config)
|
||||||
@@ -180,7 +175,6 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
|||||||
str: String that contains all nominees and their votes.
|
str: String that contains all nominees and their votes.
|
||||||
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
|
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cl_votes: dict[int, int] = {}
|
cl_votes: dict[int, int] = {}
|
||||||
dm_votes: dict[int, int] = {}
|
dm_votes: dict[int, int] = {}
|
||||||
|
|
||||||
@@ -315,7 +309,6 @@ def record_event_points(config: DakinyConfig, users: Sequence[str], is_member: b
|
|||||||
is_member (bool): whether the users are a discord member or not
|
is_member (bool): whether the users are a discord member or not
|
||||||
points (int): number of points to add
|
points (int): number of points to add
|
||||||
"""
|
"""
|
||||||
|
|
||||||
quarter_name = get_quarter_name(config)
|
quarter_name = get_quarter_name(config)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
for user in users:
|
for user in users:
|
||||||
@@ -395,7 +388,6 @@ async def update_clan_messages(guild: nextcord.Guild, channel_updates: Sequence[
|
|||||||
guild (nextcord.Guild): Guild object that all channels and messages belong to.
|
guild (nextcord.Guild): Guild object that all channels and messages belong to.
|
||||||
channel_updates: (Sequence[str]): a sequence of the channels to update.
|
channel_updates: (Sequence[str]): a sequence of the channels to update.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
dirs = [dir_name for dir_name in channel_updates if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}")]
|
dirs = [dir_name for dir_name in channel_updates if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}")]
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -410,7 +402,7 @@ async def update_clan_messages(guild: nextcord.Guild, channel_updates: Sequence[
|
|||||||
for file_name in sorted_files:
|
for file_name in sorted_files:
|
||||||
message_name = f"{dir_name}/{file_name}"
|
message_name = f"{dir_name}/{file_name}"
|
||||||
file_path = f"{dir_path}/{file_name}"
|
file_path = f"{dir_path}/{file_name}"
|
||||||
with open(file_path, "r", encoding="utf8") as reader:
|
with open(file_path, encoding="utf8") as reader:
|
||||||
await edit_clan_message(session, channel, message_name, reader.read(2000))
|
await edit_clan_message(session, channel, message_name, reader.read(2000))
|
||||||
|
|
||||||
|
|
||||||
@@ -536,7 +528,7 @@ async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig):
|
|||||||
|
|
||||||
quarter = get_quarter_name(config)
|
quarter = get_quarter_name(config)
|
||||||
|
|
||||||
with open(f"{TEMPLATES_DIR}/council_members.txt", mode="r", encoding="utf8") as file:
|
with open(f"{TEMPLATES_DIR}/council_members.txt", encoding="utf8") as file:
|
||||||
message = file.read()
|
message = file.read()
|
||||||
message = message.format(
|
message = message.format(
|
||||||
quarter=quarter,
|
quarter=quarter,
|
||||||
|
|||||||
Reference in New Issue
Block a user