diff --git a/README.md b/README.md index d8399cc..3a9ab8f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Cog Function | conquest | **Alpha** |
Manage maps for war games and RPGsLots of additional features are planned, currently function with simple map
| | dad | **Beta** |
Tell dad jokesWorks great!
| | exclusiverole | **Alpha** |
Prevent certain roles from getting any other rolesFully functional, but pretty simple
| +| fifo | **Alpha** |
Schedule commands to be run at certain times or intervalsJust released, please report bugs as you find them. Only works for bot owner for now
| | fight | **Incomplete** |
Organize bracket tournaments within discordStill in-progress, a massive project
| | flag | **Alpha** |
Create temporary marks on users that expire after specified timePorted, will not import old data. Please report bugs
| | forcemention | **Alpha** |
Mentions unmentionable rolesVery simple cog, mention doesn't persist
| diff --git a/fifo/fifo.py b/fifo/fifo.py index d4156ea..9e0580e 100644 --- a/fifo/fifo.py +++ b/fifo/fifo.py @@ -81,7 +81,7 @@ class FIFO(commands.Cog): await self.jobstore.load_from_config(self.scheduler, "default") self.scheduler.add_jobstore(self.jobstore, "default") - self.scheduler.start() # TODO: Jobs are not receiving next_run_times + self.scheduler.start() async def _check_parsable_command(self, ctx: commands.Context, command_to_parse: str): message: discord.Message = ctx.message diff --git a/fifo/info.json b/fifo/info.json index 6cc6f9d..c8c2ed9 100644 --- a/fifo/info.json +++ b/fifo/info.json @@ -3,19 +3,26 @@ "Bobloy" ], "min_bot_version": "3.3.0", - "description": "Schedule commands to be run by certain at certain times or intervals", + "description": "[ALPHA] Schedule commands to be run at certain times or intervals", "hidden": false, "install_msg": "Thank you for installing FIFO.\nGet started with `[p]load fifo`, then `[p]help FIFO`", - "short": "Schedule commands to be run by certain at certain times or intervals\"", + "short": "[ALPHA] Schedule commands to be run at certain times or intervals\"", "end_user_data_statement": "This cog does not store any End User Data", "requirements": [ - "apscheduler" + "apscheduler", + "dateutil" ], "tags": [ "bobloy", "utilities", - "tools", "tool", - "roles" + "roles", + "schedule", + "cron", + "interval", + "date", + "datetime", + "time", + "calendar" ] } \ No newline at end of file diff --git a/fifo/redconfigjobstore.py b/fifo/redconfigjobstore.py index 3747a97..aa6d967 100644 --- a/fifo/redconfigjobstore.py +++ b/fifo/redconfigjobstore.py @@ -30,8 +30,8 @@ class RedConfigJobStore(MemoryJobStore): self.bot = bot self.pickle_protocol = pickle.HIGHEST_PROTOCOL self._eventloop = self.bot.loop - # TODO: self.config.jobs_index is never read from, - # either remove or replace self._jobs_index + # TODO: self.config.jobs_index is never used, + # fine but maybe a sign of inefficient use of config # task = asyncio.create_task(self.load_from_config()) # while not task.done(): @@ -114,7 +114,7 @@ class RedConfigJobStore(MemoryJobStore): job_tuple = tuple([encoded_job, timestamp]) async with self.config.jobs() as jobs: jobs.insert(index, job_tuple) - await self.config.jobs_index.set_raw(job.id, value=job_tuple) + # await self.config.jobs_index.set_raw(job.id, value=job_tuple) return True @run_in_event_loop @@ -149,7 +149,7 @@ class RedConfigJobStore(MemoryJobStore): del jobs[old_index] jobs.insert(new_index, (encoded_job, new_timestamp)) self._jobs_index[old_job.id] = (job, new_timestamp) - await self.config.jobs_index.set_raw(old_job.id, value=(encoded_job, new_timestamp)) + # await self.config.jobs_index.set_raw(old_job.id, value=(encoded_job, new_timestamp)) log.debug(f"Async Updated {job.id=}") log.debug(f"Check job args: {job.args=}") @@ -168,7 +168,7 @@ class RedConfigJobStore(MemoryJobStore): async def _async_remove_job(self, index, job): async with self.config.jobs() as jobs: del jobs[index] - await self.config.jobs_index.clear_raw(job.id) + # await self.config.jobs_index.clear_raw(job.id) @run_in_event_loop def remove_all_jobs(self): @@ -177,108 +177,8 @@ class RedConfigJobStore(MemoryJobStore): async def _async_remove_all_jobs(self): await self.config.jobs.clear() - await self.config.jobs_index.clear() + # await self.config.jobs_index.clear() def shutdown(self): """Removes all jobs without clearing config""" super().remove_all_jobs() - - -# import asyncio -# -# from apscheduler.jobstores.base import BaseJobStore, ConflictingIdError -# from apscheduler.util import datetime_to_utc_timestamp -# from redbot.core import Config -# from redbot.core.utils import AsyncIter -# -# -# class RedConfigJobStore(BaseJobStore): -# def __init__(self, config: Config, loop): -# super().__init__() -# self.config = config -# self.loop: asyncio.BaseEventLoop = loop -# -# self._jobs = [] -# self._jobs_index = {} # id -> (job, timestamp) lookup table -# -# def lookup_job(self, job_id): -# return asyncio.run(self._async_lookup_job(job_id)) -# -# async def _async_lookup_job(self, job_id): -# return (await self.config.jobs_index.get_raw(job_id, default=(None, None)))[0] -# -# def get_due_jobs(self, now): -# return asyncio.run(self._async_get_due_jobs(now)) -# -# async def _async_get_due_jobs(self, now): -# now_timestamp = datetime_to_utc_timestamp(now) -# pending = [] -# all_jobs = await self.config.jobs() -# async for job, timestamp in AsyncIter(all_jobs, steps=100): -# if timestamp is None or timestamp > now_timestamp: -# break -# pending.append(job) -# -# return pending -# -# def get_next_run_time(self): -# return asyncio.run(self._async_get_next_run_time()) -# -# async def _async_get_next_run_time(self): -# _jobs = await self.config.jobs() -# return _jobs[0][0].next_run_time if _jobs else None -# -# def get_all_jobs(self): -# return asyncio.run(self._async_get_all_jobs()) -# -# async def _async_get_all_jobs(self): -# return [j[0] for j in (await self.config.jobs())] -# -# def add_job(self, job): -# return asyncio.run(self._async_add_job(job)) -# -# async def _async_add_job(self, job): -# if await self.config.jobs_index.get_raw(job.id, default=None) is not None: -# raise ConflictingIdError(job.id) -# -# timestamp = datetime_to_utc_timestamp(job.next_run_time) -# index = self._get_job_index(timestamp, job.id) -# self._jobs.insert(index, (job, timestamp)) -# self._jobs_index[job.id] = (job, timestamp) -# -# def update_job(self, job): -# pass -# -# def remove_job(self, job_id): -# pass -# -# def remove_all_jobs(self): -# pass -# -# def _get_job_index(self, timestamp, job_id): -# """ -# Returns the index of the given job, or if it's not found, the index where the job should be -# inserted based on the given timestamp. -# -# :type timestamp: int -# :type job_id: str -# -# """ -# lo, hi = 0, len(self._jobs) -# timestamp = float('inf') if timestamp is None else timestamp -# while lo < hi: -# mid = (lo + hi) // 2 -# mid_job, mid_timestamp = self._jobs[mid] -# mid_timestamp = float('inf') if mid_timestamp is None else mid_timestamp -# if mid_timestamp > timestamp: -# hi = mid -# elif mid_timestamp < timestamp: -# lo = mid + 1 -# elif mid_job.id > job_id: -# hi = mid -# elif mid_job.id < job_id: -# lo = mid + 1 -# else: -# return mid -# -# return lo diff --git a/fifo/task.py b/fifo/task.py index 9ed4e12..5d16ec9 100644 --- a/fifo/task.py +++ b/fifo/task.py @@ -116,7 +116,7 @@ class Task: # ) continue - if t["type"] == "cron": # TODO: Implement this, should be easy + if t["type"] == "cron": triggers.append(t) # already a string, nothing to do continue