public static async Task <DiscordChannel> GetArchiveChannel(DiscordGuild guild) { //Create a new registry, if one doesn't already exist. if (ArchiveChannelCategories == null) { ArchiveChannelCategories = new ConcurrentDictionary <ulong, DiscordChannel>(); } //Check to see if the registry does not contain the guild. if (!ArchiveChannelCategories.ContainsKey(guild.Id)) { IReadOnlyList <DiscordChannel> allDiscordChannels = await guild.GetChannelsAsync(); foreach (DiscordChannel channel in allDiscordChannels) { if (channel.Name == CrabgileConstants.CHANNEL_NAME_ARCHIVE) { //Channel exists in server, so add it to the registry and return it. ArchiveChannelCategories.TryAdd(guild.Id, channel); return(channel); } } //No channel at all, so it must be created and added to the registry. ArchiveChannelCategories.TryAdd(guild.Id, await guild.CreateChannelCategoryAsync(CrabgileConstants.CHANNEL_NAME_ARCHIVE)); } //Return registry channel. return(ArchiveChannelCategories[guild.Id]); }
public CrabgileMeeting(DiscordMember hostMember) { this.hostMember = hostMember; guild = hostMember.Guild; channels = new ConcurrentBag <DiscordChannel>(); if (!GuildMeetings.ContainsKey(guild.Id)) { GuildMeetings.TryAdd(guild.Id, new ConcurrentDictionary <ulong, CrabgileMeeting>()); } registrySuccess = GuildMeetings[guild.Id].TryAdd(hostMember.Id, this); if (registrySuccess) { Task.Run(async() => { meetingCategory = await guild.CreateChannelCategoryAsync($"::{hostMember.Id}::"); AddChannelToMeeting(meetingCategory); meetingTextChannel = await guild.CreateChannelAsync("meeting-chat", DSharpPlus.ChannelType.Text, meetingCategory, "A minuted text channel for the timebox meeting."); //AddChannelToMeeting(meetingTextChannel); //Don't add the channel to the bag, as it shouldn't get destroyed. }); } }