Skip to content

Commit bfd0fb2

Browse files
author
xyzjesper
committed
Fixed issue #26. Fixed component editor import. Updated messageHelper. Removed debug logs from embed import.
1 parent 71f2a1f commit bfd0fb2

5 files changed

Lines changed: 73 additions & 20 deletions

File tree

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helper/messageHelper.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,28 @@ export async function showComponentFollowModal(interaction: ModalSubmitInteracti
4141
}
4242
}
4343

44-
export async function updateComponentsWithPositions(message: Message, json: any, positions: string[]) {
44+
export async function updateComponentsWithPositions(message: Message, json: any, positions?: string[]) {
4545

4646
let newComponents = [];
47-
if (positions.length == 1) {
48-
newComponents = JSON.parse(JSON.stringify(message.components));
49-
newComponents[Number(positions[0])] = json;
50-
} else if (positions.length == 2) {
51-
newComponents = JSON.parse(JSON.stringify(message.components));
52-
53-
if (newComponents[Number(positions[0])]?.components) {
54-
newComponents[Number(positions[0])].components[Number(positions[1])] = json
55-
}
56-
} else if (positions.length == 3) {
57-
newComponents = JSON.parse(JSON.stringify(message.components));
47+
if (positions) {
48+
if (positions.length == 1) {
49+
newComponents = JSON.parse(JSON.stringify(message.components));
50+
newComponents[Number(positions[0])] = json;
51+
} else if (positions.length == 2) {
52+
newComponents = JSON.parse(JSON.stringify(message.components));
53+
54+
if (newComponents[Number(positions[0])]?.components) {
55+
newComponents[Number(positions[0])].components[Number(positions[1])] = json
56+
}
57+
} else if (positions.length == 3) {
58+
newComponents = JSON.parse(JSON.stringify(message.components));
5859

59-
if (newComponents[Number(positions[0])]?.components?.[Number(positions[1])]?.components) {
60-
newComponents[Number(positions[0])].components[Number(positions[1])].components[Number(positions[2])] = json
60+
if (newComponents[Number(positions[0])]?.components?.[Number(positions[1])]?.components) {
61+
newComponents[Number(positions[0])].components[Number(positions[1])].components[Number(positions[2])] = json
62+
}
6163
}
64+
} else if (positions == null){
65+
newComponents = json
6266
}
6367

6468
const updatedComponents = await Promise.all(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
ActionRowBuilder,
3+
ChannelSelectMenuBuilder,
4+
ChannelType, ContainerBuilder,
5+
EmbedBuilder, LabelBuilder,
6+
MessageFlags, ModalBuilder,
7+
ModalSubmitInteraction, StringSelectMenuBuilder, TextChannel, TextDisplayBuilder, TextInputBuilder, TextInputStyle
8+
} from "discord.js";
9+
import {ExtendedClient} from "../../../types/ExtendedClient.js";
10+
import {convertToEmojiToPng} from "../../../helper/emojis.js";
11+
import {database} from "../../../main/database.js";
12+
import {randomUUID} from "crypto";
13+
import {showComponentFollowModal, updateComponentsWithPositions} from "../../../helper/messageHelper.js";
14+
import {Channel} from "diagnostics_channel";
15+
16+
export default {
17+
id: "component-editor-create-import-modal",
18+
19+
/**
20+
*
21+
* @param {ModalSubmitInteraction} interaction
22+
* @param {ExtendedClient} client
23+
*/
24+
25+
async execute(interaction: ModalSubmitInteraction, client: ExtendedClient) {
26+
const messageId = interaction.customId.split(":")[1]
27+
28+
const message = await (interaction.channel as TextChannel).messages.fetch(messageId)
29+
30+
31+
const data = interaction.fields.getUploadedFiles("file")
32+
const url = data.first().url
33+
const blob = await fetch(url)
34+
const json = await blob.blob()
35+
const buffer = Buffer.from(await json.arrayBuffer())
36+
console.log(buffer.toString("utf-8"))
37+
38+
await updateComponentsWithPositions(
39+
message,
40+
JSON.parse(buffer.toString("utf-8")),
41+
null,
42+
)
43+
44+
await interaction.deferUpdate()
45+
}
46+
}

src/modules/embed/modals/modal-embed-import.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ export default {
3333

3434
embeds[embedIndex] = newEmbed;
3535

36-
console.log(embeds[embedIndex])
37-
console.log(embeds)
38-
3936
if (message.webhookId) {
4037
const webhooks = await interaction.guild?.fetchWebhooks();
4138
const webhook = webhooks?.find((wh) => wh.id == message.webhookId);

src/systems/level/levelImages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function generateLevelCardImage(user: GuildMember, guildId: string)
1818
.setUsername(user.user.username)
1919
.setLevel(levelData.Level)
2020
.setRequiredXP(Number(levelData.RequiredXp))
21-
.setAvatar(user.displayAvatarURL({extension: "png", forceStatic: true}))
21+
.setAvatar(user.displayAvatarURL({extension: "png", forceStatic: true}) ?? "https://cdn.discordapp.com/emojis/1259432940383768647.webp?size=96/mes")
2222
.setCurrentXP(Number(levelData.XP))
2323

2424

@@ -56,9 +56,9 @@ export async function generateLevelLeaderboard(guild: Guild, type: "default" | "
5656
level: user.Level ?? 0,
5757
username: guildMember?.user?.username ?? "N/A",
5858
displayName: guildMember?.displayName ?? "N/A",
59-
avatar: guildMember.displayAvatarURL({extension: "png", forceStatic: true}),
59+
avatar: guildMember?.displayAvatarURL({extension: "png", forceStatic: true}) ?? "https://cdn.discordapp.com/emojis/1259432940383768647.webp?size=96",
6060
xp: Number(user.XP) ?? 0,
61-
rank: rank ? (rank + 1) : 0
61+
rank: (rank + 1)
6262
};
6363
} catch (error) {
6464
return

0 commit comments

Comments
 (0)