More WIP fake message
This commit is contained in:
parent
636b3ee975
commit
68690473c0
@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
|||||||
else:
|
else:
|
||||||
class DatetimeConverter(Converter):
|
class DatetimeConverter(Converter):
|
||||||
async def convert(self, ctx, argument) -> datetime:
|
async def convert(self, ctx, argument) -> datetime:
|
||||||
dt = parser.parse(argument)
|
dt = parser.parse(argument, fuzzy=True)
|
||||||
if dt is not None:
|
if dt is not None:
|
||||||
return dt
|
return dt
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
27
fifo/fifo.py
27
fifo/fifo.py
@ -57,16 +57,14 @@ def parse_triggers(data: Union[Dict, None]):
|
|||||||
return get_trigger(data["triggers"][0])
|
return get_trigger(data["triggers"][0])
|
||||||
|
|
||||||
|
|
||||||
# class FakeMessage(discord.Message):
|
class FakeMessage2(discord.Message):
|
||||||
# def __init__(self, *, state, channel, data):
|
__slots__ = ("__dict__",)
|
||||||
# super().__init__(state=state, channel=channel, data=data)
|
|
||||||
#
|
|
||||||
# _state = None
|
|
||||||
|
|
||||||
|
|
||||||
class FakeMessage:
|
class FakeMessage:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, message: discord.Message):
|
||||||
self.__dict__.update(kwargs)
|
d = {k: getattr(message, k) for k in dir(message)}
|
||||||
|
self.__dict__.update(**d)
|
||||||
|
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
@ -114,6 +112,7 @@ class Task:
|
|||||||
"hour": dt.hour,
|
"hour": dt.hour,
|
||||||
"minute": dt.minute,
|
"minute": dt.minute,
|
||||||
"second": dt.second,
|
"second": dt.second,
|
||||||
|
"tzinfo": dt.tzinfo
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -225,7 +224,8 @@ class Task:
|
|||||||
log.warning("No message found in channel cache yet, skipping execution")
|
log.warning("No message found in channel cache yet, skipping execution")
|
||||||
return
|
return
|
||||||
|
|
||||||
message = FakeMessage(**actual_message.__dict__)
|
message = FakeMessage(actual_message)
|
||||||
|
# message = FakeMessage2
|
||||||
message.author = author
|
message.author = author
|
||||||
message.id = None
|
message.id = None
|
||||||
message.add_reaction = _do_nothing
|
message.add_reaction = _do_nothing
|
||||||
@ -451,7 +451,7 @@ class FIFO(commands.Cog):
|
|||||||
|
|
||||||
@fifo_trigger.command(name="interval")
|
@fifo_trigger.command(name="interval")
|
||||||
async def fifo_trigger_interval(
|
async def fifo_trigger_interval(
|
||||||
self, ctx: commands.Context, task_name: str, interval_str: TimedeltaConverter
|
self, ctx: commands.Context, task_name: str, *, interval_str: TimedeltaConverter
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Add an interval trigger to the specified task
|
Add an interval trigger to the specified task
|
||||||
@ -478,7 +478,7 @@ class FIFO(commands.Cog):
|
|||||||
|
|
||||||
@fifo_trigger.command(name="date")
|
@fifo_trigger.command(name="date")
|
||||||
async def fifo_trigger_date(
|
async def fifo_trigger_date(
|
||||||
self, ctx: commands.Context, task_name: str, datetime_str: DatetimeConverter
|
self, ctx: commands.Context, task_name: str, *, datetime_str: DatetimeConverter
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Add a "run once" datetime trigger to the specified task
|
Add a "run once" datetime trigger to the specified task
|
||||||
@ -501,8 +501,11 @@ class FIFO(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await task.save_data()
|
await task.save_data()
|
||||||
await self._process_task(task)
|
job: Job = await self._process_task(task)
|
||||||
await ctx.tick()
|
await ctx.maybe_send_embed(
|
||||||
|
f"Task `{task_name}` added {datetime_str} to its scheduled runtimes\n"
|
||||||
|
f"Next run time: {job.next_run_time}"
|
||||||
|
)
|
||||||
|
|
||||||
@fifo_trigger.command(name="cron")
|
@fifo_trigger.command(name="cron")
|
||||||
async def fifo_trigger_cron(
|
async def fifo_trigger_cron(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user