<commit_before>﻿using Discord;
using Discord.WebSocket;
using NadekoBot.Extensions;
using System.Threading.Tasks;
using System.Linq;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.GamesList;
using System.Collections.Generic;
using System;
using Microsoft.Extensions.Logging;
using NLog;
using Microsoft.Extensions.DependencyInjection;

namespace NadekoBot.Services.GamesList
{
    public class GamesListService : INService
    {
        private readonly DiscordSocketClient _client;
        //private readonly DbService _db;
        //private readonly ILocalization _localization;
        //private readonly NadekoStrings _strings;

        private readonly List<IGameList> _gameLists;
        private readonly Dictionary<string, IGameList> _gameListsKeyed;

        public int GamesListLength { get { return _gameLists?.Count ?? 0; } }

        private Logger _log;

        //public GamesListService(DiscordSocketClient client, DbService db, ILocalization localization, NadekoStrings strings, GameListBZ98Service bz98, GameListBZ2Service bz2)
        public GamesListService(
            DiscordSocketClient client//, /*DbService db,*/
                                      //GameListBZ98Service bz98,
                                      //GameListBZ2Service bz2,
                                      //GameListBZCCService bzcc
            )
        {
            _client = client;
            //_db = db;
            //_localization = localization;
            //_strings = strings;

            _log = LogManager.GetCurrentClassLogger();
            _log.Warn("GamesListService");

            //_bz98 = bz98;
            //_bz2 = bz2;
            //_bzcc = bzcc;

            _gameLists = new List<IGameList>();
            _gameListsKeyed = new Dictionary<string, IGameList>();
        }

        public void LoadDynamicServices(IServiceProvider services)
        {
            var itype = typeof(IGameList);
            var types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(assembly => assembly.GetTypes())
                .Where(p => itype.IsAssignableFrom(p));

            types.ForEach(type =>
            {
                IGameList gameList = (IGameList)services.GetService(type);

                _gameLists.Add(gameList);
                _gameListsKeyed.Add(gameList.Code, gameList);
            });
        }

        public IGameList[] GetGamesList(ulong? guildId, int page)
        {
            return _gameLists//.Where(x => x.GuildId == guildId)
                //.OrderByDescending(x => x.Xp + x.AwardedXp)
                .OrderBy(x => x.Title)
                .Skip(page * 10)
                .Take(10)
                .ToArray();
        }
<commit_msg>strange null exception, lets try this<commit_after>﻿using Discord;
using Discord.WebSocket;
using NadekoBot.Extensions;
using System.Threading.Tasks;
using System.Linq;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.GamesList;
using System.Collections.Generic;
using System;
using Microsoft.Extensions.Logging;
using NLog;
using Microsoft.Extensions.DependencyInjection;

namespace NadekoBot.Services.GamesList
{
    public class GamesListService : INService
    {
        private readonly DiscordSocketClient _client;
        //private readonly DbService _db;
        //private readonly ILocalization _localization;
        //private readonly NadekoStrings _strings;

        private readonly List<IGameList> _gameLists = new List<IGameList>();
        private readonly Dictionary<string, IGameList> _gameListsKeyed = new Dictionary<string, IGameList>();

        public int GamesListLength { get { return _gameLists?.Count ?? 0; } }

        private Logger _log;

        //public GamesListService(DiscordSocketClient client, DbService db, ILocalization localization, NadekoStrings strings, GameListBZ98Service bz98, GameListBZ2Service bz2)
        public GamesListService(
            DiscordSocketClient client//, /*DbService db,*/
                                      //GameListBZ98Service bz98,
                                      //GameListBZ2Service bz2,
                                      //GameListBZCCService bzcc
            )
        {
            _client = client;
            //_db = db;
            //_localization = localization;
            //_strings = strings;

            _log = LogManager.GetCurrentClassLogger();
            _log.Warn("GamesListService");

            //_bz98 = bz98;
            //_bz2 = bz2;
            //_bzcc = bzcc;

            //_gameLists = new List<IGameList>();
            //_gameListsKeyed = new Dictionary<string, IGameList>();
        }

        public void LoadDynamicServices(IServiceProvider services)
        {
            var itype = typeof(IGameList);
            var types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(assembly => assembly.GetTypes())
                .Where(p => itype.IsAssignableFrom(p));

            types.ForEach(type =>
            {
                IGameList gameList = (IGameList)services.GetService(type);

                _gameLists.Add(gameList);
                _gameListsKeyed.Add(gameList.Code, gameList);
            });
        }

        public IGameList[] GetGamesList(ulong? guildId, int page)
        {
            return _gameLists//.Where(x => x.GuildId == guildId)
                //.OrderByDescending(x => x.Xp + x.AwardedXp)
                .OrderBy(x => x.Title)
                .Skip(page * 10)
                .Take(10)
                .ToArray();
        }

{'fraction_non_alphanumeric': 0.09077757685352622, 'fraction_numerical': 0.008318264014466547, 'mean_word_length': 1.9311075781664018, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6536142', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1487, 'n_words': 318}