From a459f62cdffc3977e6f5b78d9b7b23121ba4104d Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Thu, 3 Oct 2019 10:13:13 -0400 Subject: [PATCH] Yeet haw, downloads are working and some edits were made to reactions --- cmdDownload.go | 32 ++++++++++++++++++++++++++++++++ main.go | 17 ++--------------- 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 cmdDownload.go diff --git a/cmdDownload.go b/cmdDownload.go new file mode 100644 index 0000000..acd062b --- /dev/null +++ b/cmdDownload.go @@ -0,0 +1,32 @@ +// +build !rm_basic_commands allcommands downloadcmd + +package main + +import ( + "fmt" + "strconv" +) + +func init() { + command := Command{ + Cmd: []string{"download", "d"}, + Description: "Download a file", + Help: "", + Exec: cmdDownloadFile, + } + + RegisterCommand(command) +} + +func cmdDownloadFile(cmd []string) { + messageID, _ := strconv.Atoi(cmd[1]) + fileName := cmd[2] + + chat := k.NewChat(channel) + _, 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 { + printToView("Feed", fmt.Sprintf("Downloaded %s from %s", fileName, channel.Name)) + } +} diff --git a/main.go b/main.go index f9221f4..561a058 100644 --- a/main.go +++ b/main.go @@ -124,15 +124,7 @@ func formatOutput(api keybase.ChatAPI) string { return ret } -func downloadFile(messageID int, fileName string) { - chat := k.NewChat(channel) - _, 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 { - printToView("Feed", fmt.Sprintf("Downloaded %s from %s", fileName, channel.Name)) - } -} + func populateList() { _, maxY := g.Size() @@ -353,12 +345,7 @@ func handleInput() error { } if inputString[:1] == "+" { cmd := strings.Split(inputString, " ") - if len(cmd) == 3 { - RunCommand("react", cmd[1], cmd[2]) - } - if len(cmd) == 2 { - RunCommand("react", cmd[1]) - } + RunCommand(cmd...) } else { go sendChat(inputString) }