From e1a33f8749bf0e649075994694363615eab858bc Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Thu, 3 Oct 2019 08:02:07 -0400 Subject: [PATCH] uh --- cmdUploadFile.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 cmdUploadFile.go diff --git a/cmdUploadFile.go b/cmdUploadFile.go new file mode 100644 index 0000000..9fea8d4 --- /dev/null +++ b/cmdUploadFile.go @@ -0,0 +1,37 @@ +// +build !rm_basic_commands allcommands joincmd + +package main + +import ( + "fmt" + + "github.com/jroimartin/gocui" +) + +func init() { + command := Command{ + Cmd: []string{"upload", "u"}, + Description: "Upload a file", + Help: "", + Exec: cmdUploadFile, + } + + RegisterCommand(command) +} + +func cmdUploadFile(g *gocui.Gui, cmd []string) { + filePath := cmd[1] + var fileName string + if len(cmd) == 3 { + fileName = cmd[2] + } else { + fileName = "" + } + chat := k.NewChat(channel) + _, err := chat.Upload(fileName, filePath) + if err != nil { + printToView(g, "Feed", fmt.Sprintf("There was an error uploading %s to %s", filePath, channel.Name)) + } else { + printToView(g, "Feed", fmt.Sprintf("Uploaded %s to %s", filePath, channel.Name)) + } +}