Compare commits

6 Commits

Author SHA1 Message Date
c19125894f Edit contributing.md 2025-10-16 16:17:39 -06:00
b328d325f6 Edit the self_callouts interaction.followup 2025-10-16 16:13:19 -06:00
c563d745d1 Update try/except/else interaction responses 2025-10-16 16:11:24 -06:00
72b45d9ef8 remove old todo from bot_core
All checks were successful
Test Helper Module / test (3.11.5) (push) Successful in 1m26s
2025-10-16 16:08:27 -06:00
2bfe73a703 Add todo to db_helper_tests 2025-10-16 16:08:07 -06:00
b39de87e4b Add barebones "break" additions 2025-10-16 16:06:22 -06:00
4 changed files with 49 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ This is primarily open-source so that others can implement the code that we've w
Currently, we use GitHub actions to test the database portion of the codebase. It's a bit harder to test the Discord-centric commands otherwise.
## Submitting changes
Please send a [new GitHub Pull Request](https://github.com/contrastellar/raid-callouts/compare) with a clear list of what's been done!
Please send a [new Pull Request](https://git.contrastellar.com/contrastellar/raid-callouts/pulls) with a clear list of what's been done!
When you send in a Pull Request (PR), we'll be super happy if you've made tests or otherwise commented your code clearly with what it does, and what libraries it uses in addition to our base libraries!
Please always write a clear commit message for your commits. One-line messages are fine for smaller changes, but bigger changes should be more details!

View File

@@ -247,6 +247,30 @@ async def callout(interaction: discord.Interaction, day: int, month: int, year:
await interaction.response.send_message(f'{user_char_name} -- you added a callout for {callout_date} with reason: {reason}')
await interaction.followup.send(f'{DATABASE_CONN.format_list_of_callouts(DATABASE_CONN.query_callouts(7))}')
@client.tree.command()
async def add_break(interaction: discord.Interaction, start_day: int, start_month: int,
start_year: int, end_day: int, end_month: int, end_year: int) -> None:
delete_invalidate()
cleanup_invalidate()
uid = interaction.user.id
user_nick = interaction.user.display_name
user_char_name = DATABASE_CONN.return_char_name(uid)
start_date: datetime.date = datetime.date(year=start_year, month=start_month, day=start_day)
end_date: datetime.date = datetime.date(year=end_year, month=end_month, day=end_day)
try:
DATABASE_CONN.add_break(user_id=uid, break_start=start_date, break_end=end_date)
except UNIQUEVIOLATION:
await interaction.response.send_message(f'{user_char_name} -- you have already added a break for {start_date} through {end_date}!')
except helper.db_helper.DateTimeError:
await interaction.response.send_message(f'{user_nick}, you\'re trying to submit a break for a time in the past! Please verify that this is what you want to do!')
except psycopg2.Error as e:
await interaction.response.send_message(f'{user_nick} -- an error has occured!\nNotifying <@{CONTRASTELLAR}> of this error. Error is as follows --\n{e}')
else:
await interaction.response.send_message(f'{user_char_name} -- you added a break for for {start_date} through {end_date}!')
@client.tree.command()
async def remove_callout(interaction: discord.Interaction, day: int, month: int, year: int) -> None:
@@ -282,7 +306,8 @@ async def self_callouts(interaction: discord.Interaction, days: int = 365) -> No
await interaction.response.defer(thinking=True)
callouts: list = DATABASE_CONN.query_self_callouts(user_id=uid, days=days)
callouts: str = DATABASE_CONN.formatted_list_of_callouts(callouts)
await interaction.followup.send(f'Callouts for the next **{days}** for user **{DATABASE_CONN.return_char_name(uid)}**:\n{callouts}')
character_name: str = DATABASE_CONN.return_char_name(uid)
await interaction.followup.send(f'Callouts for the next **{days}** for user **{character_name}**:\n{callouts}')
args: argparse.Namespace = parser.parse_args()

View File

@@ -57,3 +57,5 @@ class TestClass():
callouts = self.DATABASE_CONN.query_callouts(days=7)
formatted_callouts = self.DATABASE_CONN.format_list_of_callouts(callouts=callouts)
assert formatted_callouts.__class__ is str
# TODO write tests for the break addition/removal

View File

@@ -100,6 +100,15 @@ class DBHelper():
return cursor.fetchall()
def query_breaks(self) -> list:
self.__CONN = connect_config(self._config)
self.__CONN.autocommit = True
cursor = self.__CONN.cursor()
cursor.execute(f"SELECT * FROM breaks")
self.__CONN.commit()
return cursor.fetchall()
def query_self_callouts(self, user_id: int, days: int = 365):
self.__CONN = connect_config(self._config)
self.__CONN.autocommit = True
@@ -128,6 +137,17 @@ class DBHelper():
return
def add_break(self, user_id: int, break_start: datetime.date, break_end: datetime.date) -> None:
self.__CONN = connect_config(self._config)
self.__CONN.autocommit = True
cursor = self.__CONN.cursor()
is_range: int = 1
if break_start == break_end:
is_range = 0
cursor.execute("INSERT INTO breaks (created_user, is_range, open_range, close_range) VALUES (%s, %s, %s, %s)", (user_id, is_range, break_start, break_end))
def remove_callout(self, user_id: int, callout: datetime.date) -> None:
"""Remove a callout based on user + date, which form the primary key in the db