heuristic detect DC /me messages
This commit is contained in:
parent
b4ee831a0a
commit
a84b492a9a
39
NTFServer.go
39
NTFServer.go
@ -289,8 +289,43 @@ 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
|
||||
// Don't mirror them into telegram
|
||||
log.Printf("Hub(%s): * %s", msg.hubNick, msg.evt.Message)
|
||||
// But it also includes /me messages
|
||||
// Hard to tell them apart - heuristic detection by matching the first space-separated word against known online users
|
||||
|
||||
isActionMessage := false
|
||||
|
||||
if conn, ok := this.conns[msg.hubNick]; ok {
|
||||
firstWord := strings.SplitN(msg.evt.Message, ` `, 2)[0]
|
||||
_ = conn.Users(func(umap *map[string]libnmdc.UserInfo) error {
|
||||
for knownHubNick, _ := range *umap {
|
||||
if knownHubNick == firstWord {
|
||||
isActionMessage = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if isActionMessage {
|
||||
// Treat it as a full post
|
||||
|
||||
// Coalesce from multiple connections
|
||||
if this.Coalesce("*", msg.evt.Message) {
|
||||
return // ignore - we heard this message already recently
|
||||
}
|
||||
|
||||
// Display the message
|
||||
htmlMsg := "<i>* " + html.EscapeString(msg.evt.Message) + "</i>"
|
||||
err := this.GroupChatSayHTML(htmlMsg)
|
||||
if err != nil {
|
||||
log.Printf("Delivering action message to group chat: %s", err.Error())
|
||||
}
|
||||
|
||||
} else {
|
||||
// Don't mirror them into telegram
|
||||
log.Printf("Hub(%s): * %s", msg.hubNick, msg.evt.Message)
|
||||
}
|
||||
|
||||
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
||||
log.Printf("Hub(%s): * Connection %s", msg.evt.StateChange.String())
|
||||
|
Loading…
Reference in New Issue
Block a user