hopefully fix !vc
This commit is contained in:
parent
943e9fcaba
commit
ffae758587
@ -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 {
|
||||
|
@ -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…
Reference in New Issue
Block a user