Exemple #1
0
 public Diswords(DiswordsClient client, IGuildUser creator, JsonGuild guild, ITextChannel channel,
                 bool createdNewChannel, int previousSlowModeInterval, JsonLanguage language)
 {
     Creator                   = creator ?? throw new ArgumentNullException(nameof(creator));
     Channel                   = channel ?? throw new ArgumentNullException(nameof(channel));
     Language                  = language ?? throw new ArgumentNullException(nameof(language));
     Locale                    = ILocale.Find(Language.ShortName);
     Guild                     = guild;
     _newChannelCreated        = createdNewChannel;
     _previousSlowModeInterval = previousSlowModeInterval;
     _client                   = client;
     _lastSender               = null !;
 }
        private async void UpdateDatabase(IEnumerable <Suggestion> addedWords)
        {
            foreach (var group in addedWords.GroupBy(j => j.Word))
            {
                JsonLanguage language = null !;
                foreach (var suggestion in group)
                {
                    language = DiswordsClient.StaticLanguages.First(l => l.ShortName == suggestion.Language);
                    language.Words.Add(suggestion.Word.ToLower());
                }

                await File.WriteAllTextAsync(
                    $"{Client.Config.RootDirectory}{Path.DirectorySeparatorChar}{Client.Config.LanguagesDirectoryName}{(string.IsNullOrEmpty(Client.Config.LanguagesDirectoryName) ? "" : Path.DirectorySeparatorChar.ToString())}{language.ShortName}.json",
                    language.ToJson());
            }
        }
Exemple #3
0
        /// <summary>
        ///     Load every guild and language into memory. (Lists)
        ///     <para>
        ///         <bold>There are two types of lists: static and private.</bold>
        ///     </para>
        ///     <remarks>This method loads guilds and languages into <bold>static</bold> lists.</remarks>
        ///     <para>See <see cref="LoadPrivateResources" /> for loading guilds and languages into <bold>private</bold> lists.</para>
        /// </summary>
        private async Task LoadResources()
        {
            Console.WriteLine("Diswords: Loading static resources..");
            StaticGuilds.Clear();
            StaticLanguages.Clear();
            foreach (var guild in Directory.EnumerateFiles(
                         $"{Config.RootDirectory}{Path.DirectorySeparatorChar}{Config.GuildsDirectoryName}",
                         "*.json", SearchOption.AllDirectories))
            {
                if (!guild.EndsWith(".json"))
                {
                    continue;
                }
                var id = Path.GetFileNameWithoutExtension(guild);
                Console.WriteLine($"Diswords: Loading guild {id}..");
                try
                {
                    StaticGuilds.Add(await JsonGuild.FromJsonFile(guild));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Diswords: Failed to load guild {id}:\n{e}");
                    throw;
                }
            }

            foreach (var language in Directory.EnumerateFiles(
                         $"{Config.RootDirectory}{Path.DirectorySeparatorChar}{Config.LanguagesDirectoryName}",
                         "*.json", SearchOption.AllDirectories))
            {
                if (!language.EndsWith(".json"))
                {
                    continue;
                }
                var languageName = Path.GetFileNameWithoutExtension(language);
                Console.WriteLine($"Diswords: Loading language {languageName}..");
                try
                {
                    StaticLanguages.Add(await JsonLanguage.FromJsonFile(language));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Diswords: Failed to load guild {languageName}:\n{e}");
                    throw;
                }
            }
        }