Refactor monorepo (#36)

* feat: GuildChannel.edit

* fix: fmt

Co-authored-by: socram03 <marcosjgs03@gmail.com>
This commit is contained in:
Nicolas 2022-07-07 23:44:48 -03:00 committed by GitHub
parent 7d92892c9f
commit 217c100e49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 246 additions and 133 deletions

View File

@ -11,6 +11,8 @@ import type {
DiscordGuildRoleCreate, DiscordGuildRoleCreate,
DiscordGuildRoleDelete, DiscordGuildRoleDelete,
DiscordGuildRoleUpdate, DiscordGuildRoleUpdate,
DiscordIntegration,
DiscordIntegrationDelete,
DiscordInteraction, DiscordInteraction,
DiscordMemberWithUser, DiscordMemberWithUser,
DiscordMessage, DiscordMessage,
@ -26,9 +28,6 @@ import type {
DiscordThreadListSync, DiscordThreadListSync,
DiscordUser, DiscordUser,
DiscordWebhookUpdate, DiscordWebhookUpdate,
DiscordIntegration,
DiscordIntegrationDelete
} from "../vendor/external.ts"; } from "../vendor/external.ts";
import type { Snowflake } from "../util/Snowflake.ts"; import type { Snowflake } from "../util/Snowflake.ts";
import type { Session } from "../session/Session.ts"; import type { Session } from "../session/Session.ts";
@ -41,8 +40,8 @@ import ThreadMember from "../structures/ThreadMember.ts";
import Member from "../structures/Member.ts"; import Member from "../structures/Member.ts";
import Message from "../structures/Message.ts"; import Message from "../structures/Message.ts";
import User from "../structures/User.ts"; import User from "../structures/User.ts";
import Integration from "../structures/Integration.ts" import Integration from "../structures/Integration.ts";
import Guild from "../structures/guilds/Guild.ts"; import Guild from "../structures/guilds/Guild.ts";
import InteractionFactory from "../structures/interactions/InteractionFactory.ts"; import InteractionFactory from "../structures/interactions/InteractionFactory.ts";
export type RawHandler<T> = (...args: [Session, number, T]) => void; export type RawHandler<T> = (...args: [Session, number, T]) => void;
@ -186,16 +185,28 @@ export const WEBHOOKS_UPDATE: RawHandler<DiscordWebhookUpdate> = (session, _shar
session.emit("webhooksUpdate", { guildId: webhook.guild_id, channelId: webhook.channel_id }); session.emit("webhooksUpdate", { guildId: webhook.guild_id, channelId: webhook.channel_id });
}; };
export const INTEGRATION_CREATE: RawHandler<DiscordIntegration & { guildId?: Snowflake }> = (session, _shardId, payload) => { export const INTEGRATION_CREATE: RawHandler<DiscordIntegration & { guildId?: Snowflake }> = (
session,
_shardId,
payload,
) => {
session.emit("integrationCreate", new Integration(session, payload)); session.emit("integrationCreate", new Integration(session, payload));
}; };
export const INTEGRATION_UPDATE: RawHandler<DiscordIntegration & { guildId?: Snowflake }> = (session, _shardId, payload) => { export const INTEGRATION_UPDATE: RawHandler<DiscordIntegration & { guildId?: Snowflake }> = (
session,
_shardId,
payload,
) => {
session.emit("integrationCreate", new Integration(session, payload)); session.emit("integrationCreate", new Integration(session, payload));
}; };
export const INTEGRATION_DELETE: RawHandler<DiscordIntegrationDelete> = (session, _shardId, payload) => { export const INTEGRATION_DELETE: RawHandler<DiscordIntegrationDelete> = (session, _shardId, payload) => {
session.emit("integrationDelete", { id: payload.id, guildId: payload.guild_id, applicationId: payload.application_id }); session.emit("integrationDelete", {
id: payload.id,
guildId: payload.guild_id,
applicationId: payload.application_id,
});
}; };
export const MESSAGE_REACTION_ADD: RawHandler<DiscordMessageReactionAdd> = (session, _shardId, reaction) => { export const MESSAGE_REACTION_ADD: RawHandler<DiscordMessageReactionAdd> = (session, _shardId, reaction) => {
@ -206,11 +217,19 @@ export const MESSAGE_REACTION_REMOVE: RawHandler<DiscordMessageReactionRemove> =
session.emit("messageReactionRemove", null); session.emit("messageReactionRemove", null);
}; };
export const MESSAGE_REACTION_REMOVE_ALL: RawHandler<DiscordMessageReactionRemoveAll> = (session, _shardId, reaction) => { export const MESSAGE_REACTION_REMOVE_ALL: RawHandler<DiscordMessageReactionRemoveAll> = (
session,
_shardId,
reaction,
) => {
session.emit("messageReactionRemoveAll", null); session.emit("messageReactionRemoveAll", null);
}; };
export const MESSAGE_REACTION_REMOVE_EMOJI: RawHandler<DiscordMessageReactionRemoveEmoji> = (session, _shardId, reaction) => { export const MESSAGE_REACTION_REMOVE_EMOJI: RawHandler<DiscordMessageReactionRemoveEmoji> = (
session,
_shardId,
reaction,
) => {
session.emit("messageReactionRemoveEmoji", null); session.emit("messageReactionRemoveEmoji", null);
}; };

