From 7da4e13bae33fb366ccf756228f6a80109179c56 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 16 Apr 2021 20:26:30 +1000 Subject: [PATCH] Handle /me better for relay bots, fix discord bot saying (IRC) instead of (Discord) in-game --- MCGalaxy/Chat/Chat.cs | 20 ++++++++++---------- MCGalaxy/Commands/Chat/CmdMe.cs | 3 +-- MCGalaxy/Commands/Chat/MessageCmd.cs | 6 ++++-- MCGalaxy/Events/ServerEvents.cs | 18 +++++++++--------- MCGalaxy/Modules/Relay/IRC/IRCBot.cs | 9 --------- MCGalaxy/Modules/RelayBot.cs | 4 ++-- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/MCGalaxy/Chat/Chat.cs b/MCGalaxy/Chat/Chat.cs index 37898cc36..a1b151baf 100644 --- a/MCGalaxy/Chat/Chat.cs +++ b/MCGalaxy/Chat/Chat.cs @@ -119,11 +119,11 @@ public static class Chat { } public static void Message(ChatScope scope, string msg, object arg, - ChatMessageFilter filter, bool irc = false) { + ChatMessageFilter filter, bool relay = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; - OnChatSysEvent.Call(scope, msg, arg, ref filter, irc); + OnChatSysEvent.Call(scope, msg, arg, ref filter, relay); foreach (Player pl in players) { if (!scopeFilter(pl, arg)) continue; if (filter != null && !filter(pl, arg)) continue; @@ -141,9 +141,9 @@ public static class Chat { } public static void MessageFrom(Player source, string msg, - ChatMessageFilter filter = null, bool irc = false) { + ChatMessageFilter filter = null, bool relay = false) { if (source.level == null || source.level.SeesServerWideChat) { - MessageFrom(ChatScope.Global, source, msg, null, filter, irc); + MessageFrom(ChatScope.Global, source, msg, null, filter, relay); } else { string prefix = Server.Config.ServerWideChat ? "" : ""; MessageFrom(ChatScope.Level, source, prefix + msg, source.level, filter); @@ -154,11 +154,11 @@ public static class Chat { /// For player chat type messages, Chat.MessageChat is more appropriate to use. /// Only players not ignoring the given player will see this message. public static void MessageFrom(ChatScope scope, Player source, string msg, object arg, - ChatMessageFilter filter, bool irc = false) { + ChatMessageFilter filter, bool relay = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; - OnChatFromEvent.Call(scope, source, msg, arg, ref filter, irc); + OnChatFromEvent.Call(scope, source, msg, arg, ref filter, relay); foreach (Player pl in players) { if (!scopeFilter(pl, arg)) continue; if (filter != null && !filter(pl, arg)) continue; @@ -170,9 +170,9 @@ public static class Chat { public static void MessageChat(Player source, string msg, - ChatMessageFilter filter = null, bool irc = false) { + ChatMessageFilter filter = null, bool relay = false) { if (source.level.SeesServerWideChat) { - MessageChat(ChatScope.Global, source, msg, null, filter, irc); + MessageChat(ChatScope.Global, source, msg, null, filter, relay); } else { string prefix = Server.Config.ServerWideChat ? "" : ""; MessageChat(ChatScope.Level, source, prefix + msg, source.level, filter); @@ -184,12 +184,12 @@ public static class Chat { /// and count towards triggering automute for chat spamming /// Only players not ignoring the given player will see this message. public static void MessageChat(ChatScope scope, Player source, string msg, object arg, - ChatMessageFilter filter, bool irc = false) { + ChatMessageFilter filter, bool relay = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; bool counted = false; - OnChatEvent.Call(scope, source, msg, arg, ref filter, irc); + OnChatEvent.Call(scope, source, msg, arg, ref filter, relay); foreach (Player pl in players) { if (Ignoring(pl, source)) continue; // Always show message to self too (unless ignoring self) diff --git a/MCGalaxy/Commands/Chat/CmdMe.cs b/MCGalaxy/Commands/Chat/CmdMe.cs index 21ba259ef..bc4b86413 100644 --- a/MCGalaxy/Commands/Chat/CmdMe.cs +++ b/MCGalaxy/Commands/Chat/CmdMe.cs @@ -30,8 +30,7 @@ public sealed class CmdMe : MessageCmd { if (p.joker) { p.Message("Cannot use /me while jokered."); return; } string msg = p.color + "*" + Colors.StripUsed(p.DisplayName) + " " + message; - if (TryMessage(p, msg)) - OnPlayerActionEvent.Call(p, PlayerAction.Me, message); + TryMessage(p, msg, true); } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/Chat/MessageCmd.cs b/MCGalaxy/Commands/Chat/MessageCmd.cs index 882fe196f..c31201677 100644 --- a/MCGalaxy/Commands/Chat/MessageCmd.cs +++ b/MCGalaxy/Commands/Chat/MessageCmd.cs @@ -34,9 +34,11 @@ public abstract class MessageCmd : Command2 { return true; } - protected bool TryMessage(Player p, string msg) { + protected bool TryMessage(Player p, string msg) { return TryMessage(p, msg, false); } + + protected bool TryMessage(Player p, string msg, bool relay) { if (!CanSpeak(p, name)) return false; - Chat.MessageFrom(p, msg, null); + Chat.MessageFrom(p, msg, null, relay); p.CheckForMessageSpam(); return true; diff --git a/MCGalaxy/Events/ServerEvents.cs b/MCGalaxy/Events/ServerEvents.cs index 212694e4c..c3ecc2955 100644 --- a/MCGalaxy/Events/ServerEvents.cs +++ b/MCGalaxy/Events/ServerEvents.cs @@ -46,42 +46,42 @@ public sealed class OnShuttingDownEvent : IEvent { } public delegate void OnChatSys(ChatScope scope, string msg, object arg, - ref ChatMessageFilter filter, bool irc); + ref ChatMessageFilter filter, bool relay); public sealed class OnChatSysEvent : IEvent { public static void Call(ChatScope scope, string msg, object arg, - ref ChatMessageFilter filter, bool irc) { + ref ChatMessageFilter filter, bool relay) { IEvent[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { - try { items[i].method(scope, msg, arg, ref filter, irc); } + try { items[i].method(scope, msg, arg, ref filter, relay); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } } } public delegate void OnChatFrom(ChatScope scope, Player source, string msg, - object arg, ref ChatMessageFilter filter, bool irc); + object arg, ref ChatMessageFilter filter, bool relay); public sealed class OnChatFromEvent : IEvent { public static void Call(ChatScope scope,Player source, string msg, - object arg, ref ChatMessageFilter filter, bool irc) { + object arg, ref ChatMessageFilter filter, bool relay) { IEvent[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { - try { items[i].method(scope, source, msg, arg, ref filter, irc); } + try { items[i].method(scope, source, msg, arg, ref filter, relay); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } } } public delegate void OnChat(ChatScope scope, Player source, string msg, - object arg, ref ChatMessageFilter filter, bool irc); + object arg, ref ChatMessageFilter filter, bool relay); public sealed class OnChatEvent : IEvent { public static void Call(ChatScope scope, Player source, string msg, - object arg, ref ChatMessageFilter filter, bool irc) { + object arg, ref ChatMessageFilter filter, bool relay) { IEvent[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { - try { items[i].method(scope, source, msg, arg, ref filter, irc); } + try { items[i].method(scope, source, msg, arg, ref filter, relay); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } } diff --git a/MCGalaxy/Modules/Relay/IRC/IRCBot.cs b/MCGalaxy/Modules/Relay/IRC/IRCBot.cs index e3a692027..9b5d9f24d 100644 --- a/MCGalaxy/Modules/Relay/IRC/IRCBot.cs +++ b/MCGalaxy/Modules/Relay/IRC/IRCBot.cs @@ -244,8 +244,6 @@ public sealed class IRCBot : RelayBot { if (hookedEvents) return; hookedEvents = true; HookEvents(); - - OnPlayerActionEvent.Register(HandlePlayerAction, Priority.Low); OnShuttingDownEvent.Register(HandleShutdown, Priority.Low); // Regster events for incoming @@ -272,7 +270,6 @@ public sealed class IRCBot : RelayBot { hookedEvents = false; UnhookEvents(); - OnPlayerActionEvent.Unregister(HandlePlayerAction); OnShuttingDownEvent.Unregister(HandleShutdown); // Regster events for incoming @@ -294,12 +291,6 @@ public sealed class IRCBot : RelayBot { } - void HandlePlayerAction(Player p, PlayerAction action, string message, bool stealth) { - if (action != PlayerAction.Me) return; - if (p.level != null && !p.level.SeesServerWideChat) return; - Say("*" + p.DisplayName + " " + message, stealth); - } - void HandleShutdown(bool restarting, string message) { Disconnect(restarting ? "Server is restarting." : "Server is shutting down."); } diff --git a/MCGalaxy/Modules/RelayBot.cs b/MCGalaxy/Modules/RelayBot.cs index 05c915906..71c3a5ab8 100644 --- a/MCGalaxy/Modules/RelayBot.cs +++ b/MCGalaxy/Modules/RelayBot.cs @@ -159,11 +159,11 @@ public abstract class RelayBot { if (opchat) { Logger.Log(LogType.RelayChat, "(OPs): ({0}) {1}: {2}", RelayName, user.Nick, message); - Chat.MessageOps(string.Format("To Ops &f-&I(IRC) {0}&f- {1}", user.Nick, + Chat.MessageOps(string.Format("To Ops &f-&I({0}) {1}&f- {2}", RelayName, user.Nick, Server.Config.ProfanityFiltering ? ProfanityFilter.Parse(message) : message)); } else { Logger.Log(LogType.RelayChat, "({0}) {1}: {2}", RelayName, user.Nick, message); - MessageInGame(user.Nick, string.Format("&I(IRC) {0}: &f{1}", user.Nick, + MessageInGame(user.Nick, string.Format("&I({0}) {1}: &f{2}", RelayName, user.Nick, Server.Config.ProfanityFiltering ? ProfanityFilter.Parse(message) : message)); } }