Minor changes to the temporary voice channels

This commit is contained in:
kageru 2019-03-13 20:44:17 +01:00
parent c22f81d6cb
commit a99496377e
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/deckarep/golang-set"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -88,7 +89,7 @@ func addCommands() {
registerCommand(Command{Trigger: "!mods", Output: "Bei Fragen, Problemen und Beschwerden wende dich bitte an die Moderatoren oder schick mir eine Nachricht beginnend mit !complain, um dich anonym zu beschweren.\nAktuell anwesende Mods werden dir rechts mit dem Rang „Maid“ angezeigt.", Type: CommandTypeFullMatch}) registerCommand(Command{Trigger: "!mods", Output: "Bei Fragen, Problemen und Beschwerden wende dich bitte an die Moderatoren oder schick mir eine Nachricht beginnend mit !complain, um dich anonym zu beschweren.\nAktuell anwesende Mods werden dir rechts mit dem Rang „Maid“ angezeigt.", Type: CommandTypeFullMatch})
// Features :Pog: // Features :Pog:
registerCommand(Command{Trigger: "!vc ", Type: CommandTypePrefix, Function: parseVoiceChannelCommand}) registerCommand(Command{Trigger: "!vc ", Type: CommandTypePrefix, Function: parseVoiceChannelCommand, AllowedChannels: mapset.NewSetWith("525852491976278016")})
// Admin and/or debug // Admin and/or debug
registerCommand(Command{Trigger: "<@%s> <3", Output: "<@%s> <3", Type: CommandTypeFullMatch, AdminOnly: true, OutputIsReply: true, RequiresMention: true}) registerCommand(Command{Trigger: "<@%s> <3", Output: "<@%s> <3", Type: CommandTypeFullMatch, AdminOnly: true, OutputIsReply: true, RequiresMention: true})

View File

@ -19,7 +19,7 @@ func parseVoiceChannelCommand(session *discordgo.Session, message *discordgo.Mes
return return
} }
if userLimit > 99 { if userLimit > 99 {
session.ChannelMessageSend(message.ChannelID, fmt.Sprintf("Als ob %d Leute *mit dir* in einen Channel wollen", userLimit-1)) session.ChannelMessageSend(message.ChannelID, fmt.Sprintf("Als ob %d Leute *mit dir* in einen Channel wollen.", userLimit-1))
log.Printf("%s tried to create a channel with %d slots", userToString(message.Author), userLimit) log.Printf("%s tried to create a channel with %d slots", userToString(message.Author), userLimit)
return return
} }
@ -27,6 +27,7 @@ func parseVoiceChannelCommand(session *discordgo.Session, message *discordgo.Mes
Name: fmt.Sprintf("%s’s Volatile Corner", message.Author.Username), Name: fmt.Sprintf("%s’s Volatile Corner", message.Author.Username),
Type: discordgo.ChannelTypeGuildVoice, Type: discordgo.ChannelTypeGuildVoice,
UserLimit: userLimit, UserLimit: userLimit,
ParentID: "410162599762853909",
} }
channel, err := session.GuildChannelCreateComplex(message.GuildID, createData) channel, err := session.GuildChannelCreateComplex(message.GuildID, createData)
if err != nil { if err != nil {
@ -35,16 +36,23 @@ func parseVoiceChannelCommand(session *discordgo.Session, message *discordgo.Mes
return return
} }
tempChannels = append(tempChannels, channel) tempChannels = append(tempChannels, channel)
session.GuildMemberMove(config.ServerID, message.Author.ID, channel.ID) err = session.GuildMemberMove(config.ServerID, message.Author.ID, channel.ID)
if err != nil {
log.Printf("Couldn’t move user %s: %s", userToString(message.Author), err)
}
session.ChannelMessageSend(message.ChannelID, "haaaai~")
log.Printf("Created channel %s", channel.ID)
} }
func checkAndDeleteUnusedChannels(session *discordgo.Session) { func checkAndDeleteUnusedChannels(session *discordgo.Session) {
for true { for true {
time.Sleep(30 * time.Second) time.Sleep(15 * time.Second)
for i, channel := range tempChannels { for i, channel := range tempChannels {
if channelIsEmpty(channel.ID) { if channelIsEmpty(channel.ID) {
session.ChannelDelete(channel.ID) session.ChannelDelete(channel.ID)
tempChannels = remove(tempChannels, i) tempChannels = remove(tempChannels, i)
log.Printf("Deleted channel %s", channel.ID)
log.Printf("Tempchannels: %d", len(tempChannels))
break break
} }
} }