Skip to content

codemicro/dgo-toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dgo-toolkit

A DiscordGo command parser and toolkit

License Go Reference

OSS Lifecycle Lines of code Go Report Card


toolkit is a collection of modules to ease the process of creating a Discord bot using Golang and the DiscordGo package. It provides command parsing and routing capabilities, reaction handler groups and other conveniences.

Example (routing)

session, _ := discordgo.New("Bot " + "<your token>")

kit := route.NewKit(session, []string{"*"})

kit.AddCommand(&route.Command{
    Name:        "Hello",
    Help:        "Say hello to someone",
    CommandText: []string{"hello"},
    Arguments: []route.Argument{
        {
            Name: "name",
            Type: route.String,
            Default: func(_ *discordgo.Session, message *discordgo.MessageCreate) (interface{}, error) {
                return message.Author.Username, nil
            },
        },
    },
    Restrictions: nil,
    Run: func(ctx *route.MessageContext) error {
        name := ctx.Arguments["name"].(string)
        _, err := ctx.Session.ChannelMessageSend(ctx.Message.ChannelID, "Hi there "+name)
        if err != nil {
            return err
        }
        return nil
    },
})

kit.AddReaction(&route.Reaction{
    Name:  "Add notifier",
    Run: func(ctx *route.ReactionContext) error {
        fmt.Printf("ADD: %+v\n", ctx.Reaction)
        return nil
    },
    Event: route.ReactionAdd,
})

kit.CreateHandlers()

_ = session.Open()

Aims

  • Simple, easy to use
  • No dependencies except DiscordGo

TODO

  • Unified response type that can be returned from a function (or maybe is included as a pointer in Ctx?)