This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (70 loc) · 1.81 KB
/
main.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
package main
import (
"io/ioutil"
"net/url"
"os"
"os/user"
"github.com/ChimeraCoder/anaconda"
"github.com/joho/godotenv"
"github.com/ksk001100/toyotter/commands"
"github.com/ksk001100/toyotter/modules"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh/terminal"
)
func loadEnv() {
u, err := user.Current()
if err != nil {
panic(err)
}
err = godotenv.Load(u.HomeDir + "/.env.toyotter")
if err != nil {
modules.ErrorMessage("Not found ~/.env.toyotter")
}
}
func getTwitterAPI() *anaconda.TwitterApi {
anaconda.SetConsumerKey(os.Getenv("CONSUMER_KEY"))
anaconda.SetConsumerSecret(os.Getenv("CONSUMER_SECRET"))
return anaconda.NewTwitterApi(os.Getenv("ACCESS_TOKEN"), os.Getenv("ACCESS_TOKEN_SECRET"))
}
func main() {
loadEnv()
api := getTwitterAPI()
v := url.Values{}
name := "toyotter"
tweetCommand := commands.TweetCommand(api, v)
timelineCommand := commands.TimelineCommand(api, v)
searchCommand := commands.SearchCommand(api, v)
retweetCommand := commands.RetweetCommand(api, v)
favoriteCommand := commands.FavoriteCommand(api, v)
followCommand := commands.FollowCommand(api, v)
blockCommand := commands.BlockCommand(api, v)
mentionCommand := commands.MentionCommand(api, v)
muteCommand := commands.MuteCommand(api, v)
listCommand := commands.ListCommand(api, v)
app := &cli.App{
Name: name,
Usage: "CUI based Twitter client made with Golang",
Version: "0.5.7",
Commands: []*cli.Command{
&tweetCommand,
&timelineCommand,
&searchCommand,
&retweetCommand,
&favoriteCommand,
&followCommand,
&blockCommand,
&mentionCommand,
&muteCommand,
&listCommand,
},
}
args := os.Args
if !terminal.IsTerminal(0) {
b, _ := ioutil.ReadAll(os.Stdin)
args = append(args, string(b))
}
err := app.Run(args)
if err != nil {
modules.ErrorMessage("Crash...")
}
}