Skip to content

Commit

Permalink
Move to djs 14.7 and add support for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodentman87 committed Nov 30, 2022
1 parent 339f540 commit 857f6a3
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 142 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slashasaurus",
"version": "0.11.2",
"version": "0.12.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
Expand All @@ -12,14 +12,14 @@
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"discord.js": "^14.0.1",
"discord.js": "^14.7.0",
"eslint": "^8.16.0",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"typescript": "4.5.5"
},
"peerDependencies": {
"discord.js": "^14.0.1"
"discord.js": "^14.7.0"
},
"repository": {
"type": "git",
Expand Down
10 changes: 6 additions & 4 deletions src/OptionTypes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { LocalizationMap } from 'discord-api-types/v9';
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
import {
ApplicationCommandOptionType,
AutocompleteInteraction,
CommandInteraction,
ChannelType,
} from 'discord-api-types/v10';
import { AutocompleteInteraction, CommandInteraction } from 'discord.js';
} from 'discord.js';
import { SlashasaurusClient } from './SlashasaurusClient';
import { MaybePromise, OptionsMap } from './utilityTypes';

Expand Down Expand Up @@ -147,7 +148,8 @@ type ValidChannelTypes =
| ChannelType.GuildNewsThread
| ChannelType.GuildPublicThread
| ChannelType.GuildPrivateThread
| ChannelType.GuildStageVoice;
| ChannelType.GuildStageVoice
| ChannelType.GuildForum;

interface ChannelOptionsData
extends BaseApplicationCommandOptionsData<OptionsMap['CHANNEL']> {
Expand Down
39 changes: 31 additions & 8 deletions src/Page.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { EmbedBuilder } from '@discordjs/builders';
import {
CommandInteraction,
ActionRowBuilder,
APIEmbed,
ButtonInteraction,
ChannelSelectMenuInteraction,
CommandInteraction,
Embed,
ForumChannel,
InteractionWebhook,
MentionableSelectMenuInteraction,
Message,
MessageActionRowComponentBuilder,
MessageComponentInteraction,
MessageOptions,
MessageCreateOptions,
MessagePayload,
RoleSelectMenuInteraction,
SelectMenuInteraction,
TextBasedChannel,
UserSelectMenuInteraction,
WebhookEditMessageOptions,
ActionRowBuilder,
APIEmbed,
MessageActionRowComponentBuilder,
Embed,
} from 'discord.js';
import { PageActionRow, PageButton, PageSelect } from './PageComponents';
import { SlashasaurusClient } from './SlashasaurusClient';
Expand All @@ -39,7 +44,8 @@ export type PageComponentArray = PageButtonRow | PageSelectRow;
type PageComponentRows = (PageComponentArray | PageActionRow)[];

export interface RenderedPage
extends Omit<MessageOptions, 'nonce' | 'components'> {
extends Omit<MessageCreateOptions, 'nonce' | 'components' | 'content'> {
content?: string | null;
components?: PageComponentRows;
embeds?: (APIEmbed | EmbedBuilder)[];
}
Expand All @@ -58,6 +64,10 @@ export class PageInteractionReplyMessage {
async edit(options: string | MessagePayload | WebhookEditMessageOptions) {
await this.webhook.editMessage(this.id, options);
}

async delete() {
await this.webhook.deleteMessage(this.id);
}
}

interface PageStatic<P, S> {
Expand Down Expand Up @@ -127,6 +137,10 @@ export abstract class Page<
return this.client.sendPageToChannel(this, channel);
}

sendAsForumPost(channel: ForumChannel, postTitle: string) {
return this.client.sendPageToForumChannel(this, postTitle, channel);
}

sendAsReply(
interaction: MessageComponentInteraction | CommandInteraction,
ephemeral = false
Expand All @@ -152,7 +166,16 @@ export abstract class Page<
*/
abstract serializeState(): string;

handleId(id: string, interaction: ButtonInteraction | SelectMenuInteraction) {
handleId(
id: string,
interaction:
| ButtonInteraction
| SelectMenuInteraction
| UserSelectMenuInteraction
| RoleSelectMenuInteraction
| ChannelSelectMenuInteraction
| MentionableSelectMenuInteraction
) {
const handler = this.handlers.get(id);
if (handler) {
handler(interaction);
Expand Down
Loading

0 comments on commit 857f6a3

Please sign in to comment.