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
/
reply.go
105 lines (88 loc) · 2.29 KB
/
reply.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
package cmd
import (
"net/url"
"github.com/arrow2nd/ishell/v2"
"github.com/arrow2nd/twnyan/twitter"
)
func (cmd *Cmd) newReplyCmd() *ishell.Cmd {
// reply
replyCmd := &ishell.Cmd{
Name: "reply",
Aliases: []string{"rp"},
Func: cmd.execReplyCmd,
Help: "post a reply",
LongHelp: createLongHelp(
`Post a reply.
If there is no tweet text, 'にゃーん' will be posted.
If you are submitting an image, please add the file name separated by a space.
(Only available in interactive mode)`,
"rp",
"reply <tweet-number> [text] [image]...",
"reply 2 meow cat.jpg",
),
}
// reply multi
replyCmd.AddCmd(&ishell.Cmd{
Name: "multi",
Aliases: []string{"ml"},
Func: cmd.execReplyMultiCmd,
Help: "post a multi-line reply",
LongHelp: createLongHelp(
`Post a multi-line reply.
Enter a semicolon to end the input.
And if you want to cancel, input ":exit".`,
"ml",
"reply multi <tweet-number> [image]...",
"reply multi 2",
),
})
return replyCmd
}
func (cmd *Cmd) execReplyCmd(c *ishell.Context) {
if len(c.Args) < 1 {
cmd.showWrongArgMessage(c.Cmd.Name)
return
}
status, files := cmd.parseTweetCmdArgs(c.Args[1:])
cmd.execReply(c.Args[0], status, files)
}
func (cmd *Cmd) execReplyMultiCmd(c *ishell.Context) {
if len(c.Args) < 1 {
cmd.showWrongArgMessage("reply " + c.Cmd.Name)
return
}
// 添付画像を取得
_, images := cmd.parseTweetCmdArgs(c.Args[1:])
text := cmd.inputMultiLine()
if text == "" {
return
}
cmd.execReply(c.Args[0], text, images)
}
func (cmd *Cmd) execReply(tweetNumStr, status string, files []string) {
if cmd.checkCommandLineMode() {
return
}
// リプライ先のツイートIDを取得
tweetId, err := cmd.twitter.GetDataFromTweetNum(tweetNumStr, twitter.TweetId)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
// リプライ先を設定
query := url.Values{}
query.Add("in_reply_to_status_id", tweetId)
query.Add("auto_populate_reply_metadata", "true")
// 画像をアップロード
if err := cmd.upload(files, &query); err != nil {
cmd.showErrorMessage(err.Error())
return
}
// リプライを投稿
tweetText, err := cmd.twitter.PostTweet(query, status)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
cmd.showMessage("REPLYED", tweetText, cmd.config.Color.Reply)
}