Skip to content

Commit c263cb0

Browse files
committed
Fixed youtube notification settings for setting and validation.
1 parent e7992fe commit c263cb0

4 files changed

Lines changed: 86 additions & 71 deletions

File tree

bun.lock

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

src/modules/notification/buttons/youtube-manage.ts

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Parser from "rss-parser";
1313
import {database} from "../../../main/database.js";
1414
import {sendDefaultMessage} from "../../../helper/utilityHelper.js";
1515
import {convertToEmojiToPng} from "../../../helper/emojis.js";
16-
import {PaginationData} from "../../../types/Pagination.js";
16+
import type {PaginationData} from "../../../types/Pagination.js";
1717
import {PaginationBuilder} from "../../../helper/paginationHelper.js";
1818

1919
export default {
@@ -25,76 +25,68 @@ export default {
2525
* @param {ExtendedClient} client
2626
*/
2727
async execute(interaction: ButtonInteraction, client: ExtendedClient) {
28+
const parser = new Parser();
2829
const [action, uuid, currentIndexStr] = interaction.customId.split(":");
30+
// @ts-ignore
2931
const currentIndex = parseInt(currentIndexStr) || 0;
3032
const guildId = interaction.guild?.id;
3133
const pageSize = 5;
3234

33-
try {
34-
const data = await database.guildYoutubeNotifications
35-
.findMany({
36-
where: {
37-
GuildId: guildId
38-
}
39-
})
35+
const data = await database.guildYoutubeNotifications
36+
.findMany({
37+
where: {
38+
GuildId: guildId
39+
}
40+
})
4041

41-
if (!data.length) {
42-
return await sendDefaultMessage(`## ${await convertToEmojiToPng("error")} No Twitch Streamer Found`, interaction, true)
43-
}
44-
45-
const list = data.slice(currentIndex, currentIndex + pageSize);
46-
47-
const embedMessages = new TextDisplayBuilder()
48-
.setContent((await Promise.all(list.map(async (l) => {
42+
if (!data.length) {
43+
return await sendDefaultMessage(`## ${await convertToEmojiToPng("error")} No Youtube Channel Found`, interaction, true)
44+
}
4945

50-
const parser = new Parser();
51-
const videodata = await parser.parseURL(
52-
`https://www.youtube.com/feeds/videos.xml?channel_id=${l.YoutubeChannelId}`
53-
);
54-
const {author} = videodata.items[0];
46+
const list = data.slice(currentIndex, currentIndex + pageSize);
5547

56-
return `**Youtube Channel**: ${author} (${l.YoutubeChannelId})\n**Channel Name:** ${l.ChannelId ? `<#${l.ChannelId}>` : "N/A"}\n**UUID:** ${l.UUID}`
57-
}))).join("\n\n"))
48+
const embedMessages = new TextDisplayBuilder()
49+
.setContent((await Promise.all(list.map(async (l) => {
50+
const videoData = await parser.parseURL(
51+
`https://www.youtube.com/feeds/videos.xml?channel_id=${l.YoutubeChannelId}`
52+
);
53+
// @ts-ignore
54+
const {author} = videoData.items[0];
5855

56+
return `**Youtube Channel**: ${author} (${l.YoutubeChannelId})\n**Channel Name:** ${l.ChannelId ? `<#${l.ChannelId}>` : "N/A"}\n**UUID:** ${l.UUID}`
57+
}))).join("\n\n"))
5958

60-
const selectMenu = new StringSelectMenuBuilder()
61-
.setCustomId("youtube-manage-select")
62-
.setPlaceholder("Select a Option to manage")
63-
.addOptions(await Promise.all(list.map(async (l) => {
6459

65-
const parser = new Parser();
66-
const videodata = await parser.parseURL(
67-
`https://www.youtube.com/feeds/videos.xml?channel_id=${l.YoutubeChannelId}`
68-
);
69-
const {author} = videodata.items[0];
60+
const selectMenu = new StringSelectMenuBuilder()
61+
.setCustomId("youtube-manage-select")
62+
.setPlaceholder("Select a Option to manage")
63+
.addOptions(await Promise.all(list.map(async (l) => {
64+
const videoData = await parser.parseURL(
65+
`https://www.youtube.com/feeds/videos.xml?channel_id=${l.YoutubeChannelId}`
66+
);
67+
// @ts-ignore
68+
const {author} = videoData.items[0];
7069

71-
return {
72-
label: `${author} (${l.YoutubeChannelId})`,
73-
description: `UUID: ${l.UUID}`,
74-
value: l.UUID,
75-
emoji: "<:youtube:1432486146868510720>",
76-
}
77-
})));
70+
return {
71+
label: `${author} (${l.YoutubeChannelId})`,
72+
description: `UUID: ${l.UUID}`,
73+
value: l.UUID,
74+
emoji: "<:youtube:1432486146868510720>",
75+
}
76+
})));
7877

79-
const paginationData: PaginationData = {
80-
interaction: interaction,
81-
paginationData: data,
82-
buttonCustomId: "youtube-manage:",
83-
selectmenu: selectMenu,
84-
content: embedMessages,
85-
pageSize: pageSize,
86-
client: client,
87-
currentIndex: currentIndex,
88-
latestUUID: uuid
89-
};
90-
await PaginationBuilder(paginationData);
91-
} catch (error) {
92-
console.error("Error:", error);
93-
await interaction.reply({
94-
content:
95-
"## An error occurred while fetching the menus. Please try again later",
96-
flags: MessageFlags.Ephemeral
97-
});
98-
}
78+
const paginationData: PaginationData = {
79+
interaction: interaction,
80+
paginationData: data,
81+
buttonCustomId: "youtube-manage:",
82+
selectmenu: selectMenu,
83+
content: embedMessages,
84+
pageSize: pageSize,
85+
client: client,
86+
currentIndex: currentIndex,
87+
// @ts-ignore
88+
latestUUID: uuid
89+
};
90+
await PaginationBuilder(paginationData);
9991
}
10092
};

src/modules/notification/modals/youtube-add-channelid-modal.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {convertToEmojiToPng} from "../../../helper/emojis.js";
1818
import {database} from "../../../main/database.js";
1919
import {randomUUID} from "crypto";
2020
import {sendDefaultMessage} from "../../../helper/utilityHelper.js";
21+
import Parser from "rss-parser";
2122

2223
export default {
2324
id: "youtube-add-channelid-modal",
@@ -33,14 +34,25 @@ export default {
3334

3435
const uuids = randomUUID();
3536

36-
const getChannelName = interaction.fields.getTextInputValue(
37+
const youtubeChannelId = interaction.fields.getTextInputValue(
3738
"channelid"
3839
);
3940

41+
try {
42+
const parser = new Parser()
43+
const videoData = await parser.parseURL(
44+
`https://www.youtube.com/feeds/videos.xml?channel_id=${youtubeChannelId}`
45+
);
46+
// @ts-ignore
47+
const {author} = videoData.items[0];
48+
} catch (e) {
49+
return await sendDefaultMessage(`## ${await convertToEmojiToPng("error")} No Youtube Channel found with this ID!`, interaction, true)
50+
}
51+
4052
const data = await database.guildYoutubeNotifications.findFirst({
4153
where: {
4254
GuildId: interaction.guild?.id,
43-
YoutubeChannelId: getChannelName
55+
YoutubeChannelId: youtubeChannelId
4456
}
4557
});
4658

@@ -55,7 +67,7 @@ export default {
5567
GuildId: interaction.guild?.id
5668
}
5769
},
58-
YoutubeChannelId: getChannelName,
70+
YoutubeChannelId: youtubeChannelId,
5971
ChannelId: "",
6072
MessageTemplateId: "",
6173
PingRoles: [],
@@ -82,7 +94,7 @@ export default {
8294
ChannelType.GuildAnnouncement
8395
)
8496
.setCustomId(
85-
"youtube-add-channel:" + interaction.customId.split(":")[1]
97+
"youtube-add-channel:" + uuids
8698
)
8799
.setMaxValues(1)
88100
.setMinValues(1)
@@ -92,7 +104,7 @@ export default {
92104
const message = new ActionRowBuilder<ButtonBuilder>().addComponents(
93105
new ButtonBuilder()
94106
.setCustomId(
95-
"youtube-add-message:" + interaction.customId.split(":")[1]
107+
"youtube-add-message:" + uuids
96108
)
97109
.setStyle(ButtonStyle.Secondary)
98110
.setLabel("Message Template")

src/modules/notification/modals/youtube-add-message-modal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default {
3333
await database.guildYoutubeNotifications.update(
3434
{
3535
where: {
36+
GuildId: interaction.guild.id,
3637
UUID: interaction.customId.split(":")[1]
3738
},
3839
data: {

0 commit comments

Comments
 (0)