Apply smiley filter on me-command (#6153)

This commit is contained in:
Clyybber
2022-01-25 10:38:52 +01:00
committed by GitHub
parent ddcd4d267d
commit 107806775e
3 changed files with 39 additions and 24 deletions

View File

@@ -18,39 +18,29 @@ namespace Content.Server.Chat.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
var player = shell.Player as IPlayerSession; if (shell.Player is not IPlayerSession player)
if (player == null)
{ {
shell.WriteLine("This command cannot be run from the server."); shell.WriteError("This command cannot be run from the server.");
return; return;
} }
if (player.Status != SessionStatus.InGame || player.AttachedEntity == null) if (player.Status != SessionStatus.InGame)
return; return;
if (args.Length < 1) if (player.AttachedEntity is not {} playerEntity)
return;
var action = string.Join(" ", args).Trim();
if (string.IsNullOrEmpty(action))
return;
var chat = IoCManager.Resolve<IChatManager>();
var mindComponent = player.ContentData()?.Mind;
if (mindComponent == null)
{
shell.WriteError("You don't have a mind!");
return;
}
if (mindComponent.OwnedEntity == null)
{ {
shell.WriteError("You don't have an entity!"); shell.WriteError("You don't have an entity!");
return; return;
} }
chat.EntityMe(mindComponent.OwnedEntity.Value, action); if (args.Length < 1)
return;
var message = string.Join(" ", args).Trim();
if (string.IsNullOrEmpty(message))
return;
IoCManager.Resolve<IChatManager>().TryEmote(playerEntity, message, shell, player);
} }
} }
} }

View File

@@ -169,15 +169,38 @@ namespace Content.Server.Chat.Managers
var isEmote = _sanitizer.TrySanitizeOutSmilies(message, owned, out var sanitized, out var emoteStr); var isEmote = _sanitizer.TrySanitizeOutSmilies(message, owned, out var sanitized, out var emoteStr);
if (sanitized.Length != 0) if (sanitized.Length != 0)
{
SendEntityChatType(owned, sanitized, isWhisper); SendEntityChatType(owned, sanitized, isWhisper);
}
if (isEmote) if (isEmote)
EntityMe(owned, emoteStr!); EntityMe(owned, emoteStr!);
} }
} }
public void TryEmote(EntityUid source, string message, IConsoleShell? shell = null, IPlayerSession? player = null)
{
var mindComponent = player?.ContentData()?.Mind;
if (mindComponent == null)
{
shell?.WriteError("You don't have a mind!");
return;
}
if (mindComponent.OwnedEntity is not {Valid: true} owned)
{
shell?.WriteError("You don't have an entity!");
return;
}
var isEmote = _sanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity.Value, out var sanitized, out var emoteStr);
if (sanitized.Length != 0)
EntityMe(mindComponent.OwnedEntity.Value, sanitized);
if (isEmote)
EntityMe(mindComponent.OwnedEntity.Value, emoteStr!);
}
public void EntitySay(EntityUid source, string message, bool hideChat=false) public void EntitySay(EntityUid source, string message, bool hideChat=false)
{ {
if (!EntitySystem.Get<ActionBlockerSystem>().CanSpeak(source)) if (!EntitySystem.Get<ActionBlockerSystem>().CanSpeak(source))

View File

@@ -29,6 +29,8 @@ namespace Content.Server.Chat.Managers
/// </summary> /// </summary>
void TrySpeak(EntityUid source, string message, bool whisper = false, IConsoleShell? shell = null, IPlayerSession? player = null); void TrySpeak(EntityUid source, string message, bool whisper = false, IConsoleShell? shell = null, IPlayerSession? player = null);
void TryEmote(EntityUid source, string message, IConsoleShell? shell = null, IPlayerSession? player = null);
/// <param name="hideChat">If true, message will not be logged to chat boxes but will still produce a speech bubble.</param> /// <param name="hideChat">If true, message will not be logged to chat boxes but will still produce a speech bubble.</param>
void EntitySay(EntityUid source, string message, bool hideChat=false); void EntitySay(EntityUid source, string message, bool hideChat=false);
void EntityWhisper(EntityUid source, string message, bool hideChat = false); void EntityWhisper(EntityUid source, string message, bool hideChat = false);