Compare commits

...
Author SHA1 Message Date
imcompiling a8697b0187 Bandaid fix so HC votes can be viewed.
build_latest / build (push) Successful in 1m39s
build_release / build (push) Successful in 48s
build_develop / build (push) Successful in 52s
2024-01-09 20:04:49 -05:00
imcompiling 8c8dc2c638 Merge branch '44-sort-candidates'
build_latest / build (push) Successful in 47s
build_release / build (push) Successful in 51s
2024-01-03 21:47:59 -05:00
imcompiling 54933b427e Sort nominees in voting views by display name.
build_develop / build (push) Successful in 1m27s
2024-01-03 21:46:54 -05:00
imcompiling 5d05006a23 Prevent unneeded exceptions.
build_latest / build (push) Successful in 1m23s
build_develop / build (push) Successful in 1m7s
2024-01-01 14:11:07 -05:00
imcompiling 2596b9fa7b Merge branch '47-incorrect-election-cycle'
build_latest / build (push) Successful in 44s
build_release / build (push) Successful in 45s
2024-01-01 13:32:41 -05:00
imcompiling 8c654612a9 Ensure that rolback months are properly year-ed.
build_develop / build (push) Successful in 1m27s
2024-01-01 13:32:17 -05:00
imcompiling e836ead399 Force crash on no election cycle. -1 was causing last item in config array to be used.
build_develop / build (push) Successful in 1m38s
2024-01-01 13:23:29 -05:00
imcompiling fa691ced5d Space on the wrong side of the quote.
build_latest / build (push) Successful in 1m33s
build_release / build (push) Successful in 45s
2023-12-27 09:50:01 -05:00
imcompiling 81f4c7741b Merge branch '40-remove-presence'
build_latest / build (push) Successful in 1m29s
build_release / build (push) Successful in 45s
2023-12-23 14:48:23 -05:00
imcompiling 2cde9f7109 Fix bug preventing remove from working.
build_develop / build (push) Successful in 1m40s
Remove guild ids.
2023-12-23 14:48:12 -05:00
imcompiling 2632bb883f Filled out remove presence some more. Not currently working.
build_develop / build (push) Successful in 1m25s
2023-12-22 22:05:07 -05:00
imcompiling 2f75f0cdcb Finish up presence auto complete function. 2023-12-22 21:56:29 -05:00
imcompiling deb405f02b Might not have worked without list cast. 2023-12-22 21:35:52 -05:00
imcompiling ee7cbaf2f6 Merge branch '39-view-presences'
build_latest / build (push) Successful in 1m26s
2023-12-22 21:33:45 -05:00
imcompiling 39746123f1 Add beginning of remove presence. 2023-12-22 21:23:29 -05:00
imcompiling c69adb8374 Limit items sent back on autocomplete (small bug) 2023-12-22 21:23:18 -05:00
imcompiling f722a6a87b Do not want guild ids 2023-12-22 16:36:31 -05:00
imcompiling b3550bbf55 Merge commit '0a18d819afecade9a9812df4c9056ba19bb4d211'
build_develop / build (push) Successful in 1m25s
2023-12-22 16:32:42 -05:00
9 changed files with 143 additions and 27 deletions
+3 -2
View File
@@ -239,7 +239,8 @@ class ElectionCycle:
) )
await election_thread.send(message) await election_thread.send(message)
vote_msg = await election_thread.send( vote_msg = await election_thread.send(
build_votes_str(self.config), view=VoteView(self.config, self.guild) build_votes_str(self.config, self.guild),
view=VoteView(self.config, self.guild),
) )
with Session(engine) as session: with Session(engine) as session:
@@ -324,7 +325,7 @@ class ElectionCycle:
) )
await election_thread.send(message) await election_thread.send(message)
vote_msg = await election_thread.send( vote_msg = await election_thread.send(
build_highcouncil_votes_str(self.config), build_highcouncil_votes_str(self.config, self.guild),
view=VoteHighcouncilView(self.config, self.guild), view=VoteHighcouncilView(self.config, self.guild),
) )
+9 -3
View File
@@ -82,7 +82,7 @@ class VoteSelect(nextcord.ui.StringSelect):
session.execute(stmt) session.execute(stmt)
session.commit() session.commit()
vote_message_str = build_highcouncil_votes_str(self.config) vote_message_str = build_highcouncil_votes_str(self.config, interaction.guild)
vote_msg: nextcord.Message = await interaction.channel.fetch_message( vote_msg: nextcord.Message = await interaction.channel.fetch_message(
vote_msg_id vote_msg_id
) )
@@ -159,7 +159,10 @@ class VoteHighcouncilView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}", else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee), value=str(nominee),
) )
for nominee in session.scalars(stmt) for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
] ]
options.append( options.append(
SelectOption( SelectOption(
@@ -232,7 +235,10 @@ class VoteHighcouncilView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}", else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee), value=str(nominee),
) )
for nominee in session.scalars(stmt) for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
] ]
options.append( options.append(
SelectOption( SelectOption(
+5 -2
View File
@@ -64,7 +64,7 @@ class VoteSelect(nextcord.ui.StringSelect):
session.execute(stmt) session.execute(stmt)
session.commit() session.commit()
vote_message_str = build_votes_str(self.config) vote_message_str = build_votes_str(self.config, interaction.guild)
vote_msg: nextcord.Message = await interaction.channel.fetch_message( vote_msg: nextcord.Message = await interaction.channel.fetch_message(
vote_msg_id vote_msg_id
) )
@@ -135,7 +135,10 @@ class VoteView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}", else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee), value=str(nominee),
) )
for nominee in session.scalars(stmt) for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
] ]
options.append( options.append(
SelectOption( SelectOption(
+3 -1
View File
@@ -4,6 +4,7 @@ Cog loader. Adds all command cogs to the bot.
from nextcord.ext import commands from nextcord.ext import commands
from cogs.commands.remove import RemoveCog
from cogs.commands.request import RequestCog from cogs.commands.request import RequestCog
from cogs.commands.set import setCog from cogs.commands.set import setCog
from cogs.commands.test import TestCog from cogs.commands.test import TestCog
@@ -17,7 +18,8 @@ def setup(bot: commands.Bot):
Adds all command classes to bot. Adds all command classes to bot.
""" """
bot.add_cog(RemoveCog())
bot.add_cog(RequestCog(bot)) bot.add_cog(RequestCog(bot))
bot.add_cog(TestCog(bot)) bot.add_cog(TestCog(bot))
bot.add_cog(setCog())
bot.add_cog(ViewCog()) bot.add_cog(ViewCog())
bot.add_cog(setCog())
+86
View File
@@ -0,0 +1,86 @@
"""
Commands for removing information in the database.
"""
import nextcord
from nextcord.ext import commands
from sqlalchemy import delete, select
from sqlalchemy.orm import Session
from database_setup.sql_data_classes import Presences, engine
class RemoveCog(commands.Cog, name="Remove Commands"):
"""
Holds the view commands.
"""
def __init__(self) -> None:
"""
Default constructor for RemoveCog class. Does nothing.
"""
@nextcord.slash_command(
default_member_permissions=nextcord.Permissions(administrator=True),
)
async def remove(self, interaction: nextcord.Interaction):
"""
Parent slash command for set. Never called.
"""
@remove.subcommand(description="Remove a presence from the database.")
async def presence(
self,
interaction: nextcord.Interaction,
presence_str: str = nextcord.SlashOption(
description="The presence to remove", required=True
),
):
"""
Deletes the given presence id from the database.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command.
presence (str): Is SlashOption. The presence to remove. Is the ID of the presence.
"""
presence_id = int(presence_str)
with Session(engine) as session:
stmt = delete(Presences).where(Presences.Id == presence_id)
session.execute(stmt)
session.commit()
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
):
"""
Collects all presences that start with the presence string.
Sends autocomplete dict {Presence Name, Presence Id}
Args:
interaction (nextcord.Interaction): Interaction with command.
presence_str (str): String to run autocomplete on.
"""
with Session(engine) as session:
stmt = select(Presences)
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])
)
return
autofilled_presences: "dict[str,str]" = {
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])
+1 -1
View File
@@ -49,7 +49,7 @@ class RequestCog(commands.Cog, name="Request Commands"):
""" """
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)
await self.bot.get_channel(config.params.admin_channel_id).send( await self.bot.get_channel(config.params.admin_channel_id).send(
content=content, view=view content=content, view=view
+4 -9
View File
@@ -7,12 +7,7 @@ from nextcord.ext import commands
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from database_setup.sql_data_classes import ( from database_setup.sql_data_classes import Presences, Votes, engine
ElectionInformation,
Presences,
Votes,
engine,
)
class ViewCog(commands.Cog, name="View Commands"): class ViewCog(commands.Cog, name="View Commands"):
@@ -25,7 +20,7 @@ class ViewCog(commands.Cog, name="View Commands"):
Default constructor for ViewCog class. Does nothing. Default constructor for ViewCog class. Does nothing.
""" """
@nextcord.slash_command(guild_ids=[1000247361639030804]) # TODO remove guild ids @nextcord.slash_command()
async def view(self, interaction: nextcord.Interaction): async def view(self, interaction: nextcord.Interaction):
""" """
Parent slash command for set. Never called. Parent slash command for set. Never called.
@@ -121,12 +116,12 @@ class ViewCog(commands.Cog, name="View Commands"):
""" """
with Session(engine) as session: with Session(engine) as session:
stmt = select(ElectionInformation.ElectionCycle) stmt = select(Votes.ElectionCycle).distinct()
elections = session.scalars(stmt) elections = session.scalars(stmt)
# if empty compare string # if empty compare string
if not election_name: if not election_name:
await interaction.response.send_autocomplete(elections) await interaction.response.send_autocomplete(list(elections)[:25])
return return
autofilled_elections: "list[str]" = [ autofilled_elections: "list[str]" = [
+10 -2
View File
@@ -79,6 +79,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = get_current_cycle(config) cycle = get_current_cycle(config)
# prevent exception from using cycle as an Int in an array
if cycle is None:
return None
return ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id)) return ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
def update_birthdays(self) -> None: def update_birthdays(self) -> None:
@@ -107,10 +111,14 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
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
)
cakedays: list[nextcord.Member] = [ 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: for member in cakedays:
+22 -7
View File
@@ -4,6 +4,7 @@ File contains util functions.
from datetime import datetime from datetime import datetime
import nextcord
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
@@ -31,6 +32,9 @@ def get_datetime(day: str) -> datetime:
if datetime.today().month == 12 and month < 12: if datetime.today().month == 12 and month < 12:
year += 1 year += 1
if datetime.today().month == 1 and month > 1:
year -= 1
return datetime(year, month, day) return datetime(year, month, day)
@@ -88,7 +92,7 @@ def get_current_cycle(config: DakinyConfig) -> int:
config (DakinyConfig): Config object to use config (DakinyConfig): Config object to use
Returns: Returns:
int: cycle index for active election. -1 for no active cycle int: cycle index for active election. None for no active cycle
""" """
today = datetime.today() today = datetime.today()
@@ -100,15 +104,16 @@ def get_current_cycle(config: DakinyConfig) -> int:
): ):
return cycle return cycle
return -1 return None
def build_votes_str(config: DakinyConfig) -> str: def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
""" """
Creates a string that contains all nominees and their votes to be sent as a discord message. Creates a string that contains all nominees and their votes to be sent as a discord message.
Args: Args:
config (DakinyConfig): Daking config object config (DakinyConfig): Daking config object
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
Returns: Returns:
str: String that contains all nominees and their votes. str: String that contains all nominees and their votes.
@@ -121,7 +126,10 @@ def build_votes_str(config: DakinyConfig) -> str:
CouncilMembers.ElectionCycle == get_election_cycle_name(config) CouncilMembers.ElectionCycle == get_election_cycle_name(config)
) )
for nominee in session.scalars(stmt): for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
votes[nominee.MemberId] = 0 votes[nominee.MemberId] = 0
stmt = select(Votes).where( stmt = select(Votes).where(
@@ -138,7 +146,7 @@ def build_votes_str(config: DakinyConfig) -> str:
return votes_str return votes_str
def build_highcouncil_votes_str(config: DakinyConfig) -> str: def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
""" """
Creates a string that contains all high council nominees and their votes to be sent as a discord message. Creates a string that contains all high council nominees and their votes to be sent as a discord message.
@@ -147,6 +155,7 @@ def build_highcouncil_votes_str(config: DakinyConfig) -> str:
Returns: Returns:
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.
""" """
cl_votes: dict[int, int] = {} cl_votes: dict[int, int] = {}
@@ -159,7 +168,10 @@ def build_highcouncil_votes_str(config: DakinyConfig) -> str:
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None)) .filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
) )
for nominee in session.scalars(stmt): for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
cl_votes[nominee.MemberId] = 0 cl_votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_cl_election_name(config)) stmt = select(Votes).where(Votes.ElectionCycle == get_cl_election_name(config))
@@ -174,7 +186,10 @@ def build_highcouncil_votes_str(config: DakinyConfig) -> str:
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None)) .filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
) )
for nominee in session.scalars(stmt): for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
dm_votes[nominee.MemberId] = 0 dm_votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_dm_election_name(config)) stmt = select(Votes).where(Votes.ElectionCycle == get_dm_election_name(config))