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
95 lines (79 loc) · 2.15 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
package cmd
import (
"net/url"
"github.com/arrow2nd/ishell"
)
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.\nIf there is no tweet text, 'にゃーん' will be posted.\nIf you are submitting an image, please add the file name separated by a space.",
"rp",
"reply [<tweetnumber>] [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.\nEnter a semicolon to end the input.\nAnd if you want to cancel, input \":exit\".",
"ml",
"reply multi [<tweetnumber>]",
"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) {
// リプライ先のツイートIDを取得
tweetID, err := cmd.view.GetDataFromTweetNum(tweetNumStr, "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.api.PostTweet(query, status)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
cmd.showMessage("REPLYED", tweetText, cmd.cfg.Color.Reply)
}