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

Commit

Permalink
Merge pull request #8 from KeisukeToyota/feature/reply-function
Browse files Browse the repository at this point in the history
リプライ機能
  • Loading branch information
ksk001100 committed Jan 11, 2019
2 parents 163a78d + 580bd10 commit 20701ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
43 changes: 28 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"net/url"
"os"
"os/user"
Expand Down Expand Up @@ -52,29 +51,26 @@ func main() {
Name: "image, img",
Usage: "toyotter2 tweet [text] --image=[imagePath]",
},
cli.StringFlag{
Name: "reply, rep",
Usage: "toyotter2 tweet [text] --reply=[tweetID]",
},
},
Action: func(c *cli.Context) error {
text := c.Args().First()
if len(c.String("image")) > 0 {
fmt.Println(c.String("image"))
media := twitter.UploadMedia(api, c.String("image"))
v.Set("media_ids", media.MediaIDString)
}
twitter.Tweet(api, text, v)

if len(c.String("reply")) > 0 {
tweetID, _ := strconv.ParseInt(c.String("reply"), 10, 64)
twitter.Reply(api, text, tweetID, v)
} else {
twitter.Tweet(api, text, v)
}
return nil
},
Subcommands: []cli.Command{
{
Name: "delete",
Aliases: []string{"d"},
Usage: "toyotter2 tweet delete [tweetID]",
Action: func(c *cli.Context) error {
tweetID, _ := strconv.ParseInt(c.Args().First(), 10, 64)
twitter.DeleteTweet(api, tweetID)
return nil
},
},
},
},
{
Name: "timeline",
Expand Down Expand Up @@ -204,6 +200,23 @@ func main() {
return nil
},
},
{
Name: "delete",
Aliases: []string{"del", "d"},
Usage: "toyotter2 delete [command] [text]",
Subcommands: []cli.Command{
{
Name: "tweet",
Aliases: []string{"tw"},
Usage: "toyotter2 delete tweet [tweetID]",
Action: func(c *cli.Context) error {
tweetID, _ := strconv.ParseInt(c.Args().First(), 10, 64)
twitter.DeleteTweet(api, tweetID)
return nil
},
},
},
},
// {
// Name: "dm",
// Usage: "toyotter2 dm [screenName] [text]",
Expand Down
19 changes: 19 additions & 0 deletions twitter/tweet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package twitter
import (
"fmt"
"net/url"
"strconv"

"github.com/ChimeraCoder/anaconda"
"github.com/KeisukeToyota/toyotter2/modules"
Expand All @@ -29,3 +30,21 @@ func DeleteTweet(api *anaconda.TwitterApi, tweetID int64) {

fmt.Println(modules.GetFormatTweet(tweet))
}

// Reply リプライ
func Reply(api *anaconda.TwitterApi, text string, tweetID int64, v url.Values) {
v.Set("in_reply_to_status_id", strconv.FormatInt(tweetID, 10))

tweet, err := api.GetTweet(tweetID, url.Values{})
if err != nil {
modules.ErrorMessage("ツイートが見つからないよ")
}

replayUserName := "@" + tweet.User.ScreenName + " "
replayTweet, replyErr := api.PostTweet(replayUserName+text, v)
if replyErr != nil {
modules.ErrorMessage("リプライに失敗したよ")
}

fmt.Println(modules.GetFormatTweet(replayTweet))
}

0 comments on commit 20701ea

Please sign in to comment.