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
/
quote.go
93 lines (77 loc) · 2.08 KB
/
quote.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
package cmd
import (
"net/url"
"github.com/arrow2nd/ishell"
)
func (cmd *Cmd) newQuoteCmd() *ishell.Cmd {
// quote
quoteCmd := &ishell.Cmd{
Name: "quote",
Aliases: []string{"qt"},
Func: cmd.execQuoteCmd,
Help: "quote a tweet",
LongHelp: createLongHelp(
"Quote 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.",
"qt",
"quote [<tweetnumber>] [text] [image]...",
"quote 0 cute!! cat.png",
),
}
// quote multi
quoteCmd.AddCmd(&ishell.Cmd{
Name: "multi",
Aliases: []string{"ml"},
Func: cmd.execQuoteMultiCmd,
Help: "post a multi-line quote tweet",
LongHelp: createLongHelp(
"Post a multi-line quote tweet.\nEnter a semicolon to end the input.\nAnd if you want to cancel, input \":exit\".",
"ml",
"quote multi [<tweetnumber>] [images]...",
"quote multi 0 apple.png",
),
})
return quoteCmd
}
func (cmd *Cmd) execQuoteCmd(c *ishell.Context) {
if len(c.Args) < 1 {
cmd.showWrongArgMessage(c.Cmd.Name)
return
}
status, files := cmd.parseTweetCmdArgs(c.Args[1:])
cmd.execQuote(c.Args[0], status, files)
}
func (cmd *Cmd) execQuoteMultiCmd(c *ishell.Context) {
if len(c.Args) < 1 {
cmd.showWrongArgMessage("quote " + c.Cmd.Name)
return
}
// 添付画像を取得
_, images := cmd.parseTweetCmdArgs(c.Args[1:])
text := cmd.inputMultiLine()
if text == "" {
return
}
cmd.execQuote(c.Args[0], text, images)
}
func (cmd *Cmd) execQuote(tweetNumStr, text string, images []string) {
query := url.Values{}
// 引用するツイートのURLを取得
tweetUrl, err := cmd.view.GetTweetURL(tweetNumStr)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
// 画像をアップロード
if err := cmd.upload(images, &query); err != nil {
cmd.showErrorMessage(err.Error())
return
}
// URLを追加してツイート
text += " " + tweetUrl
tweetText, err := cmd.api.PostTweet(query, text)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
cmd.showMessage("QUOTED", tweetText, cmd.cfg.Color.Retweet)
}