decoupling start and shutdown
- start is no longer a blocking call - giving it back to users - the Stop method now waits for the timeout before closing
This commit is contained in:
@@ -12,6 +12,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -21,20 +23,20 @@ import (
|
||||
|
||||
/*
|
||||
A basic example of a bot with two commands and a general message handler for non-command messages. The bot uses a
|
||||
verbose log level which will log everything for debugging purposes, and registers Discord Intents for message and
|
||||
admin related permissions. This allows the bot to parse messages, send them, delete them, etc. as well as timeout
|
||||
verbose log level which will log everything for debugging purposes, and registers Discord Intents for message and
|
||||
admin related permissions. This allows the bot to parse messages, send them, delete them, etc. as well as timeout
|
||||
and mute users.
|
||||
|
||||
This example registers three commands:
|
||||
|
||||
1. .ping - a basic ping/pong command that can be run by anyone at any time
|
||||
2. .wait - a dummy command that replies "okay" it can only be run by users with the "user" role and can only be ran
|
||||
2. .wait - a dummy command that replies "okay" it can only be run by users with the "user" role and can only be ran
|
||||
once every 25 seconds
|
||||
3. .timeout - a admin command that can only be run by users with an "admin" role, this command will timeout any mentioned
|
||||
3. .timeout - a admin command that can only be run by users with an "admin" role, this command will timeout any mentioned
|
||||
users for 5 minutes
|
||||
|
||||
A message handler is also registered in this example, message handlers are used to handle messages that do not contain a
|
||||
command. This enables auto-moderation from the bot without manual intervention. The example message handler does two arbitrary
|
||||
A message handler is also registered in this example, message handlers are used to handle messages that do not contain a
|
||||
command. This enables auto-moderation from the bot without manual intervention. The example message handler does two arbitrary
|
||||
things to demo functionality:
|
||||
|
||||
1. Checks the message content for the phrase "swear word" and, if found, times the user out for 5 minutes
|
||||
@@ -43,7 +45,6 @@ things to demo functionality:
|
||||
|
||||
func main() {
|
||||
b, err := bolt.New()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -99,8 +100,16 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
qc := make(chan os.Signal, 1)
|
||||
signal.Notify(qc, os.Interrupt)
|
||||
<-qc
|
||||
|
||||
err = b.Stop()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Reference in New Issue
Block a user