Add "breaks" functionality to bot. #1
@@ -247,6 +247,35 @@ 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.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))}')
|
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)
|
||||||
|
|
||||||
|
# TODO send to DATABASE_CONN to add callout
|
||||||
|
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 callout for {callout_date} with reason: {reason}')
|
||||||
|
except INVALIDDATETIMEFORMAT:
|
||||||
|
await interaction.response.send_message(f'{user_char_name} -- please format the date as the following format: MM/DD/YYYY')
|
||||||
|
except FOREIGNKEYVIOLATION:
|
||||||
|
await interaction.response.send_message(f'{user_nick} -- please register with the bot using the following command!\n`/registercharacter`\n Please use your in-game name!')
|
||||||
|
except helper.db_helper.DateTimeError:
|
||||||
|
await interaction.response.send_message(f'{user_nick}, you\'re trying to submit a callout 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 callout for {callout_date} with reason: {reason}')
|
||||||
|
|
||||||
|
|
||||||
@client.tree.command()
|
@client.tree.command()
|
||||||
async def remove_callout(interaction: discord.Interaction, day: int, month: int, year: int) -> None:
|
async def remove_callout(interaction: discord.Interaction, day: int, month: int, year: int) -> None:
|
||||||
|
|||||||
@@ -100,6 +100,15 @@ class DBHelper():
|
|||||||
|
|
||||||
return cursor.fetchall()
|
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):
|
def query_self_callouts(self, user_id: int, days: int = 365):
|
||||||
self.__CONN = connect_config(self._config)
|
self.__CONN = connect_config(self._config)
|
||||||
self.__CONN.autocommit = True
|
self.__CONN.autocommit = True
|
||||||
@@ -128,6 +137,17 @@ class DBHelper():
|
|||||||
|
|
||||||
return
|
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:
|
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
|
"""Remove a callout based on user + date, which form the primary key in the db
|
||||||
|
|||||||
Reference in New Issue
Block a user