public async Task SpellCheckAsync(EventContext context) { IDiscordEmbed embed = Utils.Embed; embed.SetTitle("Spellcheck - top results"); API.StringComparison.StringComparer sc = new API.StringComparison.StringComparer(context.commandHandler.GetAllEventNames()); List <API.StringComparison.StringComparison> best = sc.CompareToAll(context.arguments) .OrderBy(z => z.score) .ToList(); int x = 1; foreach (API.StringComparison.StringComparison c in best) { embed.AddInlineField($"#{x}", c); x++; if (x > 16) { break; } } embed.QueueToChannel(context.Channel); await Task.Yield(); }
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); } }
/*[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 = 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(); } }
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(); } }