public async Task XpAsync([Remainder] DiscordMember?member = null) { member ??= (DiscordMember)Context.User; await Context.Channel.TriggerTypingAsync(); var serverAttachFilesPerm = Context.Guild !.CurrentMember.GetPermissions().HasPermission(Permissions.AttachFiles); var channelAttachFilesPerm = Context.Guild !.CurrentMember.PermissionsIn(Context.Channel).HasPermission(Permissions.AttachFiles); if (!serverAttachFilesPerm && !channelAttachFilesPerm) { await ReplyErrorAsync(Localization.XpNoAttachFilesPermission); return; } if (serverAttachFilesPerm && !channelAttachFilesPerm) { await ReplyErrorAsync(Localization.XpNoAttachFilesChannelPermission); return; } await using var xpImage = await Service.GenerateXpImageAsync(member); await Context.Channel.SendMessageAsync(new DiscordMessageBuilder().WithFile($"{member.Id}_xp.png", xpImage)); }
public async Task BackgroundAsync(string url) { var userDb = await DbContext.GetOrAddAsync(x => x.UserId == Context.User.Id, () => new UserEntity { UserId = Context.User.Id }); if (userDb.Currency < 1000) { await ReplyErrorAsync(Localization.GamblingCurrencyNotEnough, Configuration.Currency); return; } if (!Uri.TryCreate(url, UriKind.Absolute, out var backgroundUri)) { await ReplyErrorAsync(Localization.UtilityUrlNotValid); Context.Command.ResetCooldowns(); return; } if (backgroundUri.Scheme != Uri.UriSchemeHttps) { await ReplyErrorAsync(Localization.UtilityUrlNotHttps); Context.Command.ResetCooldowns(); return; } await Context.Channel.TriggerTypingAsync(); using var result = await HttpClient.GetAsync(backgroundUri); if (!result.IsSuccessStatusCode) { await ReplyErrorAsync(Localization.UtilityImageOrUrlNotGood); Context.Command.ResetCooldowns(); return; } await using var backgroundStream = await result.Content.ReadAsStreamAsync(); if (!(RiasUtilities.IsPng(backgroundStream) || RiasUtilities.IsJpg(backgroundStream))) { await ReplyErrorAsync(Localization.UtilityUrlNotPngJpg); return; } var serverAttachFilesPerm = Context.Guild !.CurrentMember.GetPermissions().HasPermission(Permissions.AttachFiles); var channelAttachFilesPerm = Context.Guild !.CurrentMember.PermissionsIn(Context.Channel).HasPermission(Permissions.AttachFiles); if (!serverAttachFilesPerm && !channelAttachFilesPerm) { await ReplyErrorAsync(Localization.ProfileBackgroundNoAttachFilesPermission); return; } if (serverAttachFilesPerm && !channelAttachFilesPerm) { await ReplyErrorAsync(Localization.ProfileBackgroundNoAttachFilesChannelPermission); return; } backgroundStream.Position = 0; await using var profilePreview = await Service.GenerateProfileBackgroundAsync(Context.User, backgroundStream); var componentInteractionArgs = await SendConfirmationButtonsAsync(new DiscordMessageBuilder() .WithEmbed(new DiscordEmbedBuilder { Color = RiasUtilities.Yellow, Description = GetText(Localization.ProfileBackgroundPreview), ImageUrl = $"attachment://{Context.User.Id}_profile_preview.png" }) .WithFile($"{Context.User.Id}_profile_preview.png", profilePreview)); if (componentInteractionArgs is null) { return; } userDb.Currency -= 1000; var profileDb = await DbContext.GetOrAddAsync(x => x.UserId == Context.User.Id, () => new ProfileEntity { UserId = Context.User.Id, BackgroundDim = 50 }); profileDb.BackgroundUrl = url; await DbContext.SaveChangesAsync(); await ButtonsActionModifyDescriptionAsync(componentInteractionArgs.Value.Result.Message, Localization.ProfileBackgroundSet); }