Better attachment handling after PR to samhofi.us/x/keybase
This commit is contained in:
@ -24,16 +24,29 @@ func cmdDownloadFile(cmd []string) {
|
||||
printToView("Feed", fmt.Sprintf("%s%s $messageId $fileName - Download a file to user's downloadpath", cmdPrefix, cmd[0]))
|
||||
return
|
||||
}
|
||||
messageID, _ := strconv.Atoi(cmd[1])
|
||||
messageID, err := strconv.Atoi(cmd[1])
|
||||
if err != nil {
|
||||
printToView("Feed", "There was an error converting your messageID to an int")
|
||||
return
|
||||
}
|
||||
chat := k.NewChat(channel)
|
||||
api, err := chat.ReadMessage(messageID)
|
||||
if err != nil {
|
||||
printToView("Feed", fmt.Sprintf("There was an error pulling message %d", messageID))
|
||||
return
|
||||
}
|
||||
if api.Result.Messages[0].Msg.Content.Type != "attachment" {
|
||||
printToView("Feed", "No attachment detected")
|
||||
return
|
||||
}
|
||||
var fileName string
|
||||
if len(cmd) == 3 {
|
||||
fileName = cmd[2]
|
||||
} else {
|
||||
fileName = ""
|
||||
fileName = api.Result.Messages[0].Msg.Content.Attachment.Object.Filename
|
||||
}
|
||||
|
||||
chat := k.NewChat(channel)
|
||||
_, err := chat.Download(messageID, fmt.Sprintf("%s/%s", downloadPath, fileName))
|
||||
_, err = chat.Download(messageID, fmt.Sprintf("%s/%s", downloadPath, fileName))
|
||||
if err != nil {
|
||||
printToView("Feed", fmt.Sprintf("There was an error downloading %s from %s", fileName, channel.Name))
|
||||
} else {
|
||||
|
||||
2
main.go
2
main.go
@ -365,7 +365,7 @@ func formatOutput(api keybase.ChatAPI) string {
|
||||
msg = colorRegex(msg, `(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))`, messageLinkColor, messageBodyColor)
|
||||
msg = colorText(colorReplaceMentionMe(msg, messageBodyColor), messageBodyColor, c)
|
||||
if msgType == "attachment" {
|
||||
msg = fmt.Sprintf("%s", colorText("[Attachment]", messageAttachmentColor, c))
|
||||
msg = fmt.Sprintf("%s\n%s", api.Msg.Content.Attachment.Object.Title, colorText(fmt.Sprintf("[Attachment: %s]", api.Msg.Content.Attachment.Object.Filename), messageAttachmentColor, c))
|
||||
}
|
||||
user := colorUsername(api.Msg.Sender.Username, c)
|
||||
device := colorText(api.Msg.Sender.DeviceName, messageSenderDeviceColor, c)
|
||||
|
||||
Reference in New Issue
Block a user