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
99 lines (85 loc) · 2.34 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cmd
import (
"github.com/arrow2nd/ishell/v2"
"github.com/arrow2nd/twnyan/twitter"
"github.com/arrow2nd/twnyan/util"
)
func (cmd *Cmd) newUserCmd() *ishell.Cmd {
// user
userCmd := &ishell.Cmd{
Name: "user",
Aliases: []string{"ur"},
Func: cmd.execUserCmd,
Help: "displays the timeline of user",
LongHelp: createLongHelp(
`Displays the timeline of the specified user.
If number of acquisitions is omitted, the default value in the configuration file is specified.`,
"ur",
"user <username / tweet-number> [number]",
"user github 25\n user 2",
),
}
// use own
userCmd.AddCmd(&ishell.Cmd{
Name: "own",
Help: "display your own timeline",
LongHelp: createLongHelp(
`Display your own timeline.
If number of acquisitions is omitted, the default value in the configuration file is specified.`,
"",
"user own [number]",
"user own 25",
),
Func: func(c *ishell.Context) {
count := cmd.getCountFromCmdArg(c.Args)
cmd.showUserTimeline("", count)
},
})
return userCmd
}
func (cmd *Cmd) execUserCmd(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.twitter.GetDataFromTweetNum(screenName, twitter.ScreenName)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
}
cmd.showUserTimeline(screenName, count)
}
// showUserTimeline ユーザタイムラインを表示
func (cmd *Cmd) showUserTimeline(screenName, count string) {
query := twitter.CreateQuery(count)
query.Add("screen_name", screenName)
// ユーザのツイートを取得
tweets, err := cmd.twitter.FetchTimelineTweets(twitter.User, query)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
user := cmd.twitter.OwnUser
relationships := []string{}
if screenName != "" {
// ユーザ情報を取得
user, err = cmd.twitter.FetchUserInfo(screenName)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
// ユーザとの関係を取得
relationships, err = cmd.twitter.FetchRelationships(user.IdStr)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
}
cmd.twitter.RegisterTweets(tweets)
cmd.showTweets()
cmd.view.ShowUserInfo(user, relationships)
}