From d2fae31d1aa283577e8cfbf84797225e5c320efb Mon Sep 17 00:00:00 2001 From: r4 Date: Wed, 28 Jul 2021 17:30:01 +0200 Subject: [PATCH] add code --- TODO.md | 13 ++ args.go | 16 ++ commands.go | 512 ++++++++++++++++++++++++++++++++++++++++++++++ config.go | 45 ++++ dca0/dca0.go | 261 +++++++++++++++++++++++ dca0/pcm.go | 73 +++++++ go.mod | 8 + go.sum | 8 + main.go | 359 ++++++++++++++++++++++++++++++++ util/util.go | 15 ++ ytdl/error.go | 26 +++ ytdl/extractor.go | 165 +++++++++++++++ 12 files changed, 1501 insertions(+) create mode 100644 TODO.md create mode 100644 args.go create mode 100644 commands.go create mode 100644 config.go create mode 100644 dca0/dca0.go create mode 100644 dca0/pcm.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 util/util.go create mode 100644 ytdl/error.go create mode 100644 ytdl/extractor.go diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..bbdf430 --- /dev/null +++ b/TODO.md @@ -0,0 +1,13 @@ +# TODO + +- [ ] Improve code documentation. + +- [ ] Reduce the number of long, thin, cylindrical Italian pasta contained within the code. + +- [x] Implement the queue system. + +- [ ] Fix seek for larger durations; inform the user if the desired position hasn't been loaded yet. + +- [x] Add playlist support. + +- [ ] Receive playlist items gradually, making it so you don't have to wait until youtube-dl has retrieved the entire playlist. diff --git a/args.go b/args.go new file mode 100644 index 0000000..e1ca4f2 --- /dev/null +++ b/args.go @@ -0,0 +1,16 @@ +// Parses the commands sent through Discord. This program does not use any +// traditional command line options, as it uses config.json for configuration. +package main + +import ( + "strings" +) + +// Returns a false and a nil slice if cmd was not intended for the bot. +func CmdGetArgs(cmd string) (args []string, ok bool) { + if !strings.HasPrefix(cmd, cfg.Prefix) { + return nil, false + } + cmd = strings.TrimPrefix(cmd, cfg.Prefix) + return strings.Fields(cmd), true +} diff --git a/commands.go b/commands.go new file mode 100644 index 0000000..da9d2f3 --- /dev/null +++ b/commands.go @@ -0,0 +1,512 @@ +package main + +import ( + "fmt" + "math/rand" + "path" + "strconv" + "strings" + "time" + + "dcbot/dca0" + "dcbot/ytdl" + + "github.com/bwmarrin/discordgo" +) + +//////////////////////////////// +// Helper functions. +//////////////////////////////// +func generateHelpMsg() string { + // Align all commands nicely so that the descriptions are in the same + // column. + longestCmd := 0 + var cmds, descs []string + addCmd := func(cmd, desc string) { + if len(cmd) > longestCmd { + longestCmd = len(cmd) + } + cmds = append(cmds, cmd) + descs = append(descs, desc) + } + addCmd("help", "show this page") + addCmd("play ", "play audio from a URL or a youtube search query") + addCmd("play", "start playing queue/resume playback") + addCmd("seek