~xenrox/twitch-bot

8d66c0498fa30a1cf7dac3e81782c1c4bbea57cb — Thorben Günther 8 months ago 2ac0af0
functions: Use slices package for sorting
2 files changed, 3 insertions(+), 13 deletions(-)

D functions.go
M static_commands.go
D functions.go => functions.go +0 -11
@@ 1,11 0,0 @@
package main

func sliceContains(s []string, e string) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}

	return false
}

M static_commands.go => static_commands.go +3 -2
@@ 4,6 4,7 @@ import (
	"database/sql"
	"errors"
	"fmt"
	"slices"
	"strings"

	"github.com/gempir/go-twitch-irc/v3"


@@ 66,7 67,7 @@ func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error 
			resp := strings.Join(parsed[3:], " ")

			// check if built-in commands use this name
			if sliceContains(faceitCommands(), name) {
			if slices.Contains(faceitCommands(), name) {
				b.say(msg, "Cannot override built-in command.")
				return nil
			}


@@ 90,7 91,7 @@ func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error 
		name := strings.TrimLeft(parsed[2], "!")

		// check if built-in commands use this name
		if sliceContains(faceitCommands(), name) {
		if slices.Contains(faceitCommands(), name) {
			b.say(msg, "Cannot delete built-in command.")
			return nil
		}