View File

@ -1,80 +1,77 @@
import type { Model } from "./Base.ts"; import type { Model } from "./Base.ts";
import type { Snowflake } from "../util/Snowflake.ts"; import type { Snowflake } from "../util/Snowflake.ts";
import type { Session } from "../session/Session.ts"; import type { Session } from "../session/Session.ts";
import type { import type { DiscordIntegration, IntegrationExpireBehaviors } from "../vendor/external.ts";
DiscordIntegration, import User from "./User.ts";
IntegrationExpireBehaviors
} from "../vendor/external.ts"; export interface IntegrationAccount {
import User from "./User.ts" id: Snowflake;
name: string;
export interface IntegrationAccount { }
id: Snowflake;
name: string; export interface IntegrationApplication {
} id: Snowflake;
name: string;
export interface IntegrationApplication { icon?: string;
id: Snowflake; description: string;
name: string; bot?: User;
icon?: string; }
description: string;
bot?: User; export class Integration implements Model {
} constructor(session: Session, data: DiscordIntegration & { guild_id?: Snowflake }) {
this.id = data.id;
export class Integration implements Model { this.session = session;
constructor(session: Session, data: DiscordIntegration & { guild_id?: Snowflake }) {
this.id = data.id; data.guild_id ? this.guildId = data.guild_id : null;
this.session = session;
this.name = data.name;
data.guild_id ? this.guildId = data.guild_id : null; this.type = data.type;
this.enabled = !!data.enabled;
this.name = data.name; this.syncing = !!data.syncing;
this.type = data.type; this.roleId = data.role_id;
this.enabled = !!data.enabled; this.enableEmoticons = !!data.enable_emoticons;
this.syncing = !!data.syncing; this.expireBehavior = data.expire_behavior;
this.roleId = data.role_id; this.expireGracePeriod = data.expire_grace_period;
this.enableEmoticons = !!data.enable_emoticons; this.syncedAt = data.synced_at;
this.expireBehavior = data.expire_behavior; this.subscriberCount = data.subscriber_count;
this.expireGracePeriod = data.expire_grace_period; this.revoked = !!data.revoked;
this.syncedAt = data.synced_at;
this.subscriberCount = data.subscriber_count; this.user = data.user ? new User(session, data.user) : undefined;
this.revoked = !!data.revoked; this.account = {
id: data.account.id,
this.user = data.user ? new User(session, data.user) : undefined; name: data.account.name,
this.account = { };
id: data.account.id,
name: data.account.name if (data.application) {
} this.application = {
id: data.application.id,
if (data.application) { name: data.application.name,
this.application = { icon: data.application.icon ? data.application.icon : undefined,
id: data.application.id, description: data.application.description,
name: data.application.name, bot: data.application.bot ? new User(session, data.application.bot) : undefined,
icon: data.application.icon ? data.application.icon : undefined, };
description: data.application.description, }
bot: data.application.bot ? new User(session, data.application.bot) : undefined }
};
} id: Snowflake;
} session: Session;
guildId?: Snowflake;
id: Snowflake;
session: Session; name: string;
guildId?: Snowflake; type: "twitch" | "youtube" | "discord";
enabled?: boolean;
name: string syncing?: boolean;
type: "twitch" | "youtube" | "discord"; roleId?: string;
enabled?: boolean; enableEmoticons?: boolean;
syncing?: boolean; expireBehavior?: IntegrationExpireBehaviors;
roleId?: string; expireGracePeriod?: number;
enableEmoticons?: boolean; syncedAt?: string;
expireBehavior?: IntegrationExpireBehaviors; subscriberCount?: number;
expireGracePeriod?: number; revoked?: boolean;
syncedAt?: string;
subscriberCount?: number; user?: User;
revoked?: boolean; account: IntegrationAccount;
application?: IntegrationApplication;
user?: User; }
account: IntegrationAccount;
application?: IntegrationApplication; export default Integration;
}
export default Integration;

