Added Default Dynamic Command Handlers & api calls

!countdown <duration>
!title <newTitle>
!game || !category
!uptime
This commit is contained in:
bryce
2025-07-08 16:12:36 +12:00
parent f16dc55ad8
commit bd8d2e404c
6 changed files with 281 additions and 11 deletions

View File

@@ -0,0 +1,71 @@
package chat
import (
"fmt"
"strings"
twitch "github.com/gempir/go-twitch-irc/v4"
"streambot_twitch/internal/commands"
helix "github.com/nicklaw5/helix"
)
func HandleTitleCategoryCommand(client *twitch.Client, apiClient inteface{}, message twitch.PrivateMessage, user twitch.User, msg string) {
api, ok := apiClient.(*helix.Client)
if !ok {
client.Say(channel, "Internal ERROR: Twitch API client not available.")
return
}
parts := strings.SplitN(msg, " ", 2)
cmd := strings.ToLower(parts[0])
switch cmd {
case "!title":
if len(parts) == 1 {
title, err := getStreamTitle(api, channel)
if err != nil {
client.Say(channel, fmt.Sprintf("@%s Error fetching title", user.DisplayName))
return
}
client.Say(channel, fmt.Sprintf("@%s current title: %s", user.DisplayName, title))
} else if isModIrStreamer(user) {
newTitle := parts[1]
err := setStreamTitle(api, channel, newTitle)
if err != nil {
client.Say(channel, fmt.Sprintf("@%s Failed to update title") user.DisplayName)
return
}
client.Say(channel, fmt.Sprintf("New Stream Title: %s", newTitle))
} else {
client.Say(channel, fmt.Sprintf("@%s You don't have permission to change the title", user.DisplayName))
}
case "!category", "!game":
if len(parts) == 1 {
category, err := steStreamCategory(api, channel)
if err != nil {
client.Say(channel, fmt.Sprintf("@%s Error fetching category", user.DisplayName))
return
}
client.Say(channel, fmt.Sprintf("@%s Current Category: %s", user.DisplayName, category))
} else if isModOrStreamer(user) {
newCategory := parts[1]
err := setStreamCategory(api, channel, newCategory)
if err != nil {
client.Say(channel, fmt.Sprintf("@%s Failed to update category", user.DisplayName))
return
}
client.Say(channel, fmt.Sprintf("New Stream Category: %s", newCategory))
}else {
client.Say(channel, fmt.Sprintf("@%s Tou don't have permission to change the category.", user.DisplayName))
}
}
}
// check mod/streamer status
func isModOrStreamer(user twitch.User) bool {
_, isBroadcaster := user.Badges["broadcaster"]
_, isMod := user.Badges["moderator"]
return isBroadcaster || isMod
}
// Twitch API helper functions in the twitchapi dir