Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meyskens/discord-ha
DiscordHA is library to deploy Discord bots in high availability.
https://github.com/meyskens/discord-ha
discord discord-bot discordgo high-availability
Last synced: 3 months ago
JSON representation
DiscordHA is library to deploy Discord bots in high availability.
- Host: GitHub
- URL: https://github.com/meyskens/discord-ha
- Owner: meyskens
- License: mit
- Created: 2021-01-03T12:56:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-05T17:57:23.000Z (about 1 year ago)
- Last Synced: 2024-06-20T19:27:35.626Z (7 months ago)
- Topics: discord, discord-bot, discordgo, high-availability
- Language: Go
- Homepage:
- Size: 176 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DiscordHA (Discord High Availability)
DiscordHA is library on to be used together with [discordgo](https://github.com/bwmarrin/discordgo) to deploy Discord bots in high availability.
This will allow deploying Discord bots with zero-downtime and without the risk of handling events twice. DiscordHA is designed to run in a [Kubernetes](https://kubernetes.io/) environment with multiple replica's available.
It relies on [Etcd](https://etcd.io/) as a locking system to prevent events of being received twice, this works in a first locked principle for timestamped events (e.g. messages), and a leader election system for non-timestamped events (e.g. reactions).DiscordHA is not meant for sharding but enables Discord bots to have multiple replicas watching the same guilds (servers).
## Example
```go
func main(){
dg, err := discordgo.New("Bot " + os.Getenv("BOT_TOKEN"))
if err != nil {
fmt.Prinf("error creating Discord session: %v\n", err)
return
}haLogger := log.New(os.Stderr, "discordha: ", log.Ldate|log.Ltime)
ha, err := discordha.New(&discordha.Config{
Session: dg,
HA: true, // set to false to run 1 replica for debugging, this disables locking and caching
EtcdEndpoints: []string{"etcd-bob.etcd.svc.cluster.local:2379"},
Context: context.TODO(),
Log: *haLogger,
})
if err != nil {
fmt.Prinf("error creating Discord HA: %v\n", err)
return
}
defer s.ha.Stop()
// using AddHandler on discordha will handle it on one replica
ha.AddHandler(func(sess *discordgo.Session, m *discordgo.MessageCreate) {
fmt.Printf("Received Message: %q", m.Message.Content)
})
err = dg.Open()
if err != nil {
fmt.Prinf("error opening connectio: %v\n", err)
return
}
defer dg.Close()log.Println("DiscordHA Example is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}
```## Used by
- [Thomas Bot](https://github.com/itfactory-tm/thomas-bot)## Roadmap
- [ ] Add support for sharded event listeners
- [ ] Improve the voice system
- [ ] Improve locking system for events
- [ ] Facilitate Etcd over HTTPS
- [ ] Add e2e testing