Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #38 from KeisukeToyota/develop
Browse files Browse the repository at this point in the history
release v0.5.0
  • Loading branch information
ksk001100 authored Dec 6, 2019
2 parents 6966c10 + 583083d commit eea009d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions commands/tweet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
},
}
}

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
24 changes: 12 additions & 12 deletions modules/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand All @@ -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(),
)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}


14 changes: 14 additions & 0 deletions twitter/tweet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit eea009d

Please sign in to comment.