updates from testing
This commit is contained in:
74
README.md
74
README.md
@@ -1,12 +1,14 @@
|
||||
# bolt
|
||||
|
||||
look into using retries and context's
|
||||
TODO
|
||||
pre-1. Break up msg handler method its insane
|
||||
1. Read through code and ensure I didn't miss anything
|
||||
2. do research on intents for 'admin' jobs
|
||||
3. comments and README updates, things have changed
|
||||
4. determine adjustments to timeouts and contexts and const vs options for it
|
||||
5. Figure out why the exiting printing is going after terminal exit
|
||||
|
||||
also add mentioned users to struct so the ban functions can use them
|
||||
|
||||
also do we move towards message handler or focus on command handling, this will dictate the structure going forward with the bans, etc.
|
||||
started on msg handler but it doesn't make sense, the Adding of the handlers won't work with messages since the trigger is always blank. Might need a catch all one, but then
|
||||
that blacklists a command trigger, hmmmm
|
||||
---
|
||||
|
||||
The nuts-and-bolts of Discord bots. Bolt is a wrapper for [discordgo](https://github.com/bwmarrin/discordgo) that provides quick and easy bootstrapping for simple Discord bots.
|
||||
|
||||
@@ -62,60 +64,62 @@ The Delete method will delete the message from the text channel
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.jakeyoungdev.com/jake/bolt"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//bolt defaults the command indicator to '.' however that can be changed with the options
|
||||
//Example: bolt.New(bolt.WithIndicator('!')) would support commands like !ping
|
||||
b, err := bolt.New(bolt.WithLogLevel(bolt.LogLevelCmd))
|
||||
b, err := bolt.New(bolt.WithLogLevel(bolt.LogLevelAll),
|
||||
bolt.WithMaxGoroutines(50),
|
||||
bolt.WithPermissions(bolt.MessagePermissions, bolt.AdminPermissions))
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
b.AddCommands(
|
||||
// basic ping pong command, .ping can be run at anytime by anyone and will reply "pong"
|
||||
bolt.Command{
|
||||
Trigger: "ping",
|
||||
Payload: func(msg bolt.Message) error {
|
||||
return msg.Respond("pong")
|
||||
Trigger: "test",
|
||||
Payload: func(msg *bolt.Message, admin bolt.AdminToolBox) error {
|
||||
return msg.Respond("hi")
|
||||
},
|
||||
},
|
||||
// .react will add a +1 reaction to the command message, .react can be run by anyone at any rate
|
||||
bolt.Command{
|
||||
Trigger: "react",
|
||||
Payload: func(msg bolt.Message) error {
|
||||
return msg.React(bolt.ReactionThumbsUp)
|
||||
Trigger: "timeout",
|
||||
Payload: func(msg *bolt.Message, tools bolt.AdminToolBox) error {
|
||||
if len(msg.Mentions) > 0 {
|
||||
err := tools.Timeout(msg.Mentions[0].ID, msg.ServerID, time.Now().Add(time.Minute*5))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return msg.Respond("done")
|
||||
},
|
||||
},
|
||||
// .time responds with the current date/time, .time can be run once every 25 seconds by any role
|
||||
bolt.Command{
|
||||
Trigger: "time",
|
||||
Payload: func(msg bolt.Message) error {
|
||||
return msg.Respond(time.Now().String())
|
||||
},
|
||||
Timeout: time.Second * 25,
|
||||
},
|
||||
// .role command can be ran every 10 seconds by anyone with the admin role and will return the string "admin"
|
||||
bolt.Command{
|
||||
Trigger: "role",
|
||||
Payload: func(msg bolt.Message) error {
|
||||
return msg.Respond("admin")
|
||||
},
|
||||
Timeout: time.Second * 10,
|
||||
Roles: []string{"admin"},
|
||||
Roles: []string{"admin"},
|
||||
},
|
||||
)
|
||||
|
||||
//start is a blocking call that handles safe-shutdown, all configuration and setup should be done before calling Start()
|
||||
b.AddMessageHandler(func(msg *bolt.Message, tools bolt.AdminToolBox) error {
|
||||
if strings.Contains(msg.Content, "swear word") {
|
||||
return tools.Timeout(msg.Author.ID, msg.ServerID, time.Now().Add(time.Hour*1))
|
||||
}
|
||||
|
||||
if msg.Content == "im a menace in VC" {
|
||||
return tools.Mute(msg.Author.ID, msg.ServerID)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
err = b.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Reference in New Issue
Block a user