public async Task AvatarAsync(CommandContext e) { string avatarUrl = e.Author.GetAvatarUrl(); string avatarResource = e.Author.Username; if (e.Arguments.Take(out string arg)) { if (arg == "-s") { avatarUrl = e.Guild.IconUrl; avatarResource = e.Guild.Name; return; } IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(arg, e.Guild); if (user != null) { avatarUrl = user.GetAvatarUrl(); avatarResource = user.Username; } } await new EmbedBuilder() .SetTitle($"🖼 Avatar for {avatarResource}") .SetThumbnail(avatarUrl) .SetColor(215, 158, 132) .AddInlineField("Full image", $"[click here]({avatarUrl})") .ToEmbed() .QueueToChannelAsync(e.Channel); }
public async Task SetGlobalExpAsync(EventContext e) { var cache = (ICacheClient)e.Services.GetService(typeof(ICacheClient)); if (!e.Arguments.Take(out string userName)) { return; } IDiscordUser user = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (!e.Arguments.Take(out int amount)) { return; } using (var context = new MikiContext()) { User u = await User.GetAsync(context, user.Id.ToDbLong(), user.Username); if (u == null) { return; } u.Total_Experience = amount; await context.SaveChangesAsync(); e.Channel.QueueMessage(":ok_hand:"); } }
public async Task SetExp(EventContext e) { var cache = (ICacheClient)e.Services.GetService(typeof(ICacheClient)); if (!e.Arguments.Take(out string userName)) { return; } IDiscordUser user = await DiscordExtensions.GetUserAsync(userName, e.Guild); e.Arguments.Take(out int amount); using (var context = new MikiContext()) { LocalExperience u = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), user.Id.ToDbLong(), user.Username); if (u == null) { return; } u.Experience = amount; await context.SaveChangesAsync(); await cache.UpsertAsync($"user:{e.Guild.Id}:{e.Author.Id}:exp", u.Experience); e.Channel.QueueMessage(":ok_hand:"); } }
public async Task SetGlobalExpAsync(CommandContext e) { if (!e.Arguments.Take(out string userName)) { return; } IDiscordUser user = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (!e.Arguments.Take(out int amount)) { return; } var context = e.GetService <MikiDbContext>(); User u = await User.GetAsync(context, user.Id.ToDbLong(), user.Username); if (u == null) { return; } u.Total_Experience = amount; await context.SaveChangesAsync(); e.Channel.QueueMessage(":ok_hand:"); }
public async Task ShowMekosAsync(CommandContext e) { IDiscordGuildUser member; if (e.Arguments.Take(out string value)) { member = await DiscordExtensions.GetUserAsync(value, e.Guild); } else { member = await e.Guild.GetMemberAsync(e.Author.Id); } var context = e.GetService <MikiDbContext>(); User user = await User.GetAsync(context, member.Id.ToDbLong(), member.Username); await new EmbedBuilder() { Title = "🔸 Mekos", Description = e.Locale.GetString("miki_user_mekos", user.Name, user.Currency.ToFormattedString()), Color = new Color(1f, 0.5f, 0.7f) }.ToEmbed().QueueToChannelAsync(e.Channel); await context.SaveChangesAsync(); }
public async Task ShipAsync(ICommandContext e) { var cache = e.GetService <IExtendedCacheClient>(); var context = e.GetService <MikiDbContext>(); e.Arguments.Take(out string shipPartner); IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(shipPartner, e.Guild); if (user == null) { throw new UserNullException(); } if (await cache.HashExistsAsync("avtr:sync", e.Author.Id.ToString())) { await Utils.SyncAvatarAsync(e.Author, cache, context); } if (await cache.HashExistsAsync("avtr:sync", user.Id.ToString())) { await Utils.SyncAvatarAsync(user, cache, context); } Random r = new Random((int)((e.Author.Id + user.Id + (ulong)DateTime.Now.DayOfYear) % int.MaxValue)); int value = r.Next(0, 100); Stream s = await imageClient.GetStreamAsync($"/api/ship?me={e.Author.Id}&other={user.Id}&value={value}"); await(e.Channel as IDiscordTextChannel).SendFileAsync(s, "meme.png"); }
public async Task GiveMekosAsync(ICommandContext e) { if (e.Arguments.Take(out string userName)) { var user = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (user == null) { await e.ErrorEmbedResource("give_error_no_mention") .ToEmbed().QueueToChannelAsync(e.Channel); return; } if (!e.Arguments.Take(out int amount)) { await e.ErrorEmbedResource("give_error_amount_unparsable") .ToEmbed().QueueToChannelAsync(e.Channel); return; } var context = e.GetService <MikiDbContext>(); User sender = await DatabaseHelpers.GetUserAsync(context, e.Author); User receiver = await DatabaseHelpers.GetUserAsync(context, user); if (amount <= sender.Currency) { sender.RemoveCurrency(amount); if (await receiver.IsBannedAsync(context)) { throw new UserNullException(); } await receiver.AddCurrencyAsync(amount); await new EmbedBuilder() { Title = "🔸 transaction", Description = e.Locale.GetString("give_description", sender.Name, receiver.Name, amount.ToFormattedString()), Color = new Color(255, 140, 0), }.ToEmbed().QueueToChannelAsync(e.Channel); await context.SaveChangesAsync(); } else { throw new InsufficientCurrencyException(sender.Currency, amount); } } }
public async Task WhoIsAsync(EventContext e) { if (!e.Arguments.Take(out string arg)) { throw new ArgumentNullException(); } IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(arg, e.Guild); //if (user == null) //{ // user = e.Author as IGuildUser; //} var embed = e.CreateEmbedBuilder(); embed.WithTitle("whois_title", user.Username); embed.SetColor(0.5f, 0f, 1.0f); embed.SetImage(user.GetAvatarUrl()); var roles = (await e.Guild.GetRolesAsync()).Where(x => user.RoleIds?.Contains(x.Id) ?? false && x.Color.Value != 0).OrderByDescending(x => x.Position); Color c = roles.FirstOrDefault()?.Color ?? new Color(0); StringBuilder builder = new StringBuilder(); builder.AppendLine($"User Id : **{user.Id}**"); builder.AppendLine( $"Username: **{user.Username}#{user.Discriminator} {(string.IsNullOrEmpty((user as IDiscordGuildUser).Nickname) ? "" : $"({(user as IDiscordGuildUser).Nickname})")}**"); builder.AppendLine($"Created at: **{user.CreatedAt.ToString()}**"); builder.AppendLine($"Joined at : **{user.JoinedAt.ToString()}**"); builder.AppendLine($"Color Hex : **{c.ToString()}**"); embed.AddField( e.CreateResource("miki_module_whois_tag_personal"), new RawResource(builder.ToString()) ); string r = string.Join(" ", roles.Select(x => x.Name)); if (string.IsNullOrEmpty(r)) { r = "none (yet!)"; } if (r.Length <= 1000) { embed.AddField( e.CreateResource("miki_module_general_guildinfo_roles"), new RawResource(r) ); } await embed.Build().QueueToChannelAsync(e.Channel); }
public async Task BanUserAsync(CommandContext e) { if (e.Arguments.Take(out string user)) { IDiscordUser u = await DiscordExtensions.GetUserAsync(user, e.Guild); var context = e.GetService <MikiDbContext>(); await(await User.GetAsync(context, u.Id.ToDbLong(), u.Username)) .BanAsync(context); } }
public async Task BanUserAsync(EventContext e) { if (e.Arguments.Take(out string user)) { IDiscordUser u = await DiscordExtensions.GetUserAsync(user, e.Guild); using (var context = new MikiContext()) { await(await User.GetAsync(context, u.Id.ToDbLong(), u.Username)).BanAsync(); } } }
public async Task GiveMekosAsync(EventContext e) { IDiscordUser user = null; if (e.Arguments.Take(out string userName)) { user = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (user == null) { await e.ErrorEmbedResource("give_error_no_mention") .ToEmbed().QueueToChannelAsync(e.Channel); return; } if (!e.Arguments.Take(out int amount)) { await e.ErrorEmbedResource("give_error_amount_unparsable") .ToEmbed().QueueToChannelAsync(e.Channel); return; } using (MikiContext context = new MikiContext()) { User sender = await DatabaseHelpers.GetUserAsync(context, e.Author); User receiver = await DatabaseHelpers.GetUserAsync(context, user); if (amount <= sender.Currency) { sender.RemoveCurrency(amount); await receiver.AddCurrencyAsync(amount); await new EmbedBuilder() { Title = "🔸 transaction", Description = e.Locale.GetString("give_description", sender.Name, receiver.Name, amount.ToFormattedString()), Color = new Color(255, 140, 0), }.ToEmbed().QueueToChannelAsync(e.Channel); await context.SaveChangesAsync(); } else { await e.ErrorEmbedResource("user_error_insufficient_mekos") .ToEmbed().QueueToChannelAsync(e.Channel); } } } }
public async Task AchievementsAsync(EventContext e) { using (var context = new MikiContext()) { long id = (long)e.Author.Id; if (e.Arguments.Take(out string arg)) { IDiscordUser user = await DiscordExtensions.GetUserAsync(arg, e.Guild); if (user != null) { id = (long)user.Id; } } IDiscordUser discordUser = await e.Guild.GetMemberAsync(id.FromDbLong()); User u = await User.GetAsync(context, discordUser.Id, discordUser.Username); List <Achievement> achievements = await context.Achievements .Where(x => x.UserId == id) .ToListAsync(); EmbedBuilder embed = new EmbedBuilder() .SetAuthor($"{u.Name} | " + "Achievements", discordUser.GetAvatarUrl(), "https://miki.ai/profiles/ID/achievements"); embed.SetColor(255, 255, 255); StringBuilder leftBuilder = new StringBuilder(); int totalScore = 0; foreach (var a in achievements) { IAchievement metadata = AchievementManager.Instance.GetContainerById(a.Name).Achievements[a.Rank]; leftBuilder.AppendLine(metadata.Icon + " | `" + metadata.Name.PadRight(15) + $"{metadata.Points.ToString().PadLeft(3)} pts` | 📅 {a.UnlockedAt.ToShortDateString()}"); totalScore += metadata.Points; } if (string.IsNullOrEmpty(leftBuilder.ToString())) { embed.AddInlineField("Total Pts: " + totalScore.ToFormattedString(), "None, yet."); } else { embed.AddInlineField("Total Pts: " + totalScore.ToFormattedString(), leftBuilder.ToString()); } await embed.ToEmbed().QueueToChannelAsync(e.Channel); } }
public async Task ClearCommand([Summary("the number of messages to clear")] int count) { await Context.Message.DeleteAsync(); var messages = (await Context.Channel.GetMessagesAsync(count).FlattenAsync()).ToArray(); (Context.Channel as ITextChannel)?.DeleteMessagesAsync(messages); await DiscordExtensions.SendTemporary( $"Deleted {messages.Length} message{(messages.Length != 1 ? "s" : "")}", TimeSpan.FromSeconds(5), async msg => await ReplyAsync(msg)); }
public async Task ShipAsync(ICommandContext e) { var cache = e.GetService <IExtendedCacheClient>(); var context = e.GetService <MikiDbContext>(); e.Arguments.Take(out string shipPartner); IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(shipPartner, e.Guild); if (user == null) { throw new UserNullException(); } using (var client = new RestClient(Global.Config.CdnRegionEndpoint)) { var authorResponse = await client.SendAsync(new HttpRequestMessage() { Method = new HttpMethod("HEAD"), RequestUri = new Uri($"{Global.Config.CdnRegionEndpoint}/avatars/{e.Author.Id}.png") }); if (!authorResponse.Success) { await Utils.SyncAvatarAsync(e.Author, cache, context); } var otherResponse = await client.SendAsync(new HttpRequestMessage() { Method = new HttpMethod("HEAD"), RequestUri = new Uri($"{Global.Config.CdnRegionEndpoint}/avatars/{user.Id}.png") }); if (!authorResponse.Success) { await Utils.SyncAvatarAsync(e.Author, cache, context); } } Random r = new Random((int)((e.Author.Id + user.Id + (ulong)DateTime.Now.DayOfYear) % int.MaxValue)); int value = r.Next(0, 100); Stream s = await imageClient.GetStreamAsync($"/api/ship?me={e.Author.Id}&other={user.Id}&value={value}"); await(e.Channel as IDiscordTextChannel).SendFileAsync(s, "meme.png"); }
public async Task ShipAsync(EventContext e) { e.Arguments.Take(out string shipPartner); IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(shipPartner, e.Guild); if (user == null) { throw new UserNullException(); } Random r = new Random((int)((e.Author.Id + user.Id + (ulong)DateTime.Now.DayOfYear) % int.MaxValue)); int value = r.Next(0, 100); Stream s = await imageClient.GetStreamAsync($"/api/ship?me={e.Author.Id}&other={user.Id}&value={value}"); await(e.Channel as IDiscordTextChannel).SendFileAsync(s, "meme.png"); }
public async Task AvatarAsync(EventContext e) { if (!e.Arguments.Take(out string arg)) { e.Channel.QueueMessage(e.Author.GetAvatarUrl()); } else { if (arg == "-s") { e.Channel.QueueMessage(e.Guild.IconUrl); return; } IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(arg, e.Guild); if (user != null) { e.Channel.QueueMessage(user.GetAvatarUrl()); } } }
public async Task SetMekos(CommandContext e) { if (e.Arguments.Take(out string userArg)) { IDiscordUser user = await DiscordExtensions.GetUserAsync(userArg, e.Guild); if (e.Arguments.Take(out int value)) { var context = e.GetService <MikiDbContext>(); User u = await context.Users.FindAsync((long)user.Id); if (u == null) { return; } u.Currency = value; await context.SaveChangesAsync(); e.Channel.QueueMessage(":ok_hand:"); } } }
public async Task BanAsync(EventContext e) { IDiscordGuildUser currentUser = await e.Guild.GetSelfAsync(); if ((await(e.Channel as IDiscordGuildChannel).GetPermissionsAsync(currentUser)).HasFlag(GuildPermission.BanMembers)) { e.Arguments.Take(out string userName); if (userName == null) { return; } IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (user == null) { await e.ErrorEmbed(e.Locale.GetString("ban_error_user_null")) .ToEmbed().QueueToChannelAsync(e.Channel); return; } IDiscordGuildUser author = await e.Guild.GetMemberAsync(e.Author.Id); if (await user.GetHierarchyAsync() >= await author.GetHierarchyAsync()) { await e.ErrorEmbed(e.Locale.GetString("permission_error_low", "ban")).ToEmbed() .QueueToChannelAsync(e.Channel); return; } if (await user.GetHierarchyAsync() >= await currentUser.GetHierarchyAsync()) { await e.ErrorEmbed(e.Locale.GetString("permission_error_low", "ban")).ToEmbed() .QueueToChannelAsync(e.Channel); return; } e.Arguments.Take(out int pruneDays); string reason = e.Arguments.Pack.TakeAll(); EmbedBuilder embed = new EmbedBuilder { Title = "🛑 BAN", Description = e.Locale.GetString("ban_header", $"**{e.Guild.Name}**") }; if (!string.IsNullOrWhiteSpace(reason)) { embed.AddInlineField($"💬 {e.Locale.GetString("miki_module_admin_kick_reason")}", reason); } embed.AddInlineField($"💁 {e.Locale.GetString("miki_module_admin_kick_by")}", e.Author.Username + "#" + e.Author.Discriminator); await embed.ToEmbed().SendToUser(user); await e.Guild.AddBanAsync(user, 1, reason); } else { await e.ErrorEmbed(e.Locale.GetString("permission_needed_error", $"`{e.Locale.GetString("permission_ban_members")}`")) .ToEmbed().QueueToChannelAsync(e.Channel); } }
public async Task SoftbanAsync(EventContext e) { IDiscordGuildUser currentUser = await e.Guild.GetSelfAsync(); if ((await(e.Channel as IDiscordGuildChannel).GetPermissionsAsync(currentUser)).HasFlag(GuildPermission.BanMembers)) { if (!e.Arguments.Take(out string argObject)) { return; } IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(argObject, e.Guild); string reason = null; if (e.Arguments.CanTake) { reason = e.Arguments.Pack.TakeAll(); } if (user == null) { await e.ErrorEmbed(e.Locale.GetString("ban_error_user_null")) .ToEmbed().QueueToChannelAsync(e.Channel); return; } IDiscordGuildUser author = await e.Guild.GetMemberAsync(e.Author.Id); if (await user.GetHierarchyAsync() >= await author.GetHierarchyAsync()) { await e.ErrorEmbed(e.Locale.GetString("permission_error_low", "softban")).ToEmbed() .QueueToChannelAsync(e.Channel); return; } if (await user.GetHierarchyAsync() >= await currentUser.GetHierarchyAsync()) { await e.ErrorEmbed(e.Locale.GetString("permission_error_low", "softban")).ToEmbed() .QueueToChannelAsync(e.Channel); return; } EmbedBuilder embed = new EmbedBuilder { Title = "⚠ SOFTBAN", Description = $"You've been banned from **{e.Guild.Name}**!" }; if (!string.IsNullOrWhiteSpace(reason)) { embed.AddInlineField("💬 Reason", reason); } embed.AddInlineField("💁 Banned by", e.Author.Username + "#" + e.Author.Discriminator); await embed.ToEmbed().SendToUser(user); await e.Guild.AddBanAsync(user, 1, reason); await e.Guild.RemoveBanAsync(user); } else { await e.ErrorEmbed(e.Locale.GetString("permission_needed_error", $"`{e.Locale.GetString("permission_ban_members")}`")) .ToEmbed().QueueToChannelAsync(e.Channel); } }
public async Task AcceptMarriageAsync(CommandContext e) { IDiscordUser user = await DiscordExtensions.GetUserAsync(e.Arguments.Pack.TakeAll(), e.Guild); if (user == null) { throw new UserNullException(); } if (user.Id == e.Author.Id) { await e.ErrorEmbed("Please mention someone else than yourself.") .ToEmbed().QueueToChannelAsync(e.Channel); return; } var context = e.GetService <MikiDbContext>(); MarriageRepository repository = new MarriageRepository(context); User accepter = await DatabaseHelpers.GetUserAsync(context, e.Author); User asker = await DatabaseHelpers.GetUserAsync(context, user); UserMarriedTo marriage = await repository.GetEntryAsync(accepter.Id, asker.Id); if (marriage != null) { if (accepter.MarriageSlots < (await repository.GetMarriagesAsync(accepter.Id)).Count) { throw new InsufficientMarriageSlotsException(accepter); } if (asker.MarriageSlots < (await repository.GetMarriagesAsync(asker.Id)).Count) { throw new InsufficientMarriageSlotsException(asker); } if (marriage.ReceiverId != e.Author.Id.ToDbLong()) { e.Channel.QueueMessage($"You can not accept your own responses!"); return; } if (marriage.Marriage.IsProposing) { marriage.Marriage.AcceptProposal(); await context.SaveChangesAsync(); await new EmbedBuilder() { Title = ("❤️ Happily married"), Color = new Color(190, 25, 49), Description = ($"Much love to { e.Author.Username } and { user.Username } in their future adventures together!") }.ToEmbed().QueueToChannelAsync(e.Channel); } else { await e.ErrorEmbed("You're already married to this person ya doofus!") .ToEmbed().QueueToChannelAsync(e.Channel); } } else { e.Channel.QueueMessage("This user hasn't proposed to you!"); return; } }
public async Task MarryAsync(CommandContext e) { if (!e.Arguments.Take(out string args)) { return; } IDiscordGuildUser user = await DiscordExtensions.GetUserAsync(args, e.Guild); if (user == null) { e.Channel.QueueMessage("Couldn't find this person.."); return; } if (user.Id == (await e.Guild.GetSelfAsync()).Id) { e.Channel.QueueMessage("(´・ω・`)"); return; } var context = e.GetService <MikiDbContext>(); MarriageRepository repository = new MarriageRepository(context); User mentionedPerson = await User.GetAsync(context, user.Id.ToDbLong(), user.Username); User currentUser = await DatabaseHelpers.GetUserAsync(context, e.Author); long askerId = currentUser.Id; long receiverId = mentionedPerson.Id; if (currentUser == null || mentionedPerson == null) { await e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannelAsync(e.Channel); return; } if (mentionedPerson.Banned) { await e.ErrorEmbed("This person has been banned from Miki.").ToEmbed().QueueToChannelAsync(e.Channel); return; } if (receiverId == askerId) { await e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannelAsync(e.Channel); return; } if (await repository.ExistsAsync(receiverId, askerId)) { await e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_exists")).ToEmbed().QueueToChannelAsync(e.Channel); return; } await repository.ProposeAsync(askerId, receiverId); await context.SaveChangesAsync(); await new EmbedBuilder() .SetTitle("💍" + e.Locale.GetString("miki_module_accounts_marry_text", $"**{e.Author.Username}**", $"**{user.Username}**")) .SetDescription(e.Locale.GetString("miki_module_accounts_marry_text2", user.Username, e.Author.Username)) .SetColor(0.4f, 0.4f, 0.8f) .SetThumbnail("https://i.imgur.com/TKZSKIp.png") .AddInlineField("✅ To accept", $">acceptmarriage @user") .AddInlineField("❌ To decline", $">declinemarriage @user") .SetFooter("Take your time though! This proposal won't disappear", "") .ToEmbed().QueueToChannelAsync(e.Channel); }
public async Task GiveReputationAsync(CommandContext e) { var context = e.GetService <MikiDbContext>(); User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong()); var cache = e.GetService <ICacheClient>(); var repObject = await cache.GetAsync <ReputationObject>($"user:{giver.Id}:rep"); if (repObject == null) { repObject = new ReputationObject() { LastReputationGiven = DateTime.Now, ReputationPointsLeft = 3 }; await cache.UpsertAsync( $"user:{giver.Id}:rep", repObject, DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow ); } if (!e.Arguments.CanTake) { TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now); await new EmbedBuilder() { Title = e.Locale.GetString("miki_module_accounts_rep_header"), Description = e.Locale.GetString("miki_module_accounts_rep_description") }.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_total_received"), giver.Reputation.ToFormattedString()) .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Locale).ToString()) .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft.ToString()) .ToEmbed().QueueToChannelAsync(e.Channel); return; } else { Dictionary <IDiscordUser, short> usersMentioned = new Dictionary <IDiscordUser, short>(); EmbedBuilder embed = new EmbedBuilder(); int totalAmountGiven = 0; bool mentionedSelf = false; while (e.Arguments.CanTake && totalAmountGiven <= repObject.ReputationPointsLeft) { short amount = 1; e.Arguments.Take(out string userName); var u = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (u == null) { throw new UserNullException(); } if (e.Arguments.Take(out int value)) { if (value > 0) { amount = (short)value; } } else if (e.Arguments.Peek(out string arg)) { if (Utils.IsAll(arg)) { amount = (short)(repObject.ReputationPointsLeft - ((short)usersMentioned.Sum(x => x.Value))); e.Arguments.Skip(); } } if (u.Id == e.Author.Id) { mentionedSelf = true; continue; } totalAmountGiven += amount; if (usersMentioned.Keys.Where(x => x.Id == u.Id).Count() > 0) { usersMentioned[usersMentioned.Keys.Where(x => x.Id == u.Id).First()] += amount; } else { usersMentioned.Add(u, amount); } } if (mentionedSelf) { embed.Footer = new EmbedFooter() { Text = e.Locale.GetString("warning_mention_self"), }; } if (usersMentioned.Count == 0) { return; } else { if (totalAmountGiven <= 0) { await e.ErrorEmbedResource("miki_module_accounts_rep_error_zero") .ToEmbed().QueueToChannelAsync(e.Channel); return; } if (usersMentioned.Sum(x => x.Value) > repObject.ReputationPointsLeft) { await e.ErrorEmbedResource("error_rep_limit", usersMentioned.Count, usersMentioned.Sum(x => x.Value), repObject.ReputationPointsLeft) .ToEmbed().QueueToChannelAsync(e.Channel); return; } } embed.Title = (e.Locale.GetString("miki_module_accounts_rep_header")); embed.Description = (e.Locale.GetString("rep_success")); foreach (var u in usersMentioned) { User receiver = await DatabaseHelpers.GetUserAsync(context, u.Key); receiver.Reputation += u.Value; embed.AddInlineField( receiver.Name, string.Format("{0} => {1} (+{2})", (receiver.Reputation - u.Value).ToFormattedString(), receiver.Reputation.ToFormattedString(), u.Value) ); } repObject.ReputationPointsLeft -= (short)usersMentioned.Sum(x => x.Value); await cache.UpsertAsync( $"user:{giver.Id}:rep", repObject, DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow ); await embed.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft.ToString()) .ToEmbed().QueueToChannelAsync(e.Channel); await context.SaveChangesAsync(); } }
public async Task KickAsync(EventContext e) { IDiscordGuildUser currentUser = await e.Guild.GetSelfAsync(); if ((await(e.Channel as IDiscordGuildChannel).GetPermissionsAsync(currentUser)).HasFlag(GuildPermission.KickMembers)) { IDiscordGuildUser bannedUser = null; IDiscordGuildUser author = await e.Guild.GetMemberAsync(e.Author.Id); e.Arguments.Take(out string userName); bannedUser = await DiscordExtensions.GetUserAsync(userName, e.Guild); if (bannedUser == null) { await e.ErrorEmbed(e.Locale.GetString("ban_error_user_null")) .ToEmbed().QueueToChannelAsync(e.Channel); return; } if (await bannedUser.GetHierarchyAsync() >= await author.GetHierarchyAsync()) { await e.ErrorEmbed(e.Locale.GetString("permission_error_low", "kick")).ToEmbed() .QueueToChannelAsync(e.Channel); return; } if (await bannedUser.GetHierarchyAsync() >= await currentUser.GetHierarchyAsync()) { await e.ErrorEmbed(e.Locale.GetString("permission_error_low", "kick")).ToEmbed() .QueueToChannelAsync(e.Channel); return; } string reason = ""; if (e.Arguments.CanTake) { reason = e.Arguments.Pack.TakeAll(); } EmbedBuilder embed = new EmbedBuilder(); embed.Title = e.Locale.GetString("miki_module_admin_kick_header"); embed.Description = e.Locale.GetString("miki_module_admin_kick_description", new object[] { e.Guild.Name }); if (!string.IsNullOrWhiteSpace(reason)) { embed.AddField(e.Locale.GetString("miki_module_admin_kick_reason"), reason, true); } embed.AddField(e.Locale.GetString("miki_module_admin_kick_by"), e.Author.Username + "#" + e.Author.Discriminator, true); embed.Color = new Color(1, 1, 0); await embed.ToEmbed().SendToUser(bannedUser); await bannedUser.KickAsync(reason); } else { await e.ErrorEmbed(e.Locale.GetString("permission_needed_error", $"`{e.Locale.GetString("permission_kick_members")}`")) .ToEmbed().QueueToChannelAsync(e.Channel); } }
public async Task ProfileAsync(CommandContext e) { Stopwatch sw = new Stopwatch(); sw.Start(); var context = e.GetService <MikiDbContext>(); long id = 0; ulong uid = 0; IDiscordGuildUser discordUser = null; MarriageRepository repository = new MarriageRepository(context); if (e.Arguments.Take(out string arg)) { discordUser = await DiscordExtensions.GetUserAsync(arg, e.Guild); if (discordUser == null) { throw new UserNullException(); } uid = discordUser.Id; id = uid.ToDbLong(); } else { uid = e.Message.Author.Id; discordUser = await e.Guild.GetMemberAsync(uid); id = uid.ToDbLong(); } User account = await User.GetAsync(context, discordUser.Id.ToDbLong(), discordUser.Username); string icon = ""; if (await account.IsDonatorAsync(context)) { icon = "https://cdn.discordapp.com/emojis/421969679561785354.png"; } if (account != null) { EmbedBuilder embed = new EmbedBuilder() .SetDescription(account.Title) .SetAuthor(e.Locale.GetString("miki_global_profile_user_header", discordUser.Username), icon, "https://patreon.com/mikibot") .SetThumbnail(discordUser.GetAvatarUrl()); long serverid = e.Guild.Id.ToDbLong(); LocalExperience localExp = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), (long)discordUser.Id, discordUser.Username); int rank = await localExp.GetRankAsync(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(e.Locale.GetString("miki_module_accounts_information_level", localLevel, localExp.Experience.ToFormattedString(), maxLocalExp.ToFormattedString())) .AppendText(await expBar.Print(localExp.Experience - minLocalExp, e.Guild, (IDiscordGuildChannel)e.Channel)) .AppendText(e.Locale.GetString("miki_module_accounts_information_rank", rank.ToFormattedString())) .AppendText("Reputation: " + account.Reputation.ToFormattedString(), MessageFormatting.Plain, false) .Build(); embed.AddInlineField(e.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(context); EmojiBar globalExpBar = new EmojiBar(maxGlobalExp - minGlobalExp, onBarSet, offBarSet, 6); string globalInfoValue = new MessageBuilder() .AppendText(e.Locale.GetString("miki_module_accounts_information_level", globalLevel.ToFormattedString(), account.Total_Experience.ToFormattedString(), maxGlobalExp.ToFormattedString())) .AppendText( await globalExpBar.Print(account.Total_Experience - minGlobalExp, e.Guild, e.Channel as IDiscordGuildChannel) ) .AppendText(e.Locale.GetString("miki_module_accounts_information_rank", globalRank?.ToFormattedString() ?? "We haven't calculated your rank yet!"), MessageFormatting.Plain, false) .Build(); embed.AddInlineField(e.Locale.GetString("miki_generic_global_information"), globalInfoValue); embed.AddInlineField(e.Locale.GetString("miki_generic_mekos"), account.Currency.ToFormattedString() + "<:mekos:421972155484471296>"); List <UserMarriedTo> Marriages = await repository.GetMarriagesAsync(id); Marriages.RemoveAll(x => x.Marriage.IsProposing); List <string> users = new List <string>(); int maxCount = Marriages?.Count ?? 0; for (int i = 0; i < maxCount; i++) { users.Add((await MikiApp.Instance.Discord.GetUserAsync(Marriages[i].GetOther(id).FromDbLong())).Username); } 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]} (_{Marriages[i].Marriage.TimeOfMarriage.ToShortDateString()}_)"); } } string marriageText = string.Join("\n", MarriageStrings); if (string.IsNullOrEmpty(marriageText)) { marriageText = e.Locale.GetString("miki_placeholder_null"); } embed.AddInlineField( e.Locale.GetString("miki_module_accounts_profile_marriedto"), marriageText); } Random r = new Random((int)id - 3); Color c = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble()); embed.SetColor(c); List <Achievement> allAchievements = await context.Achievements.Where(x => x.UserId == id) .ToListAsync(); string achievements = e.Locale.GetString("miki_placeholder_null"); if (allAchievements != null) { if (allAchievements.Count > 0) { achievements = AchievementManager.Instance.PrintAchievements(allAchievements); } } embed.AddInlineField( e.Locale.GetString("miki_generic_achievements"), achievements); embed.SetFooter( e.Locale.GetString( "miki_module_accounts_profile_footer", account.DateCreated.ToShortDateString(), sw.ElapsedMilliseconds), ""); sw.Stop(); await embed.ToEmbed().QueueToChannelAsync(e.Channel); } else { await e.ErrorEmbed(e.Locale.GetString("error_account_null")) .ToEmbed().QueueToChannelAsync(e.Channel); } }