Exemplo n.º 1
0
        /// <summary>
        /// Parses channels in the input string's matches.
        /// <para>Supports channel mentions, names, and IDs.</para>
        /// </summary>
        /// <returns>The parsed channels.</returns>
        public async Task <IReadOnlyCollection <SocketTextChannel> > ParseChannels()
        {
            IEnumerable <Task <SocketTextChannel> > tasks = _matches
                                                            .Where(m => m.Groups["action"].Value.Equals("submit", StringComparison.OrdinalIgnoreCase))
                                                            .Select(m => ChannelTypeReader <SocketTextChannel> .GetBestResultAsync(_context, m.Groups["value"].Value.Trim()));

            return((await Task.WhenAll(tasks)).ToImmutableArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserialises channels from the configuration file.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when a channel can't be found.</exception>
        /// <returns>No object or value is returned by this method when it completes.</returns>
        private async Task DeserialiseChannels()
        {
            SocketGuild guild = _client.Guilds.FirstOrDefault();

            LogChannel = await ParseChannel(RootSettings.program_settings.logChannel);

            GeneralChannel = await ParseChannel(RootSettings.general.welcomeChannel);

            async Task <SocketTextChannel> ParseChannel(string key)
            {
                SocketTextChannel channel = await ChannelTypeReader <SocketTextChannel> .GetBestResultAsync(guild, key);

                if (channel == null)
                {
                    throw new InvalidOperationException($"The value of key '{key}' could not be parsed as a channel.");
                }

                return(channel);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserialises channels from the configuration file.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when a channel can't be found.</exception>
        /// <returns>No object or value is returned by this method when it completes.</returns>
        private async Task DeserialiseChannels()
        {
            SocketGuild guild = _client.Guilds.FirstOrDefault();

            LogChannel = await ParseChannel("logChannel");

            AnnouncementChannel = await ParseChannel("announcementChannel");

            TestingChannel = await ParseChannel("testingChannel");

            GeneralChannel = await ParseChannel("generalChannel");

            async Task <SocketTextChannel> ParseChannel(string key)
            {
                SocketTextChannel channel = await ChannelTypeReader <SocketTextChannel> .GetBestResultAsync(guild, Config[key]);

                if (channel == null)
                {
                    throw new InvalidOperationException($"The value of key '{key}' could not be parsed as a channel.");
                }

                return(channel);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Deserialize channels from the configuration file.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when a channel can't be found.</exception>
        /// <returns>No object or value is returned by this method when it completes.</returns>
        private async Task DeserializeChannels()
        {
            Guild = _client.Guilds.FirstOrDefault();

            Console.ForegroundColor = LOG_COLOR;

            Console.WriteLine($"Active Guild: {Guild?.Name}\n");

            LevelTestVoiceChannel = Guild.GetVoiceChannel(RSettings.General.LevelTestingVoice);
            Console.WriteLine(
                $"LevelTestVoiceChannel ID:{LevelTestVoiceChannel.Id} Discovered Name:{LevelTestVoiceChannel.Name}");

            AfkVoice = Guild.GetVoiceChannel(RSettings.General.AfkVoice);
            Console.WriteLine(
                $"LevelTestVoiceChannel ID:{AfkVoice.Id} Discovered Name:{AfkVoice.Name}");

            LogChannel = await ParseChannel(RSettings.ProgramSettings.LogChannel);

            Console.WriteLine($"LogChannel ID:{LogChannel.Id} Discovered Name:{LogChannel.Name}");

            AdminChannel = await ParseChannel(RSettings.General.AdminChannel);

            Console.WriteLine($"AdminChannel ID:{AdminChannel.Id} Discovered Name:{AdminChannel.Name}");

            VoidChannel = await ParseChannel(RSettings.General.VoidChannel);

            Console.WriteLine($"VoidChannel ID:{VoidChannel.Id} Discovered Name:{VoidChannel.Name}");

            BotChannel = await ParseChannel(RSettings.General.BotChannel);

            Console.WriteLine($"BotChannel ID:{BotChannel.Id} Discovered Name:{BotChannel.Name}");

            AdminBotsChannel = await ParseChannel(RSettings.General.AdminBotsChannel);

            Console.WriteLine($"AdminBotChannel ID:{AdminBotsChannel.Id} Discovered Name:{AdminBotsChannel.Name}");

            GeneralChannel = await ParseChannel(RSettings.General.GeneralChannel);

            Console.WriteLine($"GeneralChannel ID:{GeneralChannel.Id} Discovered Name:{GeneralChannel.Name}");

            WelcomeChannel = await ParseChannel(RSettings.General.WelcomeChannel);

            Console.WriteLine($"WelcomeChannel ID:{WelcomeChannel.Id} Discovered Name:{WelcomeChannel.Name}");

            CSGOAnnouncementChannel = await ParseChannel(RSettings.General.CSGOAnnouncementChannel);

            Console.WriteLine(
                $"CSGO AnnouncementChannel ID:{CSGOAnnouncementChannel.Id} Discovered Name:{CSGOAnnouncementChannel.Name}");

            TF2AnnouncementChannel = await ParseChannel(RSettings.General.TF2AnnouncementChannel);

            Console.WriteLine(
                $"TF2 AnnouncementChannel ID:{TF2AnnouncementChannel.Id} Discovered Name:{TF2AnnouncementChannel.Name}");

            CSGOTestingChannel = await ParseChannel(RSettings.General.CSGOTestingChannel);

            Console.WriteLine(
                $"CSGO TestingChannel ID:{CSGOTestingChannel.Id} Discovered Name:{CSGOTestingChannel.Name}");

            TF2TestingChannel = await ParseChannel(RSettings.General.TF2TestingChannel);

            Console.WriteLine($"TF2 TestingChannel ID:{TF2TestingChannel.Id} Discovered Name:{TF2TestingChannel.Name}");

            WebhookChannel = await ParseChannel(RSettings.General.WebhookChannel);

            Console.WriteLine($"WebhookChannel ID:{WebhookChannel.Id} Discovered Name:{WebhookChannel.Name}");

            CompetitiveTestingChannel = await ParseChannel(RSettings.General.CompetitiveTestingChannel);

            Console.WriteLine(
                $"CompetitiveTestingChannel ID:{CompetitiveTestingChannel.Id} Discovered Name:{CompetitiveTestingChannel.Name}");

            Console.ResetColor();

            async Task <SocketTextChannel> ParseChannel(string key)
            {
                var channel = await ChannelTypeReader <SocketTextChannel> .GetBestResultAsync(Guild, key);

                if (channel == null)
                {
                    throw new InvalidOperationException($"The value of key '{key}' could not be parsed as a channel.");
                }

                return(channel);
            }
        }