/[sudobot]/trunk/src/utils/Pagination.ts
ViewVC logotype

Diff of /trunk/src/utils/Pagination.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 447 by rakin, Mon Jul 29 17:30:17 2024 UTC revision 467 by rakin, Mon Jul 29 17:30:23 2024 UTC
# Line 14  export interface PaginationOptions<T> { Line 14  export interface PaginationOptions<T> {
14      guild_id: string;      guild_id: string;
15      channel_id: string;      channel_id: string;
16      user_id?: string;      user_id?: string;
17        timeout?: number;
18      embedBuilder: (options: EmbedBuilderOptions<T>) => MessageEmbed;      embedBuilder: (options: EmbedBuilderOptions<T>) => MessageEmbed;
19      actionRowBuilder?: (options: { first: boolean, last: boolean, next: boolean, back: boolean }) => MessageActionRow<MessageButton>;      actionRowBuilder?: (options: { first: boolean, last: boolean, next: boolean, back: boolean }) => MessageActionRow<MessageButton>;
20  }  }
# Line 60  export default class Pagination<T> { Line 61  export default class Pagination<T> {
61    
62          options.embeds ??= [];          options.embeds ??= [];
63          options.embeds.push(this.getEmbed(page));          options.embeds.push(this.getEmbed(page));
64          console.log(options.embeds);          
65          options.components ??= [];          options.components ??= [];
66          options.components.push(this.getActionRow(actionRowOptionsDup));          options.components.push(this.getActionRow(actionRowOptionsDup));
67    
# Line 72  export default class Pagination<T> { Line 73  export default class Pagination<T> {
73              return this.options.actionRowBuilder({ first, last, next, back });              return this.options.actionRowBuilder({ first, last, next, back });
74          }          }
75    
76          const actionRow = new MessageActionRow<MessageButton>;          const actionRow = new MessageActionRow<MessageButton>();
77    
78          actionRow.addComponents(          actionRow.addComponents(
79              new MessageButton()              new MessageButton()
# Line 107  export default class Pagination<T> { Line 108  export default class Pagination<T> {
108              interactionType: 'MESSAGE_COMPONENT',              interactionType: 'MESSAGE_COMPONENT',
109              componentType: 'BUTTON',              componentType: 'BUTTON',
110              message,              message,
111              time: 60_000,              time: this.options.timeout ?? 60_000,
112              filter: interaction => {              filter: interaction => {
113                  if (interaction.inGuild() && (!this.options.user_id || interaction.user.id === this.options.user_id)) {                  if (interaction.inGuild() && (!this.options.user_id || interaction.user.id === this.options.user_id)) {
114                      return true;                      return true;
# Line 126  export default class Pagination<T> { Line 127  export default class Pagination<T> {
127                  return;                  return;
128              }              }
129    
130                // await interaction.deferUpdate();
131                
132              const maxPage = Math.ceil(this.data.length / this.options.limit);              const maxPage = Math.ceil(this.data.length / this.options.limit);
133              const componentOptions = { first: true, last: true, next: true, back: true };              const componentOptions = { first: true, last: true, next: true, back: true };
134    
# Line 162  export default class Pagination<T> { Line 165  export default class Pagination<T> {
165          });          });
166    
167          collector.on("end", async () => {          collector.on("end", async () => {
168              await message.edit({ components: [this.getActionRow({ first: false, last: false, next: false, back: false })] });              const component = message.components[0]; // this.getActionRow({ first: false, last: false, next: false, back: false })
169    
170                for (const i in component.components) {
171                    component.components[i].disabled = true;
172                }
173    
174                await message.edit({ components: [component] });
175          });          });
176      }      }
177  }  }

Legend:
Removed from v.447  
changed lines
  Added in v.467

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26