Welcome to Ops Bot III, or as the cool kids like to call it, OBIII! š
OBIII is the third iteration of Ops Bot. You can find the previous version, Ops Bot II (OBII), on the RITSEC Gitlab here. The original is closed-source for your own safety š.
OBIII is a Discord bot specifically built for RITSEC and its Discord server. As such, much of the code is purpose-built for RITSEC. If you plan to implement OBIII outside of RITSEC, significant code refactoring may be required.
OBIII shares many of the same goals as OBII:
We want OBIII to grow as the needs of its users do. We strive to make it a project that is not only easy to contribute to but also one that people want to contribute to!
OBIII is licensed under the Apache License 2.0.
config.yml
Make a copy of config_example.yml and name it config.yml
:
cp config_example.yml config.yml
Instructions for setting up a general bot can be found everywhere, so we won't rehash it here. You can refer to the Discord.py documentation for guidance.
config.yml
under token
.config.yml
under app_id
.config.yml
under guild_id
.You need to add the IDs of the channels where you want the bot to log.
config.yml
under logging.[level]_channel
respectively.config.yml
under logging.level
.config.yml
under logging.log_file
.All other configurations will depend on what you wish to run within your bot.
In the file commands/enabled.go, you can enable and disable all the functionality of OBIII by commenting out the respective lines.
OBIII is divided into three types of events it can handle: slash
, handlers
, and scheduled
.
Once one of these events is created, it can be enabled in commands/enabled.go.
These events correspond to different ways a function can be triggered:
Slashes are application commands triggered when you press /
in a Discord message box.
To configure a new slash command, create a new file under commands/slash/. Use the following template:
package slash
import (
"github.com/bwmarrin/discordgo"
)
func [Name]() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *discordgo.InteractionCreate)) {
return &discordgo.ApplicationCommand{
Name: [Name],
Description: [Description],
DefaultMemberPermissions: [Permission],
},
func(s *discordgo.Session, i *discordgo.InteractionCreate) {
[code]
}
}
Handlers act as hooks. They execute based on specific actions, defined by the parameters that the function takes.
To configure a new handler, create a new file under commands/handlers/
Handlers can respond to various events such as a user joining or leaving, a message being sent, deleted, or edited, and more.
A full set of handlers can be found here
package handlers
import (
"github.com/bwmarrin/discordgo"
)
func [Name](s *discordgo.Session, m *discordgo.[event]) {
[code]
}
Scheduled events run once when the bot starts and manage scheduling tasks on their own.
To configure a new scheduled event, create a new file under commands/scheduled/
There are two main examples that can be used:
Cron events run on a schedule or at specific times defined by a cron expression.
package scheduled
import (
"time"
"github.com/bwmarrin/discordgo"
"github.com/robfig/cron"
)
func [Name](s *discordgo.Session, quit chan interface{}) error {
est, _ := time.LoadLocation([location])
c := cron.NewWithLocation(est)
c.AddFunc([cron expression], func() { [function] })
c.Start()
<-quit
c.Stop()
return nil
}
Continuous events are scheduled on a ticker and execute at regular intervals.
package scheduled
import (
"time"
"github.com/bwmarrin/discordgo"
)
func Heartbeat() *structs.ScheduledEvent {
return structs.NewScheduledTask(
func(s *discordgo.Session, quit chan interface{}) error {
ticker := time.NewTicker([interval])
for {
select {
case <-quit:
return nil
case <-ticker.C:
[code]
}
}
},
)
}
With this information, you have the context needed to understand, contribute to, and deploy OBIII.
Good luck and godspeed!