From 6a98372e893e202e03054d65f5980efe71bfe378 Mon Sep 17 00:00:00 2001 From: KeisukeToyota Date: Fri, 6 Dec 2019 11:52:17 +0900 Subject: [PATCH 1/3] Quote tweet function --- commands/tweet.go | 7 +++++++ modules/utils.go | 24 ++++++++++++------------ twitter/tweet.go | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/commands/tweet.go b/commands/tweet.go index 0524e78..ad48eca 100644 --- a/commands/tweet.go +++ b/commands/tweet.go @@ -36,6 +36,10 @@ func tweetFlags() []cli.Flag { Name: "delete, del, d", Usage: "toyotter tweet --delete=[tweetID]", }, + cli.StringFlag{ + Name: "quote, q", + Usage: "toyotter tweet [text] --quote=[tweetID]", + }, } } @@ -53,6 +57,9 @@ func tweetAction(c *cli.Context) error { if len(c.String("reply")) > 0 { tweetID, _ := strconv.ParseInt(c.String("reply"), 10, 64) twitter.Reply(api, text, tweetID, v) + } else if len(c.String("quote")) > 0 { + quoteTweetID, _ := strconv.ParseInt(c.String("quote"), 10, 64) + twitter.QuoteTweet(api, text, quoteTweetID, v) } else { twitter.Tweet(api, text, v) } diff --git a/modules/utils.go b/modules/utils.go index 69ee1f0..fb76670 100644 --- a/modules/utils.go +++ b/modules/utils.go @@ -20,7 +20,7 @@ func GetFormatTweet(tweet anaconda.Tweet) string { aurora.Green(tweet.User.ScreenName).String(), aurora.Red(tweet.User.IdStr).String(), aurora.Green(tweet.FavoriteCount).String(), aurora.Green(tweet.RetweetCount).String(), aurora.Bold(tweet.FullText).String(), aurora.Red(tweet.IdStr).String(), - aurora.Green(getTweetURL(tweet)), + aurora.Green(GetTweetURL(tweet)), SeparatorString(), ) } @@ -42,7 +42,7 @@ func GetFormatList(list anaconda.List) string { aurora.Blue(list.Name), aurora.Red(list.Description), aurora.Yellow(list.MemberCount), - aurora.Green(getListURL(list)), + aurora.Green(GetListURL(list)), SeparatorString(), ) } @@ -58,6 +58,16 @@ func SeparatorString() string { return strings.Repeat("-", width) } +// GetTweetURL get twwet url +func GetTweetURL(tweet anaconda.Tweet) string { + return fmt.Sprintf("https://twitter.com/%s/status/%s", tweet.User.ScreenName, tweet.IdStr) +} + +// GetListURL get list url +func GetListURL(list anaconda.List) string { + return fmt.Sprintf("https://twitter.com%s", list.URL) +} + func getJapanDateTimeString(t time.Time) string { japanTime, _ := time.LoadLocation("Asia/Tokyo") createdAt := t.In(japanTime) @@ -101,13 +111,3 @@ func getFormatListTemplate() string { %s` } - -func getTweetURL(tweet anaconda.Tweet) string { - return fmt.Sprintf("https://twitter.com/%s/status/%s", tweet.User.ScreenName, tweet.IdStr) -} - -func getListURL(list anaconda.List) string { - return fmt.Sprintf("https://twitter.com%s", list.URL) -} - - diff --git a/twitter/tweet.go b/twitter/tweet.go index 3b70e3a..b157edd 100644 --- a/twitter/tweet.go +++ b/twitter/tweet.go @@ -48,3 +48,17 @@ func Reply(api *anaconda.TwitterApi, text string, tweetID int64, v url.Values) { fmt.Println(modules.GetFormatTweet(replayTweet)) } + +// QuoteTweet quote tweet function +func QuoteTweet(api *anaconda.TwitterApi, text string, quoteTweetID int64, v url.Values) { + quoteTweet, err := api.GetTweet(quoteTweetID, url.Values{}) + + if err != nil { + modules.ErrorMessage("The tweet you quoted is not valid") + } + + quoteTweetURL := modules.GetTweetURL(quoteTweet) + quotedTweetText := fmt.Sprintf("%s\n%s", text, quoteTweetURL) + + Tweet(api, quotedTweetText, v) +} From f1b7e00b54be2be45e90106f5225bdbfaee9d640 Mon Sep 17 00:00:00 2001 From: KeisukeToyota Date: Fri, 6 Dec 2019 12:00:04 +0900 Subject: [PATCH 2/3] fix readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fa0e3d9..eb40ddd 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ $ toyotter tweet delete 34820348023 #=> Delete the 34820348023 tweet $ toyotter tw d 34820348023 #=> Delete the 34820348023 tweet $ toyotter tweet "Hi" --reply 34820348023 #=> Reply to tweet of 34820348023 $ toyotter tw "Bye" --reply 34820348023 #=> Reply to tweet of 34820348023 +$ toyotter tweet "Quote tweet" --quote 34820348023 #=> Quoted tweet of 34820348023 +$ toyotter tw "Quote tweet" -q 34820348023 #=> Quoted tweet of 34820348023 ``` ### Timeline From 583083dd19cb79c88195007d00512506ed36cee3 Mon Sep 17 00:00:00 2001 From: KeisukeToyota Date: Fri, 6 Dec 2019 12:03:13 +0900 Subject: [PATCH 3/3] v0.5.0 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index d8a79c9..bee927c 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,7 @@ func main() { |___/` app.Usage = "" - app.Version = "0.4.0" + app.Version = "0.5.0" app.Commands = []cli.Command{ commands.TweetCommand(api, v), commands.TimelineCommand(api, v),