mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
initialize the helix client in a more elegant way
This commit is contained in:
parent
f5d6eca30c
commit
48e16c06a9
1 changed files with 24 additions and 22 deletions
|
@ -55,7 +55,7 @@ func main() {
|
||||||
log.Fatal("Error loading .env file")
|
log.Fatal("Error loading .env file")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Twitch
|
// Twitch config variables
|
||||||
cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
|
cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
|
||||||
cfg.twitchOauth = os.Getenv("TWITCH_OAUTH")
|
cfg.twitchOauth = os.Getenv("TWITCH_OAUTH")
|
||||||
cfg.twitchClientId = os.Getenv("TWITCH_CLIENT_ID")
|
cfg.twitchClientId = os.Getenv("TWITCH_CLIENT_ID")
|
||||||
|
@ -67,38 +67,43 @@ func main() {
|
||||||
// Will be used someday Copesen
|
// Will be used someday Copesen
|
||||||
cfg.environment = "Development"
|
cfg.environment = "Development"
|
||||||
|
|
||||||
// Database
|
// Database config variables
|
||||||
cfg.db.dsn = os.Getenv("DB_DSN")
|
cfg.db.dsn = os.Getenv("DB_DSN")
|
||||||
cfg.db.maxOpenConns = 25
|
cfg.db.maxOpenConns = 25
|
||||||
cfg.db.maxIdleConns = 25
|
cfg.db.maxIdleConns = 25
|
||||||
cfg.db.maxIdleTime = "15m"
|
cfg.db.maxIdleTime = "15m"
|
||||||
|
|
||||||
|
// Initialize a new Helix Client, request a new AppAccessToken
|
||||||
|
// and set the token on the client.
|
||||||
helixClient, err := helix.NewClient(&helix.Options{
|
helixClient, err := helix.NewClient(&helix.Options{
|
||||||
ClientID: cfg.twitchClientId,
|
ClientID: cfg.twitchClientId,
|
||||||
ClientSecret: cfg.twitchClientSecret,
|
ClientSecret: cfg.twitchClientSecret,
|
||||||
AppAccessToken: cfg.twitchAccessToken,
|
|
||||||
// ClientID: cfg.twitchClientId,
|
|
||||||
})
|
|
||||||
helixResp, err := helixClient.GetUsers(&helix.UsersParams{
|
|
||||||
IDs: []string{"596581605", "31437432"},
|
|
||||||
Logins: []string{"nourybot", "nourylul"},
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sugar.Errorw("Helix: Error getting user data",
|
sugar.Fatalw("Error creating new helix client",
|
||||||
"helixResp", helixResp,
|
"helixClient", helixClient,
|
||||||
"err", err,
|
"err", err,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helixResp, err := helixClient.RequestAppAccessToken([]string{"user:read:email"})
|
||||||
|
if err != nil {
|
||||||
|
sugar.Fatalw("Helix: Error getting new helix AppAcessToken",
|
||||||
|
"resp", helixResp,
|
||||||
|
"err", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the access token on the client
|
||||||
|
helixClient.SetAppAccessToken(helixResp.Data.AccessToken)
|
||||||
|
|
||||||
// Establish database connection
|
// Establish database connection
|
||||||
db, err := openDB(cfg)
|
db, err := openDB(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sugar.Fatal(err)
|
sugar.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//s := gocron.NewScheduler(time.UTC)
|
// Initialize Application with the new values
|
||||||
|
|
||||||
// Initialize Application
|
|
||||||
app := &Application{
|
app := &Application{
|
||||||
TwitchClient: tc,
|
TwitchClient: tc,
|
||||||
HelixClient: helixClient,
|
HelixClient: helixClient,
|
||||||
|
@ -110,12 +115,6 @@ func main() {
|
||||||
|
|
||||||
// Received a PrivateMessage (normal chat message).
|
// Received a PrivateMessage (normal chat message).
|
||||||
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
||||||
// app.Logger.Infow("Private Message received",
|
|
||||||
// // "message", message,
|
|
||||||
// "message.Channel", message.Channel,
|
|
||||||
// "message.User", message.User.DisplayName,
|
|
||||||
// "message.Message", message.Message,
|
|
||||||
// )
|
|
||||||
|
|
||||||
// roomId is the Twitch UserID of the channel the message originated from.
|
// roomId is the Twitch UserID of the channel the message originated from.
|
||||||
// If there is no roomId something went really wrong.
|
// If there is no roomId something went really wrong.
|
||||||
|
@ -129,7 +128,7 @@ func main() {
|
||||||
|
|
||||||
// Message was shorter than our prefix is therefore it's irrelevant for us.
|
// Message was shorter than our prefix is therefore it's irrelevant for us.
|
||||||
if len(message.Message) >= 2 {
|
if len(message.Message) >= 2 {
|
||||||
// This bots prefix is "()" configured above at `cfg.commandPrefix`,
|
// This bots prefix is "()" configured above at cfg.commandPrefix,
|
||||||
// Check if the first 2 characters of the mesage were our prefix.
|
// Check if the first 2 characters of the mesage were our prefix.
|
||||||
// if they were forward the message to the command handler.
|
// if they were forward the message to the command handler.
|
||||||
if message.Message[:2] == cfg.commandPrefix {
|
if message.Message[:2] == cfg.commandPrefix {
|
||||||
|
@ -167,7 +166,10 @@ func main() {
|
||||||
// Join the channels in the database.
|
// Join the channels in the database.
|
||||||
app.InitialJoin()
|
app.InitialJoin()
|
||||||
|
|
||||||
|
// Load the initial timers from the database.
|
||||||
app.InitialTimers()
|
app.InitialTimers()
|
||||||
|
|
||||||
|
// Start the timers.
|
||||||
app.Scheduler.Start()
|
app.Scheduler.Start()
|
||||||
|
|
||||||
common.Send("nourylul", "dankCircle", app.TwitchClient)
|
common.Send("nourylul", "dankCircle", app.TwitchClient)
|
||||||
|
|
Loading…
Reference in a new issue