discordBots/cmd/vcbot/event/event.go
2023-03-08 21:39:42 +01:00

63 lines
2.3 KiB
Go

package event
import (
"fmt"
"github.com/disgoorg/disgo/events"
"grow.rievo.dev/discordBots/cmd/vcbot/helper"
)
func JoinEvent(event *events.GuildVoiceJoin) {
event.Client().Logger().Debug("JoinEvent")
channelId := *event.VoiceState.ChannelID
channel, _ := event.Client().Rest().GetChannel(channelId)
channelName := channel.Name()
userName := event.Member.EffectiveName()
userMention := event.Member.Mention()
message := fmt.Sprintf("**CHANNEL LOG:** %v joined %v", userName, channelName)
messageEdit := fmt.Sprintf("**CHANNEL LOG:** %v joined %v", userMention, channelName)
go helper.SendNoMention(event.Client(), message, messageEdit)
helper.UpdateVoiceChannels(event.Client(), false)
}
func MoveEvent(event *events.GuildVoiceMove) {
if event.OldVoiceState.ChannelID.String() == event.VoiceState.ChannelID.String() {
// no that's not a move event
return
}
event.Client().Logger().Debug("MoveEvent")
channelOldId := *event.OldVoiceState.ChannelID
channelOld, _ := event.Client().Rest().GetChannel(channelOldId)
channelOldName := channelOld.Name()
channelId := *event.VoiceState.ChannelID
channel, _ := event.Client().Rest().GetChannel(channelId)
channelName := channel.Name()
userName := event.Member.EffectiveName()
userMention := event.Member.Mention()
message := fmt.Sprintf("**CHANNEL LOG:** %v moved from %v to %v", userName, channelOldName, channelName)
messageEdit := fmt.Sprintf("**CHANNEL LOG:** %v moved from %v to %v", userMention, channelOldName, channelName)
go helper.SendNoMention(event.Client(), message, messageEdit)
helper.UpdateVoiceChannels(event.Client(), false)
}
func LeaveEvent(event *events.GuildVoiceLeave) {
event.Client().Logger().Debug("LeaveEvent")
if event.OldVoiceState.ChannelID == nil {
event.Client().Logger().Error("OldVoiceState.ChannelID missing")
return
}
channelOldId := *event.OldVoiceState.ChannelID
channelOld, _ := event.Client().Rest().GetChannel(channelOldId)
channelOldName := channelOld.Name()
userName := event.Member.EffectiveName()
userMention := event.Member.Mention()
message := fmt.Sprintf("**CHANNEL LOG:** %v left %v", userName, channelOldName)
messageEdit := fmt.Sprintf("**CHANNEL LOG:** %v left %v", userMention, channelOldName)
go helper.SendNoMention(event.Client(), message, messageEdit)
helper.UpdateVoiceChannels(event.Client(), true)
}