This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
85 lines (74 loc) · 2.09 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cmd
import (
"github.com/arrow2nd/ishell"
"github.com/arrow2nd/twnyan/api"
"github.com/arrow2nd/twnyan/util"
)
func (cmd *Cmd) addUserCmd() {
// user
userCmd := &ishell.Cmd{
Name: "user",
Aliases: []string{"ur"},
Func: cmd.userCmd,
Help: "get a user timeline",
LongHelp: createLongHelp(
"Get a user timeline.\nIf you omit the counts, the default value in the configuration file (25 by default) will be specified.",
"ur",
"user [<username/tweetnumber>] [counts]",
"user github 25\n user 2",
),
}
// use own
userCmd.AddCmd(&ishell.Cmd{
Name: "own",
Help: "get your own timeline",
LongHelp: createLongHelp(
"Get your own timeline.\nIf you omit the counts, the default value in the configuration file (25 by default) will be specified.",
"",
"user own [counts]",
"user own 25",
),
Func: func(c *ishell.Context) {
count := cmd.getCountFromCmdArg(c.Args)
cmd.showUserTimeline("", count)
},
})
cmd.shell.AddCmd(userCmd)
}
func (cmd *Cmd) userCmd(c *ishell.Context) {
screenName, count, err := cmd.parseTimelineCmdArgs(c.Args)
if err != nil {
cmd.showWrongArgMessage(c.Cmd.Name)
return
}
// ツイート番号ならスクリーンネームに置換
if util.IsThreeDigitsNumber(screenName) {
screenName, err = cmd.view.GetDataFromTweetNum(screenName, "screenName")
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
}
cmd.showUserTimeline(screenName, count)
}
// showUserTimeline ユーザータイムラインを表示
func (cmd *Cmd) showUserTimeline(screenName, count string) {
query := api.CreateQuery(count)
query.Add("screen_name", screenName)
// ユーザーのツイートを取得
tweets, err := cmd.api.FetchTimelineTweets("user", query)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
// ユーザーとの関係を取得
user := (*tweets)[0].User
relationships, err := cmd.api.FetchRelationships(user.IdStr)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
cmd.view.RegisterTweets(tweets)
cmd.view.ShowRegisteredTweets()
cmd.view.ShowUserInfo(&user, relationships)
}