示例#1
0
        public async Task <Embed> AddToDatabase(PlayersRulesService _playersRulesService, string filename, bool songsOnly)
        {
            List <SongData> data = await JsonHandler.ConvertJson(new FileInfo(filename));

            List <string> rules = await _playersRulesService.GetRules();

            foreach (SongData song in data)
            {
                if (_db.Find <SongTableObject>(MakeSongTableKey(song.anime.english, song.type, song.name)) == null)
                {
                    SongTableObject tableObject = ConvertSongDataToTable(song);
                    await _db.AddAsync(tableObject);
                }
                if (!songsOnly)
                {
                    await UpdatePlayerStats(_playersRulesService, song, rules);
                }
            }
            await _db.SaveChangesAsync();

            Console.WriteLine("Added only songs for this file" + filename);
            File.Move(filename, ArchivedFiles + filename.Substring(filename.LastIndexOf("\\")), true);
            return(await EmbedHandler.CreateBasicEmbed("Data", "All songs from the Json File have" +
                                                       " been added to the Database and player stats were updated", Color.Blue));
        }
示例#2
0
        public async Task <Embed> AddAllToDatabase(PlayersRulesService _playersRulesService)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            IEnumerable <string> strings = await JsonHandler.GetAllJsonInFolder(JsonFiles);

            bool songsOnly = false;

            foreach (string s in strings)
            {
                if (s.ToLower().Contains("teams") || s.ToLower().Contains("co-op") || s.ToLower().Contains("coop"))
                {
                    songsOnly = true;
                }

                await Task.Run(async() => await AddToDatabase(_playersRulesService, s, songsOnly));
            }
            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;
            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}.{2:00}",
                                               ts.Minutes, ts.Seconds,
                                               ts.Milliseconds / 10);

            return(await EmbedHandler.CreateBasicEmbed("Data", "All songs from the Json Files have" +
                                                       " been added to the Database and player stats were updated \n" + "RunTime: " + elapsedTime, Color.Blue));
        }
示例#3
0
        private async Task UpdatePlayerStats(PlayersRulesService _service, SongData song, List <string> rules)
        {
            Dictionary <string, int> tempDict     = new Dictionary <string, int>();
            List <string>            RulesMetList = new List <string>();

            if (!song.gameMode.Equals("Ranked"))
            {
                foreach (Fromlist listInfo in song.fromList)
                {
                    tempDict.Add(listInfo.name, listInfo.listStatus);
                }
                RulesMetList = await _service.RulesMetBySongData(song, rules);

                RulesMetList.Add("");
            }
            else
            {
                RulesMetList.Add("Ranked");
                RulesMetList.Add("");
            }
            foreach (string rule in RulesMetList)
            {
                foreach (Player player in song.players)
                {
                    //If the player is not inside our array of players to track then continue to the next player
                    if (Array.IndexOf(await _service.GetPlayersTracked(), player.name) == -1)
                    {
                        continue;
                    }
                    else
                    {
                        try
                        {
                            if (_db.Find <PlayerTableObject>(MakePlayerTableKey(song.anime.english, song.type, song.name, player.name, rule)) == null)
                            {
                                await AddPlayerTableObject(song, tempDict, player, rule);
                            }
                            else
                            {
                                await IncrementPlayerStats(song, tempDict, player, rule);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
        }
示例#4
0
        public DiscordService()
        {
            _services            = ConfigureServices();
            _client              = _services.GetRequiredService <DiscordSocketClient>();
            _commandHandler      = _services.GetRequiredService <CommandHandler>();
            _lavaNode            = _services.GetRequiredService <LavaNode>();
            _globalData          = _services.GetRequiredService <GlobalData>();
            _audioService        = _services.GetRequiredService <LavaLinkAudio>();
            _playersRulesService = _services.GetRequiredService <PlayersRulesService>();
            _dataService         = new DataService(_services.GetRequiredService <CsharpiEntities>());
            _helpService         = new HelpService(_services.GetRequiredService <CommandService>());

            SubscribeLavaLinkEvents();
            SubscribeDiscordEvents();
        }
示例#5
0
 public async Task <Embed> CalcCorrectByRule(PlayersRulesService _playersRulesService, string rule)
 {
     return(await DBCalculationHandler.CalcCorrectByRule(_db, _playersRulesService, rule));
 }
示例#6
0
 public async Task <Embed> CalcTotalCorrect(PlayersRulesService _service)
 {
     return(await DBCalculationHandler.CalcTotalCorrect(_db, _service));
 }