From 99ab9fc1b484bd6f0c18f185b48238a65a3c474a Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 11 Nov 2020 09:44:49 -0500 Subject: [PATCH 1/3] [HOTFIX] Fix not applying the similarity threshold --- chatter/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatter/chat.py b/chatter/chat.py index 4e3400c..41affb6 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -272,7 +272,7 @@ class Chatter(Cog): ) return else: - self.similarity_algo = threshold + self.similarity_threshold = threshold self.similarity_algo = algos[algo_number] async with ctx.typing(): From 2ea077bb0cec5a9fe338e49f89377559d74d72cd Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 11 Nov 2020 10:38:54 -0500 Subject: [PATCH 2/3] Add relative trigger, better error handling --- fifo/fifo.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/fifo/fifo.py b/fifo/fifo.py index c6479b4..9bfe2e1 100644 --- a/fifo/fifo.py +++ b/fifo/fifo.py @@ -152,10 +152,16 @@ class FIFO(commands.Cog): return job async def _pause_job(self, task: Task): - return self.scheduler.pause_job(job_id=_assemble_job_id(task.name, task.guild_id)) + try: + return self.scheduler.pause_job(job_id=_assemble_job_id(task.name, task.guild_id)) + except JobLookupError: + return False async def _remove_job(self, task: Task): - return self.scheduler.remove_job(job_id=_assemble_job_id(task.name, task.guild_id)) + try: + self.scheduler.remove_job(job_id=_assemble_job_id(task.name, task.guild_id)) + except JobLookupError: + pass async def _get_tz(self, user: Union[discord.User, discord.Member]) -> Union[None, tzinfo]: if self.tz_cog is None: @@ -483,6 +489,40 @@ class FIFO(commands.Cog): f"Next run time: {job.next_run_time} ({delta_from_now.total_seconds()} seconds)" ) + @fifo_trigger.command(name="relative") + async def fifo_trigger_relative( + self, ctx: commands.Context, task_name: str, *, time_from_now: TimedeltaConverter + ): + """ + Add a "run once" trigger at a time relative from now to the specified task + """ + + task = Task(task_name, ctx.guild.id, self.config) + await task.load_from_config() + + if task.data is None: + await ctx.maybe_send_embed( + f"Task by the name of {task_name} is not found in this guild" + ) + return + + time_to_run = datetime.now() + time_from_now + + result = await task.add_trigger("date", time_to_run, time_to_run.tzinfo) + if not result: + await ctx.maybe_send_embed( + "Failed to add a date trigger to this task, see console for logs" + ) + return + + await task.save_data() + job: Job = await self._process_task(task) + delta_from_now: timedelta = job.next_run_time - datetime.now(job.next_run_time.tzinfo) + await ctx.maybe_send_embed( + f"Task `{task_name}` added {time_to_run} to its scheduled runtimes\n" + f"Next run time: {job.next_run_time} ({delta_from_now.total_seconds()} seconds)" + ) + @fifo_trigger.command(name="date") async def fifo_trigger_date( self, ctx: commands.Context, task_name: str, *, datetime_str: DatetimeConverter From 40b01cff262e49aac82d5421bce6ea03e4845dc2 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 11 Nov 2020 10:40:49 -0500 Subject: [PATCH 3/3] Black formatting --- fifo/fifo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fifo/fifo.py b/fifo/fifo.py index 9bfe2e1..f060211 100644 --- a/fifo/fifo.py +++ b/fifo/fifo.py @@ -491,7 +491,7 @@ class FIFO(commands.Cog): @fifo_trigger.command(name="relative") async def fifo_trigger_relative( - self, ctx: commands.Context, task_name: str, *, time_from_now: TimedeltaConverter + self, ctx: commands.Context, task_name: str, *, time_from_now: TimedeltaConverter ): """ Add a "run once" trigger at a time relative from now to the specified task