-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcmdUploadFile.go
50 lines (45 loc) · 1.26 KB
/
cmdUploadFile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build !rm_basic_commands allcommands uploadcmd
package main
import (
"fmt"
"os"
"strings"
)
func init() {
command := Command{
Cmd: []string{"upload", "u"},
Description: "$filePath $fileName - Upload file from absolute path with optional name",
Help: "",
Exec: cmdUploadFile,
}
RegisterCommand(command)
}
func cmdUploadFile(cmd []string) {
if len(cmd) < 2 {
printInfo(fmt.Sprintf("%s%s $filePath $fileName - Upload file from absolute path with optional name", config.Basics.CmdPrefix, cmd[0]))
return
}
filePath := cmd[1]
if !strings.HasPrefix(filePath, "/") {
dir, err := os.Getwd()
if err != nil {
printError(fmt.Sprintf("There was an error determining path %+v", err))
}
filePath = fmt.Sprintf("%s/%s", dir, filePath)
}
var fileName string
if len(cmd) == 3 {
fileName = cmd[2]
} else {
fileName = ""
}
chat := k.NewChat(channel)
_, err := chat.Upload(fileName, filePath)
channelName := config.Colors.Message.LinkKeybase.stylize(channel.Name)
fileNameStylized := config.Colors.Feed.File.stylize(filePath)
if err != nil {
printError(fmt.Sprintf("There was an error uploading %s to %s\n%+v", filePath, channel.Name, err))
} else {
printInfoF("Uploaded $TEXT to $TEXT", fileNameStylized, channelName)
}
}