inline replies always flatten onto a single line

This commit is contained in:
mappu 2018-06-05 18:16:50 +12:00
parent e30f973e3c
commit b4ee831a0a

View File

@ -479,22 +479,25 @@ func (this *NTFServer) HandleGroupMessage(update telegram.Update) error {
sendMsg := update.Message.Text sendMsg := update.Message.Text
// Was it a reply to another message? If so, format it as "<OrigUser> OrigMessage // update text" // Was it a reply to another message? If so, format it as "<OrigUser> OrigMessage // update text"
// That includes collapsing the original message onto a single line
if update.Message.ReplyToMessage != nil && len(update.Message.ReplyToMessage.Text) > 0 && update.Message.ReplyToMessage.From != nil { if update.Message.ReplyToMessage != nil && len(update.Message.ReplyToMessage.Text) > 0 && update.Message.ReplyToMessage.From != nil {
origSenderId := int64(update.Message.ReplyToMessage.From.ID) origSenderId := int64(update.Message.ReplyToMessage.From.ID)
flatten := func(s string) string { return strings.Replace(s, "\n", " ", -1) }
if origSenderNick, ok := this.config.KnownUsers[origSenderId]; ok { if origSenderNick, ok := this.config.KnownUsers[origSenderId]; ok {
// Quoted messages from another hub user // Quoted messages from another hub user
sendMsg = fmt.Sprintf(`"<%s> %s" // %s`, origSenderNick, update.Message.ReplyToMessage.Text, sendMsg) sendMsg = fmt.Sprintf(`"<%s> %s" // %s`, origSenderNick, flatten(update.Message.ReplyToMessage.Text), sendMsg)
} else if origSenderId == int64(this.bot.Self.ID) { } else if origSenderId == int64(this.bot.Self.ID) {
// Quoted messages from the hublink bot // Quoted messages from the hublink bot
sendMsg = fmt.Sprintf(`"%s" // %s`, update.Message.ReplyToMessage.Text, sendMsg) // the username is already present in the plaintext sendMsg = fmt.Sprintf(`"%s" // %s`, flatten(update.Message.ReplyToMessage.Text), sendMsg) // the username is already present in the plaintext
} else { } else {
// No idea what was quoted. But it really was quoting something // 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 // 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) log.Printf("Quoting message '%#v' with unknown source", update.Message.ReplyToMessage)
sendMsg = fmt.Sprintf(`"%s" // %s`, update.Message.ReplyToMessage.Text, sendMsg) sendMsg = fmt.Sprintf(`"%s" // %s`, flatten(update.Message.ReplyToMessage.Text), sendMsg)
} }
} }