public async ValueTask <AdminCommandResult> GetBackpackProfileAsync([Remainder] BackpackUser user)
        {
            var now     = DateTimeOffset.UtcNow;
            var builder = new LocalEmbedBuilder()
                          .WithSuccessColor()
                          .WithTitle(Localize("backpack_info_title", user.Name))
                          .WithThumbnailUrl(user.AvatarUrl.ToString())
                          .AddField(Localize("info_id"), user.Id)
                          .AddField(Localize("backpack_info_lastonline"),
                                    string.Join('\n', user.LastOnline.ToString("g", Context.Language.Culture),
                                                (now - user.LastOnline).HumanizeFormatted(Localization, Context.Language, TimeUnit.Second,
                                                                                          true)))
                          .AddField(Localize("backpack_info_flags"),
                                    user.Flags == BackpackUserFlags.None
                        ? Localize("info_none")
                        : user.Flags.Humanize(LetterCasing.Title));

            if (user.AmountDonated != default)
            {
                builder.AddField(Localize("backpack_info_donated"), $"${user.AmountDonated:F} USD");
            }

            if (user.PremiumMonthsGifted != default)
            {
                builder.AddField(Localize("backpack_info_premiumgifts"), user.PremiumMonthsGifted);
            }

            if (user.Trust.Negative != default || user.Trust.Positive != default)
            {
                var netTrust = user.Trust.Positive - user.Trust.Negative;

                builder.AddField(Localize("backpack_info_trust"),
                                 $"{(netTrust > 0 ? "+" : string.Empty)}{netTrust} (+{user.Trust.Positive}/-{user.Trust.Negative})");
            }

            var currencies = await BackpackClient.GetCurrenciesAsync();

            var inventoryValue = user.Inventory.Keys * currencies.CrateKey.Price.Value + user.Inventory.Metal +
                                 user.Inventory.Value;

            builder.AddField(Localize("backpack_info_worth"),
                             Localize("backpack_info_worth_text", (inventoryValue / currencies.CrateKey.Price.Value).ToString("F"),
                                      inventoryValue.ToString("F"),
                                      (inventoryValue * currencies.RefinedMetal.Price.Value).ToString("F")));


            if (!user.SiteBans.IsDefaultOrEmpty ||
                user.Flags.HasFlag(BackpackUserFlags.SteamCommunityBanned) ||
                user.Flags.HasFlag(BackpackUserFlags.SteamRepCaution) ||
                user.Flags.HasFlag(BackpackUserFlags.SteamRepScammer) ||
                user.Flags.HasFlag(BackpackUserFlags.SteamVACBanned) ||
                user.Flags.HasFlag(BackpackUserFlags.SteamEconomyBanned) ||
                user.Flags.HasFlag(BackpackUserFlags.ValveGameBanned))
            {
                builder.WithErrorColor()
                .WithFooter(Localize("backpack_info_caution",
                                     Markdown.Code($"{Context.Prefix}backpack bans <user>")));
            }


            return(CommandSuccess(embed: builder.Build()));
        }
Example #2
0
        public async ValueTask <AdminCommandResult> ModifySuggestionAsync(int id, [Remainder] string reason = null)
        {
            var suggestion = await Context.Database.Suggestions.FindAsync(id);

            if (suggestion?.GuildId != Context.Guild.Id)
            {
                return(CommandErrorLocalized("suggestion_notfound"));
            }

            if (!(await Context.Database.GetLoggingChannelAsync(Context.Guild.Id, LogType.SuggestionArchive) is { }
                  archiveChannel))
            {
                return(CommandErrorLocalized("suggestion_noarchive"));
            }

            IUserMessage message = null;
            int          upvotes = 0, downvotes = 0;

            if (await Context.Database.GetLoggingChannelAsync(Context.Guild.Id, LogType.Suggestion) is { }
                suggestionChannel)
            {
                try
                {
                    message = (IUserMessage)await suggestionChannel.GetMessageAsync(suggestion.MessageId);

                    var upvote = (await Context.Database.SpecialEmojis.FindAsync(Context.Guild.Id.RawValue, EmojiType.Upvote))?.Emoji ??
                                 EmojiTools.Upvote;
                    var downvote = (await Context.Database.SpecialEmojis.FindAsync(Context.Guild.Id.RawValue, EmojiType.Downvote))?.Emoji ??
                                   EmojiTools.Downvote;

                    upvotes   = Math.Max((await message.GetReactionsAsync(upvote, int.MaxValue)).Count - 1, 0);
                    downvotes = Math.Max((await message.GetReactionsAsync(downvote, int.MaxValue)).Count - 1, 0);
                }
                catch { /* ignored */ }
            }

            var author = await Context.Client.GetOrDownloadUserAsync(suggestion.UserId);

            var builder = new LocalEmbedBuilder()
                          .WithAuthor(Context.Localize(Context.Alias.Equals("approve")
                        ? "suggestion_approved_title"
                        : "suggestion_denied_title", suggestion.Id, author.Tag, upvotes, downvotes),
                                      author.GetAvatarUrl())
                          .WithDescription(suggestion.Text)
                          .WithFooter(Context.Localize(Context.Alias.Equals("approve")
                        ? "suggestion_approved_footer"
                        : "suggestion_denied_footer", Context.User.Tag),
                                      Context.User.GetAvatarUrl());

            if (Context.Alias.Equals("approve"))
            {
                builder.WithSuccessColor();
            }
            else
            {
                builder.WithErrorColor();
            }

            if (!string.IsNullOrWhiteSpace(reason))
            {
                builder.AddField(Context.Localize("title_reason"), reason);
            }

            if (suggestion.Format != ImageFormat.Default)
            {
                await archiveChannel.SendMessageAsync(new LocalAttachment(suggestion.Image, $"attachment.{suggestion.Format.ToString().ToLower()}"),
                                                      embed : builder.WithImageUrl($"attachment://attachment.{suggestion.Format.ToString().ToLower()}").Build());
            }
            else
            {
                await archiveChannel.SendMessageAsync(embed : builder.Build());
            }

            _ = message?.DeleteAsync();

            Context.Database.Suggestions.Remove(suggestion);
            await Context.Database.SaveChangesAsync();

            return(CommandSuccessLocalized(Context.Alias.Equals("approve")
                ? "suggestion_approved"
                : "suggestion_denied"));
        }