Fix for long-running !whatbuffs commands
fixes for !wb
This commit is contained in:
@@ -3,14 +3,14 @@ from typing import Union
|
||||
|
||||
from core.chat_blob import ChatBlob
|
||||
from core.command_alias_service import CommandAliasService
|
||||
from core.command_param_types import Any, Const
|
||||
from core.command_param_types import Any
|
||||
from core.decorators import instance, command, event
|
||||
from core.igncore import IgnCore
|
||||
from core.job_scheduler import JobScheduler
|
||||
from core.logger import Logger
|
||||
from core.message_hub_service import MessageHubService
|
||||
from core.setting_service import SettingService
|
||||
from core.setting_types import BooleanSettingType, TextSettingType
|
||||
from core.setting_types import BooleanSettingType
|
||||
from core.text import Text
|
||||
from core.util import Util
|
||||
from modules.standard.datanet.ws_controller import WebsocketRelayController
|
||||
@@ -32,6 +32,7 @@ class TimerObj:
|
||||
def update(self, obj):
|
||||
self.spawn = obj.spawn
|
||||
self.time = obj.time
|
||||
self.mortal = obj.mortal
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} " \
|
||||
@@ -67,7 +68,7 @@ class TimerObj:
|
||||
return 6 * 60 * 60
|
||||
# elif self.name in ["Abmouth Indomitus"]:
|
||||
# return 0
|
||||
# No respawn timer?
|
||||
# No/unknown respawn timer?
|
||||
return 0
|
||||
|
||||
|
||||
@@ -99,10 +100,10 @@ class WorldBossController:
|
||||
self.command_alias_service.add_alias("loren", "wb loren")
|
||||
self.command_alias_service.add_alias("reaper", "wb reaper")
|
||||
|
||||
def spam_timer(self, time, mob, msg, next=None):
|
||||
def spam_timer(self, _, mob, msg, _next=None):
|
||||
self.send_warn(msg)
|
||||
self.jobs.pop(mob.name, 0)
|
||||
if next == "spawn":
|
||||
if _next == "spawn":
|
||||
if mob.get_respawn_timer() != 0:
|
||||
i = self.job_scheduler.scheduled_job(self.spam_timer, mob.time + mob.get_respawn_timer(), mob=mob.name,
|
||||
msg=f"<highlight>{mob.name}</highlight> should spawn soon.")
|
||||
@@ -110,7 +111,6 @@ class WorldBossController:
|
||||
|
||||
@event(WebsocketRelayController.WS_RELAY, "save most current local_timers")
|
||||
def get_timer(self, _, data):
|
||||
# print(data)
|
||||
if data.type != "timer":
|
||||
return
|
||||
for x in data.payload:
|
||||
@@ -129,7 +129,7 @@ class WorldBossController:
|
||||
if job:
|
||||
self.job_scheduler.cancel_job(job)
|
||||
self.send_warn(f"<highlight>{x.name}</highlight> has spawned.")
|
||||
i = self.job_scheduler.scheduled_job(self.spam_timer, x.time-1, mob=x, msg=f"<highlight>{x.name}</highlight> is now mortal.", next="spawn")
|
||||
i = self.job_scheduler.scheduled_job(self.spam_timer, x.time-1, mob=x, msg=f"<highlight>{x.name}</highlight> is now mortal.", _next="spawn")
|
||||
self.jobs[x.name] = i
|
||||
elif x.alive_mortal(True):
|
||||
x.spam = x.getTime()
|
||||
@@ -141,6 +141,9 @@ class WorldBossController:
|
||||
i = self.job_scheduler.scheduled_job(self.spam_timer, x.time+x.get_respawn_timer(), mob=x, msg=f"<highlight>{x.name}</highlight> should spawn soon.")
|
||||
self.jobs[x.name] = i
|
||||
elif (x.time + 60) < x.getTime() < (x.time + x.get_respawn_timer()):
|
||||
job = self.jobs.pop(x.name, None)
|
||||
if job:
|
||||
self.job_scheduler.cancel_job(job)
|
||||
i = self.job_scheduler.scheduled_job(self.spam_timer, x.time + x.get_respawn_timer(), mob=x,
|
||||
msg=f"<highlight>{x.name}</highlight> should spawn soon.")
|
||||
self.jobs[x.name] = i
|
||||
@@ -162,20 +165,14 @@ class WorldBossController:
|
||||
return x.name
|
||||
|
||||
return None
|
||||
# if name in ["tara", "tarasque"]:
|
||||
# return "Tarasque"
|
||||
# elif name in ["lw", "loren", "warr", "loren warr"]:
|
||||
# return "Loren Warr"
|
||||
# elif name in ["thr", "reaper", "hollow reaper", "the hollow reaper"]:
|
||||
# return "The Hollow Reaper"
|
||||
|
||||
@command(command="wb", params=[Any("worldboss", is_optional=True)],
|
||||
description="Displays the next worldboss spawns", access_level="member")
|
||||
def show_worldboss(self, request, boss: str):
|
||||
def show_worldboss(self, _, boss: str):
|
||||
if boss:
|
||||
boss = self.getWorldbossName(boss)
|
||||
if boss:
|
||||
return self.getWBTimer(boss)
|
||||
return self.getWBTimer(boss) or f"Could not find any data for the Worldboss <highlight>{boss}</highlight>."
|
||||
return ChatBlob("Next Worldboss spawns", "<red></red>"+self.getWBTimer())
|
||||
|
||||
def getWBTimer(self, name=None) -> Union[TimerObj, list[TimerObj]]:
|
||||
@@ -195,6 +192,21 @@ class WorldBossController:
|
||||
else:
|
||||
rt = x.get_respawn_timer()
|
||||
if rt != 0:
|
||||
if (x.time + rt) < x.getTime() < (x.time + 2 * rt):
|
||||
if (x.time + rt) < x.getTime() < (x.time + 1.5*rt):
|
||||
return f" <highlight>{x.name}</highlight> :: should have spawned {self.util.format_time(abs(x.getTime() - (x.time + rt)))} ago"
|
||||
return f" <highlight>{x.name}</highlight> :: spawn in {self.util.format_time(x.time + rt - x.getTime())}"
|
||||
|
||||
if x.time < x.getTime() < (x.time + 5 * rt):
|
||||
skips = 0
|
||||
time = x.time
|
||||
while time < x.getTime():
|
||||
time += x.get_respawn_timer()
|
||||
skips += 1
|
||||
if (x.time + rt) < x.getTime():
|
||||
if skips >= 5:
|
||||
return ""
|
||||
return f" <highlight>{x.name}</highlight> :: spawn in {self.util.format_time(x.time + rt * skips - x.getTime())} [Skipped: {skips - 1}]"
|
||||
return f" <highlight>{x.name}</highlight> :: spawn in {self.util.format_time(x.time + rt - x.getTime())}"
|
||||
return ""
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user