<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Linq;
using System.Text;
using Mirror;
using Tilemaps.Behaviours.Meta;

public partial class Chat
{
	private static Dictionary<string, UniqueQueue<DestroyChatMessage>> messageQueueDict = new Dictionary<string, UniqueQueue<DestroyChatMessage>>();
	private static Coroutine composeMessageHandle;
	private static StringBuilder stringBuilder = new StringBuilder();
	private struct DestroyChatMessage
	{
		public string Message;
		public Vector2Int WorldPosition;
	}

	public Color oocColor;
	public Color ghostColor;
	public Color binaryColor;
	public Color supplyColor;
	public Color centComColor;
	public Color commandColor;
	public Color commonColor;
	public Color engineeringColor;
	public Color medicalColor;
	public Color scienceColor;
	public Color securityColor;
	public Color serviceColor;
	public Color localColor;
	public Color combatColor;
	public Color warningColor;
	public Color defaultColor;


	/// <summary>
	/// This channels can't be heared as sound by other players (like binary or changeling hivemind)
	/// </summary>
	public const ChatChannel NonVerbalChannels = ChatChannel.Binary | ChatChannel.Ghost;

	/// <summary>
	/// This channels are OOC or service messages and shouldn't affect IC communications
	/// </summary>
	public const ChatChannel ServiceChannels = ChatChannel.Action | ChatChannel.Admin | ChatChannel.Combat
		| ChatChannel.Examine | ChatChannel.OOC | ChatChannel.System | ChatChannel.Warning;


