From 2668a6abbd7e1f80d1a6eb8834744b3060d00660 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 5 Jun 2018 18:41:19 +1200 Subject: [PATCH] fix extra star-space prefix on system messages breaking heuristic action detection --- NTFServer.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/NTFServer.go b/NTFServer.go index 6a4613b..dc730a7 100644 --- a/NTFServer.go +++ b/NTFServer.go @@ -290,12 +290,15 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) { case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB: // This includes "want to register your nick?" and chat-catchup messages // But it also includes /me messages - // Hard to tell them apart - heuristic detection by matching the first space-separated word against known online users + // First, remove system characters from the front (star, space) + systemMessage := strings.TrimLeft(msg.evt.Message, `* `) + + // Heuristic detect action messages if the first space-separated word is a known online user isActionMessage := false if conn, ok := this.conns[msg.hubNick]; ok { - firstWord := strings.SplitN(msg.evt.Message, ` `, 2)[0] + firstWord := strings.SplitN(systemMessage, ` `, 2)[0] _ = conn.Users(func(umap *map[string]libnmdc.UserInfo) error { for knownHubNick, _ := range *umap { if knownHubNick == firstWord { @@ -311,18 +314,19 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) { // Treat it as a full post // Coalesce from multiple connections - if this.Coalesce("*", msg.evt.Message) { + if this.Coalesce("*", systemMessage) { return // ignore - we heard this message already recently } // Display the message - htmlMsg := "* " + html.EscapeString(msg.evt.Message) + "" + htmlMsg := "* " + html.EscapeString(systemMessage) + "" err := this.GroupChatSayHTML(htmlMsg) if err != nil { log.Printf("Delivering action message to group chat: %s", err.Error()) } } else { + // Not an action message, just clerical notices // Don't mirror them into telegram log.Printf("Hub(%s): * %s", msg.hubNick, msg.evt.Message) }