Merge new rendering into master #60

Merged
JanGross merged 25 commits from dev-new-rendering into master 2023-08-07 17:34:19 +02:00
5 changed files with 52 additions and 8 deletions
Showing only changes of commit 34dbc91d1e - Show all commits

1
.gitignore vendored
View File

@@ -6,6 +6,7 @@
assets/image_cache assets/image_cache
assets/cards assets/cards
assets/import assets/import
assets/userdata
### Visual Studio Code ### ### Visual Studio Code ###
.vscode .vscode

View File

View File

@@ -1,6 +1,6 @@
const { SlashCommandBuilder, ComponentType, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder } = require("discord.js"); const { SlashCommandBuilder, ComponentType, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, Attachment } = require("discord.js");
const { Card, User, Character } = require("../models"); const { Card, User, Character } = require("../models");
const { UserUtils, ReplyUtils } = require("../util"); const { UserUtils, ReplyUtils, GeneralUtils } = require("../util");
const pageSize = 8; const pageSize = 8;
@@ -8,12 +8,18 @@ const pageSize = 8;
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName("editprofile") .setName("editprofile")
.setDescription("Edit your profile"), .setDescription("Edit your profile")
.addAttachmentOption((option) =>
option
.setName("attachement")
.setDescription("Attachement to be used")
.setRequired(false)
),
permissionLevel: 0, permissionLevel: 0,
async execute(interaction) { async execute(interaction) {
await interaction.deferReply(); await interaction.deferReply();
let user = await UserUtils.getUserByDiscordId(interaction.member.id); let user = await UserUtils.getUserByDiscordId(interaction.member.id);
let patreon = await UserUtils.getPatreonPerks(interaction.client, user);
let profile = await user.getProfile(); let profile = await user.getProfile();
@@ -31,6 +37,15 @@ module.exports = {
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
); );
if (patreon.perks?.["custom_bg"] === true && interaction.options.getAttachment("attachement")) {
mainRow.addComponents(
new ButtonBuilder()
.setLabel('Set attachment as custom background')
.setCustomId('setCustomBg')
.setStyle(ButtonStyle.Primary)
);
}
const pingRow = new ActionRowBuilder(); const pingRow = new ActionRowBuilder();
pingRow.addComponents( pingRow.addComponents(
new ButtonBuilder() new ButtonBuilder()
@@ -62,6 +77,19 @@ module.exports = {
case 'editShowcase': case 'editShowcase':
await this.openShowcaseModal(i, user, profile); await this.openShowcaseModal(i, user, profile);
break; break;
case 'setCustomBg':
await i.deferReply();
let allowedContentTypes = [ "image/png", "image/jpeg" ];
let image = interaction.options.getAttachment("attachement");
if (!allowedContentTypes.includes(image.contentType)) {
await i.editReply({ content: "An invalid image has been attached. Allowed are .png and .jpeg", ephemeral: true });
return;
}
await GeneralUtils.downloadFile(image.url, `/app/assets/userdata/profiles/${image.id}_${image.name}`);
profile.customBackground = `${process.env.ASSET_URL}/userdata/profiles/${image.id}_${image.name}`;
await profile.save();
await i.editReply('Custom profile background has been set!');
break;
case 'toggle-wishlist-ping': case 'toggle-wishlist-ping':
await i.deferUpdate(); await i.deferUpdate();
user.wishlistPing = !user.wishlistPing; user.wishlistPing = !user.wishlistPing;

View File

@@ -24,7 +24,7 @@ module.exports = {
let discordUser = interaction.options.getUser("user") ? interaction.options.getUser("user") : interaction.member.user; let discordUser = interaction.options.getUser("user") ? interaction.options.getUser("user") : interaction.member.user;
let user = await UserUtils.getUserByDiscordId(discordUser.id); let user = await UserUtils.getUserByDiscordId(discordUser.id);
let patreon = await UserUtils.getPatreonPerks(interaction.client, user);
let profile = await user.getProfile(); let profile = await user.getProfile();
let customStatus = profile.customStatus; let customStatus = profile.customStatus;
@@ -154,6 +154,18 @@ module.exports = {
] ]
} }
if (patreon.perks?.['custom_bg'] && profile.customBackground) {
job.elements.unshift(
{
"type": "image",
"asset": profile.customBackground,
"x": 0,
"y": 0,
"width": 1200,
"height": 600
}
);
}
console.log("Fetching ", ); console.log("Fetching ", );
if(process.env.NODE_ENV === "development") { if(process.env.NODE_ENV === "development") {
await interaction.channel.send(`\`\`\`${JSON.stringify(job)}\`\`\``); await interaction.channel.send(`\`\`\`${JSON.stringify(job)}\`\`\``);

View File

@@ -101,7 +101,8 @@ const PATREON = {
wishlist: 15, wishlist: 15,
currency: 1.25, currency: 1.25,
daily: 1.5 daily: 1.5
} },
custom_bg: true
}, },
4 : { 4 : {
modifiers: { modifiers: {
@@ -110,7 +111,8 @@ const PATREON = {
wishlist: 25, wishlist: 25,
currency: 1.75, currency: 1.75,
daily: 2 daily: 2
} },
custom_bg: true
}, },
5 : { 5 : {
modifiers: { modifiers: {
@@ -119,7 +121,8 @@ const PATREON = {
wishlist: 45, wishlist: 45,
currency: 2, currency: 2,
daily: 4 daily: 4
} },
custom_bg: true
} }
} }
} }