add /countdown and !options

This commit is contained in:
Fabian Dill 2020-07-05 21:45:52 +02:00
parent 252f9600fe
commit 12273c396b
2 changed files with 27 additions and 25 deletions

View File

@ -620,9 +620,33 @@ class CommandProcessor(metaclass=CommandMeta):
self.output(str(exception)) self.output(str(exception))
class CommonCommandProcessor(CommandProcessor):
ctx: Context
simple_options = {"hint_cost": int,
"location_check_points": int,
"password": str,
"forfeit_mode": str,
"item_cheat": bool,
"auto_save_interval": int}
def _cmd_countdown(self, seconds: str = "10") -> bool:
"""Start a countdown in seconds"""
try:
timer = int(seconds, 10)
except ValueError:
timer = 10
asyncio.create_task(countdown(self.ctx, timer))
return True
def _cmd_options(self):
"""List all current options. Warning: lists password."""
self.output("Current options:")
for option in self.simple_options:
self.output(f"Option {option} is set to {getattr(self.ctx, option)}")
class ClientMessageProcessor(CommandProcessor): class ClientMessageProcessor(CommandProcessor):
marker = "!" marker = "!"
ctx: Context
def __init__(self, ctx: Context, client: Client): def __init__(self, ctx: Context, client: Client):
self.ctx = ctx self.ctx = ctx
@ -695,14 +719,6 @@ class ClientMessageProcessor(CommandProcessor):
"Your client is too old to send game beaten information. Please update, load you savegame and reconnect.") "Your client is too old to send game beaten information. Please update, load you savegame and reconnect.")
return False return False
def _cmd_countdown(self, seconds: str = "10") -> bool:
"""Start a countdown in seconds"""
try:
timer = int(seconds, 10)
except ValueError:
timer = 10
asyncio.create_task(countdown(self.ctx, timer))
return True
def _cmd_missing(self) -> bool: def _cmd_missing(self) -> bool:
"""List all missing location checks from the server's perspective""" """List all missing location checks from the server's perspective"""
@ -959,15 +975,7 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args):
client.messageprocessor(args) client.messageprocessor(args)
class ServerCommandProcessor(CommandProcessor): class ServerCommandProcessor(CommonCommandProcessor):
ctx: Context
simple_options = {"hint_cost": int,
"location_check_points": int,
"password": str,
"forfeit_mode": str,
"item_cheat": bool,
"auto_save_interval": int}
def __init__(self, ctx: Context): def __init__(self, ctx: Context):
self.ctx = ctx self.ctx = ctx
super(ServerCommandProcessor, self).__init__() super(ServerCommandProcessor, self).__init__()
@ -1115,12 +1123,6 @@ class ServerCommandProcessor(CommandProcessor):
f"{', '.join(known)}") f"{', '.join(known)}")
return False return False
def _cmd_options(self):
"""List all current options. Warning: lists password."""
self.output("Current options:")
for option in self.simple_options:
self.output(f"Option {option} is set to {getattr(self.ctx, option)}")
async def console(ctx: Context): async def console(ctx: Context):
session = prompt_toolkit.PromptSession() session = prompt_toolkit.PromptSession()
while ctx.running: while ctx.running:

View File

@ -6,7 +6,7 @@ def tuplize_version(version: str) -> typing.Tuple[int, ...]:
return tuple(int(piece, 10) for piece in version.split(".")) return tuple(int(piece, 10) for piece in version.split("."))
__version__ = "2.3.3" __version__ = "2.3.4"
_version_tuple = tuplize_version(__version__) _version_tuple = tuplize_version(__version__)
import os import os