hopefully fix !vc
This commit is contained in:
parent
943e9fcaba
commit
ffae758587
|
@ -56,9 +56,9 @@ func isAdmin(u *discordgo.User) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServer() *discordgo.Guild {
|
func getServer() (*discordgo.Guild, error) {
|
||||||
server, _ := state.Guild(config.ServerID)
|
server, err := state.Guild(config.ServerID)
|
||||||
return server
|
return server, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove(channels []*discordgo.Channel, position int) []*discordgo.Channel {
|
func remove(channels []*discordgo.Channel, position int) []*discordgo.Channel {
|
||||||
|
|
|
@ -46,22 +46,27 @@ func parseVoiceChannelCommand(session *discordgo.Session, message *discordgo.Mes
|
||||||
|
|
||||||
func checkAndDeleteUnusedChannels(session *discordgo.Session) {
|
func checkAndDeleteUnusedChannels(session *discordgo.Session) {
|
||||||
for true {
|
for true {
|
||||||
time.Sleep(15 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
for i, channel := range tempChannels {
|
server, err := getServer()
|
||||||
if channelIsEmpty(channel.ID) {
|
if err == nil {
|
||||||
session.ChannelDelete(channel.ID)
|
for i, channel := range tempChannels {
|
||||||
tempChannels = remove(tempChannels, i)
|
if channelIsEmpty(channel.ID, server.VoiceStates) {
|
||||||
log.Printf("Deleted channel %s", channel.ID)
|
session.ChannelDelete(channel.ID)
|
||||||
log.Printf("Tempchannels: %d", len(tempChannels))
|
tempChannels = remove(tempChannels, i)
|
||||||
break
|
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 {
|
func channelIsEmpty(channelID string, voiceStates []*discordgo.VoiceState) bool {
|
||||||
for _, voiceState := range getServer().VoiceStates {
|
for _, state := range voiceStates {
|
||||||
if channelID == voiceState.ChannelID {
|
if channelID == state.ChannelID {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user