Example #1
0
        protected async Task DiscordRebuildChannels()
        {
            List <string> required_cats = new List <string>()
            {
                "bot", "group", "im"
            };
            IReadOnlyCollection <ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);

            foreach (ICategoryChannel fcat in found_cats)
            {
                if (required_cats.Contains(fcat.Name) == true)
                {
                    required_cats.Remove(fcat.Name);
                    catmap.Add(fcat.Name, fcat);
                }
            }
            foreach (string A in required_cats)
            {
                ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);

                catmap.Add(A, newcat);
            }
            List <string> required_channels = new List <string>()
            {
                "status", "interface", "localchat"
            };
            IReadOnlyCollection <ITextChannel> found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload);

            List <string> GroupChannels = new List <string>();

            foreach (ITextChannel chan in found_chans)
            {
                if (chan.CategoryId == catmap["bot"].Id)
                {
                    required_channels.Remove(chan.Name);
                }
                else
                {
                    if (chan.CategoryId == catmap["group"].Id)
                    {
                        GroupChannels.Add(chan.Name);
                    }
                }
            }
            foreach (string A in required_channels)
            {
                _ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false);
            }
            foreach (Group G in mygroups.Values)
            {
                string groupname = G.Name.ToLowerInvariant();
                groupname = String.Concat(groupname.Where(char.IsLetterOrDigit));
                if (GroupChannels.Contains(groupname) == false)
                {
                    _ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false);
                }
            }
        }