Compare commits
9 Commits
contributi
...
1315cb294f
| Author | SHA1 | Date | |
|---|---|---|---|
|
1315cb294f
|
|||
|
090d370ce1
|
|||
|
97a3ae22fa
|
|||
|
9b7c70576b
|
|||
|
aca7358af8
|
|||
|
6b2421e55c
|
|||
|
5b58c6e8ea
|
|||
|
26276b0989
|
|||
|
a928fa54d4
|
@@ -6,7 +6,6 @@ This automation will be run on a daily basis, through a cron job + docker.
|
|||||||
@author: Gabriella 'contrastellar' Agathon
|
@author: Gabriella 'contrastellar' Agathon
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
|
||||||
import discord
|
import discord
|
||||||
import helper.db_helper
|
import helper.db_helper
|
||||||
|
|
||||||
|
|||||||
@@ -287,6 +287,24 @@ async def remove_callout(interaction: discord.Interaction, day: int, month: int,
|
|||||||
await interaction.response.send_message(f'{user_char_name} removed a callout for {callout_date}')
|
await interaction.response.send_message(f'{user_char_name} removed a callout for {callout_date}')
|
||||||
|
|
||||||
|
|
||||||
|
@client.tree.command()
|
||||||
|
async def remove_break(interaction: discord.Interaction, day: int, month: int, year: int) -> None:
|
||||||
|
delete_invalidate()
|
||||||
|
cleanup_invalidate()
|
||||||
|
user_id = interaction.user.id
|
||||||
|
user_char_name = DATABASE_CONN.return_char_name(user_id)
|
||||||
|
break_date: datetime.date = datetime.date(year=year, month=month, day=day)
|
||||||
|
|
||||||
|
try:
|
||||||
|
DATABASE_CONN.remove_break(user_id=user_id, break_date=break_date)
|
||||||
|
except psycopg2.Error:
|
||||||
|
await interaction.response.send_message(f'{user_char_name} -- no break was added for {break_date}')
|
||||||
|
else:
|
||||||
|
await interaction.response.send_message(f'{user_char_name} -- you removed the break starting on {break_date}')
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
@client.tree.command()
|
@client.tree.command()
|
||||||
async def schedule(interaction: discord.Interaction, days: int = DAYS_FOR_CALLOUTS) -> None:
|
async def schedule(interaction: discord.Interaction, days: int = DAYS_FOR_CALLOUTS) -> None:
|
||||||
delete_invalidate()
|
delete_invalidate()
|
||||||
@@ -297,6 +315,15 @@ async def schedule(interaction: discord.Interaction, days: int = DAYS_FOR_CALLOU
|
|||||||
await interaction.followup.send(f'Callouts for the next {days} days:\n{callouts}')
|
await interaction.followup.send(f'Callouts for the next {days} days:\n{callouts}')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@client.tree.command()
|
||||||
|
async def breaks(interaction: discord.Interaction, days: int = 365) -> None:
|
||||||
|
delete_invalidate()
|
||||||
|
cleanup_invalidate()
|
||||||
|
await interaction.response.defer(thinking=True)
|
||||||
|
await interaction.response.send_message(str(DATABASE_CONN.query_breaks()))
|
||||||
|
|
||||||
|
|
||||||
@client.tree.command()
|
@client.tree.command()
|
||||||
async def self_callouts(interaction: discord.Interaction, days: int = 365) -> None:
|
async def self_callouts(interaction: discord.Interaction, days: int = 365) -> None:
|
||||||
delete_invalidate()
|
delete_invalidate()
|
||||||
|
|||||||
@@ -58,4 +58,12 @@ class TestClass():
|
|||||||
formatted_callouts = self.DATABASE_CONN.format_list_of_callouts(callouts=callouts)
|
formatted_callouts = self.DATABASE_CONN.format_list_of_callouts(callouts=callouts)
|
||||||
assert formatted_callouts.__class__ is str
|
assert formatted_callouts.__class__ is str
|
||||||
|
|
||||||
# TODO write tests for the break addition/removal
|
def test_add_break(self) -> None:
|
||||||
|
today: datetime.date = datetime.date.today()
|
||||||
|
new_break = self.DATABASE_CONN.add_break(user_id=1, break_start=today, break_end=today)
|
||||||
|
assert new_break is None
|
||||||
|
|
||||||
|
def test_remove_break(self) -> None:
|
||||||
|
today: datetime.date = datetime.date.today()
|
||||||
|
remove_break = self.DATABASE_CONN.remove_break(user_id=1, start_date=today)
|
||||||
|
assert remove_break is None
|
||||||
|
|||||||
@@ -142,11 +142,12 @@ class DBHelper():
|
|||||||
self.__CONN = connect_config(self._config)
|
self.__CONN = connect_config(self._config)
|
||||||
self.__CONN.autocommit = True
|
self.__CONN.autocommit = True
|
||||||
cursor = self.__CONN.cursor()
|
cursor = self.__CONN.cursor()
|
||||||
is_range: int = 1
|
is_range: bool = True
|
||||||
if break_start == break_end:
|
if break_start == break_end:
|
||||||
is_range = 0
|
is_range = False
|
||||||
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))
|
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))
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def remove_callout(self, user_id: int, callout: datetime.date) -> None:
|
def remove_callout(self, user_id: int, callout: datetime.date) -> None:
|
||||||
@@ -166,6 +167,23 @@ class DBHelper():
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def remove_break(self, user_id: int, start_date: datetime.date) -> None:
|
||||||
|
"""Remove a callout based on user + date, which form the primary key in the db
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user_id (int): The Discord UUID of the user removing something from the db
|
||||||
|
callout (datetime.datetime): The date of the callout
|
||||||
|
"""
|
||||||
|
self.__CONN = connect_config(self._config)
|
||||||
|
self.__CONN.autocommit = True
|
||||||
|
cursor = self.__CONN.cursor()
|
||||||
|
|
||||||
|
cursor.execute("DELETE FROM breaks WHERE created_user = %s AND open_range = %s", (user_id, start_date))
|
||||||
|
self.__CONN.commit()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def formatted_list_of_callouts(self, callouts: list) -> str:
|
def formatted_list_of_callouts(self, callouts: list) -> str:
|
||||||
"""Format the python list of callouts.
|
"""Format the python list of callouts.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user