hopefully fix !vc

This commit is contained in:
kageru 2019-06-08 05:31:06 +02:00
parent 943e9fcaba
commit ffae758587
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 19 additions and 14 deletions

@ -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
}
}