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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ksk001100 committed Dec 24, 2019
2 parents 63e215d + fdc618e commit ed2d914
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 47 deletions.
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ builds:
- main: main.go
binary: toyotter
goos:
- windows
- darwin
- linux
goarch:
Expand All @@ -32,7 +31,6 @@ archive:
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
Expand Down
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
language: go

go:
- "1.11.4"
- "1.13.4"
env:
- GO111MODULE=on

install:
- go mod download
- go get -u github.com/goreleaser/goreleaser

deploy:
- provider: script
skip_cleanup: true
script: bash goreleaser.sh
on:
tags: true
condition: $TRAVIS_OS_NAME = linux
after_success:
- goreleaser

notifications:
email:
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ $ 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
```shell
$ toyotter timeline #=> Get timeline(Get 5 by default)
$ toyotter timeline #=> Get timeline(Get 5 by default)
$ toyotter timeline --count 30 #=> Get 30 timelines
$ toyotter tl -c=20 #=> Get 20 timelines
$ toyotter timeline --list 38594385458 #=> Get list timesline of 38594385458(Get 5 by default)
$ toyotter tl -li=38594385458 #=> Get list timesline of 38594385458(Get 5 by default)
$ toyotter tl --list=38594385458 --count 10 #=> Get 10 list timeline of 38594385458
```

### Search
Expand Down Expand Up @@ -110,6 +115,12 @@ $ toyotter mute TwitterJP --delete #=> UnMute @TwitterJP
$ toyotter mu TwitterJP -d #=> UnMute @TwitterJP
```

### List
```shell
$ toyotter list #=> Get lists
$ toyotter li #=> Get lists
```

### Help
```shell
$ toyotter --help #=> Overall help
Expand Down
37 changes: 37 additions & 0 deletions commands/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

import (
"net/url"

"github.com/ChimeraCoder/anaconda"
"github.com/KeisukeToyota/toyotter/twitter"
"github.com/urfave/cli"
)

// ListCommand list command function
func ListCommand(a *anaconda.TwitterApi, val url.Values) cli.Command {
api = a
v = val
return cli.Command{
Name: "list",
Aliases: []string{"li"},
Usage: "toyotter list [...option]",
Flags: listFlags(),
Action: listAction,
}
}

func listFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "count c",
Value: "10",
Usage: "toyotter list --count=[count]",
},
}
}

func listAction(c *cli.Context) error {
twitter.Lists(api, v)
return nil
}
13 changes: 12 additions & 1 deletion commands/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"net/url"
"strconv"

"github.com/ChimeraCoder/anaconda"
"github.com/KeisukeToyota/toyotter/twitter"
Expand All @@ -28,11 +29,21 @@ func timelineFlags() []cli.Flag {
Value: "5",
Usage: "toyotter timeline --count=[count]",
},
cli.StringFlag{
Name: "list, li",
Usage: "toyotter timeline --list=[listID]",
},
}
}

func timelineAction(c *cli.Context) error {
v.Set("count", c.String("count"))
twitter.HomeTimeline(api, v)

if len(c.String("list")) > 0 {
listID, _ := strconv.ParseInt(c.String("list"), 10, 64)
twitter.ListTimeline(api, listID, v)
} else {
twitter.HomeTimeline(api, v)
}
return nil
}
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: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ require (
github.com/urfave/cli v1.20.0
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529
)

go 1.13
34 changes: 0 additions & 34 deletions goreleaser.sh

This file was deleted.

3 changes: 2 additions & 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.3.5"
app.Version = "0.5.3"
app.Commands = []cli.Command{
commands.TweetCommand(api, v),
commands.TimelineCommand(api, v),
Expand All @@ -57,6 +57,7 @@ func main() {
commands.BlockCommand(api, v),
commands.MentionCommand(api, v),
commands.MuteCommand(api, v),
commands.ListCommand(api, v),
}

err := app.Run(os.Args)
Expand Down
35 changes: 35 additions & 0 deletions modules/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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)),
SeparatorString(),
)
}
Expand All @@ -34,6 +35,18 @@ func GetFormatUser(user anaconda.User) string {
)
}

// GetFormatList format list information function
func GetFormatList(list anaconda.List) string {
return fmt.Sprintf(getFormatListTemplate(),
aurora.Red(list.Id),
aurora.Blue(list.Name),
aurora.Red(list.Description),
aurora.Yellow(list.MemberCount),
aurora.Green(GetListURL(list)),
SeparatorString(),
)
}

// ErrorMessage error message function
func ErrorMessage(text string) {
log.Fatal(aurora.Red(text))
Expand All @@ -45,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 All @@ -63,6 +86,7 @@ func getFormatTweetTemplate() string {
%s
[TweetID : %s]
[URL : %s]
%s`
}
Expand All @@ -76,3 +100,14 @@ func getFormatUserTemplate() string {
%s`
}

func getFormatListTemplate() string {
return `
[ID : %d]
[Name : %s]
[Description : %s]
[Member count : %d]
[URL : %s]
%s`
}
23 changes: 23 additions & 0 deletions twitter/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package twitter

import (
"fmt"
"net/url"

"github.com/ChimeraCoder/anaconda"
"github.com/KeisukeToyota/toyotter/modules"
)

// Lists lists function
func Lists(api *anaconda.TwitterApi, v url.Values) {
user, _ := api.GetSelf(v)
lists, err := api.GetListsOwnedBy(user.Id, v)

if err != nil {
modules.ErrorMessage("Get lists failed")
}

for _, list := range lists {
fmt.Println(modules.GetFormatList(list))
}
}
13 changes: 13 additions & 0 deletions twitter/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ func HomeTimeline(api *anaconda.TwitterApi, v url.Values) {
fmt.Println(modules.GetFormatTweet(tweet))
}
}

// ListTimeline List timeline function
func ListTimeline(api *anaconda.TwitterApi, listID int64, v url.Values) {
tweets, err := api.GetListTweets(listID, false, v)

if err != nil {
modules.ErrorMessage("Get list timeline failed")
}

for _, tweet := range tweets {
fmt.Println(modules.GetFormatTweet(tweet))
}
}
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 ed2d914

Please sign in to comment.