small pixel drawing of a pufferfish neoarkbot

Add intro feature, fix list bug, etc
Jes Olson j3s@c3f.net
Sun, 20 Mar 2022 15:17:01 -0400
commit

e6def66346a0287656559a71174a938bbaf457fa

parent

90ae615d4c1ee1672e880e7968e456c7c7c0c2cb

1 files changed, 56 insertions(+), 11 deletions(-)

jump to
M main.gomain.go

@@ -4,6 +4,7 @@ import (

"flag" "fmt" "io" + "log" "os" "path/filepath" "regexp"

@@ -30,7 +31,7 @@ }

gumbleutil.Main(gumbleutil.AutoBitrate, gumbleutil.Listener{ Connect: func(e *gumble.ConnectEvent) { - // hardcode access token cuz idgaf rn + // hardcode access token cuz idgaf e.Client.Config.Tokens = []string{"welcome"} e.Client.Send(e.Client.Config.Tokens)

@@ -44,8 +45,11 @@ fmt.Printf("audio player loaded! (%d files)\n", len(files))

}, UserChange: func(e *gumble.UserChangeEvent) { + fmt.Println("entered userchangeevent") if e.Type.Has(gumble.UserChangeConnected) { - file := "intro-" + e.User.Name + fmt.Println("entered userchangeconnected") + file := "sounds/intro-" + e.User.Name + fmt.Println(file) if stream != nil && stream.State() == gumbleffmpeg.StatePlaying { stream.Stop() }

@@ -54,7 +58,7 @@ if err := stream.Play(); err != nil {

fmt.Printf("%s\n", err) } else { fmt.Printf("playing %s\n", file) - time.Sleep(1 * time.Second) + time.Sleep(5 * time.Second) stream.Stop() } }

@@ -75,6 +79,40 @@ fmt.Println("stopping")

stream.Stop() return } + if e.Message == "!help" { + helpmsg := ` + # help + !help + # list sounds + list + # make youtube thing + !https://www.youtube.com/watch?v=dQw4w9WgXcQ > rickroll + # make personal intro + !intro rickroll` + e.Sender.Send(helpmsg) + } + if strings.HasPrefix(e.Message, "!intro ") { + introSelection := strings.Split(e.Message, " ")[1] + original, err := os.Open("sounds/" + introSelection) + if err != nil { + e.Sender.Send("sound not found: " + introSelection) + return + } + defer original.Close() + new, err := os.Create("sounds/" + "intro-" + e.Sender.Name) + if err != nil { + e.Sender.Send("error during creation check logs") + fmt.Println(err) + } + defer new.Close() + fmt.Println("intro src: " + original.Name()) + fmt.Println("intro dst: " + new.Name()) + _, err = io.Copy(new, original) + if err != nil { + log.Fatal(err) + } + e.Sender.Send("your intro has been set to " + introSelection) + } volmatched, err := regexp.MatchString(`^vol [0-9]+$`, e.Message) if err != nil { fmt.Printf("regex match blew up: %s", err)

@@ -87,13 +125,13 @@ vol64, _ := strconv.ParseFloat(vol, 32)

vol32 := float32(vol64) truevol := vol32 / 100.0 if vol32 > 100 { - e.Sender.Send("volume too high") + e.Sender.Send("volume too DAMN high") return } stream.Volume = truevol return } - if e.Message == "list" { + if e.Message == "list" || e.Message == "!list" { // send list to sender fmt.Println("listing") var keys []string

@@ -107,10 +145,18 @@ }

keys = append(keys, k) } sort.Strings(keys) - listone := strings.Join(keys[:200], "<br>") - listtwo := strings.Join(keys[201:], "<br>") - e.Sender.Send(listone) - e.Sender.Send(listtwo) + selectionScopeStart := 0 + selectionScopeEnd := 200 + for i := len(keys); i > 0; { + if selectionScopeEnd > len(keys) { + selectionScopeEnd = len(keys) + } + listThing := strings.Join(keys[selectionScopeStart:selectionScopeEnd], "<br>") + selectionScopeStart += 200 + selectionScopeEnd += 200 + e.Sender.Send(listThing) + i = i - 200 + } } var file string matched, err := regexp.MatchString(`https:\/\/(www.)?youtube\.com\/watch\?v=[A-z_\-0-9]{11}`, e.Message)

@@ -127,7 +173,7 @@

// !rick=https://www.youtube.com/watch?v=dQw4w9WgXcQ // this is handled separately because of weird mumble HTML // business - setcmd := regexp.MustCompile(` &gt; [a-z0-9]+`) + setcmd := regexp.MustCompile(` &gt; [a-z0-9-]+`) cmd := setcmd.FindString(e.Message) fmt.Println(e.Message) fmt.Println(cmd)

@@ -136,7 +182,6 @@ if cmd != "" {

splits := strings.Split(cmd, " ") // the name cmdname = "sounds/" + splits[2] - fmt.Println(cmdname) files[splits[2]] = cmdname }