	/// <summary>
	/// Processes a message to be used in the chat log and chat bubbles.
	/// 1. Detects which modifiers should be present in the messages.
	///    - Some of the modifiers will come from the player being unconcious, being a clown, etc.
	///    - Other modifiers are voluntary, such as shouting. They normally cannot override involuntary modifiers.
	///    - Certain emotes override each other and will never be present at the same time.
	///      - Emote overrides whispering, and whispering overrides yelling.
	/// 2. Modifies the message to match the previously detected modifiers.
	///    - Stutters, honks, drunkenness, etc. are directly applied to the message.
	///    - The chat log and chat bubble may add minor changes to the text, such as narration ("Player says, ...").
	/// </summary>
	/// <param name="sendByPlayer">The player sending the message. Used for detecting conciousness and occupation.</param>
	/// <param name="message">The chat message to process.</param>
	/// <returns>A tuple of the processed chat message and the detected modifiers.</returns>
	private static (string, ChatModifier) ProcessMessage(ConnectedPlayer sentByPlayer, string message)
	{
		ChatModifier chatModifiers = ChatModifier.None; // Modifier that will be returned in the end.
		ConsciousState playerConsciousState = ConsciousState.DEAD;

		if (sentByPlayer.Script == null)
		{
			return (message, chatModifiers);
		}

		if (sentByPlayer.Script.playerHealth != null)
		{
			playerConsciousState = sentByPlayer.Script.playerHealth.ConsciousState;
		}

		if (playerConsciousState == ConsciousState.UNCONSCIOUS || playerConsciousState == ConsciousState.DEAD)
		{
			// Only the Mute modifier matters if the player cannot speak. We can skip everything else.
			return (message, ChatModifier.Mute);
		}

		// Emote
		if (message.StartsWith("*") || message.StartsWith("/me ",true,CultureInfo.CurrentCulture))
		{
			message = message.Substring(1);
			chatModifiers |= ChatModifier.Emote;
		}
		// Whisper
		else if (message.StartsWith("#") || message.StartsWith("/w ",true,CultureInfo.CurrentCulture))
		{
			message = message.Substring(1);
			chatModifiers |= ChatModifier.Whisper;
		}
		// Sing
		else if (message.StartsWith("%") || message.StartsWith("/s ",true,CultureInfo.CurrentCulture))
		{
			message = message.Substring(1);
			message = Sing(message);
			chatModifiers |= ChatModifier.Sing;
		}
		// Involuntaly whisper due to not being fully concious
		else if (playerConsciousState == ConsciousState.BARELY_CONSCIOUS)
		{
			chatModifiers |= ChatModifier.Whisper;
		}
		// Yell
		else if ((message == message.ToUpper(CultureInfo.InvariantCulture) // Is it all caps?
			&& message.Any(char.IsLetter)))// AND does it contain at least one letter?
		{
			chatModifiers |= ChatModifier.Yell;
		}
		// Question
		else if (message.EndsWith("?"))
		{
			chatModifiers |= ChatModifier.Question;
		}
		// Exclaim
		else if (message.EndsWith("!"))
		{
			chatModifiers |= ChatModifier.Exclaim;
		}

		// Clown
		if (sentByPlayer.Script.mind != null &&
			sentByPlayer.Script.mind.occupation != null &&
			sentByPlayer.Script.mind.occupation.JobType == JobType.CLOWN)<commit_msg>didnt spot this one, thanks gilles<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Linq;
using System.Text;
using Mirror;
using Tilemaps.Behaviours.Meta;

public partial class Chat
{
	private static Dictionary<string, UniqueQueue<DestroyChatMessage>> messageQueueDict = new Dictionary<string, UniqueQueue<DestroyChatMessage>>();
	private static Coroutine composeMessageHandle;
	private static StringBuilder stringBuilder = new StringBuilder();
	private struct DestroyChatMessage
	{
		public string Message;
		public Vector2Int WorldPosition;
	}

	public Color oocColor;
	public Color ghostColor;
	public Color binaryColor;
	public Color supplyColor;
	public Color centComColor;
	public Color commandColor;
	public Color commonColor;
	public Color engineeringColor;
	public Color medicalColor;
	public Color scienceColor;
	public Color securityColor;
	public Color serviceColor;
	public Color localColor;
	public Color combatColor;
	public Color warningColor;
	public Color defaultColor;


	/// <summary>
	/// This channels can't be heared as sound by other players (like binary or changeling hivemind)
	/// </summary>
	public const ChatChannel NonVerbalChannels = ChatChannel.Binary | ChatChannel.Ghost;

	/// <summary>
	/// This channels are OOC or service messages and shouldn't affect IC communications
	/// </summary>
	public const ChatChannel ServiceChannels = ChatChannel.Action | ChatChannel.Admin | ChatChannel.Combat
		| ChatChannel.Examine | ChatChannel.OOC | ChatChannel.System | ChatChannel.Warning;


	/// <summary>
	/// Processes a message to be used in the chat log and chat bubbles.
	/// 1. Detects which modifiers should be present in the messages.
	///    - Some of the modifiers will come from the player being unconcious, being a clown, etc.
	///    - Other modifiers are voluntary, such as shouting. They normally cannot override involuntary modifiers.
	///    - Certain emotes override each other and will never be present at the same time.
	///      - Emote overrides whispering, and whispering overrides yelling.
	/// 2. Modifies the message to match the previously detected modifiers.
	///    - Stutters, honks, drunkenness, etc. are directly applied to the message.
	///    - The chat log and chat bubble may add minor changes to the text, such as narration ("Player says, ...").
	/// </summary>
	/// <param name="sendByPlayer">The player sending the message. Used for detecting conciousness and occupation.</param>
	/// <param name="message">The chat message to process.</param>
	/// <returns>A tuple of the processed chat message and the detected modifiers.</returns>
	private static (string, ChatModifier) ProcessMessage(ConnectedPlayer sentByPlayer, string message)
	{
		ChatModifier chatModifiers = ChatModifier.None; // Modifier that will be returned in the end.
		ConsciousState playerConsciousState = ConsciousState.DEAD;

		if (sentByPlayer.Script == null)
		{
			return (message, chatModifiers);
		}

		if (sentByPlayer.Script.playerHealth != null)
		{
			playerConsciousState = sentByPlayer.Script.playerHealth.ConsciousState;
		}

		if (playerConsciousState == ConsciousState.UNCONSCIOUS || playerConsciousState == ConsciousState.DEAD)
		{
			// Only the Mute modifier matters if the player cannot speak. We can skip everything else.
			return (message, ChatModifier.Mute);
		}

		// Emote
		if (message.StartsWith("*") || message.StartsWith("/me ",true,CultureInfo.CurrentCulture))
		{
			message = message.Substring(message.StartsWith("/me ") ? 4 : 1);
			chatModifiers |= ChatModifier.Emote;
		}
		// Whisper
		else if (message.StartsWith("#") || message.StartsWith("/w ",true,CultureInfo.CurrentCulture))
		{
			message = message.Substring(message.StartsWith("/w ") ? 3 : 1);
			chatModifiers |= ChatModifier.Whisper;
		}
		// Sing
		else if (message.StartsWith("%") || message.StartsWith("/s ",true,CultureInfo.CurrentCulture))
		{
			message = message.Substring(message.StartsWith("/s ") ? 3 : 1);
			message = Sing(message);
			chatModifiers |= ChatModifier.Sing;
		}
		// Involuntaly whisper due to not being fully concious
		else if (playerConsciousState == ConsciousState.BARELY_CONSCIOUS)
		{
			chatModifiers |= ChatModifier.Whisper;
		}
		// Yell
		else if ((message == message.ToUpper(CultureInfo.InvariantCulture) // Is it all caps?
			&& message.Any(char.IsLetter)))// AND does it contain at least one letter?
		{
			chatModifiers |= ChatModifier.Yell;
		}
		// Question
		else if (message.EndsWith("?"))
		{
			chatModifiers |= ChatModifier.Question;
		}
		// Exclaim
		else if (message.EndsWith("!"))
		{
			chatModifiers |= ChatModifier.Exclaim;
		}

		// Clown
		if (sentByPlayer.Script.mind != null &&
			sentByPlayer.Script.mind.occupation != null &&
			sentByPlayer.Script.mind.occupation.JobType == JobType.CLOWN)
{'fraction_non_alphanumeric': 0.1021694214876033, 'fraction_numerical': 0.0015495867768595042, 'mean_word_length': 4.092582851130984, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5317987', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2764, 'n_words': 868}