-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
135 lines (119 loc) · 2.97 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"fmt"
"github.com/mattn/go-colorable"
log "github.com/sirupsen/logrus"
lfm "github.com/twangodev/lfm-api"
"github.com/urfave/cli/v2"
"os"
"time"
)
const name = "lfm-cli"
const version = "v1.2.3"
const discordAppId = "970003417277812736"
// Flags
var username string
var refreshInterval int
var showProfile bool
var showLoved bool
var covers bool
var elapsed bool
var keepStatus bool
var debug bool
var profileUrl string
func exec(ctx *cli.Context) error {
showProfile = !ctx.Bool("hide-profile")
showLoved = ctx.Bool("show-loved")
covers = !ctx.Bool("rm-covers")
elapsed = !ctx.Bool("rm-time")
keepStatus = ctx.Bool("keep-status")
debug = ctx.Bool("debug")
if debug {
log.SetLevel(log.TraceLevel)
} else {
log.SetLevel(log.InfoLevel)
}
profileUrl = fmt.Sprintf("%vuser/%v", lfm.LastFmUrl, username)
log.WithFields(log.Fields{
"username": username,
"refresh_interval": refreshInterval,
"show_profile": showProfile,
"show_loved": showLoved,
"show_covers": covers,
"show_elapsed": elapsed,
"keep_status": keepStatus,
"debug_enabled": debug,
}).Infoln("Configuration loaded from arguments")
for {
log.Traceln("Cycle begin.")
cycle()
log.Traceln("Cycle complete.")
time.Sleep(time.Duration(refreshInterval) * time.Second)
}
}
func main() {
log.SetFormatter(&log.TextFormatter{ForceColors: true})
log.SetOutput(colorable.NewColorableStdout())
app := &cli.App{
Name: name,
Description: "Show your Last.FM scrobbles on Discord!",
Version: version,
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: "James Ding",
Email: "[email protected]",
},
},
Copyright: "(c) 2022 James Ding",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "user",
Aliases: []string{"u"},
Usage: "Display Last.FM scrobbles from `USERNAME`",
Required: true,
Destination: &username,
},
&cli.IntFlag{
Name: "refresh",
Aliases: []string{"r"},
Usage: "Checks Last.FM every `X` seconds for new scrobbles",
Value: 10,
Destination: &refreshInterval,
},
&cli.BoolFlag{
Name: "hide-profile",
Usage: "Removes buttons to the specified Last.FM profile",
},
&cli.BoolFlag{
Name: "show-loved",
Aliases: []string{"l"},
Usage: "Replaces the default smallImage key with a heart for loved songs.",
},
&cli.BoolFlag{
Name: "rm-covers",
Usage: "Does not show album cover images.",
},
&cli.BoolFlag{
Name: "rm-time",
Usage: "Does not show time elapsed for the scrobble.",
},
&cli.BoolFlag{
Name: "keep-status",
Usage: "Shows status even when there is no active scrobble.",
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Enable verbose and debug logging",
},
},
Action: func(context *cli.Context) error {
return exec(context)
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}