~xenrox/twitch-bot

4e1d2a4c5611e8badaf1bdc4a196600eed252677 — Thorben Günther 1 year, 6 months ago ea8192e
bot: Check badges to see if a user is authorized
3 files changed, 9 insertions(+), 7 deletions(-)

M bot.go
M settings.go
M static_commands.go
M bot.go => bot.go +7 -0
@@ 1,6 1,7 @@
package main

import (
	"errors"
	"log"
	"os"



@@ 8,12 9,18 @@ import (
	"github.com/gempir/go-twitch-irc/v3"
)

var errNotAuthorized = errors.New("not authorized")

type bot struct {
	client *twitch.Client
	cfg    *config
	db     *database.DB
}

func (b *bot) isAuthorized(user *twitch.User) bool {
	return user.Badges["broadcaster"] == 1
}

func (b *bot) say(msg *twitch.PrivateMessage, text string) {
	useReply := b.cfg.Channels[msg.Channel].UseReply
	if useReply {

M settings.go => settings.go +1 -3
@@ 7,9 7,7 @@ import (
)

func (b *bot) handleSet(parsed []string, msg *twitch.PrivateMessage) error {
	// NOTE: Only allow mods or owner to use this
	// Wait for https://github.com/gempir/go-twitch-irc/pull/188 to get merged
	if msg.User.Name != msg.Channel {
	if !b.isAuthorized(&msg.User) {
		return errNotAuthorized
	}


M static_commands.go => static_commands.go +1 -4
@@ 9,13 9,10 @@ import (
	"github.com/gempir/go-twitch-irc/v3"
)

var errNotAuthorized = errors.New("not authorized")
var errTooShort = errors.New("input too short")

func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error {
	// NOTE: Only allow mods or owner to use this
	// Wait for https://github.com/gempir/go-twitch-irc/pull/188 to get merged
	if msg.User.Name != msg.Channel {
	if !b.isAuthorized(&msg.User) {
		return errNotAuthorized
	}