2024-02-29 19:32:43 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nicklaw5/helix/v2"
|
|
|
|
)
|
|
|
|
|
2024-02-29 21:17:39 +01:00
|
|
|
// getUserID returns the Twitch userID for given twitch username.
|
2024-02-29 19:56:36 +01:00
|
|
|
func (app *application) getUserID(username string) (string, error) {
|
2024-02-29 19:32:43 +01:00
|
|
|
resp, err := app.HelixClient.GetUsers(&helix.UsersParams{
|
|
|
|
Logins: []string{username},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
app.Log.Error(err)
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Data.Users[0].ID, nil
|
|
|
|
}
|
|
|
|
|
2024-02-29 21:17:39 +01:00
|
|
|
// userIDtoUsername returns the Twitch username for a given twitch user ID.
|
|
|
|
func (app *application) userIDtoUsername(channelID string) (string, error) {
|
2024-02-29 19:56:36 +01:00
|
|
|
resp, err := app.HelixClient.GetUsers(&helix.UsersParams{
|
|
|
|
IDs: []string{channelID},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
app.Log.Error(err)
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Data.Users[0].Login, nil
|
|
|
|
}
|
|
|
|
|
2024-02-29 21:17:39 +01:00
|
|
|
// getChannelTitle queries the Twitch API for the current Title for
|
|
|
|
// the provided Twitch channel username.
|
2024-02-29 19:32:43 +01:00
|
|
|
func (app *application) getChannelTitle(channelID string) string {
|
|
|
|
resp, err := app.HelixClient.GetChannelInformation(&helix.GetChannelInformationParams{
|
|
|
|
BroadcasterID: channelID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
app.Log.Error(err)
|
|
|
|
return "Something went wrong FeelsBadMan"
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Data.Channels[0].Title
|
|
|
|
}
|
|
|
|
|
2024-02-29 21:17:39 +01:00
|
|
|
// getChannelTitleByUsername returns the current title of the provided
|
|
|
|
// Twitch channel username.
|
2024-02-29 19:32:43 +01:00
|
|
|
func (app *application) getChannelTitleByUsername(username string) string {
|
2024-02-29 19:56:36 +01:00
|
|
|
channelID, err := app.getUserID(username)
|
2024-02-29 19:32:43 +01:00
|
|
|
if err != nil {
|
|
|
|
app.Log.Error(err)
|
|
|
|
return "Something went wrong FeelsBadMan"
|
|
|
|
}
|
|
|
|
|
|
|
|
reply := app.getChannelTitle(channelID)
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *application) getChannelGame(channelId string) string {
|
|
|
|
resp, err := app.HelixClient.GetChannelInformation(&helix.GetChannelInformationParams{
|
|
|
|
BroadcasterID: channelId,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
app.Log.Error(err)
|
|
|
|
return "Something went wrong FeelsBadMan"
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Data.Channels[0].GameName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *application) getChannelGameByUsername(username string) string {
|
2024-02-29 19:56:36 +01:00
|
|
|
channelID, err := app.getUserID(username)
|
2024-02-29 19:32:43 +01:00
|
|
|
if err != nil {
|
|
|
|
app.Log.Error(err)
|
|
|
|
return "Something went wrong FeelsBadMan"
|
|
|
|
}
|
|
|
|
|
|
|
|
reply := app.getChannelGame(channelID)
|
|
|
|
return reply
|
|
|
|
}
|
2024-05-16 22:20:11 +02:00
|
|
|
|
|
|
|
//func (app *application) sendWhisper(username, text string) {
|
|
|
|
// toID, err := app.getUserID(username)
|
|
|
|
// if err != nil {
|
|
|
|
// app.Log.Error(err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// resp, err := app.HelixClient.SendUserWhisper(&helix.SendUserWhisperParams{
|
|
|
|
// FromUserID: "mycoolid",
|
|
|
|
// ToUserID: toID,
|
|
|
|
// Message: text,
|
|
|
|
// })
|
|
|
|
// if err != nil {
|
|
|
|
// app.Log.Error(err)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// app.Log.Infof("%+v\n", resp)
|
|
|
|
//}
|