diff --git a/config_sample/command_aliases.yaml b/config_sample/command_aliases.yaml index cf06f3c0..8d0256db 100644 --- a/config_sample/command_aliases.yaml +++ b/config_sample/command_aliases.yaml @@ -45,6 +45,7 @@ evimod: evidence_mod eviswap: evidence_swap force_follow: follow_me force_pos: forcepos +timer_format: format_timer fp: firstperson fps: firstperson ga: getarea @@ -111,4 +112,4 @@ get_link: getlink get_links: getlinks remove_musiclist: musiclist_remove add_musiclist: musiclist_add -save_musiclist: musiclist_save \ No newline at end of file +save_musiclist: musiclist_save diff --git a/docs/commands.md b/docs/commands.md index 68b7c495..65e459c4 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -518,6 +518,15 @@ - `start` starts the previously set timer, so `/timer 0 start`. - `pause` OR `stop` pauses the timer that's currently running, so `/timer 0 pause`. - `unset` OR `hide` hides the timer for it to no longer show up, so `/timer 0 hide`. +* **format_timer** ` ` + - Format the timer in the current area or hub. + - Example of format: `Time Left: hh:mm` + - Default format: `hh:mm:ss.zzz` + - For more information on how to implement your format, [go here!](https://doc.qt.io/qt-6/qtime.html#toString) +* **timer_interval** ` ` + - Set timer interval in the current area or hub. + - Example: `/timer_interval 1 15m` + - Default interval: `/timer_interval 1 16ms` ## Musiclists * **musiclist\_add** `` `` `` `[Length]` `[Path]` - Allow you to add a song in a loaded musiclist! diff --git a/server/area.py b/server/area.py index ab6e4c8e..a1513c39 100644 --- a/server/area.py +++ b/server/area.py @@ -42,6 +42,8 @@ def __init__( self.caller = caller self.schedule = None self.commands = [] + self.format = "hh:mm:ss.zzz" + self.interval = 16 def timer_expired(self): if self.schedule: diff --git a/server/area_manager.py b/server/area_manager.py index b3f9b1f5..903cc023 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -34,6 +34,8 @@ def __init__( self.caller = caller self.schedule = None self.commands = [] + self.format = "hh:mm:ss.zzz" + self.interval = 16 def timer_expired(self): if self.schedule: diff --git a/server/client_manager.py b/server/client_manager.py index c8cfc1a2..20ff0ea7 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -3,6 +3,7 @@ import time import math import os +import arrow from heapq import heappop, heappush @@ -300,6 +301,23 @@ def send_timer_set_time(self, timer_id=None, new_time=None, start=False): else: self.send_command("TI", timer_id, 2, new_time) # Show timer self.send_command("TI", timer_id, int(not start), new_time) # Set timer with value and start + if timer_id == 0: + timer = self.area.area_manager.timer + else: + timer = self.area.timers[timer_id-1] + self.send_command("TF", timer_id, timer.format, new_time) + self.send_command("TIN", timer_id, timer.interval) + + def send_timer_set_interval(self, timer_id, timer): + if timer.started: + current_time = timer.target - arrow.get() + current_time = int(current_time.total_seconds()) * 1000 + else: + current_time = int(timer.static.total_seconds()) * 1000 + if timer_id == 0: + self.area.area_manager.send_timer_set_time(timer_id, current_time, timer.started) + else: + self.area.send_timer_set_time(timer_id, current_time, timer.started) def send_timer_set_step_length(self, timer_id=None, new_step_length=None): if self.software == "DRO": diff --git a/server/commands/roleplay.py b/server/commands/roleplay.py index ae9dbcca..b1035730 100644 --- a/server/commands/roleplay.py +++ b/server/commands/roleplay.py @@ -35,6 +35,8 @@ "ooc_cmd_timer", "ooc_cmd_demo", "ooc_cmd_trigger", + "ooc_cmd_format_timer", + "ooc_cmd_timer_interval", ] @@ -944,3 +946,83 @@ def ooc_cmd_trigger(client, arg): val = args[1] client.area.triggers[trig] = val client.send_ooc(f'Changed to Call "{val}" on trigger "{trig}"') + + +def ooc_cmd_format_timer(client, arg): + """ + Format the timer + Usage: /format_timer + """ + args = shlex.split(arg) + try: + args[0] = int(args[0]) + except: + raise ArgumentError("Timer ID should be an integer") + if args[0] == 0: + if client.is_mod or client in client.area.area_manager.owners: + timer = client.area.area_manager.timer + else: + client.send_ooc("You cannot change timer 0 format if you are not GM") + return + else: + if ( + client.is_mod + or client in client.area.area_manager.owners + or client in client.area.owners + ): + timer = client.area.timers[args[0] - 1] + else: + client.send_ooc("You cannot change timer format if you are at least CM") + return + timer.format = args[1:] + if timer.set: + if timer.started: + current_time = timer.target - arrow.get() + current_time = int(current_time.total_seconds()) * 1000 + else: + current_time = int(timer.static.total_seconds()) * 1000 + if args[0] == 0: + client.area.area_manager.send_timer_set_time(args[0], current_time, timer.started) + else: + client.area.send_timer_set_time(args[0], current_time, timer.started) + client.send_ooc(f"Timer {args[0]} format: '{args[1]}'") + + +def ooc_cmd_timer_interval(client, arg): + """ + Set timer interval + If timer interval is not written than will show default timer interval (16ms) + Example: /timer_interval 1 15m + Usage: /timer_interval + """ + args = shlex.split(arg) + try: + args[0] = int(args[0]) + except: + raise ArgumentError("Timer ID should be an integer") + if args[0] == 0: + if client.is_mod or client in client.area.area_manager.owners: + timer = client.area.area_manager.timer + else: + client.send_ooc("You cannot change timer 0 interval if you are not GM") + return + else: + if ( + client.is_mod + or client in client.area.area_manager.owners + or client in client.area.owners + ): + timer = client.area.timers[args[0] - 1] + else: + client.send_ooc("You cannot change timer interval if you are at least CM") + return + try: + if len(args) == 1: + timer.interval = 16 + else: + timer.interval = pytimeparse.parse(args[1]) * 1000 + except: + raise ArgumentError("Interval value not valid!") + if timer.set: + client.send_timer_set_interval(args[0], timer) + client.send_ooc(f"Timer {args[0]} interval is set to '{args[1]}'")