Example #1
0
        protected async Task <ITextChannel> FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string TopicType)
        {
            await WaitForUnlock().ConfigureAwait(false);

            channelname = channelname.ToLowerInvariant();
            channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
            DiscordLock = true;
            IReadOnlyCollection <ITextChannel> found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload);

            ITextChannel result = null;

            foreach (ITextChannel ITC in found_chans)
            {
                if (ITC.CategoryId == cat.Id)
                {
                    if (ITC.Name == channelname)
                    {
                        result = ITC;
                        break;
                    }
                }
            }
            if (result == null)
            {
                result = await CreateChannel(channelname, TopicType, sender.ToString()).ConfigureAwait(false);
            }
            else
            {
                await CleanDiscordChannel(result, 24).ConfigureAwait(false);
            }
            DiscordLock = false;
            return(result);
        }
Example #2
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);
                }
            }
        }