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