transform telegram quoted-messages into DC-style inline replies
This commit is contained in:
parent
4a38cb7b39
commit
e30f973e3c
30
NTFServer.go
30
NTFServer.go
@ -476,15 +476,37 @@ func (this *NTFServer) HandleGroupMessage(update telegram.Update) error {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Actual chat message
|
// Actual chat message
|
||||||
|
sendMsg := update.Message.Text
|
||||||
|
|
||||||
|
// Was it a reply to another message? If so, format it as "<OrigUser> OrigMessage // update text"
|
||||||
|
if update.Message.ReplyToMessage != nil && len(update.Message.ReplyToMessage.Text) > 0 && update.Message.ReplyToMessage.From != nil {
|
||||||
|
origSenderId := int64(update.Message.ReplyToMessage.From.ID)
|
||||||
|
|
||||||
|
if origSenderNick, ok := this.config.KnownUsers[origSenderId]; ok {
|
||||||
|
// Quoted messages from another hub user
|
||||||
|
sendMsg = fmt.Sprintf(`"<%s> %s" // %s`, origSenderNick, update.Message.ReplyToMessage.Text, sendMsg)
|
||||||
|
|
||||||
|
} else if origSenderId == int64(this.bot.Self.ID) {
|
||||||
|
// Quoted messages from the hublink bot
|
||||||
|
sendMsg = fmt.Sprintf(`"%s" // %s`, update.Message.ReplyToMessage.Text, sendMsg) // the username is already present in the plaintext
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// No idea what was quoted. But it really was quoting something
|
||||||
|
// Paste it as-is but with some info in the logs for future cleanup
|
||||||
|
log.Printf("Quoting message '%#v' with unknown source", update.Message.ReplyToMessage)
|
||||||
|
sendMsg = fmt.Sprintf(`"%s" // %s`, update.Message.ReplyToMessage.Text, sendMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Also add it to the coalesce buffer so that we don't replay it from someone else's NMDC connection
|
// Also add it to the coalesce buffer so that we don't replay it from someone else's NMDC connection
|
||||||
this.Coalesce(hubNick, update.Message.Text)
|
this.Coalesce(hubNick, sendMsg)
|
||||||
|
|
||||||
// Submit to NMDC
|
// Submit to NMDC
|
||||||
err := conn.SayPublic(update.Message.Text)
|
err := conn.SayPublic(sendMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to deliver message '%s': %s", update.Message.Text, err.Error())
|
log.Printf("Failed to deliver message '%s': %s", sendMsg, err.Error())
|
||||||
this.GroupChatSayHTML(fmt.Sprintf("<i>Couldn't sync message '%s' because: %s</i>", html.EscapeString(update.Message.Text), html.EscapeString(err.Error())))
|
this.GroupChatSayHTML(fmt.Sprintf("<i>Couldn't sync message '%s' because: %s</i>", html.EscapeString(sendMsg), html.EscapeString(err.Error())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user