using Microsoft.EntityFrameworkCore; using System; using System.Linq; using System.Threading.Tasks; using SharedLibraryCore; using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using IW4MAdmin.Plugins.Stats.Models; using SharedLibraryCore.Database; namespace IW4MAdmin.Plugins.Stats.Commands { class TopStats : Command { public TopStats() : base("topstats", Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_DESC"], "ts", Player.Permission.User, false) { } public override async Task ExecuteAsync(GameEvent E) { var statsSvc = new GenericRepository(); int serverId = E.Owner.GetHashCode(); using (var db = new DatabaseContext()) { var thirtyDaysAgo = DateTime.UtcNow.AddMonths(-1); var topStats = await (from stats in db.Set() join client in db.Clients on stats.ClientId equals client.ClientId join alias in db.Aliases on client.CurrentAliasId equals alias.AliasId where stats.TimePlayed >= 3600 where client.Level != Player.Permission.Banned where client.LastConnection >= thirtyDaysAgo orderby stats.Skill descending select new { alias.Name, stats.KDR, stats.Skill }) .Take(5) .ToListAsync(); if (!E.Message.IsBroadcastCommand()) { await E.Origin.Tell($"^5--{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--"); foreach (var stat in topStats) await E.Origin.Tell($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_TEXT_SKILL"]}"); } else { await E.Owner.Broadcast($"^5--{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--"); foreach (var stat in topStats) await E.Owner.Broadcast($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_TEXT_SKILL"]}"); } } } } }