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 WhoIsAsync(EventContext e) { ArgObject arg = e.Arguments.Join(); if (arg == null) { throw new ArgumentNullException(); } IDiscordGuildUser user = await arg.GetUserAsync(e.Guild); //if (user == null) //{ // user = e.Author as IGuildUser; //} var embed = e.CreateEmbedBuilder(); embed.WithTitle("whois_title", user.Username); embed.EmbedBuilder.SetColor(0.5f, 0f, 1.0f); embed.EmbedBuilder.ImageUrl = user.GetAvatarUrl(); var roles = (await e.Guild.GetRolesAsync()).Where(x => user.RoleIds.Contains(x.Id) && 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.ToHexString()}**"); embed.AddField( e.CreateResource("miki_module_whois_tag_personal"), new StringResource(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 StringResource(r) ); } embed.Build().QueueToChannel(e.Channel); }
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 AvatarAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { e.Channel.QueueMessageAsync(e.Author.GetAvatarUrl()); } else { if (arg.Argument == "-s") { e.Channel.QueueMessageAsync(e.Guild.IconUrl); return; } IDiscordGuildUser user = await arg.GetUserAsync(e.Guild); if (user != null) { e.Channel.QueueMessageAsync(user.GetAvatarUrl()); } } }
public async Task WarningsAsync(IDiscordGuild guild, MessageContext context, IDiscordGuildUser user) { var warnings = await _warningRepository.GetWarningsForUserAsync(guild.Id, user.Id); string GetLine(UserWarning w) { var title = w.ConsoleChannelId.HasValue && w.ConsoleMessageId.HasValue ? $"[#{w.Id}](https://discordapp.com/channels/{guild.Id}/{w.ConsoleChannelId}/{w.ConsoleMessageId})" : $"#{w.Id}"; return($"[{title} | {w.Created:d}] {w.Reason.MaxLength(50, "...")}"); } var lastYear = DateTime.UtcNow.Subtract(TimeSpan.FromDays(365)); var lastMonth = DateTime.UtcNow.Subtract(TimeSpan.FromDays(31)); var lastWeek = DateTime.UtcNow.Subtract(TimeSpan.FromDays(7)); var stats = _localizer["Moderation.Warnings.Stats"] .WithToken("total", warnings.Count) .WithToken("year", warnings.Count(w => w.Created >= lastYear)) .WithToken("month", warnings.Count(w => w.Created >= lastMonth)) .WithToken("week", warnings.Count(w => w.Created >= lastWeek)); context.Response.AddEmbed() .SetEmbedAuthor(_localizer["Moderation.Warnings.Title"].WithToken("user", user), user.GetAvatarUrl(size: ImageSize.x32)) .AddEmbedField(_localizer["Moderation.Warnings.Stats.Header"], stats) .AddEmbedField(_localizer["Moderation.Warnings.Warnings.Header"], string.Join("\n", warnings.Select(GetLine))); }
public async Task ProfileAsync(EventContext e) { Stopwatch sw = new Stopwatch(); sw.Start(); using (var context = new MikiContext()) { long id = 0; ulong uid = 0; var arg = e.Arguments.FirstOrDefault(); if (arg != null) { uid = (await arg.GetUserAsync(e.Guild)).Id; id = uid.ToDbLong(); } else { uid = e.message.Author.Id; id = uid.ToDbLong(); } IDiscordGuildUser discordUser = await e.Guild.GetUserAsync(uid); User account = await User.GetAsync(context, discordUser); string icon = ""; if (await account.IsDonatorAsync(context)) { icon = "https://cdn.discordapp.com/emojis/421969679561785354.png"; } if (account != null) { EmbedBuilder embed = Utils.Embed .SetDescription(account.Title) .SetAuthor(e.GetResource("miki_global_profile_user_header", account.Name), icon, "https://patreon.com/mikibot") .SetThumbnail(discordUser.GetAvatarUrl()); long serverid = e.Guild.Id.ToDbLong(); LocalExperience localExp = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), discordUser); if (localExp == null) { localExp = await LocalExperience.CreateAsync(context, serverid, discordUser); } 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(e.GetResource("miki_module_accounts_information_level", localLevel, localExp.Experience, maxLocalExp)) .AppendText(await expBar.Print(localExp.Experience - minLocalExp, (IDiscordGuildChannel)e.Channel)) .AppendText(e.GetResource("miki_module_accounts_information_rank", rank)) .AppendText("Reputation: " + account.Reputation, MessageFormatting.Plain, false) .Build(); embed.AddInlineField(e.GetResource("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(e.GetResource("miki_module_accounts_information_level", globalLevel, account.Total_Experience, maxGlobalExp)) .AppendText( await globalExpBar.Print(account.Total_Experience - minGlobalExp, e.Channel as IDiscordGuildChannel) ) .AppendText(e.GetResource("miki_module_accounts_information_rank", globalRank), MessageFormatting.Plain, false) .Build(); embed.AddInlineField(e.GetResource("miki_generic_global_information"), globalInfoValue); embed.AddInlineField(e.GetResource("miki_generic_mekos"), account.Currency + "<:mekos:421972155484471296>"); List <UserMarriedTo> Marriages = await Marriage.GetMarriagesAsync(context, 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 User.GetNameAsync(context, 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]} (_{Marriages[i].Marriage.TimeOfMarriage.ToShortDateString()}_)"); } } string marriageText = string.Join("\n", MarriageStrings); if (string.IsNullOrEmpty(marriageText)) { marriageText = e.GetResource("miki_placeholder_null"); } embed.AddInlineField( e.GetResource("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); CommandUsage favouriteCommand = await context.CommandUsages .OrderByDescending(x => x.Amount) .FirstOrDefaultAsync(x => x.UserId == id); string favCommand = $"{favouriteCommand?.Name ?? e.GetResource("miki_placeholder_null")} ({ favouriteCommand?.Amount ?? 0 })"; embed.AddInlineField(e.GetResource("miki_module_accounts_profile_favourite_command"), favCommand); List <Achievement> allAchievements = await context.Achievements.Where(x => x.Id == id).ToListAsync(); string achievements = e.GetResource("miki_placeholder_null"); if (allAchievements != null) { if (allAchievements.Count > 0) { achievements = AchievementManager.Instance.PrintAchievements(allAchievements); } } embed.AddInlineField( e.GetResource("miki_generic_achievements"), achievements); embed.SetFooter( e.GetResource("miki_module_accounts_profile_footer", account.DateCreated.ToShortDateString(), sw.ElapsedMilliseconds), ""); sw.Stop(); embed.ToEmbed().QueueToChannel(e.Channel); } else { e.ErrorEmbed(e.GetResource("error_account_null")) .ToEmbed().QueueToChannel(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); } }