View File

@ -2,12 +2,12 @@ import type { Session } from "../session/Session.ts";
import type { Snowflake } from "../util/Snowflake.ts"; import type { Snowflake } from "../util/Snowflake.ts";
import type { import type {
DiscordChannel, DiscordChannel,
DiscordMemberWithUser,
DiscordInvite, DiscordInvite,
DiscordMemberWithUser,
DiscordScheduledEventEntityMetadata, DiscordScheduledEventEntityMetadata,
ScheduledEventEntityType,
ScheduledEventPrivacyLevel, ScheduledEventPrivacyLevel,
ScheduledEventStatus, ScheduledEventStatus,
ScheduledEventEntityType
} from "../vendor/external.ts"; } from "../vendor/external.ts";
import { TargetTypes } from "../vendor/external.ts"; import { TargetTypes } from "../vendor/external.ts";
import InviteGuild from "./guilds/InviteGuild.ts"; import InviteGuild from "./guilds/InviteGuild.ts";
@ -67,7 +67,7 @@ export class Invite {
if (data.channel) { if (data.channel) {
const guildId = (data.guild && data.guild?.id) ? data.guild.id : ""; const guildId = (data.guild && data.guild?.id) ? data.guild.id : "";
this.channel = new GuildChannel(session, (data.channel as DiscordChannel), guildId); this.channel = new GuildChannel(session, data.channel as DiscordChannel, guildId);
} }
this.code = data.code; this.code = data.code;
@ -83,17 +83,25 @@ export class Invite {
channelId: data.guild_scheduled_event.channel_id ? data.guild_scheduled_event.channel_id : undefined, channelId: data.guild_scheduled_event.channel_id ? data.guild_scheduled_event.channel_id : undefined,
creatorId: data.guild_scheduled_event.creator_id ? data.guild_scheduled_event.creator_id : undefined, creatorId: data.guild_scheduled_event.creator_id ? data.guild_scheduled_event.creator_id : undefined,
name: data.guild_scheduled_event.name, name: data.guild_scheduled_event.name,
description: data.guild_scheduled_event.description ? data.guild_scheduled_event.description : undefined, description: data.guild_scheduled_event.description
? data.guild_scheduled_event.description
: undefined,
scheduledStartTime: data.guild_scheduled_event.scheduled_start_time, scheduledStartTime: data.guild_scheduled_event.scheduled_start_time,
scheduledEndTime: data.guild_scheduled_event.scheduled_end_time ? data.guild_scheduled_event.scheduled_end_time : undefined, scheduledEndTime: data.guild_scheduled_event.scheduled_end_time
? data.guild_scheduled_event.scheduled_end_time
: undefined,
privacyLevel: data.guild_scheduled_event.privacy_level, privacyLevel: data.guild_scheduled_event.privacy_level,
status: data.guild_scheduled_event.status, status: data.guild_scheduled_event.status,
entityType: data.guild_scheduled_event.entity_type, entityType: data.guild_scheduled_event.entity_type,
entityId: data.guild ? data.guild.id : undefined, entityId: data.guild ? data.guild.id : undefined,
entityMetadata: data.guild_scheduled_event.entity_metadata ? data.guild_scheduled_event.entity_metadata : undefined, entityMetadata: data.guild_scheduled_event.entity_metadata
creator: data.guild_scheduled_event.creator ? new User(session, data.guild_scheduled_event.creator) : undefined, ? data.guild_scheduled_event.entity_metadata
: undefined,
creator: data.guild_scheduled_event.creator
? new User(session, data.guild_scheduled_event.creator)
: undefined,
userCount: data.guild_scheduled_event.user_count ? data.guild_scheduled_event.user_count : undefined, userCount: data.guild_scheduled_event.user_count ? data.guild_scheduled_event.user_count : undefined,
image: data.guild_scheduled_event.image ? data.guild_scheduled_event.image : undefined image: data.guild_scheduled_event.image ? data.guild_scheduled_event.image : undefined,
}; };
} }
@ -108,10 +116,12 @@ export class Invite {
if (data.stage_instance) { if (data.stage_instance) {
const guildId = (data.guild && data.guild?.id) ? data.guild.id : ""; const guildId = (data.guild && data.guild?.id) ? data.guild.id : "";
this.stageInstance = { this.stageInstance = {
members: data.stage_instance.members.map(m => new Member(session, (m as DiscordMemberWithUser), guildId)), members: data.stage_instance.members.map((m) =>
new Member(session, m as DiscordMemberWithUser, guildId)
),
participantCount: data.stage_instance.participant_count, participantCount: data.stage_instance.participant_count,
speakerCount: data.stage_instance.speaker_count, speakerCount: data.stage_instance.speaker_count,
topic: data.stage_instance.topic topic: data.stage_instance.topic,
}; };
} }

View File

@ -47,7 +47,7 @@ export class Webhook implements Model {
guildId?: Snowflake; guildId?: Snowflake;
user?: User; user?: User;
async execute(options?: WebhookOptions & CreateMessage & { avatarUrl?: string, username?: string }) { async execute(options?: WebhookOptions & CreateMessage & { avatarUrl?: string; username?: string }) {
if (!this.token) { if (!this.token) {
return; return;
} }

View File

@ -1,17 +1,23 @@
import type { Model } from "../Base.ts"; import type { Model } from "../Base.ts";
import type { Snowflake } from "../../util/Snowflake.ts"; import type { Snowflake } from "../../util/Snowflake.ts";
import type { PermissionsOverwrites } from "../../util/permissions.ts";
import type { Session } from "../../session/Session.ts"; import type { Session } from "../../session/Session.ts";
import type { import type {
ChannelTypes, ChannelTypes,
DiscordChannel, DiscordChannel,
DiscordInviteMetadata, DiscordInviteMetadata,
DiscordListArchivedThreads, DiscordListArchivedThreads,
VideoQualityModes,
} from "../../vendor/external.ts"; } from "../../vendor/external.ts";
import type { ListArchivedThreads } from "../../util/Routes.ts"; import type { ListArchivedThreads } from "../../util/Routes.ts";
import BaseChannel from "./BaseChannel.ts"; import BaseChannel from "./BaseChannel.ts";
import VoiceChannel from "./VoiceChannel.ts";
import NewsChannel from "./NewsChannel.ts";
import StageChannel from "./StageChannel.ts";
import ThreadMember from "../ThreadMember.ts"; import ThreadMember from "../ThreadMember.ts";
import Invite from "../Invite.ts"; import Invite from "../Invite.ts";
import * as Routes from "../../util/Routes.ts"; import * as Routes from "../../util/Routes.ts";
import { Channel, ChannelFactory } from "./ChannelFactory.ts";
/** /**
* Represent the options object to create a thread channel * Represent the options object to create a thread channel
@ -26,6 +32,40 @@ export interface ThreadCreateOptions {
reason?: string; reason?: string;
} }
/**
* Representations of the objects to edit a guild channel
* @link https://discord.com/developers/docs/resources/channel#modify-channel-json-params-guild-channel
*/
export interface EditGuildChannelOptions {
name?: string;
position?: number;
permissionOverwrites?: PermissionsOverwrites[];
}
export interface EditNewsChannelOptions extends EditGuildChannelOptions {
type?: ChannelTypes.GuildNews | ChannelTypes.GuildText;
topic?: string | null;
nfsw?: boolean | null;
parentId?: Snowflake | null;
defaultAutoArchiveDuration?: number | null;
}
export interface EditGuildTextChannelOptions extends EditNewsChannelOptions {
rateLimitPerUser?: number | null;
}
export interface EditStageChannelOptions extends EditGuildChannelOptions {
bitrate?: number | null;
rtcRegion?: Snowflake | null;
}
export interface EditVoiceChannelOptions extends EditStageChannelOptions {
nsfw?: boolean | null;
userLimit?: number | null;
parentId?: Snowflake | null;
videoQualityMode?: VideoQualityModes | null;
}
/** /**
* Represents the option object to create a thread channel from a message * Represents the option object to create a thread channel from a message
* @link https://discord.com/developers/docs/resources/channel#start-thread-from-message * @link https://discord.com/developers/docs/resources/channel#start-thread-from-message
@ -63,6 +103,37 @@ export class GuildChannel extends BaseChannel implements Model {
return invites.map((invite) => new Invite(this.session, invite)); return invites.map((invite) => new Invite(this.session, invite));
} }
async edit(options: EditNewsChannelOptions): Promise<NewsChannel>;
async edit(options: EditStageChannelOptions): Promise<StageChannel>;
async edit(options: EditVoiceChannelOptions): Promise<VoiceChannel>;
async edit(
options: EditGuildTextChannelOptions | EditNewsChannelOptions | EditVoiceChannelOptions,
): Promise<Channel> {
const channel = await this.session.rest.runMethod<DiscordChannel>(
this.session.rest,
"PATCH",
Routes.CHANNEL(this.id),
{
name: options.name,
type: "type" in options ? options.type : undefined,
position: options.position,
topic: "topic" in options ? options.topic : undefined,
nsfw: "nfsw" in options ? options.nfsw : undefined,
rate_limit_per_user: "rateLimitPerUser" in options ? options.rateLimitPerUser : undefined,
bitrate: "bitrate" in options ? options.bitrate : undefined,
user_limit: "userLimit" in options ? options.userLimit : undefined,
permissions_overwrites: options.permissionOverwrites,
parent_id: "parentId" in options ? options.parentId : undefined,
rtc_region: "rtcRegion" in options ? options.rtcRegion : undefined,
video_quality_mode: "videoQualityMode" in options ? options.videoQualityMode : undefined,
default_auto_archive_duration: "defaultAutoArchiveDuration" in options
? options.defaultAutoArchiveDuration
: undefined,
},
);
return ChannelFactory.from(this.session, channel);
}
/* /*
async getArchivedThreads(options: ListArchivedThreads & { type: "public" | "private" | "privateJoinedThreads" }) { async getArchivedThreads(options: ListArchivedThreads & { type: "public" | "private" | "privateJoinedThreads" }) {
let func: (channelId: Snowflake, options: ListArchivedThreads) => string; let func: (channelId: Snowflake, options: ListArchivedThreads) => string;
@ -113,5 +184,4 @@ export class GuildChannel extends BaseChannel implements Model {
}*/ }*/
} }
export default GuildChannel; export default GuildChannel;

View File

@ -1,4 +1,3 @@
import type { Model } from "../Base.ts"; import type { Model } from "../Base.ts";
import type { Snowflake } from "../../util/Snowflake.ts"; import type { Snowflake } from "../../util/Snowflake.ts";
import type { Session } from "../../session/Session.ts"; import type { Session } from "../../session/Session.ts";
@ -32,7 +31,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
{ {
data: { choices }, data: { choices },
type: InteractionResponseTypes.ApplicationCommandAutocompleteResult, type: InteractionResponseTypes.ApplicationCommandAutocompleteResult,
} },
); );
} }
} }

