mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add game command that returns current game for a provided twitch channel
This commit is contained in:
parent
f45b141cc3
commit
4bfc29c1b6
|
@ -119,6 +119,15 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
||||||
case "frankerfacez":
|
case "frankerfacez":
|
||||||
reply = commands.Ffz(cmdParams[1])
|
reply = commands.Ffz(cmdParams[1])
|
||||||
|
|
||||||
|
case "game":
|
||||||
|
if msgLen == 1 {
|
||||||
|
reply = app.getChannelGameByUsername(target)
|
||||||
|
} else if msgLen == 2 {
|
||||||
|
reply = app.getChannelGameByUsername(cmdParams[1])
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
case "ddg":
|
case "ddg":
|
||||||
reply = commands.DuckDuckGo(message.Message[6:len(message.Message)])
|
reply = commands.DuckDuckGo(message.Message[6:len(message.Message)])
|
||||||
|
|
||||||
|
@ -187,10 +196,16 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
||||||
reply, _ = commands.Xkcd()
|
reply, _ = commands.Xkcd()
|
||||||
|
|
||||||
case "uid":
|
case "uid":
|
||||||
reply, _ = app.getChannelID(cmdParams[1])
|
reply, _ = app.getUserID(cmdParams[1])
|
||||||
|
|
||||||
case "userid":
|
case "userid":
|
||||||
reply, _ = app.getChannelID(cmdParams[1])
|
reply, _ = app.getUserID(cmdParams[1])
|
||||||
|
|
||||||
|
case "uname":
|
||||||
|
reply, _ = app.getChannelUsername(cmdParams[1])
|
||||||
|
|
||||||
|
case "username":
|
||||||
|
reply, _ = app.getChannelUsername(cmdParams[1])
|
||||||
|
|
||||||
case "commands":
|
case "commands":
|
||||||
reply = app.ListChannelCommands(message.Channel)
|
reply = app.ListChannelCommands(message.Channel)
|
||||||
|
@ -525,6 +540,13 @@ var helpText = map[string]command{
|
||||||
Level: "0",
|
Level: "0",
|
||||||
Usage: "()followage <channel> <username>",
|
Usage: "()followage <channel> <username>",
|
||||||
},
|
},
|
||||||
|
"game": {
|
||||||
|
Name: "game",
|
||||||
|
Alias: nil,
|
||||||
|
Description: "Returns the currenct game Twitch channel. If no channel is provided will default to the channel the message was sent from.",
|
||||||
|
Level: "0",
|
||||||
|
Usage: "()game [channel]",
|
||||||
|
},
|
||||||
"godocs": {
|
"godocs": {
|
||||||
Name: "godocs",
|
Name: "godocs",
|
||||||
Alias: nil,
|
Alias: nil,
|
||||||
|
@ -682,7 +704,7 @@ var helpText = map[string]command{
|
||||||
"title": {
|
"title": {
|
||||||
Name: "title",
|
Name: "title",
|
||||||
Alias: nil,
|
Alias: nil,
|
||||||
Description: "Returns the title of a Twitch channel.",
|
Description: "Returns the title of a Twitch channel. If no channel is provided will default to the channel the message was sent from.",
|
||||||
Level: "0",
|
Level: "0",
|
||||||
Usage: "()title [name]",
|
Usage: "()title [name]",
|
||||||
},
|
},
|
||||||
|
@ -714,6 +736,13 @@ var helpText = map[string]command{
|
||||||
Level: "0",
|
Level: "0",
|
||||||
Usage: "()uid <username>",
|
Usage: "()uid <username>",
|
||||||
},
|
},
|
||||||
|
"username": {
|
||||||
|
Name: "username",
|
||||||
|
Alias: []string{"username", "uname"},
|
||||||
|
Description: "Returns the Twitch login name for a given Twitch user ID.",
|
||||||
|
Level: "0",
|
||||||
|
Usage: "()username <userID>",
|
||||||
|
},
|
||||||
"wa": {
|
"wa": {
|
||||||
Name: "wa",
|
Name: "wa",
|
||||||
Alias: []string{"wa", "query"},
|
Alias: []string{"wa", "query"},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"github.com/nicklaw5/helix/v2"
|
"github.com/nicklaw5/helix/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *application) getChannelID(username string) (string, error) {
|
func (app *application) getUserID(username string) (string, error) {
|
||||||
resp, err := app.HelixClient.GetUsers(&helix.UsersParams{
|
resp, err := app.HelixClient.GetUsers(&helix.UsersParams{
|
||||||
Logins: []string{username},
|
Logins: []string{username},
|
||||||
})
|
})
|
||||||
|
@ -16,6 +16,18 @@ func (app *application) getChannelID(username string) (string, error) {
|
||||||
return resp.Data.Users[0].ID, nil
|
return resp.Data.Users[0].ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *application) getChannelUsername(channelID string) (string, error) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func (app *application) getChannelTitle(channelID string) string {
|
func (app *application) getChannelTitle(channelID string) string {
|
||||||
resp, err := app.HelixClient.GetChannelInformation(&helix.GetChannelInformationParams{
|
resp, err := app.HelixClient.GetChannelInformation(&helix.GetChannelInformationParams{
|
||||||
BroadcasterID: channelID,
|
BroadcasterID: channelID,
|
||||||
|
@ -29,7 +41,7 @@ func (app *application) getChannelTitle(channelID string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) getChannelTitleByUsername(username string) string {
|
func (app *application) getChannelTitleByUsername(username string) string {
|
||||||
channelID, err := app.getChannelID(username)
|
channelID, err := app.getUserID(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log.Error(err)
|
app.Log.Error(err)
|
||||||
return "Something went wrong FeelsBadMan"
|
return "Something went wrong FeelsBadMan"
|
||||||
|
@ -52,7 +64,7 @@ func (app *application) getChannelGame(channelId string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) getChannelGameByUsername(username string) string {
|
func (app *application) getChannelGameByUsername(username string) string {
|
||||||
channelID, err := app.getChannelID(username)
|
channelID, err := app.getUserID(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log.Error(err)
|
app.Log.Error(err)
|
||||||
return "Something went wrong FeelsBadMan"
|
return "Something went wrong FeelsBadMan"
|
||||||
|
|
Loading…
Reference in a new issue