This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.go
106 lines (96 loc) · 2.4 KB
/
tweet.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package cmd
import (
"net/url"
"github.com/arrow2nd/ishell"
)
func (cmd *Cmd) newTweetCmd() {
tc := &ishell.Cmd{
Name: "tweet",
Aliases: []string{"tw"},
Func: cmd.tweetCmd,
Help: "post a tweet",
LongHelp: createLongHelp(
"Post a tweet.\nIf there is no tweet text, 'にゃーん' will be posted.\nIf you are submitting an image, please add the file name separated by a space.",
"tw",
"tweet [text] [image]...",
"tweet meow🐱 cat.png supercat.jpg",
),
}
tc.AddCmd(&ishell.Cmd{
Name: "multi",
Aliases: []string{"ml"},
Func: cmd.tweetMultiCmd,
Help: "post a multi-line tweet",
LongHelp: createLongHelp(
"Post a multi-line tweet.\nEnter a semicolon to end the input.\nAlso, if it is blank, the tweet will be canceled.",
"ml",
"tweet multi",
"tweet multi",
),
})
tc.AddCmd(&ishell.Cmd{
Name: "remove",
Aliases: []string{"rm"},
Func: cmd.tweetRemoveCmd,
Help: "delete a tweet",
LongHelp: createLongHelp(
"Delete a tweet.\nIf there is more than one, please separate them with a space.",
"rm",
"tweet remove [<tweetnumber>]",
"tweet remove 0 1",
),
})
cmd.shell.AddCmd(tc)
}
func (cmd *Cmd) tweetCmd(c *ishell.Context) {
// 引数をパース
status, files := cmd.parseTweetCmdArgs(c.Args)
// ツイート
cmd.tweet(status, files)
}
func (cmd *Cmd) tweetMultiCmd(c *ishell.Context) {
// 入力
status, files := cmd.inputMultiLine()
if status == "" {
return
}
// ツイート
cmd.tweet(status, files)
}
func (cmd *Cmd) tweetRemoveCmd(c *ishell.Context) {
// 引数をチェック
if len(c.Args) <= 0 {
cmd.drawWrongArgMessage("tweet " + c.Cmd.Name)
return
}
// 引数の数だけ削除処理
for _, v := range c.Args {
id, err := cmd.view.GetDataFromTweetNum(v, "tweetID")
if err != nil {
cmd.drawErrorMessage(err.Error())
return
}
tweetStr, err := cmd.api.DeleteTweet(id)
if err != nil {
cmd.drawErrorMessage(err.Error())
return
}
cmd.drawMessage("DELETED", tweetStr, cmd.cfg.Color.Accent2)
}
}
func (cmd *Cmd) tweet(status string, files []string) {
val := url.Values{}
// 画像をアップロード
err := cmd.upload(files, &val)
if err != nil {
cmd.drawErrorMessage(err.Error())
return
}
// ツイート
tweetStr, err := cmd.api.PostTweet(val, status)
if err != nil {
cmd.drawErrorMessage(err.Error())
return
}
cmd.drawMessage("TWEETED", tweetStr, cmd.cfg.Color.Accent2)
}