use discord CreateGuild instead of Ready
This commit is contained in:
parent
79f305cec1
commit
daacaaad50
@ -15,25 +15,15 @@ type DiscordListener struct {
|
|||||||
Bridge *BridgeState
|
Bridge *BridgeState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DiscordListener) ready(s *discordgo.Session, event *discordgo.Ready) {
|
func (l *DiscordListener) guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
|
||||||
log.Println("READY event registered")
|
log.Println("CREATE event registered")
|
||||||
|
|
||||||
//Setup initial discord state
|
if event.ID != l.Bridge.BridgeConfig.GID {
|
||||||
var g *discordgo.Guild
|
log.Println("received GuildCreate from a guild not in config")
|
||||||
g = nil
|
|
||||||
|
|
||||||
for _, i := range event.Guilds {
|
|
||||||
if i.ID == l.Bridge.BridgeConfig.GID {
|
|
||||||
g = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if g == nil {
|
|
||||||
log.Println("bad guild on READY")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, vs := range g.VoiceStates {
|
for _, vs := range event.VoiceStates {
|
||||||
if vs.ChannelID == l.Bridge.BridgeConfig.CID {
|
if vs.ChannelID == l.Bridge.BridgeConfig.CID {
|
||||||
if s.State.User.ID == vs.UserID {
|
if s.State.User.ID == vs.UserID {
|
||||||
// Ignore bot
|
// Ignore bot
|
||||||
@ -143,20 +133,6 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DiscordListener) guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
|
|
||||||
|
|
||||||
if event.Guild.Unavailable {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, channel := range event.Guild.Channels {
|
|
||||||
if channel.ID == event.Guild.ID {
|
|
||||||
log.Println("Mumble-Discord bridge is active in new guild")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *DiscordListener) voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
|
func (l *DiscordListener) voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
|
||||||
l.Bridge.DiscordUsersMutex.Lock()
|
l.Bridge.DiscordUsersMutex.Lock()
|
||||||
defer l.Bridge.DiscordUsersMutex.Unlock()
|
defer l.Bridge.DiscordUsersMutex.Unlock()
|
||||||
|
1
main.go
1
main.go
@ -144,7 +144,6 @@ func main() {
|
|||||||
Bridge.DiscordListener = &DiscordListener{
|
Bridge.DiscordListener = &DiscordListener{
|
||||||
Bridge: Bridge,
|
Bridge: Bridge,
|
||||||
}
|
}
|
||||||
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.ready)
|
|
||||||
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.messageCreate)
|
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.messageCreate)
|
||||||
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.guildCreate)
|
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.guildCreate)
|
||||||
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.voiceUpdate)
|
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.voiceUpdate)
|
||||||
|
Loading…
Reference in New Issue
Block a user