diff --git a/main.go b/main.go index d6cea3c..a56b734 100644 --- a/main.go +++ b/main.go @@ -183,6 +183,26 @@ func main() { return nil }, }, + { + Name: "block", + Aliases: []string{"blk"}, + Usage: "toyotter2 block [screenName]", + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "delete, d", + Usage: "toyotter2 block [screenName] --delete", + }, + }, + Action: func(c *cli.Context) error { + screenName := c.Args().First() + if c.Bool("delete") { + twitter.UnBlock(api, screenName, v) + } else { + twitter.Block(api, screenName, v) + } + return nil + }, + }, // { // Name: "dm", // Usage: "toyotter2 dm [screenName] [text]", diff --git a/twitter/block.go b/twitter/block.go new file mode 100644 index 0000000..80ab31c --- /dev/null +++ b/twitter/block.go @@ -0,0 +1,31 @@ +package twitter + +import ( + "fmt" + "net/url" + + "github.com/ChimeraCoder/anaconda" + "github.com/KeisukeToyota/toyotter2/modules" +) + +// Block ブロック +func Block(api *anaconda.TwitterApi, screenName string, v url.Values) { + user, err := api.BlockUser(screenName, v) + + if err != nil { + modules.ErrorMessage("ブロックに失敗したよ") + } + + fmt.Println(modules.GetFormatUser(user)) +} + +// UnBlock ブロック解除 +func UnBlock(api *anaconda.TwitterApi, screenName string, v url.Values) { + user, err := api.UnblockUser(screenName, v) + + if err != nil { + modules.ErrorMessage("ブロック解除に失敗したよ") + } + + fmt.Println(modules.GetFormatUser(user)) +} diff --git a/twitter/follow.go b/twitter/follow.go index 04521c6..557138c 100644 --- a/twitter/follow.go +++ b/twitter/follow.go @@ -23,7 +23,7 @@ func UnFollow(api *anaconda.TwitterApi, screenName string) { user, err := api.UnfollowUser(screenName) if err != nil { - modules.ErrorMessage("フォローに失敗したよ") + modules.ErrorMessage("フォロー解除に失敗したよ") } fmt.Println(modules.GetFormatUser(user))