Added afk/brb

Timer messages ("Timer XX has yyy left") now get resumed after a bot restart
Alliance relay is discord compatible now. [Orgbot]
This commit is contained in:
2021-10-26 22:35:31 +02:00
parent bd8055dac7
commit 2d7ecf4883
14 changed files with 119 additions and 48 deletions
+11 -4
View File
@@ -2,7 +2,8 @@ import time
from core.chat_blob import ChatBlob
from core.command_param_types import Any, Const, Time, Options
from core.decorators import instance, command
from core.decorators import instance, command, event
from core.igncore import IgnCore
from core.registry import Registry
from modules.standard.news.worldboss_controller import WorldBossController
@@ -35,7 +36,7 @@ class TimerController:
self.alerts = [60 * 60, 60 * 15, 60 * 1]
def inject(self, registry):
self.bot = registry.get_instance("bot")
self.bot: IgnCore = registry.get_instance("bot")
self.db = registry.get_instance("db")
self.util = registry.get_instance("util")
self.job_scheduler = registry.get_instance("job_scheduler")
@@ -129,6 +130,12 @@ class TimerController:
else:
return f"Error! Insufficient access level to remove timer <highlight>{timer.name}</highlight>."
@event("connect", description="reload timers on restart")
def reload_timers(self, _, _1):
timers = self.db.query("SELECT * from timer")
for timer in timers:
self.timer_alert(time.time(), timer.name)
@command(command="rtimer",
params=[Const("add", is_optional=True),
TimerTime("start_time"),
@@ -195,7 +202,6 @@ class TimerController:
if timer.finished_at > t:
msg = f"Timer <highlight>{timer.name}</highlight> has " \
f"<highlight>{self.util.time_to_readable(timer.finished_at - t)}</highlight> left."
alert_duration = self.get_next_alert(timer.finished_at - t)
job_id = self.job_scheduler.scheduled_job(self.timer_alert, t + alert_duration, timer.name)
@@ -213,7 +219,8 @@ class TimerController:
new_t += timer.repeating_every
self.add_timer(timer.name, timer.char_id, timer.channel, new_t, timer.repeating_every,
timer.repeating_every)
if not self.bot.is_ready():
return
if timer.channel == "org":
self.bot.send_org_message(msg)
elif timer.channel == "priv":