Tweaks to ShowRulesCommand structure, localization, and autocomplete. (#38855)
commit
This commit is contained in:
@@ -10,55 +10,46 @@ using Robust.Shared.Network;
|
|||||||
namespace Content.Server.Info;
|
namespace Content.Server.Info;
|
||||||
|
|
||||||
[AdminCommand(AdminFlags.Admin)]
|
[AdminCommand(AdminFlags.Admin)]
|
||||||
public sealed class ShowRulesCommand : IConsoleCommand
|
public sealed class ShowRulesCommand : LocalizedCommands
|
||||||
{
|
{
|
||||||
[Dependency] private readonly INetManager _net = default!;
|
|
||||||
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
||||||
|
[Dependency] private readonly INetManager _net = default!;
|
||||||
[Dependency] private readonly IPlayerManager _player = default!;
|
[Dependency] private readonly IPlayerManager _player = default!;
|
||||||
|
|
||||||
public string Command => "showrules";
|
public override string Command => "showrules";
|
||||||
public string Description => "Opens the rules popup for the specified player.";
|
|
||||||
public string Help => "showrules <username> [seconds]";
|
public override async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
||||||
{
|
{
|
||||||
string target;
|
if (args.Length is < 1 or > 2)
|
||||||
float seconds;
|
|
||||||
|
|
||||||
switch (args.Length)
|
|
||||||
{
|
{
|
||||||
case 1:
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
||||||
{
|
return;
|
||||||
target = args[0];
|
|
||||||
seconds = _configuration.GetCVar(CCVars.RulesWaitTime);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
if (!float.TryParse(args[1], out seconds))
|
|
||||||
{
|
|
||||||
shell.WriteError($"{args[1]} is not a valid amount of seconds.\n{Help}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target = args[0];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
shell.WriteLine(Help);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var seconds = _configuration.GetCVar(CCVars.RulesWaitTime);
|
||||||
|
|
||||||
if (!_player.TryGetSessionByUsername(target, out var player))
|
if (args.Length == 2 && !float.TryParse(args[1], out seconds))
|
||||||
{
|
{
|
||||||
shell.WriteError("Unable to find a player with that name.");
|
shell.WriteError(Loc.GetString("cmd-showrules-invalid-seconds", ("seconds", args[1])));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_player.TryGetSessionByUsername(args[0], out var player))
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("shell-target-player-does-not-exist"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var coreRules = _configuration.GetCVar(CCVars.RulesFile);
|
var coreRules = _configuration.GetCVar(CCVars.RulesFile);
|
||||||
var message = new SendRulesInformationMessage { PopupTime = seconds, CoreRules = coreRules, ShouldShowRules = true};
|
var message = new SendRulesInformationMessage
|
||||||
|
{ PopupTime = seconds, CoreRules = coreRules, ShouldShowRules = true };
|
||||||
_net.ServerSendMessage(message, player.Channel);
|
_net.ServerSendMessage(message, player.Channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||||
|
{
|
||||||
|
return args.Length == 1
|
||||||
|
? CompletionResult.FromOptions(CompletionHelper.SessionNames(players: _player))
|
||||||
|
: CompletionResult.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
Resources/Locale/en-US/commands/showrules-command.ftl
Normal file
3
Resources/Locale/en-US/commands/showrules-command.ftl
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
cmd-showrules-desc = Opens the rules popup for the specified player.
|
||||||
|
cmd-showrules-help = Usage: showrules <username> [seconds]
|
||||||
|
cmd-showrules-invalid-seconds = {$seconds} is not a valid number of seconds!
|
||||||
Reference in New Issue
Block a user