public async Task GetPlayerAsync(IGuildUser guildUser) { using (var context = new GuildContext()) { var users = context.Users .Include(x => x.Rank) .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString() && (x.PointDisplay != PointDisplay.HideAll || x.PointDisplay != PointDisplay.HideTotal)) .OrderByDescending(x => x.TotalPoints) .AsAsyncEnumerable(); ProfessorMewData.Interfaces.Guild.IUser user = null; int ranking = 0; await foreach (var entry in users) { if (entry.DiscordID == guildUser.Id) { user = entry; user.GuildRanking = ranking; break; } ranking++; } if (user is null) { await ReplyAsync("User was not found in the database."); return; } var embed = EmbedUtils.CreatePlayerDataEmbed(user); await ReplyAsync(embed : embed); } }
public static Embed CreateRankUpEmbed(ProfessorMewData.Interfaces.Guild.IUser user, string imageUrl) { return(new EmbedBuilder() .WithTitle($"Congratulations you reached {user.Rank.Name} rank!") .WithDescription($"Now you have: {user.TotalPoints} points") .WithColor(user.Rank.GetDiscordColor()) .WithImageUrl(imageUrl) .Build()); }
public static Embed CreateRankDownEmbed(ProfessorMewData.Interfaces.Guild.IUser user, string imageUrl) { return(new EmbedBuilder() .WithTitle($"You were demoted\nNow you have {user.Rank.Name} rank") .WithDescription($"Now you have: {user.TotalPoints} points") .WithColor(user.Rank.GetDiscordColor()) .WithImageUrl(imageUrl) .Build()); }
public async Task GetPlayerProfileAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var users = context.Users .Include(x => x.Rank) .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString() && (x.PointDisplay != PointDisplay.HideAll || x.PointDisplay != PointDisplay.HideTotal)) .OrderByDescending(x => x.TotalPoints) .AsAsyncEnumerable(); ProfessorMewData.Interfaces.Guild.IUser user = null; int ranking = 0; await foreach (var entry in users) { if (entry.DiscordID == Context.User.Id) { user = entry; user.GuildRanking = ranking; break; } ranking++; } if (user is null) { await ReplyAsync("User was not found in the database."); return; } user.AvatarUrl = user.GetAvatarUrl(Context); user.Name = user.GetName(Context); var profilePicture = await user.DownloadAvatarAsync(Services.GetRequiredService <HttpClient>()); //string path = PointsProfileOLD.CreatePlayerProfile(user); //try //{ // await Context.Channel.SendFileAsync(path); //} //catch (Exception) //{ // await Context.Channel.SendMessageAsync(embed: EmbedUtils.CreatePointsProfileEmbed(user)); //} try { await Context.Channel.SendFileAsync(await PointsProfile.CreateProfileImage(user, profilePicture)); } catch { await Context.Channel.SendMessageAsync(embed : EmbedUtils.CreatePointsProfileEmbed(user)); } } }
public static Embed CreatePlayerDataEmbed(ProfessorMewData.Interfaces.Guild.IUser user) { return(new EmbedBuilder() .WithTitle(user.Name) .WithColor(user.Rank.GetDiscordColor()) .AddField("Rank", user.Rank.Name) .AddField("Guild ranking", user.GuildRanking) .AddField("Total points", user.TotalPoints) .AddField("Month points", user.MonthPoints) .AddField("Last time points added", user.LastUpdate) .AddField("Point display", user.PointDisplay) .AddField("Privileges", user.Privileges) .Build()); }
public static Embed CreatePointsProfileEmbed(ProfessorMewData.Interfaces.Guild.IUser user) { return(new EmbedBuilder() .WithColor(user.Rank.GetDiscordColor()) .WithCurrentTimestamp() .WithAuthor(new EmbedAuthorBuilder() .WithName(user.Name) .WithIconUrl(user.AvatarUrl)) .WithFooter(new EmbedFooterBuilder() .WithText("Due to technical difficulties image was replaced.\nIt will return once everything is fixed.")) .AddField("💰 Total points", $"```{user.TotalPoints}/{user.Rank.MaxPoints}```", true) .AddField("📅 Monthly points", $"```{user.MonthPoints}```", true) .AddField("📊 Ranking", $"```{user.GuildRanking}```") .AddField("🆙 Rank", $"```{user.Rank.Name}```") .AddField("🔄 Last update", string.Format(CultureInfo.InvariantCulture, "```{0:yy/MM}```", user.LastUpdate)) .Build()); }