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
2 changed files with 47 additions and 6 deletions
|
@ -119,6 +119,15 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
case "frankerfacez":
|
||||
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":
|
||||
reply = commands.DuckDuckGo(message.Message[6:len(message.Message)])
|
||||
|
||||
|
@ -187,10 +196,16 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
reply, _ = commands.Xkcd()
|
||||
|
||||
case "uid":
|
||||
reply, _ = app.getChannelID(cmdParams[1])
|
||||
reply, _ = app.getUserID(cmdParams[1])
|
||||
|
||||
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":
|
||||
reply = app.ListChannelCommands(message.Channel)
|
||||
|
@ -525,6 +540,13 @@ var helpText = map[string]command{
|
|||
Level: "0",
|
||||
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": {
|
||||
Name: "godocs",
|
||||
Alias: nil,
|
||||
|
@ -682,7 +704,7 @@ var helpText = map[string]command{
|
|||
"title": {
|
||||
Name: "title",
|
||||
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",
|
||||
Usage: "()title [name]",
|
||||
},
|
||||
|
@ -714,6 +736,13 @@ var helpText = map[string]command{
|
|||
Level: "0",
|
||||
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": {
|
||||
Name: "wa",
|
||||
Alias: []string{"wa", "query"},
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"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{
|
||||
Logins: []string{username},
|
||||
})
|
||||
|
@ -16,6 +16,18 @@ func (app *application) getChannelID(username string) (string, error) {
|
|||
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 {
|
||||
resp, err := app.HelixClient.GetChannelInformation(&helix.GetChannelInformationParams{
|
||||
BroadcasterID: channelID,
|
||||
|
@ -29,7 +41,7 @@ func (app *application) getChannelTitle(channelID string) string {
|
|||
}
|
||||
|
||||
func (app *application) getChannelTitleByUsername(username string) string {
|
||||
channelID, err := app.getChannelID(username)
|
||||
channelID, err := app.getUserID(username)
|
||||
if err != nil {
|
||||
app.Log.Error(err)
|
||||
return "Something went wrong FeelsBadMan"
|
||||
|
@ -52,7 +64,7 @@ func (app *application) getChannelGame(channelId string) string {
|
|||
}
|
||||
|
||||
func (app *application) getChannelGameByUsername(username string) string {
|
||||
channelID, err := app.getChannelID(username)
|
||||
channelID, err := app.getUserID(username)
|
||||
if err != nil {
|
||||
app.Log.Error(err)
|
||||
return "Something went wrong FeelsBadMan"
|
||||
|
|
Loading…
Reference in a new issue