small pixel drawing of a pufferfish neoarkbot

First version of intro
Jes Olson j3s@c3f.net
Sun, 20 Mar 2022 14:23:57 -0400
commit

90ae615d4c1ee1672e880e7968e456c7c7c0c2cb

parent

961c56d409c241b174b070b9450ff3c10fed7d73

1 files changed, 22 insertions(+), 1 deletions(-)

jump to
M main.gomain.go

@@ -10,6 +10,7 @@ "regexp"

"sort" "strconv" "strings" + "time" "github.com/kkdai/youtube/v2" "layeh.com/gumble/gumble"

@@ -42,6 +43,23 @@

fmt.Printf("audio player loaded! (%d files)\n", len(files)) }, + UserChange: func(e *gumble.UserChangeEvent) { + if e.Type.Has(gumble.UserChangeConnected) { + file := "intro-" + e.User.Name + if stream != nil && stream.State() == gumbleffmpeg.StatePlaying { + stream.Stop() + } + stream = gumbleffmpeg.New(e.Client, gumbleffmpeg.SourceFile(file)) + if err := stream.Play(); err != nil { + fmt.Printf("%s\n", err) + } else { + fmt.Printf("playing %s\n", file) + time.Sleep(1 * time.Second) + stream.Stop() + } + } + }, + TextMessage: func(e *gumble.TextMessageEvent) { if e.Sender == nil { return

@@ -80,6 +98,9 @@ // send list to sender

fmt.Println("listing") var keys []string for k, _ := range files { + if strings.HasPrefix(k, "intro-") { + continue + } if strings.HasPrefix(k, "s-") { continue }

@@ -101,7 +122,7 @@ if matched && strings.HasPrefix(e.Message, "!") {

m := regexp.MustCompile(`https:\/\/(www.)?youtube\.com\/watch\?v=[A-z_\-0-9]{11}`) videoUrl := m.FindString(e.Message) fmt.Println("downloading...") - fmt.Println("videoUrl: %s", videoUrl) + fmt.Println("videoUrl: ", videoUrl) // !rick=https://www.youtube.com/watch?v=dQw4w9WgXcQ // this is handled separately because of weird mumble HTML