Skip to content

Commit 45bd991

Browse files
committed
ENHANCEMENTS:
- /server restart now has a delay option
1 parent 8019d43 commit 45bd991

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

plugins/scheduler/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,22 @@ The following environment variables can be used in the "run" command:
128128
129129
## Discord Commands
130130
131-
| Command | Parameter | Channel | Role | Description |
132-
|------------------------|------------------------------------------|---------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
133-
| /scheduler maintenance | | admin-channel | DCS Admin | Sets the servers maintenance mode. |
134-
| /scheduler clear | | admin-channel | DCS Admin | Clears the maintenance state of a server. |
135-
| /server cleanup | | admin-channel | DCS Admin | Delete the temporary directories of a shutdown server. |
136-
| /server config | | admin-channel | DCS Admin | Changes the configuration of a server, like name, password, max players. |
137-
| /server list | | all | DCS | Lists all available servers. |
138-
| /server migrate | instance | admin-channel | DCS Admin | WIP: Migrate a server to another instance (maybe even node). |
139-
| /server password | | admin-channel | DCS Admin | Sets a new server or [coalition](../../COALITIONS.md) password. |
140-
| /server rename | | admin-channel | DCS Admin | Rename the respective DCS server. Handle with care! |
141-
| /server restart | [force] [run_extensions] [mission] | admin-channel | DCS Admin | Restarts a running DCS server and optionally launches another mission. |
142-
| /server shutdown | [force] [maintenance] | admin-channel | DCS Admin | Shuts the dedicated DCS server process down.<br/>If force is used, no player check will be executed and no onShutdown command will be run. Optional: don't set maintenance flag. |
143-
| /server start | | admin-channel | DCS Admin | Starts a stopped DCS server. |
144-
| /server startup | [maintenance] [mission] [run_extensions] | admin-channel | DCS Admin | Starts a dedicated DCS server process and optionally launches a specified mission (default is last one). Optional: don't set maintenance flag, don't run extensions. |
145-
| /server stop | | admin-channel | DCS Admin | Stops a DCS server. |
146-
| /server timeleft | server | all | DCS | Shows the time until the next scheduled restart. |
131+
| Command | Parameter | Channel | Role | Description |
132+
|------------------------|--------------------------------------------|---------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
133+
| /scheduler maintenance | | admin-channel | DCS Admin | Sets the servers maintenance mode. |
134+
| /scheduler clear | | admin-channel | DCS Admin | Clears the maintenance state of a server. |
135+
| /server cleanup | | admin-channel | DCS Admin | Delete the temporary directories of a shutdown server. |
136+
| /server config | | admin-channel | DCS Admin | Changes the configuration of a server, like name, password, max players. |
137+
| /server list | | all | DCS | Lists all available servers. |
138+
| /server migrate | instance | admin-channel | DCS Admin | WIP: Migrate a server to another instance (maybe even node). |
139+
| /server password | | admin-channel | DCS Admin | Sets a new server or [coalition](../../COALITIONS.md) password. |
140+
| /server rename | | admin-channel | DCS Admin | Rename the respective DCS server. Handle with care! |
141+
| /server restart | [delay] [force] [run_extensions] [mission] | admin-channel | DCS Admin | Restarts a running DCS server and optionally launches another mission. |
142+
| /server shutdown | [force] [maintenance] | admin-channel | DCS Admin | Shuts the dedicated DCS server process down.<br/>If force is used, no player check will be executed and no onShutdown command will be run. Optional: don't set maintenance flag. |
143+
| /server start | | admin-channel | DCS Admin | Starts a stopped DCS server. |
144+
| /server startup | [maintenance] [mission] [run_extensions] | admin-channel | DCS Admin | Starts a dedicated DCS server process and optionally launches a specified mission (default is last one). Optional: don't set maintenance flag, don't run extensions. |
145+
| /server stop | | admin-channel | DCS Admin | Stops a DCS server. |
146+
| /server timeleft | server | all | DCS | Shows the time until the next scheduled restart. |
147147
148148
> [!IMPORTANT]
149149
> If a server gets started or stopped manually (using `/server startup` or `/server shutdown`), it will be put into

plugins/scheduler/commands.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from contextlib import suppress
88
from core import (Plugin, PluginRequiredError, utils, Status, Server, Coalition, Channel, Group, Node, Instance,
9-
DEFAULT_TAG)
9+
DEFAULT_TAG, get_translation)
1010
from datetime import datetime, timedelta, timezone
1111
from discord import app_commands
1212
from discord.ext import tasks
@@ -24,6 +24,8 @@
2424
from ruamel.yaml import YAML
2525
yaml = YAML()
2626

27+
_ = get_translation(__name__.split('.')[1])
28+
2729

2830
class Scheduler(Plugin[SchedulerListener]):
2931

@@ -649,7 +651,7 @@ async def restart(self, interaction: discord.Interaction,
649651
status=[
650652
Status.RUNNING, Status.PAUSED, Status.STOPPED
651653
])],
652-
force: Optional[bool] = False, run_extensions: Optional[bool] = True,
654+
delay: Optional[int] = 120, force: Optional[bool] = False, run_extensions: Optional[bool] = True,
653655
use_orig: Optional[bool] = True, mission_id: Optional[int] = None):
654656
ephemeral = utils.get_ephemeral(interaction)
655657
# noinspection PyUnresolvedReferences
@@ -660,9 +662,24 @@ async def restart(self, interaction: discord.Interaction,
660662
if not await utils.yn_question(interaction, question, ephemeral=ephemeral):
661663
await interaction.followup.send("Aborted.", ephemeral=ephemeral)
662664
return
665+
# send warnings (TODO: change to warn structure)
666+
if server.is_populated():
667+
if delay > 0:
668+
message = _("!!! Server will restart in {}!!!").format(utils.format_time(delay))
669+
else:
670+
message = _("!!! Server will restart NOW !!!")
671+
672+
msg = await interaction.followup.send(
673+
_('Server will restart in {} (warning users before)...').format(utils.format_time(delay)),
674+
ephemeral=ephemeral
675+
)
676+
await server.sendPopupMessage(Coalition.ALL, message, sender=interaction.user.display_name)
677+
await asyncio.sleep(delay)
678+
await msg.delete()
663679

664-
msg = await interaction.followup.send(f"Shutting down DCS server \"{server.display_name}\" ...",
665-
ephemeral=ephemeral)
680+
msg = await interaction.followup.send(
681+
f'Shutting down DCS server "{server.display_name}" ...', ephemeral=ephemeral
682+
)
666683
try:
667684
maintenance = server.maintenance
668685
server.maintenance = True

0 commit comments

Comments
 (0)