|
|
|
@ -12,6 +12,7 @@ import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
|
|
"git.lalonde.me/matth/AltVRBot/pkg/discord/mux"
|
|
|
|
"git.lalonde.me/matth/AltVRBot/pkg/discord/mux"
|
|
|
|
|
|
|
|
"git.lalonde.me/matth/AltVRBot/pkg/utils"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,6 +28,10 @@ type Discord struct {
|
|
|
|
User *discordgo.User
|
|
|
|
User *discordgo.User
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
allowedChannelTypes = []discordgo.ChannelType{discordgo.ChannelTypeGuildText, discordgo.ChannelTypeDM, discordgo.ChannelTypeGroupDM}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// New instanciates a new discord bot
|
|
|
|
// New instanciates a new discord bot
|
|
|
|
func New(token, sID, cID string) (*Discord, error) {
|
|
|
|
func New(token, sID, cID string) (*Discord, error) {
|
|
|
|
dg := &Discord{
|
|
|
|
dg := &Discord{
|
|
|
|
@ -49,6 +54,15 @@ func New(token, sID, cID string) (*Discord, error) {
|
|
|
|
|
|
|
|
|
|
|
|
dg.Session = session
|
|
|
|
dg.Session = session
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c, err := dg.Session.Channel(cID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Fatalf("Invalid channel ID: %+v\n", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !utils.SliceContainsChannelType(allowedChannelTypes, c.Type) {
|
|
|
|
|
|
|
|
log.Fatalf("Cannot join channel, invalid channel type")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dg.addHandlers()
|
|
|
|
dg.addHandlers()
|
|
|
|
|
|
|
|
|
|
|
|
// Open a websocket connection to Discord
|
|
|
|
// Open a websocket connection to Discord
|
|
|
|
|