From 796b052bfc0b5a59b4a224a7af84ca722482b685 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Wed, 22 May 2024 15:06:39 -0400 Subject: [PATCH] Turned on all ruff rules. Formatted all files. --- classes/election_cycle.py | 118 +++++++------------------- classes/nominate_highcouncil_views.py | 50 +++-------- classes/nominate_views.py | 21 ++--- classes/voting_highcouncil_views.py | 32 ++----- classes/voting_views.py | 21 ++--- cogs/clan_messages/__init__.py | 26 ++---- cogs/commands/record.py | 49 +++-------- cogs/commands/refresh.py | 12 +-- cogs/commands/remove.py | 20 ++--- cogs/commands/request.py | 41 +++------ cogs/commands/set.py | 32 ++----- cogs/commands/view.py | 63 +++----------- cogs/loops/bot_presence.py | 12 +-- cogs/loops/daily_loop.py | 8 +- cogs/message_listener/__init__.py | 4 +- main.py | 4 +- pyproject.toml | 22 ++++- utils.py | 95 +++++---------------- 18 files changed, 161 insertions(+), 469 deletions(-) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index 6cd6946..c10b672 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -55,15 +55,9 @@ class ElectionCycle: self.term_end: datetime = get_datetime(self.election_cycle.term_end) self.voting_start: datetime = get_datetime(self.election_cycle.voting_start) self.voting_end: datetime = get_datetime(self.election_cycle.voting_end) - self.highcouncil_election_announce: datetime = get_datetime( - self.election_cycle.highcouncil_election_announce - ) - self.highcouncil_election_start: datetime = get_datetime( - self.election_cycle.highcouncil_election_start - ) - self.highcouncil_election_end: datetime = get_datetime( - self.election_cycle.highcouncil_election_end - ) + self.highcouncil_election_announce: datetime = get_datetime(self.election_cycle.highcouncil_election_announce) + self.highcouncil_election_start: datetime = get_datetime(self.election_cycle.highcouncil_election_start) + self.highcouncil_election_end: datetime = get_datetime(self.election_cycle.highcouncil_election_end) self.guild: nextcord.Guild = guild self.election_over: bool = False @@ -76,15 +70,11 @@ class ElectionCycle: long. """ - with open( - f"{TEMPLATES_DIR}/election_announcement.txt", mode="r", encoding="utf8" - ) as file: + with open(f"{TEMPLATES_DIR}/election_announcement.txt", mode="r", encoding="utf8") as file: message = file.read() next_election = get_datetime( - self.config.election_cycles[ - (self.cycle + 1) % len(self.config.election_cycles) - ].election_start + self.config.election_cycles[(self.cycle + 1) % len(self.config.election_cycles)].election_start ) message = message.format( @@ -109,22 +99,14 @@ class ElectionCycle: str: Message to send. """ - with open( - f"{TEMPLATES_DIR}/highcouncil_election.txt", mode="r", encoding="utf8" - ) as file: + with open(f"{TEMPLATES_DIR}/highcouncil_election.txt", mode="r", encoding="utf8") as file: message = file.read() return message.format( clan_council_elect_role_id=self.config.params.clan_council_elect_role_id, - highcouncil_election_announce=self.highcouncil_election_announce.strftime( - "%B %d" - ), - highcouncil_election_start=self.highcouncil_election_start.strftime( - "%B %d" - ), - highcouncil_election_end=self.highcouncil_election_end.strftime( - "%B %d" - ), + highcouncil_election_announce=self.highcouncil_election_announce.strftime("%B %d"), + highcouncil_election_start=self.highcouncil_election_start.strftime("%B %d"), + highcouncil_election_end=self.highcouncil_election_end.strftime("%B %d"), term_start=self.term_start.strftime("%B %d"), ) @@ -136,9 +118,7 @@ class ElectionCycle: str: Message to send. """ - with open( - f"{TEMPLATES_DIR}/highcouncil_vote.txt", mode="r", encoding="utf8" - ) as file: + with open(f"{TEMPLATES_DIR}/highcouncil_vote.txt", mode="r", encoding="utf8") as file: message = file.read() return message.format( @@ -156,9 +136,7 @@ class ElectionCycle: with open(f"{TEMPLATES_DIR}/vote_start.txt", mode="r", encoding="utf8") as file: 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) return message.format( clan_member_id=self.config.params.clan_member_role_id, @@ -177,11 +155,7 @@ class ElectionCycle: await self.election_start_action() elif today.date() == self.voting_start.date(): await self.voting_start_action() - elif ( - (self.voting_end - timedelta(3)).date() - <= today.date() - < self.voting_end.date() - ): + elif (self.voting_end - timedelta(3)).date() <= today.date() < self.voting_end.date(): await self.election_reminder() elif today.date() == self.voting_end.date(): await self.voting_end_action() @@ -195,16 +169,12 @@ class ElectionCycle: Performs required actions for when the election cycle starts. """ # create new channel for election - parent: nextcord.TextChannel = self.guild.get_channel( - self.config.params.voting_parent_id - ) + parent: nextcord.TextChannel = self.guild.get_channel(self.config.params.voting_parent_id) quarter_name: str = get_election_name(self.config) thread_msg: nextcord.Message = await parent.send(content=quarter_name) - thread: nextcord.Thread = await parent.create_thread( - name=quarter_name, message=thread_msg - ) + thread: nextcord.Thread = await parent.create_thread(name=quarter_name, message=thread_msg) # post message announcing election # election start message is returned as an array of string because it is too long. send each string @@ -213,9 +183,7 @@ class ElectionCycle: for index, message in enumerate(messages): # if last item, add the nominate button if index + 1 == len(messages): - nominate_msg: nextcord.Message = await thread.send( - message, view=NominateView(self.config, self.guild) - ) + nominate_msg: nextcord.Message = await thread.send(message, view=NominateView(self.config, self.guild)) else: await thread.send(message) @@ -235,9 +203,7 @@ class ElectionCycle: Removes write permission from the general clan member role. """ message = self.build_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) vote_msg = await election_thread.send( build_votes_str(self.config, self.guild), @@ -253,9 +219,7 @@ class ElectionCycle: session.commit() thread: nextcord.Thread = self.guild.get_thread(info.ThreadId) - nominate_msg: nextcord.Message = await thread.fetch_message( - info.CouncilNominationMsgId - ) + nominate_msg: nextcord.Message = await thread.fetch_message(info.CouncilNominationMsgId) await nominate_msg.edit(view=None) async def voting_end_action(self) -> None: @@ -264,12 +228,8 @@ class ElectionCycle: """ message = self.build_highcouncil_election_announce() - 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 - ) + 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) nominate_msg: nextcord.Message = await election_thread.send( message, view=NominateHighCouncilView(self.config, self.guild) @@ -279,13 +239,9 @@ class ElectionCycle: with Session(engine) as session: # remove vote button from vote message - stmt = select(ElectionInformation).where( - ElectionInformation.ElectionCycle == election_name - ) + stmt = select(ElectionInformation).where(ElectionInformation.ElectionCycle == election_name) info = session.scalar(stmt) - vote_msg: nextcord.Message = await election_thread.fetch_message( - info.CouncilVoteMsgId - ) + vote_msg: nextcord.Message = await election_thread.fetch_message(info.CouncilVoteMsgId) await vote_msg.edit(view=None) # add the highcouncil nomination message to election information @@ -324,9 +280,7 @@ class ElectionCycle: """ 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) vote_msg = await election_thread.send( build_highcouncil_votes_str(self.config, self.guild), @@ -342,9 +296,7 @@ class ElectionCycle: session.commit() # remove highcouncil nomination view - nomination_msg: nextcord.Message = await election_thread.fetch_message( - info.HighCouncilNominationMsgId - ) + nomination_msg: nextcord.Message = await election_thread.fetch_message(info.HighCouncilNominationMsgId) await nomination_msg.edit(view=None) async def term_start_action(self) -> None: @@ -354,12 +306,8 @@ class ElectionCycle: self.election_over = True - elect_role: nextcord.Role = self.guild.get_role( - self.config.params.clan_council_elect_role_id - ) - council_role: nextcord.Role = self.guild.get_role( - self.config.params.clan_council_role_id - ) + elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id) + council_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_role_id) election_cycle = get_election_name(self.config) @@ -422,9 +370,7 @@ class ElectionCycle: session.commit() - 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) # clear view from vote message stmt = select(ElectionInformation.HighCouncilVoteMsgId).where( @@ -434,15 +380,11 @@ class ElectionCycle: vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id) await vote_msg.edit(view=None) - highcouncil_msg: str = ( - f"Congratulations for our high council members!\nClan Leader: <@{cl_winner}>\n" - ) + highcouncil_msg: str = f"Congratulations for our high council members!\nClan Leader: <@{cl_winner}>\n" highcouncil_msg += f"Discord Manager: <@{dm_winner}>" await election_thread.send(highcouncil_msg) - await election_thread.send( - "This election cycle is now over. Thank you everyone for participating!" - ) + await election_thread.send("This election cycle is now over. Thank you everyone for participating!") await election_thread.edit(archived=True, locked=True) await edit_clan_council_info(self.guild, self.config) @@ -466,9 +408,7 @@ class ElectionCycle: 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"to <#{self.get_election_info().ThreadId}> to cast your vote!" diff --git a/classes/nominate_highcouncil_views.py b/classes/nominate_highcouncil_views.py index 9a32fa8..8d7d363 100644 --- a/classes/nominate_highcouncil_views.py +++ b/classes/nominate_highcouncil_views.py @@ -74,14 +74,8 @@ class NominateDMModal(nextcord.ui.Modal): council_elect.DiscordManagerSpeechId = msg.id session.commit() else: - msg: nextcord.Message = await interaction.channel.fetch_message( - council_elect.DiscordManagerSpeechId - ) - await msg.edit( - content=decorate_dm_nomination( - interaction.user.id, self.speech.value - ) - ) + msg: nextcord.Message = await interaction.channel.fetch_message(council_elect.DiscordManagerSpeechId) + await msg.edit(content=decorate_dm_nomination(interaction.user.id, self.speech.value)) class NominateCLModal(nextcord.ui.Modal): @@ -141,14 +135,8 @@ class NominateCLModal(nextcord.ui.Modal): council_elect.ClanLeaderSpeechId = msg.id session.commit() else: - msg: nextcord.Message = await interaction.channel.fetch_message( - council_elect.ClanLeaderSpeechId - ) - await msg.edit( - content=decorate_cl_nomination( - interaction.user.id, self.speech.value - ) - ) + msg: nextcord.Message = await interaction.channel.fetch_message(council_elect.ClanLeaderSpeechId) + await msg.edit(content=decorate_cl_nomination(interaction.user.id, self.speech.value)) class NominateHighCouncilView(nextcord.ui.View): @@ -166,9 +154,7 @@ class NominateHighCouncilView(nextcord.ui.View): style=nextcord.ButtonStyle.primary, custom_id="nominate-dm", ) - async def nominate_dm( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ) -> None: + async def nominate_dm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: """ Gathers previous information about the user if they have already nominated themselves, then launches the nomination modal to get their speech. @@ -179,10 +165,7 @@ class NominateHighCouncilView(nextcord.ui.View): """ # 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( f"You must have the <@&{self.config.params.clan_council_elect_role_id}> role to vote.", ephemeral=True, @@ -203,15 +186,11 @@ class NominateHighCouncilView(nextcord.ui.View): # user needs to exist to get here anyways... if obj.DiscordManagerSpeechId is not None: usr_nominated = True - msg = await interaction.channel.fetch_message( - obj.DiscordManagerSpeechId - ) + msg = await interaction.channel.fetch_message(obj.DiscordManagerSpeechId) speech_content = msg.content.split(NOMINEE_SPLITTER)[1] await interaction.response.send_modal( - NominateDMModal( - self.config, interaction.user.id, usr_nominated, speech_content - ) + NominateDMModal(self.config, interaction.user.id, usr_nominated, speech_content) ) @nextcord.ui.button( @@ -219,9 +198,7 @@ class NominateHighCouncilView(nextcord.ui.View): style=nextcord.ButtonStyle.primary, custom_id="nominate-cl", ) - async def nominate_cl( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ) -> None: + async def nominate_cl(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: """ Gathers previous information about the user if they have already nominated themselves, then launches the nomination modal to get their speech. @@ -232,10 +209,7 @@ class NominateHighCouncilView(nextcord.ui.View): """ # 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( f"You must have the <@&{self.config.params.clan_council_elect_role_id}> role to vote.", ephemeral=True, @@ -260,7 +234,5 @@ class NominateHighCouncilView(nextcord.ui.View): speech_content = msg.content.split(NOMINEE_SPLITTER)[1] await interaction.response.send_modal( - NominateCLModal( - self.config, interaction.user.id, usr_nominated, speech_content - ) + NominateCLModal(self.config, interaction.user.id, usr_nominated, speech_content) ) diff --git a/classes/nominate_views.py b/classes/nominate_views.py index cc26bb6..1b253af 100644 --- a/classes/nominate_views.py +++ b/classes/nominate_views.py @@ -74,12 +74,8 @@ class NominateModal(nextcord.ui.Modal): ) obj = session.scalar(stmt) - msg: nextcord.Message = await interaction.channel.fetch_message( - obj.SpeechMsgId - ) - await msg.edit( - content=decorate_nomination(interaction.user.id, self.speech.value) - ) + msg: nextcord.Message = await interaction.channel.fetch_message(obj.SpeechMsgId) + await msg.edit(content=decorate_nomination(interaction.user.id, self.speech.value)) class NominateView(nextcord.ui.View): @@ -97,9 +93,7 @@ class NominateView(nextcord.ui.View): style=nextcord.ButtonStyle.primary, custom_id="nominate", ) - async def nominate( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ) -> None: + async def nominate(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: """ Gathers previous information about the user if they have already nominated themselves, then launches the nomination modal to get their speech. @@ -110,10 +104,7 @@ class NominateView(nextcord.ui.View): """ # 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( f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.", ephemeral=True, @@ -136,7 +127,5 @@ class NominateView(nextcord.ui.View): speech_content = msg.content.split(NOMINEE_SPLITTER)[1] await interaction.response.send_modal( - NominateModal( - self.config, interaction.user.id, usr_nominated, speech_content - ) + NominateModal(self.config, interaction.user.id, usr_nominated, speech_content) ) diff --git a/classes/voting_highcouncil_views.py b/classes/voting_highcouncil_views.py index f52ef5b..bf74387 100644 --- a/classes/voting_highcouncil_views.py +++ b/classes/voting_highcouncil_views.py @@ -21,9 +21,7 @@ from utils import VoteType, build_highcouncil_votes_str, get_election_name 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__( placeholder="Choose 1", min_values=1, @@ -71,9 +69,7 @@ class VoteSelect(nextcord.ui.StringSelect): session.commit() vote_message_str = build_highcouncil_votes_str(self.config, interaction.guild) - vote_msg: nextcord.Message = await interaction.channel.fetch_message( - vote_msg_id - ) + vote_msg: nextcord.Message = await interaction.channel.fetch_message(vote_msg_id) await vote_msg.edit(content=vote_message_str) if voted_for is not None: @@ -99,9 +95,7 @@ class VoteHighcouncilView(nextcord.ui.View): style=nextcord.ButtonStyle.primary, custom_id="vote-cl", ) - async def vote_cl( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ) -> None: + async def vote_cl(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: """ Enforces only council elect vote. Gets election cycle, creates voting options for clan leader (checking if user has voted already), @@ -113,10 +107,7 @@ class VoteHighcouncilView(nextcord.ui.View): """ # 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( f"You must have the <@&{self.config.params.clan_council_elect_role_id}> role to vote.", ephemeral=True, @@ -162,11 +153,7 @@ class VoteHighcouncilView(nextcord.ui.View): ) view = nextcord.ui.View() - view.add_item( - VoteSelect( - options=options, config=self.config, election_type=VoteType.CLANLEADER - ) - ) + view.add_item(VoteSelect(options=options, config=self.config, election_type=VoteType.CLANLEADER)) await interaction.response.send_message( content="Please vote for a Clan Leader!", @@ -179,9 +166,7 @@ class VoteHighcouncilView(nextcord.ui.View): style=nextcord.ButtonStyle.primary, custom_id="vote-dm", ) - async def vote_dm( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ) -> None: + async def vote_dm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: """ Enforces only council elect vote. Gets election cycle, creates voting options for discord manager (checking if user has voted already), @@ -193,10 +178,7 @@ class VoteHighcouncilView(nextcord.ui.View): """ # 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( f"You must have the <@&{self.config.params.clan_council_elect_role_id}> role to vote.", ephemeral=True, diff --git a/classes/voting_views.py b/classes/voting_views.py index cdfc8ca..7c9420a 100644 --- a/classes/voting_views.py +++ b/classes/voting_views.py @@ -67,9 +67,7 @@ class VoteSelect(nextcord.ui.StringSelect): session.commit() vote_message_str = build_votes_str(self.config, interaction.guild) - vote_msg: nextcord.Message = await interaction.channel.fetch_message( - vote_msg_id - ) + vote_msg: nextcord.Message = await interaction.channel.fetch_message(vote_msg_id) await vote_msg.edit(content=vote_message_str) if voted_for is not None: @@ -90,12 +88,8 @@ class VoteView(nextcord.ui.View): self.config = config self.guild = guild - @nextcord.ui.button( - label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote" - ) - async def vote( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ) -> None: + @nextcord.ui.button(label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote") + async def vote(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: """ Enforces only members vote. Gets election cycle, creates voting options (checking if user has voted already), then sends the voting view. @@ -106,10 +100,7 @@ class VoteView(nextcord.ui.View): """ # 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( f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.", ephemeral=True, @@ -127,9 +118,7 @@ class VoteView(nextcord.ui.View): ) voted_for = session.scalar(stmt) - stmt = select(CouncilMembers.MemberId).where( - CouncilMembers.ElectionCycle == election - ) + stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionCycle == election) options = [ SelectOption( diff --git a/cogs/clan_messages/__init__.py b/cogs/clan_messages/__init__.py index 3db7212..619685b 100644 --- a/cogs/clan_messages/__init__.py +++ b/cogs/clan_messages/__init__.py @@ -47,19 +47,11 @@ class ClanMessages(commands.Cog, name="Clan Messages"): # Get all modified/added files 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 ] - template_updates = { - file.split("/")[1] for file in modified_files if "message_templates" in file - } - channel_updates = { - file.split("/")[1] - for file in modified_files - if file.split("/")[1] not in template_updates - } + template_updates = {file.split("/")[1] for file in modified_files if "message_templates" in file} + channel_updates = {file.split("/")[1] for file in modified_files if file.split("/")[1] not in template_updates} self.origin.pull() guild: nextcord.Guild = self.bot.get_guild(self.config.params.guild_id) @@ -68,9 +60,7 @@ class ClanMessages(commands.Cog, name="Clan Messages"): # if the council members template has changed, update the message if "council_members.txt" in template_updates: - await edit_clan_council_info( - self.bot.get_guild(self.config.params.guild_id), self.config - ) + await edit_clan_council_info(self.bot.get_guild(self.config.params.guild_id), self.config) return {"message": "Successfully updated all discord messages."} @@ -87,13 +77,9 @@ class ClanMessages(commands.Cog, name="Clan Messages"): self.origin = self.repo.remote("origin") if self.config.params.git_branch == "test": - self.repo.create_head("test", self.origin.refs.test).set_tracking_branch( - self.origin.refs.test - ).checkout() + self.repo.create_head("test", self.origin.refs.test).set_tracking_branch(self.origin.refs.test).checkout() else: - self.repo.create_head("main", self.origin.refs.main).set_tracking_branch( - self.origin.refs.main - ).checkout() + self.repo.create_head("main", self.origin.refs.main).set_tracking_branch(self.origin.refs.main).checkout() self.origin.pull() diff --git a/cogs/commands/record.py b/cogs/commands/record.py index 2e53b23..435eab9 100644 --- a/cogs/commands/record.py +++ b/cogs/commands/record.py @@ -32,9 +32,7 @@ class RecordCog(commands.Cog, name="Record Commands"): async def event( self, interaction: nextcord.Interaction, - name: str = nextcord.SlashOption( - required=True, description="Name of the event that was hosted." - ), + name: str = nextcord.SlashOption(required=True, description="Name of the event that was hosted."), host: nextcord.Member = nextcord.SlashOption( required=False, description="An alternative host if you are recording event for someone else.", @@ -51,10 +49,7 @@ class RecordCog(commands.Cog, name="Record Commands"): """ # 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( f"You must have the <@&{self.bot.config.params.event_host_role_id}> role to record an event.", ephemeral=True, @@ -95,15 +90,11 @@ class EventView(nextcord.ui.View): self.add_item(self.event_participants) @nextcord.ui.button(label="Cancel", style=nextcord.ButtonStyle.red, row=1) - async def cancel( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ): + async def cancel(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): """ Cancels event submission. Removes embed and view. """ - await interaction.response.edit_message( - "Canceled", ephemeral=True, embed=None, view=None - ) + await interaction.response.edit_message("Canceled", ephemeral=True, embed=None, view=None) self.stop() @nextcord.ui.button(label="Edit", style=nextcord.ButtonStyle.blurple, row=1) @@ -111,14 +102,10 @@ class EventView(nextcord.ui.View): """ Calls modal to update the text input information of the event. """ - await interaction.response.send_modal( - ParticipantModal(interaction.message.embeds[0]) - ) + await interaction.response.send_modal(ParticipantModal(interaction.message.embeds[0])) @nextcord.ui.button(label="Confirm", style=nextcord.ButtonStyle.green, row=1) - async def confirm( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ): + async def confirm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): """ Submits the event embed to the event channel. Removes view and embed from recording message. Sends point information to database. @@ -126,9 +113,7 @@ class EventView(nextcord.ui.View): discord_users = self.event_participants.values.members 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] record_event_points( self.config, discord_users_list, @@ -146,17 +131,11 @@ class EventView(nextcord.ui.View): self.config.params.event_participate_points, ) - record_event_points( - self.config, [self.host_id], True, self.config.params.event_host_points - ) + record_event_points(self.config, [self.host_id], True, self.config.params.event_host_points) - event_channel: nextcord.TextChannel = interaction.guild.get_channel( - self.config.params.event_post_channel_id - ) + event_channel: nextcord.TextChannel = interaction.guild.get_channel(self.config.params.event_post_channel_id) await event_channel.send(embed=interaction.message.embeds[0]) - await interaction.response.edit_message( - content="Event has been submitted.", view=None, embed=None - ) + await interaction.response.edit_message(content="Event has been submitted.", view=None, embed=None) self.stop() @@ -201,9 +180,7 @@ class ParticipantModal(nextcord.ui.Modal): async def callback(self, interaction: nextcord.Interaction): self.embed.title = self.name.value self.embed.description = self.description.value - self.embed.set_field_at( - index=1, name="Non-Discord Participants", value=self.participants.value - ) + self.embed.set_field_at(index=1, name="Non-Discord Participants", value=self.participants.value) await interaction.response.edit_message(embed=self.embed) @@ -223,8 +200,6 @@ class ParticipantSelect(nextcord.ui.UserSelect): async def callback(self, interaction: nextcord.Interaction): embed: nextcord.Embed = interaction.message.embeds[0] - participants: str = "\n".join( - [f"<@{participant.id}>" for participant in self.values.members] - ) + participants: str = "\n".join([f"<@{participant.id}>" for participant in self.values.members]) embed.set_field_at(0, name="Participants", value=participants) await interaction.response.edit_message(embed=embed) diff --git a/cogs/commands/refresh.py b/cogs/commands/refresh.py index ba92dd0..1bc30bc 100644 --- a/cogs/commands/refresh.py +++ b/cogs/commands/refresh.py @@ -22,9 +22,7 @@ class RefreshCog(commands.Cog, name="Refresh Commands"): super().__init__() self.bot: commands.Bot = bot - @nextcord.slash_command( - default_member_permissions=nextcord.Permissions(administrator=True) - ) + @nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True)) async def refresh(self, interaction: nextcord.Interaction): """ Parent slash command for refresh. Never called. @@ -50,9 +48,7 @@ class RefreshCog(commands.Cog, name="Refresh Commands"): if channel is None: channel_updates = [ - dir_name - for dir_name in os.listdir(MESSAGES_DIR) - if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}") + dir_name for dir_name in os.listdir(MESSAGES_DIR) if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}") ] else: channel_updates = [channel.name] @@ -69,6 +65,4 @@ class RefreshCog(commands.Cog, name="Refresh Commands"): interaction (nextcord.Interaction): Interaction with the command. """ await edit_clan_council_info(interaction.guild, self.bot.config) - await interaction.response.send_message( - "Clan Council Info message updated.", ephemeral=True - ) + await interaction.response.send_message("Clan Council Info message updated.", ephemeral=True) diff --git a/cogs/commands/remove.py b/cogs/commands/remove.py index 1f86346..43715ba 100644 --- a/cogs/commands/remove.py +++ b/cogs/commands/remove.py @@ -32,9 +32,7 @@ class RemoveCog(commands.Cog, name="Remove Commands"): async def presence( self, interaction: nextcord.Interaction, - presence_str: str = nextcord.SlashOption( - description="The presence to remove", required=True - ), + presence_str: str = nextcord.SlashOption(description="The presence to remove", required=True), ): """ Deletes the given presence id from the database. @@ -53,9 +51,7 @@ class RemoveCog(commands.Cog, name="Remove Commands"): await interaction.response.send_message("Presence deleted.", ephemeral=True) @presence.on_autocomplete("presence_str") - async def presence_autocomplete( - self, interaction: nextcord.Interaction, presence_str: str - ): + async def presence_autocomplete(self, interaction: nextcord.Interaction, presence_str: str): """ Collects all presences that start with the presence string. Sends autocomplete dict {Presence Name, Presence Id} @@ -67,20 +63,14 @@ class RemoveCog(commands.Cog, name="Remove Commands"): with Session(engine) as session: 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)} # if empty compare string if not presence_str: - await interaction.response.send_autocomplete( - dict(list(presences_dict.items())[:25]) - ) + await interaction.response.send_autocomplete(dict(list(presences_dict.items())[:25])) return autofilled_presences: "dict[str,str]" = { - pres: pres_id - for pres, pres_id in presences_dict.items() - if presence_str.lower() in pres.lower() + pres: pres_id for pres, pres_id in presences_dict.items() if presence_str.lower() in pres.lower() } await interaction.response.send_autocomplete(autofilled_presences[:25]) diff --git a/cogs/commands/request.py b/cogs/commands/request.py index 14924d2..b1b0401 100644 --- a/cogs/commands/request.py +++ b/cogs/commands/request.py @@ -27,9 +27,7 @@ class RequestCog(commands.Cog, name="Request Commands"): Parent slash command for request. Never called. """ - @request.subcommand( - description="Request to add a presence to the bot's presence list." - ) + @request.subcommand(description="Request to add a presence to the bot's presence list.") async def add_presence( self, interaction: nextcord.Interaction, @@ -51,12 +49,8 @@ class RequestCog(commands.Cog, name="Request Commands"): config: DakinyConfig = self.bot.config content = f'<@{interaction.user.id}> would like to add presence "{presence}."' view = PresenceChange(presence) - await self.bot.get_channel(config.params.admin_channel_id).send( - content=content, view=view - ) - await interaction.response.send_message( - "Request sent to admins.", ephemeral=True - ) + await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view) + await interaction.response.send_message("Request sent to admins.", ephemeral=True) @request.subcommand(description="Request to change your Dakiny nickname") async def change_nickname( @@ -80,12 +74,8 @@ class RequestCog(commands.Cog, name="Request Commands"): config: DakinyConfig = self.bot.config content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."' view = UsernameRequest(interaction.user.id, new_nickname) - await self.bot.get_channel(config.params.admin_channel_id).send( - content=content, view=view - ) - await interaction.response.send_message( - "Request sent to admins.", ephemeral=True - ) + await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view) + await interaction.response.send_message("Request sent to admins.", ephemeral=True) class UsernameRequest(nextcord.ui.View): @@ -103,9 +93,7 @@ class UsernameRequest(nextcord.ui.View): self.new_nickname = new_nickname @nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green) - async def approve( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ): + async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): """ Approve button for a nickname change request. Changes the target's nickname to self.new_nickname. Catches an error if the target as a higher role than the bot. @@ -119,10 +107,7 @@ class UsernameRequest(nextcord.ui.View): if user is not None: try: await user.edit(nick=self.new_nickname) - content = ( - interaction.message.content - + f"\nApproved by <@{interaction.user.id}>." - ) + content = interaction.message.content + f"\nApproved by <@{interaction.user.id}>." await interaction.response.edit_message(content=content, view=None) except nextcord.errors.Forbidden: await interaction.response.send_message( @@ -133,9 +118,7 @@ class UsernameRequest(nextcord.ui.View): interaction.message.content + "\n\nFailed. User has too high permissions for bot to change nickname." ) - await interaction.followup.edit_message( - interaction.message.id, content=content, view=None - ) + await interaction.followup.edit_message(interaction.message.id, content=content, view=None) else: await interaction.response.edit_message( content="An error occured while changing the user's nickname.", @@ -168,9 +151,7 @@ class PresenceChange(nextcord.ui.View): self.presence = presence @nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green) - async def approve( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ): + async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): """ Approve button for a presence add request. Adds the presence to the database. Removes the view from the interaction message. @@ -184,9 +165,7 @@ class PresenceChange(nextcord.ui.View): session.add(Presences(Presence=self.presence)) session.commit() - content = ( - interaction.message.content + f"\nApproved by <@{interaction.user.id}>." - ) + content = interaction.message.content + f"\nApproved by <@{interaction.user.id}>." await interaction.response.edit_message(content=content, view=None) @nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red) diff --git a/cogs/commands/set.py b/cogs/commands/set.py index 5a9f338..4331e41 100644 --- a/cogs/commands/set.py +++ b/cogs/commands/set.py @@ -30,18 +30,12 @@ class setCog(commands.Cog, name="Set Commands"): Parent slash command for set. Never called. """ - @set.subcommand( - description="Sets your birth month and day for the Birthday Fun. Use 0/0 to remove yourself." - ) + @set.subcommand(description="Sets your birth month and day for the Birthday Fun. Use 0/0 to remove yourself.") async def birthday( self, interaction: nextcord.Interaction, - month: int = nextcord.SlashOption( - required=True, min_value=0, max_value=12, description="Your birth month." - ), - day: int = nextcord.SlashOption( - required=True, min_value=0, max_value=31, description="Your birth day." - ), + month: int = nextcord.SlashOption(required=True, min_value=0, max_value=12, description="Your birth month."), + day: int = nextcord.SlashOption(required=True, min_value=0, max_value=31, description="Your birth day."), ): """ Sets a user's birthday in the database. Removes on input 0/0. If birthday is today, adds to the birthday_list. @@ -56,9 +50,7 @@ class setCog(commands.Cog, name="Set Commands"): await interaction.response.defer(ephemeral=True) if month == 0 and day == 0: - stmt = delete(UserBirthday).where( - UserBirthday.UserId == interaction.user.id - ) + stmt = delete(UserBirthday).where(UserBirthday.UserId == interaction.user.id) with Session(engine) as session: session.execute(stmt) session.commit() @@ -70,18 +62,14 @@ class setCog(commands.Cog, name="Set Commands"): try: birthday = datetime(today.year, month, day) except ValueError: - await interaction.followup.send( - f"Invalid date: {month}/{day}.", ephemeral=True - ) + await interaction.followup.send(f"Invalid date: {month}/{day}.", ephemeral=True) return # If the birthday is today, add to birthday_list if today.date() == birthday.date(): birthday_list.append(interaction.user.id) - new_birthday = UserBirthday( - UserId=interaction.user.id, Birthday=f"{month}/{day}" - ) + new_birthday = UserBirthday(UserId=interaction.user.id, Birthday=f"{month}/{day}") with Session(engine) as session: try: session.add(new_birthday) @@ -89,13 +77,9 @@ class setCog(commands.Cog, name="Set Commands"): except IntegrityError: # User already has birthday, change it instead. session.rollback() - stmt = select(UserBirthday).where( - UserBirthday.UserId == interaction.user.id - ) + stmt = select(UserBirthday).where(UserBirthday.UserId == interaction.user.id) new_birthday = session.scalar(stmt) new_birthday.Birthday = f"{month}/{day}" session.commit() - await interaction.followup.send( - f"Birthday set to {month}/{day}.", ephemeral=True - ) + await interaction.followup.send(f"Birthday set to {month}/{day}.", ephemeral=True) diff --git a/cogs/commands/view.py b/cogs/commands/view.py index b186812..fe37d04 100644 --- a/cogs/commands/view.py +++ b/cogs/commands/view.py @@ -60,9 +60,7 @@ class ViewCog(commands.Cog, name="View Commands"): ) if df.empty: - await interaction.followup.send( - f'Quarter "{quarter_name}" is invalid.', ephemeral=True - ) + await interaction.followup.send(f'Quarter "{quarter_name}" is invalid.', ephemeral=True) return cycles = df.groupby("Cycle") @@ -74,32 +72,19 @@ class ViewCog(commands.Cog, name="View Commands"): non_members = unsorted_all.get_group(False) sorted_members = members.sort_values( by="UserId", - key=lambda user_ids: ( - [ - interaction.guild.get_member(int(id)).display_name - for id in user_ids - ] - ), + key=lambda user_ids: ([interaction.guild.get_member(int(id)).display_name for id in user_ids]), ) sorted_non_members = non_members.sort_values(by="UserId") - sorted_all = pd.concat( - [sorted_members, sorted_non_members], ignore_index=True, sort=False - ) + sorted_all = pd.concat([sorted_members, sorted_non_members], ignore_index=True, sort=False) for row in sorted_all.itertuples(): userid = row.UserId points = row.Points discord_member = row.DiscordMember - content += ( - f"<@{userid}>: {points}\n" - if discord_member - else f"{userid}: {points}\n" - ) + content += f"<@{userid}>: {points}\n" if discord_member else f"{userid}: {points}\n" content += "\n" if len(content) > 2000: - await interaction.followup.send( - "Message length is too long, please select search to limit results." - ) + await interaction.followup.send("Message length is too long, please select search to limit results.") return await interaction.followup.send(content=content, ephemeral=True) @@ -128,21 +113,13 @@ class ViewCog(commands.Cog, name="View Commands"): presences = session.scalars(stmt) if search: - message = "\n".join( - [ - presence - for presence in presences - if search.lower() in presence.lower() - ] - ) + message = "\n".join([presence for presence in presences if search.lower() in presence.lower()]) else: message = "\n".join(list(presences)) await interaction.followup.send(content=message, ephemeral=True) - @view.subcommand( - description="Shows all voters and who they voted for in a given election." - ) + @view.subcommand(description="Shows all voters and who they voted for in a given election.") async def votes( self, interaction: nextcord.Interaction, @@ -165,18 +142,12 @@ class ViewCog(commands.Cog, name="View Commands"): 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: # Check if election exists. if session.scalar(stmt) is None: - await interaction.response.send_message( - f"Invalid election: {election_name}.", ephemeral=True - ) + await interaction.response.send_message(f"Invalid election: {election_name}.", ephemeral=True) return votes = session.scalars(stmt) @@ -191,9 +162,7 @@ class ViewCog(commands.Cog, name="View Commands"): await interaction.response.send_message(content=content, ephemeral=True) @votes.on_autocomplete("election_name") - async def election_autocomplete( - self, interaction: nextcord.Interaction, election_name: str - ): + async def election_autocomplete(self, interaction: nextcord.Interaction, election_name: str): """ Collects all elections that start with the election string. @@ -212,16 +181,12 @@ class ViewCog(commands.Cog, name="View Commands"): return autofilled_elections: "list[str]" = [ - election - for election in elections - if election.lower().startswith(election_name.lower()) + election for election in elections if election.lower().startswith(election_name.lower()) ] await interaction.response.send_autocomplete(autofilled_elections[:25]) @event_points.on_autocomplete("quarter_name") - async def event_points_autocomplete( - self, interaction: nextcord.Interaction, quarter_name: str - ): + async def event_points_autocomplete(self, interaction: nextcord.Interaction, quarter_name: str): """ Collects all elections that start with the election string. @@ -240,8 +205,6 @@ class ViewCog(commands.Cog, name="View Commands"): return autofilled_quarters: "list[str]" = [ - quarter - for quarter in quarters - if quarter.lower().startswith(quarter_name.lower()) + quarter for quarter in quarters if quarter.lower().startswith(quarter_name.lower()) ] await interaction.response.send_autocomplete(autofilled_quarters[:25]) diff --git a/cogs/loops/bot_presence.py b/cogs/loops/bot_presence.py index f026809..ada7f3d 100644 --- a/cogs/loops/bot_presence.py +++ b/cogs/loops/bot_presence.py @@ -17,9 +17,7 @@ class BotPresence(commands.Cog, name="Bot Presence"): self.bot = bot @commands.Cog.listener() - async def on_guild_join( - self, guild: nextcord.Guild - ): # pylint: disable=unused-argument + async def on_guild_join(self, guild: nextcord.Guild): # pylint: disable=unused-argument """Listener for Guild Join. Updated presence on guild join.""" await self.change_presence() @@ -39,10 +37,6 @@ class BotPresence(commands.Cog, name="Bot Presence"): """Randomly chooses a presence and updates bot's presence.""" 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())) - await self.bot.change_presence( - activity=nextcord.CustomActivity(name="Custom Status", state=presence) - ) + await self.bot.change_presence(activity=nextcord.CustomActivity(name="Custom Status", state=presence)) diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index 81fc81c..4dd1dd0 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -111,14 +111,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"): today = datetime.today() 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) cakedays: list[nextcord.Member] = [ - human - for human in guild.humans - if human.joined_at.month == today.month and human.joined_at.day == today.day + human for human in guild.humans if human.joined_at.month == today.month and human.joined_at.day == today.day ] for member in cakedays: diff --git a/cogs/message_listener/__init__.py b/cogs/message_listener/__init__.py index 0da2bce..38d745e 100644 --- a/cogs/message_listener/__init__.py +++ b/cogs/message_listener/__init__.py @@ -39,7 +39,5 @@ async def birthday_action(message: nextcord.Message) -> None: 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("🎂") diff --git a/main.py b/main.py index b1679fb..49cd47e 100644 --- a/main.py +++ b/main.py @@ -22,9 +22,7 @@ birthday_list: list[int] = [] logger = logging.getLogger("nextcord") logger.setLevel(logging.DEBUG) handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w") -handler.setFormatter( - logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s") -) +handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) diff --git a/pyproject.toml b/pyproject.toml index 9d89a20..7cdc9f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,8 +63,26 @@ target-version = "py38" # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or # McCabe complexity (`C901`) by default. -select = ["E4", "E7", "E9", "F", "D100", "D1"] -ignore = ["D107"] +select = ["ALL"] +ignore = [ + "D107", + "W191", + "E111", + "E114", + "E117", + "D203", + "D206", + "D212", + "D300", + "Q000", + "Q001", + "Q002", + "Q003", + "COM812", + "COM819", + "ISC001", + "ISC002", +] # Allow fix for all enabled rules (when `--fix`) is provided. fixable = ["ALL"] diff --git a/utils.py b/utils.py index 18d9973..389a478 100644 --- a/utils.py +++ b/utils.py @@ -149,9 +149,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str: election_name = get_election_name(config) with Session(engine) as session: - stmt = select(CouncilMembers).where( - CouncilMembers.ElectionCycle == election_name - ) + stmt = select(CouncilMembers).where(CouncilMembers.ElectionCycle == election_name) for nominee in sorted( session.scalars(stmt), @@ -159,11 +157,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str: ): votes[nominee.MemberId] = 0 - stmt = ( - select(Votes) - .where(Votes.ElectionCycle == election_name) - .where(Votes.Type == VoteType.COUNCIL) - ) + stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == VoteType.COUNCIL) for vote in session.scalars(stmt): if vote.VotedForId is not None: @@ -205,11 +199,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> ): cl_votes[nominee.MemberId] = 0 - stmt = ( - select(Votes) - .where(Votes.ElectionCycle == election_name) - .where(Votes.Type == VoteType.CLANLEADER) - ) + stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == VoteType.CLANLEADER) for vote in session.scalars(stmt): if vote.VotedForId is not None: @@ -227,11 +217,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> ): dm_votes[nominee.MemberId] = 0 - stmt = ( - select(Votes) - .where(Votes.ElectionCycle == election_name) - .where(Votes.Type == VoteType.DISCORDMANAGER) - ) + stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == VoteType.DISCORDMANAGER) for vote in session.scalars(stmt): if vote.VotedForId is not None: @@ -318,9 +304,7 @@ def decorate_dm_nomination(user_id: int, speech: str) -> str: return msg -def record_event_points( - config: DakinyConfig, users: Sequence[str], is_member: bool, add_points: int -): +def record_event_points(config: DakinyConfig, users: Sequence[str], is_member: bool, add_points: int): """ Adds event points to all users listed. Checks if they don't exist in order to make a new entry, otherwise adds points to the existing value. Can be used for hosting or participating. @@ -343,9 +327,7 @@ def record_event_points( points = session.scalar(stmt) if points is None: - add_points = get_allowed_points( - session, config.params.event_points_weekly_limit, user, add_points - ) + add_points = get_allowed_points(session, config.params.event_points_weekly_limit, user, add_points) new_points = ParticipationPoints( Cycle=quarter_name, UserId=user, @@ -354,17 +336,13 @@ def record_event_points( ) session.add(new_points) else: - add_points = get_allowed_points( - session, config.params.event_points_weekly_limit, user, add_points - ) + add_points = get_allowed_points(session, config.params.event_points_weekly_limit, user, add_points) points.Points += add_points session.commit() -def get_allowed_points( - session: Session, points_limit: int, user: str, points: int -) -> int: +def get_allowed_points(session: Session, points_limit: int, user: str, points: int) -> int: """ Gets the maximum number of points a user can be given. Searches how many points they have been given this week and subtracts that from the weekly limit. If under, returns up to "points" number of points (will not @@ -380,14 +358,8 @@ def get_allowed_points( int: how many points are allowed to be given to the user. """ # check for limit - this_week = ( - f"{datetime.today().isocalendar().year}-{datetime.today().isocalendar().week}" - ) - stmt = ( - select(EventPointsLimit) - .where(EventPointsLimit.UserId == user) - .where(EventPointsLimit.Week == this_week) - ) + this_week = f"{datetime.today().isocalendar().year}-{datetime.today().isocalendar().week}" + stmt = select(EventPointsLimit).where(EventPointsLimit.UserId == user).where(EventPointsLimit.Week == this_week) # if under limit, can add up to however many points would make the current limit equal to the # allowed limit. @@ -424,11 +396,7 @@ async def update_clan_messages(guild: nextcord.Guild, channel_updates: Sequence[ 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: for dir_name in dirs: @@ -443,14 +411,10 @@ async def update_clan_messages(guild: nextcord.Guild, channel_updates: Sequence[ message_name = f"{dir_name}/{file_name}" file_path = f"{dir_path}/{file_name}" with open(file_path, "r", 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)) -async def get_clan_message_channel( - session: Session, channel_name: str, guild: nextcord.Guild -) -> nextcord.TextChannel: +async def get_clan_message_channel(session: Session, channel_name: str, guild: nextcord.Guild) -> nextcord.TextChannel: """ Used to obtain a channel from the guild object. Searches database for an id to get the channel. If that is not found, then searches through all channels in the guild to find one with a matching name. If that also doesn't @@ -472,10 +436,7 @@ async def get_clan_message_channel( # channel is not tracked. see if it exists channels = await guild.fetch_channels() for channel in channels: - if ( - channel.name == channel_name - and channel.__class__ is nextcord.TextChannel - ): + if channel.name == channel_name and channel.__class__ is nextcord.TextChannel: ret_channel = channel if ret_channel is None: @@ -499,11 +460,7 @@ async def get_clan_message_channel( channel_name, reason="Creating channel as required for by design of Dakiny-Messages repo.", ) - stmt = ( - update(Messages) - .where(Messages.Path == channel_name) - .values(Id=ret_channel.id) - ) + stmt = update(Messages).where(Messages.Path == channel_name).values(Id=ret_channel.id) session.execute(stmt) session.commit() return ret_channel @@ -540,9 +497,7 @@ async def edit_clan_message( await msg.edit(message_content) except nextcord.NotFound: msg = await channel.send(message_content) - stmt = ( - update(Messages).where(Messages.Path == message_name).values(Id=msg.id) - ) + stmt = update(Messages).where(Messages.Path == message_name).values(Id=msg.id) session.execute(stmt) session.commit() @@ -555,9 +510,7 @@ async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig): guild (nextcord.Guild): Guild object that to use to get channel. config (DakinyConfig): Configs """ - clan_info_channel: nextcord.TextChannel = await guild.fetch_channel( - config.params.clan_info_channel_id - ) + clan_info_channel: nextcord.TextChannel = await guild.fetch_channel(config.params.clan_info_channel_id) election = get_election_name(config) with Session(engine) as session: @@ -579,17 +532,11 @@ async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig): .where(CouncilMembers.Elected == true()) ) - council_members_strs = [ - f"<@{id}>" - for id in session.scalars(stmt) - if id not in (discord_manager, clan_leader) - ] + council_members_strs = [f"<@{id}>" for id in session.scalars(stmt) if id not in (discord_manager, clan_leader)] 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", mode="r", encoding="utf8") as file: message = file.read() message = message.format( quarter=quarter, @@ -598,6 +545,4 @@ async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig): discord_manager=discord_manager, ) - await edit_clan_message( - session, clan_info_channel, "council_members.txt", message - ) + await edit_clan_message(session, clan_info_channel, "council_members.txt", message)