discordBots/cmd/vcbot/event/event.go

65 lines
2.3 KiB
Go
Raw Permalink Normal View History

2023-03-08 20:39:42 +00:00
package event
import (
"fmt"
"github.com/disgoorg/disgo/events"
"grow.rievo.dev/discordBots/cmd/vcbot/helper"
"log"
2023-03-08 20:39:42 +00:00
)
func JoinEvent(event *events.GuildVoiceJoin) {
log.Println("DEBUG: JoinEvent")
2023-03-08 20:39:42 +00:00
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
}
log.Println("DEBUG: MoveEvent")
2023-03-08 20:39:42 +00:00
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) {
log.Println("DEBUG: LeaveEvent")
2023-03-08 20:39:42 +00:00
if event.OldVoiceState.ChannelID == nil {
log.Println("ERROR: OldVoiceState.ChannelID missing")
2023-03-08 20:39:42 +00:00
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)
}