/// <summary> /// Fires the <see cref="PlayerChat"/> event. /// </summary> /// <param name="ply">The player firing the event.</param> /// <param name="rawtext">The raw chat text sent by the player.</param> /// <param name="tshockText">The chat text after being formatted.</param> public static void OnPlayerChat(TSPlayer ply, string rawtext, ref string tshockText) { if (PlayerChat == null) { return; } var args = new PlayerChatEventArgs { Player = ply, RawText = rawtext, TShockFormattedText = tshockText }; PlayerChat(args); tshockText = args.TShockFormattedText; }
/// <summary> /// Called when a chat message is intercepted /// </summary> /// <param name="args">event arguments passed by hook</param> //private void OnChat(ServerChatEventArgs args) private void OnChat(TShockAPI.Hooks.PlayerChatEventArgs args) { // Do not relay game chat to Discord if this option is enabled if (Config.SilenceChat) { return; } // PlayerHooks.OnPlayerChat() already handles filtering commands and muted players. // Do not relay commands or messages from muted players //if(args.Text.StartsWith(TShock.Config.CommandSpecifier, StringComparison.InvariantCulture) || args.Text.StartsWith(TShock.Config.CommandSilentSpecifier, StringComparison.InvariantCulture) || TShock.Players[args.Who].mute) // return; // Attempt to convert any channel mentions //string modifiedMessage = args.Text; string modifiedMessage = args.RawText; if (Regex.IsMatch(modifiedMessage, @"#.+")) { modifiedMessage = Util.ConvertChannelMentions(modifiedMessage, discord.Client); } // Attempt to convert any role/user mentions if (Regex.IsMatch(modifiedMessage, @"@.+")) { modifiedMessage = Util.ConvertRoleUserMentions(modifiedMessage, discord.Client); } if (Config.LogChat) { //Util.Log($"{TShock.Players[args.Who].Name} said: {modifiedMessage}", Util.Severity.Info); Util.Log($"{args.Player.Name} said: {modifiedMessage}", Util.Severity.Info); } //discord.Send($"**<{TShock.Players[args.Who].Name}>** {modifiedMessage}"); discord.Send($"**<{args.Player.Name}>** {modifiedMessage}"); }
public static void OnPlayerChat(TSPlayer ply, string rawtext, ref string tshockText) { if (PlayerChat == null) return; var args = new PlayerChatEventArgs {Player = ply, RawText = rawtext, TShockFormattedText = tshockText}; PlayerChat(args); tshockText = args.TShockFormattedText; }