View File

@ -1,7 +1,12 @@
import type { Model } from "../Base.ts"; import type { Model } from "../Base.ts";
import type { Snowflake } from "../../util/Snowflake.ts"; import type { Snowflake } from "../../util/Snowflake.ts";
import type { Session } from "../../session/Session.ts"; import type { Session } from "../../session/Session.ts";
import type { ApplicationCommandTypes, DiscordMemberWithUser, DiscordInteraction, InteractionTypes } from "../../vendor/external.ts"; import type {
ApplicationCommandTypes,
DiscordInteraction,
DiscordMemberWithUser,
InteractionTypes,
} from "../../vendor/external.ts";
import type { CreateMessage } from "../Message.ts"; import type { CreateMessage } from "../Message.ts";
import type { MessageFlags } from "../../util/shared/flags.ts"; import type { MessageFlags } from "../../util/shared/flags.ts";
import { InteractionResponseTypes } from "../../vendor/external.ts"; import { InteractionResponseTypes } from "../../vendor/external.ts";
@ -17,7 +22,7 @@ import * as Routes from "../../util/Routes.ts";
/** /**
* @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response * @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response
* */ */
export interface InteractionResponse { export interface InteractionResponse {
type: InteractionResponseTypes; type: InteractionResponseTypes;
data?: InteractionApplicationCommandCallbackData; data?: InteractionApplicationCommandCallbackData;
@ -25,8 +30,9 @@ export interface InteractionResponse {
/** /**
* @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata * @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata
* */ */
export interface InteractionApplicationCommandCallbackData extends Pick<CreateMessage, "allowedMentions" | "content" | "embeds" | "files"> { export interface InteractionApplicationCommandCallbackData
extends Pick<CreateMessage, "allowedMentions" | "content" | "embeds" | "files"> {
customId?: string; customId?: string;
title?: string; title?: string;
// components?: MessageComponents; // components?: MessageComponents;
@ -36,10 +42,10 @@ export interface InteractionApplicationCommandCallbackData extends Pick<CreateMe
/** /**
* @link https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice * @link https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice
* */ */
export interface ApplicationCommandOptionChoice { export interface ApplicationCommandOptionChoice {
name: string; name: string;
value: string | number; value: string | number;
} }
export class CommandInteraction extends BaseInteraction implements Model { export class CommandInteraction extends BaseInteraction implements Model {

View File

@ -1,5 +1,5 @@
import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from '../../vendor/external.ts'; import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from "../../vendor/external.ts";
import { ApplicationCommandOptionTypes } from "../../vendor/external.ts"; import { ApplicationCommandOptionTypes } from "../../vendor/external.ts";
export function transformOasisInteractionDataOption(o: DiscordInteractionDataOption): CommandInteractionOption { export function transformOasisInteractionDataOption(o: DiscordInteractionDataOption): CommandInteractionOption {
const output: CommandInteractionOption = { ...o, Otherwise: o.value as string | boolean | number | undefined }; const output: CommandInteractionOption = { ...o, Otherwise: o.value as string | boolean | number | undefined };
@ -37,7 +37,7 @@ export function transformOasisInteractionDataOption(o: DiscordInteractionDataOpt
return output; return output;
} }
export interface CommandInteractionOption extends Omit<DiscordInteractionDataOption, 'value'> { export interface CommandInteractionOption extends Omit<DiscordInteractionDataOption, "value"> {
Attachment?: string; Attachment?: string;
Boolean?: boolean; Boolean?: boolean;
User?: bigint; User?: bigint;
@ -97,7 +97,7 @@ export class CommandInteractionOptionResolver {
} }
if (required === true && properties.every((prop) => typeof option[prop] === "undefined")) { if (required === true && properties.every((prop) => typeof option[prop] === "undefined")) {
throw new TypeError(`Properties ${properties.join(', ')} are missing in option ${name}`); throw new TypeError(`Properties ${properties.join(", ")} are missing in option ${name}`);
} }
return option; return option;
@ -107,12 +107,12 @@ export class CommandInteractionOptionResolver {
get(name: string | number, required: boolean): CommandInteractionOption | undefined; get(name: string | number, required: boolean): CommandInteractionOption | undefined;
get(name: string | number, required?: boolean) { get(name: string | number, required?: boolean) {
const option = this.hoistedOptions.find((o) => const option = this.hoistedOptions.find((o) =>
typeof name === 'number' ? o.name === name.toString() : o.name === name typeof name === "number" ? o.name === name.toString() : o.name === name
); );
if (!option) { if (!option) {
if (required && name in this.hoistedOptions.map((o) => o.name)) { if (required && name in this.hoistedOptions.map((o) => o.name)) {
throw new TypeError('Option marked as required was undefined'); throw new TypeError("Option marked as required was undefined");
} }
return; return;
@ -125,7 +125,7 @@ export class CommandInteractionOptionResolver {
getString(name: string | number, required: true): string; getString(name: string | number, required: true): string;
getString(name: string | number, required?: boolean): string | undefined; getString(name: string | number, required?: boolean): string | undefined;
getString(name: string | number, required = false) { getString(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.String, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.String, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -134,7 +134,7 @@ export class CommandInteractionOptionResolver {
getNumber(name: string | number, required: true): number; getNumber(name: string | number, required: true): number;
getNumber(name: string | number, required?: boolean): number | undefined; getNumber(name: string | number, required?: boolean): number | undefined;
getNumber(name: string | number, required = false) { getNumber(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Number, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Number, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -143,7 +143,7 @@ export class CommandInteractionOptionResolver {
getInteger(name: string | number, required: true): number; getInteger(name: string | number, required: true): number;
getInteger(name: string | number, required?: boolean): number | undefined; getInteger(name: string | number, required?: boolean): number | undefined;
getInteger(name: string | number, required = false) { getInteger(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Integer, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Integer, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -152,7 +152,7 @@ export class CommandInteractionOptionResolver {
getBoolean(name: string | number, required: true): boolean; getBoolean(name: string | number, required: true): boolean;
getBoolean(name: string | number, required?: boolean): boolean | undefined; getBoolean(name: string | number, required?: boolean): boolean | undefined;
getBoolean(name: string | number, required = false) { getBoolean(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Boolean, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Boolean, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -161,7 +161,7 @@ export class CommandInteractionOptionResolver {
getUser(name: string | number, required: true): bigint; getUser(name: string | number, required: true): bigint;
getUser(name: string | number, required?: boolean): bigint | undefined; getUser(name: string | number, required?: boolean): bigint | undefined;
getUser(name: string | number, required = false) { getUser(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.User, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.User, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -170,7 +170,7 @@ export class CommandInteractionOptionResolver {
getChannel(name: string | number, required: true): bigint; getChannel(name: string | number, required: true): bigint;
getChannel(name: string | number, required?: boolean): bigint | undefined; getChannel(name: string | number, required?: boolean): bigint | undefined;
getChannel(name: string | number, required = false) { getChannel(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Channel, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Channel, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -179,7 +179,7 @@ export class CommandInteractionOptionResolver {
getMentionable(name: string | number, required: true): string; getMentionable(name: string | number, required: true): string;
getMentionable(name: string | number, required?: boolean): string | undefined; getMentionable(name: string | number, required?: boolean): string | undefined;
getMentionable(name: string | number, required = false) { getMentionable(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Mentionable, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Mentionable, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -188,7 +188,7 @@ export class CommandInteractionOptionResolver {
getRole(name: string | number, required: true): bigint; getRole(name: string | number, required: true): bigint;
getRole(name: string | number, required?: boolean): bigint | undefined; getRole(name: string | number, required?: boolean): bigint | undefined;
getRole(name: string | number, required = false) { getRole(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Role, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Role, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -197,7 +197,7 @@ export class CommandInteractionOptionResolver {
getAttachment(name: string | number, required: true): string; getAttachment(name: string | number, required: true): string;
getAttachment(name: string | number, required?: boolean): string | undefined; getAttachment(name: string | number, required?: boolean): string | undefined;
getAttachment(name: string | number, required = false) { getAttachment(name: string | number, required = false) {
const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Attachment, ['Otherwise'], required); const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Attachment, ["Otherwise"], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -207,7 +207,7 @@ export class CommandInteractionOptionResolver {
const focusedOption = this.hoistedOptions.find((option) => option.focused); const focusedOption = this.hoistedOptions.find((option) => option.focused);
if (!focusedOption) { if (!focusedOption) {
throw new TypeError('No option found'); throw new TypeError("No option found");
} }
return full ? focusedOption : focusedOption.Otherwise; return full ? focusedOption : focusedOption.Otherwise;
@ -215,7 +215,7 @@ export class CommandInteractionOptionResolver {
getSubCommand(required = true) { getSubCommand(required = true) {
if (required && !this.#subcommand) { if (required && !this.#subcommand) {
throw new TypeError('Option marked as required was undefined'); throw new TypeError("Option marked as required was undefined");
} }
return [this.#subcommand, this.hoistedOptions]; return [this.#subcommand, this.hoistedOptions];
@ -223,7 +223,7 @@ export class CommandInteractionOptionResolver {
getSubCommandGroup(required = false) { getSubCommandGroup(required = false) {
if (required && !this.#group) { if (required && !this.#group) {
throw new TypeError('Option marked as required was undefined'); throw new TypeError("Option marked as required was undefined");
} }
return [this.#group, this.hoistedOptions]; return [this.#group, this.hoistedOptions];

View File

@ -1,8 +1,12 @@
import type { Model } from "../Base.ts"; import type { Model } from "../Base.ts";
import type { Snowflake } from "../../util/Snowflake.ts"; import type { Snowflake } from "../../util/Snowflake.ts";
import type { Session } from "../../session/Session.ts"; import type { Session } from "../../session/Session.ts";
import type { DiscordInteraction, InteractionTypes, MessageComponentTypes, DiscordMessageComponents } from "../../vendor/external.ts"; import type {
DiscordInteraction,
DiscordMessageComponents,
InteractionTypes,
MessageComponentTypes,
} from "../../vendor/external.ts";
import BaseInteraction from "./BaseInteraction.ts"; import BaseInteraction from "./BaseInteraction.ts";
import Message from "../Message.ts"; import Message from "../Message.ts";

View File

@ -1,4 +1,3 @@
import type { Model } from "../Base.ts"; import type { Model } from "../Base.ts";
import type { Snowflake } from "../../util/Snowflake.ts"; import type { Snowflake } from "../../util/Snowflake.ts";
import type { Session } from "../../session/Session.ts"; import type { Session } from "../../session/Session.ts";
@ -30,7 +29,7 @@ export class PingInteraction extends BaseInteraction implements Model {
Routes.INTERACTION_ID_TOKEN(this.id, this.token), Routes.INTERACTION_ID_TOKEN(this.id, this.token),
{ {
type: InteractionResponseTypes.Pong, type: InteractionResponseTypes.Pong,
} },
); );
} }
} }

9
util/permissions.ts Normal file
View File

@ -0,0 +1,9 @@
import { Snowflake } from "./Snowflake.ts";
import { Permissions } from "../structures/Permissions.ts";
export interface PermissionsOverwrites {
id: Snowflake;
type: 0 | 1;
allow: Permissions;
deny: Permissions;
}