2023-02-28 08:15:48 -08:00
using Content.Server.Administration ;
using Content.Server.Administration.Logs ;
using Content.Shared.Administration ;
using Content.Shared.Database ;
using Content.Shared.CCVar ;
using Content.Server.Chat.Managers ;
using Robust.Shared.Configuration ;
using Robust.Shared.Console ;
namespace Content.Server.Motd ;
/// <summary>
/// A console command usable by any user which prints or sets the Message of the Day.
/// </summary>
[AdminCommand(AdminFlags.Admin)]
public sealed class SetMotdCommand : LocalizedCommands
{
[Dependency] private readonly IAdminLogManager _adminLogManager = default ! ;
[Dependency] private readonly IChatManager _chatManager = default ! ;
[Dependency] private readonly IConfigurationManager _configurationManager = default ! ;
public override string Command = > "set-motd" ;
2023-10-28 09:59:53 +11:00
2023-02-28 08:15:48 -08:00
public override void Execute ( IConsoleShell shell , string argStr , string [ ] args )
{
string motd = "" ;
2023-10-28 09:59:53 +11:00
var player = shell . Player ;
2023-02-28 08:15:48 -08:00
if ( args . Length > 0 )
{
motd = string . Join ( " " , args ) . Trim ( ) ;
if ( player ! = null & & _chatManager . MessageCharacterLimit ( player , motd ) )
return ; // check function prints its own error response
}
2023-10-28 09:59:53 +11:00
2023-02-28 08:15:48 -08:00
_configurationManager . SetCVar ( CCVars . MOTD , motd ) ; // A hook in MOTDSystem broadcasts changes to the MOTD to everyone so we don't need to do it here.
if ( string . IsNullOrEmpty ( motd ) )
{
shell . WriteLine ( Loc . GetString ( "cmd-set-motd-cleared-motd-message" ) ) ;
2024-01-22 23:14:13 +01:00
_adminLogManager . Add ( LogType . Chat , LogImpact . Low , $"{(player == null ? " LOCALHOST " : player.Channel.UserName):Player} cleared the MOTD for the server." ) ;
2023-02-28 08:15:48 -08:00
}
else
{
shell . WriteLine ( Loc . GetString ( "cmd-set-motd-set-motd-message" , ( "motd" , motd ) ) ) ;
2024-01-22 23:14:13 +01:00
_adminLogManager . Add ( LogType . Chat , LogImpact . Low , $"{(player == null ? " LOCALHOST " : player.Channel.UserName):Player} set the MOTD for the server to \"{motd:motd}\"" ) ;
2023-02-28 08:15:48 -08:00
}
}
public override CompletionResult GetCompletion ( IConsoleShell shell , string [ ] args )
{
if ( args . Length = = 1 )
return CompletionResult . FromHint ( Loc . GetString ( "cmd-set-motd-hint-head" ) ) ;
return CompletionResult . FromHint ( Loc . GetString ( "cmd-set-motd-hint-cont" ) ) ;
}
}