Browse Source

hopefully fix !vc

master
kageru 3 years ago
parent
commit
ffae758587
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
  1. 6
      helpers.go
  2. 27
      voicechannel.go

6
helpers.go

@ -56,9 +56,9 @@ func isAdmin(u *discordgo.User) bool {
return false
}
func getServer() *discordgo.Guild {
server, _ := state.Guild(config.ServerID)
return server
func getServer() (*discordgo.Guild, error) {
server, err := state.Guild(config.ServerID)
return server, err
}
func remove(channels []*discordgo.Channel, position int) []*discordgo.Channel {

27
voicechannel.go

@ -46,22 +46,27 @@ func parseVoiceChannelCommand(session *discordgo.Session, message *discordgo.Mes
func checkAndDeleteUnusedChannels(session *discordgo.Session) {
for true {
time.Sleep(15 * time.Second)
for i, channel := range tempChannels {
if channelIsEmpty(channel.ID) {
session.ChannelDelete(channel.ID)
tempChannels = remove(tempChannels, i)
log.Printf("Deleted channel %s", channel.ID)
log.Printf("Tempchannels: %d", len(tempChannels))
break
time.Sleep(30 * time.Second)
server, err := getServer()
if err == nil {
for i, channel := range tempChannels {
if channelIsEmpty(channel.ID, server.VoiceStates) {
session.ChannelDelete(channel.ID)
tempChannels = remove(tempChannels, i)
log.Printf("Deleted channel %s", channel.ID)
log.Printf("Tempchannels: %d", len(tempChannels))
break
}
}
} else {
log.Printf("Could not retrieve voice state from API, %s", err)
}
}
}
func channelIsEmpty(channelID string) bool {
for _, voiceState := range getServer().VoiceStates {
if channelID == voiceState.ChannelID {
func channelIsEmpty(channelID string, voiceStates []*discordgo.VoiceState) bool {
for _, state := range voiceStates {
if channelID == state.ChannelID {
return false
}
}

Loading…
Cancel
Save