Fifo release ready
This commit is contained in:
parent
607b7b6718
commit
4f494d115d
@ -12,6 +12,7 @@ Cog Function
|
||||
| conquest | **Alpha** | <details><summary>Manage maps for war games and RPGs</summary>Lots of additional features are planned, currently function with simple map</details> |
|
||||
| dad | **Beta** | <details><summary>Tell dad jokes</summary>Works great!</details> |
|
||||
| exclusiverole | **Alpha** | <details><summary>Prevent certain roles from getting any other roles</summary>Fully functional, but pretty simple</details> |
|
||||
| fifo | **Alpha** | <details><summary>Schedule commands to be run at certain times or intervals</summary>Just released, please report bugs as you find them. Only works for bot owner for now</details> |
|
||||
| fight | **Incomplete** | <details><summary>Organize bracket tournaments within discord</summary>Still in-progress, a massive project</details> |
|
||||
| flag | **Alpha** | <details><summary>Create temporary marks on users that expire after specified time</summary>Ported, will not import old data. Please report bugs</details> |
|
||||
| forcemention | **Alpha** | <details><summary>Mentions unmentionable roles</summary>Very simple cog, mention doesn't persist</details> |
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user