@@ -13,7 +13,7 @@ import Parser from "rss-parser";
1313import { database } from "../../../main/database.js" ;
1414import { sendDefaultMessage } from "../../../helper/utilityHelper.js" ;
1515import { convertToEmojiToPng } from "../../../helper/emojis.js" ;
16- import { PaginationData } from "../../../types/Pagination.js" ;
16+ import type { PaginationData } from "../../../types/Pagination.js" ;
1717import { PaginationBuilder } from "../../../helper/paginationHelper.js" ;
1818
1919export 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} ;
0 commit comments