public async Task GuildTop(EventContext e) { int amountToTake = 12; int.TryParse(e.arguments, out int amountToSkip); using (var context = new MikiContext()) { int totalGuilds = (int)Math.Ceiling((double)await context.GuildUsers.CountAsync() / amountToTake); List <GuildUser> leaderboards = await context.GuildUsers.OrderByDescending(x => x.Experience) .Skip(amountToSkip * amountToTake) .Take(amountToTake) .ToListAsync(); IDiscordEmbed embed = Utils.Embed .SetTitle(e.GetResource("guildtop_title")); foreach (GuildUser i in leaderboards) { embed.AddInlineField(i.Name, i.Experience.ToString()); } embed.SetFooter(e.GetResource("page_index", amountToSkip + 1, totalGuilds), null); await embed.QueueToChannel(e.Channel); } }
public async Task GuildTop(EventContext e) { int amountToSkip = 0; int amountToTake = 12; int.TryParse(e.arguments, out amountToSkip); using (var context = new MikiContext()) { List <GuildUser> leaderboards = context.GuildUsers.OrderByDescending(x => x.Experience) .Skip(amountToSkip * amountToTake) .Take(amountToTake) .ToList(); IDiscordEmbed embed = Utils.Embed .SetTitle(e.GetResource("guildtop_title")); foreach (GuildUser i in leaderboards) { embed.AddInlineField(i.Name, i.Experience.ToString()); } embed.SetFooter(e.GetResource("pasta_page_index", amountToSkip, "#"), null); await embed.SendToChannel(e.Channel); } }
public async Task FavouritePastaList(EventContext e, bool lovedPastas = true) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); IDiscordUser targetUser = e.Author; float totalPerPage = 25f; int page = 0; if (e.message.MentionedUserIds.Count() >= 1) { targetUser = await e.Guild.GetUserAsync(e.message.MentionedUserIds.First()); string[] args = e.arguments.Split(' '); int.TryParse((args.Count() > 1 ? args[1] : "0"), out page); page -= page <= 0 ? 0 : 1; } else { int.TryParse(e.arguments, out page); page -= 1; } using (MikiContext context = new MikiContext()) { long authorId = targetUser.Id.ToDbLong(); IEnumerable <PastaVote> pastaVotes = context.Votes.Where(x => x.UserId == authorId && x.PositiveVote == lovedPastas); int maxPage = (int)Math.Floor(pastaVotes.Count() / totalPerPage); page = page > maxPage ? maxPage : page; page = page < 0 ? 0 : page; if (pastaVotes.Count() <= 0) { string loveString = (lovedPastas ? locale.GetString("miki_module_pasta_loved") : locale.GetString("miki_module_pasta_hated")); string errorString = locale.GetString("miki_module_pasta_favlist_self_none", loveString); if (e.message.MentionedUserIds.Count() >= 1) { errorString = locale.GetString("miki_module_pasta_favlist_mention_none", loveString); } await Utils.ErrorEmbed(e, errorString).QueueToChannel(e.Channel.Id); return; } IDiscordEmbed embed = Utils.Embed; List <PastaVote> neededPastas = pastaVotes.Skip((int)totalPerPage * page).Take((int)totalPerPage).ToList(); string resultString = ""; neededPastas.ForEach(x => { resultString += "`" + x.Id + "` "; }); string useName = string.IsNullOrEmpty(targetUser.Nickname) ? targetUser.Username : targetUser.Nickname; embed.SetTitle($"{( lovedPastas ? locale.GetString( "miki_module_pasta_loved_header" ) : locale.GetString( "miki_module_pasta_hated_header" ) )} - {useName}"); embed.SetDescription(resultString); embed.SetFooter(locale.GetString("page_index", page + 1, Math.Ceiling(pastaVotes.Count() / totalPerPage)), ""); await embed.QueueToChannel(e.Channel); } }
public async Task SteamGameAsync(EventContext context) { DateTime requestStart = DateTime.Now; string[] args = context.arguments.Split(' '); IDiscordEmbed embed = Utils.Embed; embed.SetAuthor("Steam Game", steamAuthorIcon, ""); SteamGameInfo gameInfo = await steam.GetGameInfo(args[0]); embed.SetDescription(gameInfo.Name); embed.SetThumbnailUrl(gameInfo.HeaderImage); embed.SetFooter("Request took in " + Math.Round((DateTime.Now - requestStart).TotalMilliseconds) + "ms", ""); embed.QueueToChannel(context.Channel); }
public async Task ProfileAsync(EventContext e) { Stopwatch sw = new Stopwatch(); sw.Start(); using (var context = new MikiContext()) { long id = 0; ulong uid = 0; if (e.message.MentionedUserIds.Count() > 0) { uid = e.message.MentionedUserIds.First(); id = uid.ToDbLong(); } else { uid = e.message.Author.Id; id = uid.ToDbLong(); } User account = await context.Users.FindAsync(id); Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); IDiscordUser discordUser = await e.Guild.GetUserAsync(uid); if (account != null) { IDiscordEmbed embed = Utils.Embed .SetDescription(account.Title) .SetAuthor(locale.GetString("miki_global_profile_user_header", account.Name), "http://veld.one/assets/profile-icon.png", "https://patreon.com/mikibot") .SetThumbnailUrl(discordUser.AvatarUrl); long serverid = e.Guild.Id.ToDbLong(); LocalExperience localExp = await context.Experience.FindAsync(serverid, id); int globalExp = account.Total_Experience; int rank = await account.GetLocalRank(e.Guild.Id); EmojiBarSet onBarSet = new EmojiBarSet("<:mbaronright:334479818924228608>", "<:mbaronmid:334479818848468992>", "<:mbaronleft:334479819003789312>"); EmojiBarSet offBarSet = new EmojiBarSet("<:mbaroffright:334479818714513430>", "<:mbaroffmid:334479818504536066>", "<:mbaroffleft:334479818949394442>"); EmojiBar expBar = new EmojiBar(account.CalculateMaxExperience(localExp.Experience), onBarSet, offBarSet, 6); string infoValue = new MessageBuilder() .AppendText(locale.GetString("miki_module_accounts_information_level", account.CalculateLevel(localExp.Experience), localExp.Experience, account.CalculateMaxExperience(localExp.Experience))) .AppendText(await expBar.Print(localExp.Experience, e.Channel)) .AppendText(locale.GetString("miki_module_accounts_information_rank", rank)) .AppendText("Reputation: " + account.Reputation, MessageFormatting.PLAIN, false) .Build(); embed.AddInlineField(locale.GetString("miki_generic_information"), infoValue); int globalLevel = account.CalculateLevel(account.Total_Experience); int globalRank = account.CalculateMaxExperience(account.Total_Experience); EmojiBar globalExpBar = new EmojiBar(account.CalculateMaxExperience(account.Total_Experience), onBarSet, offBarSet, 6); string globalInfoValue = new MessageBuilder() .AppendText(locale.GetString("miki_module_accounts_information_level", globalLevel, account.Total_Experience, globalRank)) .AppendText(await globalExpBar.Print(account.Total_Experience, e.Channel)) .AppendText(locale.GetString("miki_module_accounts_information_rank", account.GetGlobalRank()), MessageFormatting.PLAIN, false) .Build(); embed.AddInlineField(locale.GetString("miki_generic_global_information"), globalInfoValue); embed.AddInlineField(locale.GetString("miki_generic_mekos"), account.Currency + "🔸"); List <Marriage> marriages = Marriage.GetMarriages(context, id); marriages = marriages.OrderBy(mar => mar.TimeOfMarriage).ToList(); List <User> users = new List <User>(); int maxCount = marriages.Count; for (int i = 0; i < maxCount; i++) { users.Add(await context.Users.FindAsync(marriages[i].GetOther(id))); } if (marriages.Count > 0) { List <string> marriageStrings = new List <string>(); for (int i = 0; i < maxCount; i++) { if (marriages[i].GetOther(id) != 0 && marriages[i].TimeOfMarriage != null) { marriageStrings.Add("💕 " + users[i].Name + " (_" + marriages[i].TimeOfMarriage.ToShortDateString() + "_)"); } } embed.AddInlineField( locale.GetString("miki_module_accounts_profile_marriedto"), string.Join("\n", marriageStrings)); } Random r = new Random((int)id - 3); embed.Color = new IA.SDK.Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble()); List <CommandUsage> List = context.CommandUsages.Where(c => c.UserId == id).OrderByDescending(c => c.Amount).ToList(); string favCommand = (List.Count > 0) ? List[0].Name + " (" + List[0].Amount + ")" : "none (yet!)"; embed.AddInlineField(locale.GetString("miki_module_accounts_profile_favourite_command"), favCommand); string achievements = AchievementManager.Instance.PrintAchievements(context, account.Id.FromDbLong()); embed.AddInlineField( locale.GetString("miki_generic_achievements"), achievements != "" ? achievements : locale.GetString("miki_placeholder_null")); embed.AddInlineField(locale.GetString("miki_module_accounts_profile_url"), "http://miki.veld.one/profile/" + account.Id); embed.SetFooter(locale.GetString("miki_module_accounts_profile_footer", account.DateCreated.ToShortDateString(), sw.ElapsedMilliseconds), ""); sw.Stop(); await embed.SendToChannel(e.Channel); } else { await Utils.ErrorEmbed(locale, locale.GetString("miki_module_accounts_error_null")).SendToChannel(e.Channel); } } }
public async Task SteamUserAsync(EventContext context) { DateTime requestStart = DateTime.Now; string[] args = context.arguments.Split(' '); IDiscordEmbed embed = Utils.Embed; embed.SetAuthor("Steam Profile", steamAuthorIcon, ""); SteamUserInfo user = await steam.GetSteamUser(args[0]); if (user == null) { embed = Utils.ErrorEmbed(context, "No user was found!"); embed.QueueToChannel(context.Channel); return; } string userLevel = await steam.GetSteamLevel(user.SteamID); embed.SetThumbnailUrl(user.GetAvatarURL()); /* Current Game & Embed Colour */ if (user.IsPlayingGame()) { if (user.CurrentGameName != "???") { embed.SetDescription("Currently playing " + user.CurrentGameName); } else { embed.SetDescription("Currently in-game"); } embed.Color = new Color(0.5f, 1, 0.5f); } else if (user.PersonaState != 0) { embed.Color = new Color(0.5f, 0.5f, 1); } /* Name & ID */ embed.AddInlineField("Name", user.GetUsername()); embed.AddInlineField("ID", user.SteamID); /* Real Name & Country */ embed.AddInlineField("Real Name", user.RealName); embed.AddInlineField("Country", (user.CountryCode != "???" ? ":flag_" + user.CountryCode.ToLower() + ": " : "") + user.CountryCode); /* Profile Link */ embed.AddField("Link", user.ProfileURL); /* Created & Status */ embed.AddInlineField("Created", String.Format("{0:MMMM d, yyyy}", user.TimeCreated)); if (user.GetStatus() == "Offline") { embed.AddInlineField("Offline Since", ToTimeString(user.OfflineSince())); } else { embed.AddInlineField("Status", user.GetStatus()); } /* Level */ embed.AddInlineField("Level", userLevel); embed.SetFooter("Request took in " + Math.Round((DateTime.Now - requestStart).TotalMilliseconds) + "ms", ""); embed.QueueToChannel(context.Channel); }
public async Task GiveReputationAsync(EventContext e) { using (var context = new MikiContext()) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong()); List <ulong> mentionedUsers = e.message.MentionedUserIds.ToList(); string[] args = e.arguments.Split(' '); short repAmount = 1; bool mentionedSelf = mentionedUsers.RemoveAll(x => x == e.Author.Id) > 0; if (giver.LastReputationGiven.Day != DateTime.Now.Day) { giver.ReputationPointsLeft = 3; giver.LastReputationGiven = DateTime.Now; } IDiscordEmbed embed = Utils.Embed; if (mentionedSelf) { embed.SetFooter(e.GetResource("warning_mention_self"), ""); } if (mentionedUsers.Count == 0) { TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now); await embed .SetTitle(locale.GetString("miki_module_accounts_rep_header")) .SetDescription(locale.GetString("miki_module_accounts_rep_description")) .AddInlineField(locale.GetString("miki_module_accounts_rep_total_received"), giver.Reputation.ToString()) .AddInlineField(locale.GetString("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Channel.GetLocale())) .AddInlineField(locale.GetString("miki_module_accounts_rep_remaining"), giver.ReputationPointsLeft) .SendToChannel(e.Channel); return; } else { if (args.Length > 1) { if (Utils.IsAll(args[args.Length - 1], e.Channel.GetLocale())) { repAmount = giver.ReputationPointsLeft; } else if (short.TryParse(args[1], out short x)) { repAmount = x; } } if (repAmount <= 0) { await e.ErrorEmbed(locale.GetString("miki_module_accounts_rep_error_zero")) .SendToChannel(e.Channel); return; } if (mentionedUsers.Count * repAmount > giver.ReputationPointsLeft) { await e.ErrorEmbed("You can not give {0} user(s) {1} reputation point(s) while you only have {2} points left.", mentionedUsers.Count, repAmount, giver.ReputationPointsLeft) .SendToChannel(e.Channel); return; } } embed.SetTitle(locale.GetString("miki_module_accounts_rep_header")) .SetDescription("You've successfully given reputation"); foreach (ulong user in mentionedUsers) { User receiver = await context.Users.FindAsync(user.ToDbLong()); if (receiver == null) { IDiscordUser u = await e.Guild.GetUserAsync(user); receiver = await User.CreateAsync(u); } receiver.Reputation += repAmount; embed.AddInlineField(receiver.Name, string.Format("{0} => {1} (+{2})", receiver.Reputation - repAmount, receiver.Reputation, repAmount)); } giver.ReputationPointsLeft -= (short)(repAmount * mentionedUsers.Count); await embed .AddInlineField(locale.GetString("miki_module_accounts_rep_points_left"), giver.ReputationPointsLeft) .SendToChannel(e.Channel); await context.SaveChangesAsync(); } }
/*[Command(Name = "setrolelevel")] * public async Task SetRoleLevelAsync(EventContext e) * { * using (var context = new MikiContext()) * { * Locale locale = new Locale(e.Channel.Id.ToDbLong()); * * List<string> allArgs = new List<string>(); * allArgs.AddRange(e.arguments.Split(' ')); * if (allArgs.Count >= 2) * { * int levelrequirement = int.Parse(allArgs[allArgs.Count - 1]); * allArgs.RemoveAt(allArgs.Count - 1); * IDiscordRole role = e.Guild.Roles * .Find(r => r.Name.ToLower() == string.Join(" ", allArgs).TrimEnd(' ').TrimStart(' ').ToLower()); * * if (role == null) * { * e.ErrorEmbed(e.GetResource("error_role_not_found")) * .QueueToChannel(e.Channel); * return; * } * * LevelRole lr = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong()); * if (lr == null) * { * lr = context.LevelRoles.Add(new LevelRole() * { * GuildId = e.Guild.Id.ToDbLong(), * RoleId = role.Id.ToDbLong(), * RequiredLevel = levelrequirement * }).Entity; * * IDiscordEmbed embed = Utils.Embed; * embed.Title = "Added Role!"; * embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!"; * * IDiscordUser currentUser = await e.GetCurrentUserAsync(); * * if (!currentUser.HasPermissions(e.Channel, DiscordGuildPermission.ManageRoles)) * { * embed.AddInlineField(e.GetResource("miki_warning"), e.GetResource("setrolelevel_error_no_permissions", $"`{e.GetResource("permission_manage_roles")}`")); * } * * embed.QueueToChannel(e.Channel); * } * else * { * lr.RequiredLevel = levelrequirement; * * IDiscordEmbed embed = Utils.Embed; * embed.Title = "Updated Role!"; * embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!"; * embed.QueueToChannel(e.Channel); * } * await context.SaveChangesAsync(); * } * else * { * e.ErrorEmbed("Make sure to fill out both the role and the level when creating this!") * .QueueToChannel(e.Channel); * } * } * }*/ //[Command(Name = "mybadges")] //public async Task MyBadgesAsync(EventContext e) //{ // int page = 0; // using (var context = new MikiContext()) // { // User u = await context.Users.FindAsync(e.Author.Id.ToDbLong()); // string output = string.Join<long>(" ", u.BadgesOwned.Select(x => x.Id).ToList()); // await e.Channel.SendMessage(output.DefaultIfEmpty("none, yet!")); // } //} public async Task ShowLeaderboardsAsync(IDiscordMessage mContext, LeaderboardsOptions leaderboardOptions) { using (var context = new MikiContext()) { Locale locale = new Locale(mContext.Channel.Id); int p = Math.Max(leaderboardOptions.pageNumber - 1, 0); if (Global.MikiApi == null) { IDiscordEmbed embed = Utils.Embed .SetColor(1.0f, 0.6f, 0.4f); switch (leaderboardOptions.type) { case LeaderboardsType.COMMANDS: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_commands_header"); if (leaderboardOptions.mentionedUserId != 0) { long mentionedId = leaderboardOptions.mentionedUserId.ToDbLong(); var mentionedUser = await context.Users.FindAsync(mentionedId); p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalCommandsRankAsync()) - 1) / 12)); } List <User> output = await context.Users .OrderByDescending(x => x.Total_Commands) .Skip(12 * p) .Take(12) .ToListAsync(); for (int i = 0; i < output.Count; i++) { string nameToOutput = leaderboardOptions.mentionedUserId != 0 ? string.Join("", output[i].Name.Take(16)) : "~" + string.Join("", output[i].Name.Take(16)) + "~"; embed.AddInlineField($"#{i + (12 * p) + 1}: {nameToOutput}", $"{output[i].Total_Commands} commands used!"); } } break; case LeaderboardsType.CURRENCY: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_mekos_header"); if (leaderboardOptions.mentionedUserId != 0) { long mentionedId = leaderboardOptions.mentionedUserId.ToDbLong(); var mentionedUser = await context.Users.FindAsync(mentionedId); p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalMekosRankAsync()) - 1) / 12)); } List <User> output = await context.Users .OrderByDescending(x => x.Currency) .Skip(12 * p) .Take(12) .ToListAsync(); for (int i = 0; i < output.Count; i++) { embed.AddInlineField($"#{i + (12 * p) + 1}: {string.Join("", output[i].Name.Take(16))}", $"{output[i].Currency} mekos!"); } } break; case LeaderboardsType.EXPERIENCE: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_header"); if (leaderboardOptions.mentionedUserId != 0) { long mentionedId = leaderboardOptions.mentionedUserId.ToDbLong(); var mentionedUser = await context.Users.FindAsync(mentionedId); p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalRankAsync()) - 1) / 12)); } List <User> output = await context.Users .OrderByDescending(x => x.Total_Experience) .Skip(12 * p) .Take(12) .ToListAsync(); for (int i = 0; i < output.Count; i++) { embed.AddInlineField($"#{i + (12 * p) + 1}: {string.Join("", output[i].Name.Take(16))}", $"{output[i].Total_Experience} experience!"); } } break; case LeaderboardsType.REPUTATION: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_reputation_header"); if (leaderboardOptions.mentionedUserId != 0) { long mentionedId = leaderboardOptions.mentionedUserId.ToDbLong(); var mentionedUser = await context.Users.FindAsync(mentionedId); p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalReputationRankAsync()) - 1) / 12)); } List <User> output = await context.Users .OrderByDescending(x => x.Reputation) .Skip(12 * p) .Take(12) .ToListAsync(); for (int i = 0; i < output.Count; i++) { embed.AddInlineField($"#{i + (12 * p) + 1}: {string.Join("", output[i].Name.Take(16))}", $"{output[i].Reputation} reputation!"); } } break; case LeaderboardsType.PASTA: { List <GlobalPasta> leaderboards = await context.Pastas .OrderByDescending(x => x.Score) .Skip(12 * p) .Take(12) .ToListAsync(); embed.SetTitle(locale.GetString("toppasta_title")); foreach (GlobalPasta t in leaderboards) { int amount = t.Score; embed.AddInlineField(t.Id, (t == leaderboards.First() ? "💖 " + amount : (amount < 0 ? "💔 " : "� ") + amount)); } } break; } embed.SetFooter(locale.GetString("page_index", p + 1, Math.Ceiling(context.Users.Count() / 12f)), "") .QueueToChannel(mContext.Channel); } else { LeaderboardsObject obj = await Global.MikiApi.GetPagedLeaderboardsAsync(leaderboardOptions); Utils.RenderLeaderboards(Utils.Embed, obj.items, obj.currentPage * 10) .SetFooter(locale.GetString("page_index", p + 1, Math.Ceiling((double)obj.totalItems / 10)), "") .SetTitle($"Leaderboards: {leaderboardOptions.type.ToString()}") .QueueToChannel(mContext.Channel); } } }
public async Task GiveReputationAsync(EventContext e) { using (var context = new MikiContext()) { Locale locale = new Locale(e.Channel.Id.ToDbLong()); User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong()); List <ulong> mentionedUsers = e.message.MentionedUserIds.ToList(); string[] args = e.arguments.Split(' '); short repAmount = 1; bool mentionedSelf = mentionedUsers.RemoveAll(x => x == e.Author.Id) > 0; var repObject = Global.redisClient.Get <ReputationObject>($"user:{giver.Id}:rep"); if (repObject == null) { repObject = new ReputationObject() { LastReputationGiven = DateTime.Now, ReputationPointsLeft = 3 }; } IDiscordEmbed embed = Utils.Embed; if (mentionedSelf) { embed.SetFooter(e.GetResource("warning_mention_self"), ""); } if (mentionedUsers.Count == 0) { TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now); embed.SetTitle(locale.GetString("miki_module_accounts_rep_header")) .SetDescription(locale.GetString("miki_module_accounts_rep_description")) .AddInlineField(locale.GetString("miki_module_accounts_rep_total_received"), giver.Reputation.ToString()) .AddInlineField(locale.GetString("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Channel.GetLocale())) .AddInlineField(locale.GetString("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft) .QueueToChannel(e.Channel); return; } else { if (args.Length > 1) { if (Utils.IsAll(args[args.Length - 1], e.Channel.GetLocale())) { repAmount = repObject.ReputationPointsLeft; } else if (short.TryParse(args[1], out short x)) { repAmount = x; } } if (repAmount <= 0) { e.ErrorEmbedResource("miki_module_accounts_rep_error_zero") .QueueToChannel(e.Channel); return; } if (mentionedUsers.Count * repAmount > repObject.ReputationPointsLeft) { e.ErrorEmbedResource("error_rep_limit", mentionedUsers.Count, repAmount, repObject.ReputationPointsLeft) .QueueToChannel(e.Channel); return; } } embed.SetTitle(locale.GetString("miki_module_accounts_rep_header")) .SetDescription(locale.GetString("rep_success")); foreach (ulong user in mentionedUsers) { IDiscordUser u = await e.Guild.GetUserAsync(user); User receiver = await User.GetAsync(context, u); receiver.Reputation += repAmount; embed.AddInlineField(receiver.Name, string.Format("{0} => {1} (+{2})", receiver.Reputation - repAmount, receiver.Reputation, repAmount)); } repObject.ReputationPointsLeft -= (short)(repAmount * mentionedUsers.Count); await Global.redisClient.AddAsync($"user:{giver.Id}:rep", repObject); embed.AddInlineField(locale.GetString("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft) .QueueToChannel(e.Channel); await context.SaveChangesAsync(); } }
public async Task ProfileAsync(EventContext e) { Stopwatch sw = new Stopwatch(); sw.Start(); using (var context = new MikiContext()) { long id = 0; ulong uid = 0; if (e.message.MentionedUserIds.Any()) { uid = e.message.MentionedUserIds.First(); id = uid.ToDbLong(); } else { uid = e.message.Author.Id; id = uid.ToDbLong(); } Locale locale = new Locale(e.Channel.Id.ToDbLong()); IDiscordUser discordUser = await e.Guild.GetUserAsync(uid); User account = await User.GetAsync(context, discordUser); EmojiBarSet onBarSet = new EmojiBarSet( "<:mbarlefton:391971424442646534>", "<:mbarmidon:391971424920797185>", "<:mbarrighton:391971424488783875>"); EmojiBarSet offBarSet = new EmojiBarSet( "<:mbarleftoff:391971424824459265>", "<:mbarmidoff:391971424824197123>", "<:mbarrightoff:391971424862208000>"); if (account != null) { IDiscordEmbed embed = Utils.Embed .SetDescription(account.Title) .SetAuthor(locale.GetString("miki_global_profile_user_header", account.Name), "", "https://patreon.com/mikibot") .SetThumbnailUrl(discordUser.AvatarUrl); long serverid = e.Guild.Id.ToDbLong(); LocalExperience localExp = account.LocalExperience.FirstOrDefault(x => x.ServerId == e.Guild.Id.ToDbLong()); if (localExp == null) { localExp = await LocalExperience.CreateAsync(context, serverid, id); } int rank = await localExp.GetRank(context); int localLevel = User.CalculateLevel(localExp.Experience); int maxLocalExp = User.CalculateLevelExperience(localLevel); int minLocalExp = User.CalculateLevelExperience(localLevel - 1); EmojiBar expBar = new EmojiBar(maxLocalExp - minLocalExp, onBarSet, offBarSet, 6); string infoValue = new MessageBuilder() .AppendText(locale.GetString("miki_module_accounts_information_level", localLevel, localExp.Experience, maxLocalExp)) .AppendText(await expBar.Print(localExp.Experience - minLocalExp, e.Channel)) .AppendText(locale.GetString("miki_module_accounts_information_rank", rank)) .AppendText("Reputation: " + account.Reputation, MessageFormatting.Plain, false) .Build(); embed.AddInlineField(locale.GetString("miki_generic_information"), infoValue); int globalLevel = User.CalculateLevel(account.Total_Experience); int maxGlobalExp = User.CalculateLevelExperience(globalLevel); int minGlobalExp = User.CalculateLevelExperience(globalLevel - 1); int globalRank = await account.GetGlobalRankAsync(); EmojiBar globalExpBar = new EmojiBar(maxGlobalExp - minGlobalExp, onBarSet, offBarSet, 6); string globalInfoValue = new MessageBuilder() .AppendText(locale.GetString("miki_module_accounts_information_level", globalLevel, account.Total_Experience, maxGlobalExp)) .AppendText(await globalExpBar.Print(account.Total_Experience - minGlobalExp, e.Channel)) .AppendText(locale.GetString("miki_module_accounts_information_rank", globalRank), MessageFormatting.Plain, false) .Build(); embed.AddInlineField(locale.GetString("miki_generic_global_information"), globalInfoValue); embed.AddInlineField(locale.GetString("miki_generic_mekos"), account.Currency + "🔸"); List <Marriage> Marriages = account.Marriages? .Select(x => x.Marriage) .Where(x => !x.IsProposing) .OrderBy(mar => mar.TimeOfMarriage) .ToList(); List <User> users = new List <User>(); int maxCount = Marriages?.Count ?? 0; for (int i = 0; i < maxCount; i++) { users.Add(await context.Users.FindAsync(Marriages[i].GetOther(id))); } if (Marriages?.Count > 0) { List <string> MarriageStrings = new List <string>(); for (int i = 0; i < maxCount; i++) { if (Marriages[i].GetOther(id) != 0) { MarriageStrings.Add($"💕 {users[i].Name} (_{Marriages[i].TimeOfMarriage.ToShortDateString()}_)"); } } embed.AddInlineField( locale.GetString("miki_module_accounts_profile_marriedto"), string.Join("\n", MarriageStrings)); } Random r = new Random((int)id - 3); embed.Color = new Miki.Common.Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble()); CommandUsage favouriteCommand = account.CommandsUsed? .OrderByDescending(c => c.Amount) .FirstOrDefault(); string favCommand = $"{favouriteCommand?.Name ?? locale.GetString("miki_placeholder_null")} ({ favouriteCommand?.Amount ?? 0 })"; embed.AddInlineField(locale.GetString("miki_module_accounts_profile_favourite_command"), favCommand); if (account.Achievements != null) { string achievements = AchievementManager.Instance.PrintAchievements(account.Achievements); embed.AddInlineField( locale.GetString("miki_generic_achievements"), achievements != "" ? achievements : locale.GetString("miki_placeholder_null")); } embed.SetFooter( locale.GetString("miki_module_accounts_profile_footer", account.DateCreated.ToShortDateString(), sw.ElapsedMilliseconds), ""); sw.Stop(); embed.QueueToChannel(e.Channel); } else { e.ErrorEmbed(locale.GetString("error_account_null")) .QueueToChannel(e.Channel); } } }
public async Task ShowLeaderboardsAsync(IDiscordMessage mContext, LeaderboardsType leaderboardType = LeaderboardsType.Experience, int page = 0) { using (var context = new MikiContext()) { Locale locale = Locale.GetEntity(mContext.Channel.Id.ToDbLong()); IDiscordEmbed embed = Utils.Embed; embed.SetFooter( locale.GetString("miki_module_accounts_leaderboards_page", page + 1, Math.Ceiling(context.Users.Count() / 12.0)), ""); switch (leaderboardType) { case LeaderboardsType.Commands: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_commands_header"); embed.Color = new IA.SDK.Color(0.4f, 1.0f, 0.6f); List <User> output = await context.Users.OrderByDescending(x => x.Total_Commands) .Skip(12 * page) .Take(12) .ToListAsync(); int i = 1; foreach (User user in output) { embed.AddInlineField($"#{i + (12 * page)}: {string.Join("", user.Name.Take(16))}", $"{user.Total_Commands} commands used!"); i++; } await embed.SendToChannel(mContext.Channel); } break; case LeaderboardsType.Currency: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_mekos_header"); embed.Color = new IA.SDK.Color(1.0f, 0.6f, 0.4f); List <User> output = await context.Users.OrderByDescending(x => x.Currency) .Skip(12 * page) .Take(12) .ToListAsync(); int i = 1; foreach (User user in output) { embed.AddInlineField($"#{i + (12 * page)}: {string.Join("", user.Name.Take(16))}", $"{user.Currency} mekos!"); i++; } await embed.SendToChannel(mContext.Channel); } break; case LeaderboardsType.LocalExperience: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_local_header"); embed.Color = new IA.SDK.Color(1.0f, 0.6f, 0.4f); long guildId = mContext.Guild.Id.ToDbLong(); List <LocalExperience> output = await context.Experience .Where(x => x.ServerId == guildId) .OrderByDescending(x => x.Experience) .Skip(12 * page) .Take(12) .ToListAsync(); List <User> users = new List <User>(); for (int i = 0; i < output.Count; i++) { users.Add(await context.Users.FindAsync(output[i].UserId)); } for (int i = 0; i < users.Count; i++) { embed.AddInlineField($"#{i + (12 * page) + 1}: {string.Join("", users[i].Name.Take(16))}", $"{output[i].Experience} experience!"); } await embed.SendToChannel(mContext.Channel); } break; case LeaderboardsType.Experience: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_header"); embed.Color = new IA.SDK.Color(1.0f, 0.6f, 0.4f); List <User> output = await context.Users.OrderByDescending(x => x.Total_Experience) .Skip(12 * page) .Take(12) .ToListAsync(); int i = 1; foreach (User user in output) { embed.AddInlineField($"#{i + (12 * page)}: {string.Join("", user.Name.Take(16))}", $"{user.Total_Experience} experience!"); i++; } await embed.SendToChannel(mContext.Channel); } break; case LeaderboardsType.Reputation: { embed.Title = locale.GetString("miki_module_accounts_leaderboards_reputation_header"); embed.Color = new IA.SDK.Color(1.0f, 0.6f, 0.4f); List <User> output = await context.Users.OrderByDescending(x => x.Reputation) .Skip(12 * page) .Take(12) .ToListAsync(); int i = 1; foreach (User user in output) { embed.AddInlineField($"#{i + (12 * page)}: {string.Join("", user.Name.Take(16))}", $"{user.Reputation} reputation!"); i++; } await embed.SendToChannel(mContext.Channel); } break; } } }