mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
Refactor monorepo (#36)
* feat: GuildChannel.edit * fix: fmt Co-authored-by: socram03 <marcosjgs03@gmail.com>
This commit is contained in:
parent
7d92892c9f
commit
217c100e49
@ -11,6 +11,8 @@ import type {
|
||||
DiscordGuildRoleCreate,
|
||||
DiscordGuildRoleDelete,
|
||||
DiscordGuildRoleUpdate,
|
||||
DiscordIntegration,
|
||||
DiscordIntegrationDelete,
|
||||
DiscordInteraction,
|
||||
DiscordMemberWithUser,
|
||||
DiscordMessage,
|
||||
@ -26,9 +28,6 @@ import type {
|
||||
DiscordThreadListSync,
|
||||
DiscordUser,
|
||||
DiscordWebhookUpdate,
|
||||
DiscordIntegration,
|
||||
DiscordIntegrationDelete
|
||||
|
||||
} from "../vendor/external.ts";
|
||||
import type { Snowflake } from "../util/Snowflake.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 Message from "../structures/Message.ts";
|
||||
import User from "../structures/User.ts";
|
||||
import Integration from "../structures/Integration.ts"
|
||||
import Guild from "../structures/guilds/Guild.ts";
|
||||
import Integration from "../structures/Integration.ts";
|
||||
import Guild from "../structures/guilds/Guild.ts";
|
||||
import InteractionFactory from "../structures/interactions/InteractionFactory.ts";
|
||||
|
||||
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 });
|
||||
};
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
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) => {
|
||||
@ -206,11 +217,19 @@ export const MESSAGE_REACTION_REMOVE: RawHandler<DiscordMessageReactionRemove> =
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -1,80 +1,77 @@
|
||||
import type { Model } from "./Base.ts";
|
||||
import type { Snowflake } from "../util/Snowflake.ts";
|
||||
import type { Session } from "../session/Session.ts";
|
||||
import type {
|
||||
DiscordIntegration,
|
||||
IntegrationExpireBehaviors
|
||||
} from "../vendor/external.ts";
|
||||
import User from "./User.ts"
|
||||
|
||||
export interface IntegrationAccount {
|
||||
id: Snowflake;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface IntegrationApplication {
|
||||
id: Snowflake;
|
||||
name: string;
|
||||
icon?: string;
|
||||
description: string;
|
||||
bot?: User;
|
||||
}
|
||||
|
||||
export class Integration implements Model {
|
||||
constructor(session: Session, data: DiscordIntegration & { guild_id?: Snowflake }) {
|
||||
this.id = data.id;
|
||||
this.session = session;
|
||||
|
||||
data.guild_id ? this.guildId = data.guild_id : null;
|
||||
|
||||
this.name = data.name;
|
||||
this.type = data.type;
|
||||
this.enabled = !!data.enabled;
|
||||
this.syncing = !!data.syncing;
|
||||
this.roleId = data.role_id;
|
||||
this.enableEmoticons = !!data.enable_emoticons;
|
||||
this.expireBehavior = data.expire_behavior;
|
||||
this.expireGracePeriod = data.expire_grace_period;
|
||||
this.syncedAt = data.synced_at;
|
||||
this.subscriberCount = data.subscriber_count;
|
||||
this.revoked = !!data.revoked;
|
||||
|
||||
this.user = data.user ? new User(session, data.user) : undefined;
|
||||
this.account = {
|
||||
id: data.account.id,
|
||||
name: data.account.name
|
||||
}
|
||||
|
||||
if (data.application) {
|
||||
this.application = {
|
||||
id: data.application.id,
|
||||
name: data.application.name,
|
||||
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;
|
||||
|
||||
name: string
|
||||
type: "twitch" | "youtube" | "discord";
|
||||
enabled?: boolean;
|
||||
syncing?: boolean;
|
||||
roleId?: string;
|
||||
enableEmoticons?: boolean;
|
||||
expireBehavior?: IntegrationExpireBehaviors;
|
||||
expireGracePeriod?: number;
|
||||
syncedAt?: string;
|
||||
subscriberCount?: number;
|
||||
revoked?: boolean;
|
||||
|
||||
user?: User;
|
||||
account: IntegrationAccount;
|
||||
application?: IntegrationApplication;
|
||||
}
|
||||
|
||||
export default Integration;
|
||||
import type { Model } from "./Base.ts";
|
||||
import type { Snowflake } from "../util/Snowflake.ts";
|
||||
import type { Session } from "../session/Session.ts";
|
||||
import type { DiscordIntegration, IntegrationExpireBehaviors } from "../vendor/external.ts";
|
||||
import User from "./User.ts";
|
||||
|
||||
export interface IntegrationAccount {
|
||||
id: Snowflake;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface IntegrationApplication {
|
||||
id: Snowflake;
|
||||
name: string;
|
||||
icon?: string;
|
||||
description: string;
|
||||
bot?: User;
|
||||
}
|
||||
|
||||
export class Integration implements Model {
|
||||
constructor(session: Session, data: DiscordIntegration & { guild_id?: Snowflake }) {
|
||||
this.id = data.id;
|
||||
this.session = session;
|
||||
|
||||
data.guild_id ? this.guildId = data.guild_id : null;
|
||||
|
||||
this.name = data.name;
|
||||
this.type = data.type;
|
||||
this.enabled = !!data.enabled;
|
||||
this.syncing = !!data.syncing;
|
||||
this.roleId = data.role_id;
|
||||
this.enableEmoticons = !!data.enable_emoticons;
|
||||
this.expireBehavior = data.expire_behavior;
|
||||
this.expireGracePeriod = data.expire_grace_period;
|
||||
this.syncedAt = data.synced_at;
|
||||
this.subscriberCount = data.subscriber_count;
|
||||
this.revoked = !!data.revoked;
|
||||
|
||||
this.user = data.user ? new User(session, data.user) : undefined;
|
||||
this.account = {
|
||||
id: data.account.id,
|
||||
name: data.account.name,
|
||||
};
|
||||
|
||||
if (data.application) {
|
||||
this.application = {
|
||||
id: data.application.id,
|
||||
name: data.application.name,
|
||||
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;
|
||||
|
||||
name: string;
|
||||
type: "twitch" | "youtube" | "discord";
|
||||
enabled?: boolean;
|
||||
syncing?: boolean;
|
||||
roleId?: string;
|
||||
enableEmoticons?: boolean;
|
||||
expireBehavior?: IntegrationExpireBehaviors;
|
||||
expireGracePeriod?: number;
|
||||
syncedAt?: string;
|
||||
subscriberCount?: number;
|
||||
revoked?: boolean;
|
||||
|
||||
user?: User;
|
||||
account: IntegrationAccount;
|
||||
application?: IntegrationApplication;
|
||||
}
|
||||
|
||||
export default Integration;
|
||||
|
@ -2,12 +2,12 @@ import type { Session } from "../session/Session.ts";
|
||||
import type { Snowflake } from "../util/Snowflake.ts";
|
||||
import type {
|
||||
DiscordChannel,
|
||||
DiscordMemberWithUser,
|
||||
DiscordInvite,
|
||||
DiscordMemberWithUser,
|
||||
DiscordScheduledEventEntityMetadata,
|
||||
ScheduledEventEntityType,
|
||||
ScheduledEventPrivacyLevel,
|
||||
ScheduledEventStatus,
|
||||
ScheduledEventEntityType
|
||||
} from "../vendor/external.ts";
|
||||
import { TargetTypes } from "../vendor/external.ts";
|
||||
import InviteGuild from "./guilds/InviteGuild.ts";
|
||||
@ -67,7 +67,7 @@ export class Invite {
|
||||
|
||||
if (data.channel) {
|
||||
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;
|
||||
@ -83,17 +83,25 @@ export class Invite {
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
status: data.guild_scheduled_event.status,
|
||||
entityType: data.guild_scheduled_event.entity_type,
|
||||
entityId: data.guild ? data.guild.id : undefined,
|
||||
entityMetadata: data.guild_scheduled_event.entity_metadata ? data.guild_scheduled_event.entity_metadata : undefined,
|
||||
creator: data.guild_scheduled_event.creator ? new User(session, data.guild_scheduled_event.creator) : undefined,
|
||||
entityMetadata: data.guild_scheduled_event.entity_metadata
|
||||
? 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,
|
||||
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) {
|
||||
const guildId = (data.guild && data.guild?.id) ? data.guild.id : "";
|
||||
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,
|
||||
speakerCount: data.stage_instance.speaker_count,
|
||||
topic: data.stage_instance.topic
|
||||
topic: data.stage_instance.topic,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ export class Webhook implements Model {
|
||||
guildId?: Snowflake;
|
||||
user?: User;
|
||||
|
||||
async execute(options?: WebhookOptions & CreateMessage & { avatarUrl?: string, username?: string }) {
|
||||
async execute(options?: WebhookOptions & CreateMessage & { avatarUrl?: string; username?: string }) {
|
||||
if (!this.token) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,17 +1,23 @@
|
||||
import type { Model } from "../Base.ts";
|
||||
import type { Snowflake } from "../../util/Snowflake.ts";
|
||||
import type { PermissionsOverwrites } from "../../util/permissions.ts";
|
||||
import type { Session } from "../../session/Session.ts";
|
||||
import type {
|
||||
ChannelTypes,
|
||||
DiscordChannel,
|
||||
DiscordInviteMetadata,
|
||||
DiscordListArchivedThreads,
|
||||
VideoQualityModes,
|
||||
} from "../../vendor/external.ts";
|
||||
import type { ListArchivedThreads } from "../../util/Routes.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 Invite from "../Invite.ts";
|
||||
import * as Routes from "../../util/Routes.ts";
|
||||
import { Channel, ChannelFactory } from "./ChannelFactory.ts";
|
||||
|
||||
/**
|
||||
* Represent the options object to create a thread channel
|
||||
@ -26,6 +32,40 @@ export interface ThreadCreateOptions {
|
||||
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
|
||||
* @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));
|
||||
}
|
||||
|
||||
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" }) {
|
||||
let func: (channelId: Snowflake, options: ListArchivedThreads) => string;
|
||||
@ -113,5 +184,4 @@ export class GuildChannel extends BaseChannel implements Model {
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
export default GuildChannel;
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
import type { Model } from "../Base.ts";
|
||||
import type { Snowflake } from "../../util/Snowflake.ts";
|
||||
import type { Session } from "../../session/Session.ts";
|
||||
@ -32,7 +31,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
|
||||
{
|
||||
data: { choices },
|
||||
type: InteractionResponseTypes.ApplicationCommandAutocompleteResult,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,12 @@
|
||||
import type { Model } from "../Base.ts";
|
||||
import type { Snowflake } from "../../util/Snowflake.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 { MessageFlags } from "../../util/shared/flags.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
|
||||
* */
|
||||
*/
|
||||
export interface InteractionResponse {
|
||||
type: InteractionResponseTypes;
|
||||
data?: InteractionApplicationCommandCallbackData;
|
||||
@ -25,8 +30,9 @@ export interface InteractionResponse {
|
||||
|
||||
/**
|
||||
* @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;
|
||||
title?: string;
|
||||
// components?: MessageComponents;
|
||||
@ -36,10 +42,10 @@ export interface InteractionApplicationCommandCallbackData extends Pick<CreateMe
|
||||
|
||||
/**
|
||||
* @link https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice
|
||||
* */
|
||||
*/
|
||||
export interface ApplicationCommandOptionChoice {
|
||||
name: string;
|
||||
value: string | number;
|
||||
name: string;
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
export class CommandInteraction extends BaseInteraction implements Model {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from '../../vendor/external.ts';
|
||||
import { ApplicationCommandOptionTypes } from "../../vendor/external.ts";
|
||||
import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from "../../vendor/external.ts";
|
||||
import { ApplicationCommandOptionTypes } from "../../vendor/external.ts";
|
||||
|
||||
export function transformOasisInteractionDataOption(o: DiscordInteractionDataOption): CommandInteractionOption {
|
||||
const output: CommandInteractionOption = { ...o, Otherwise: o.value as string | boolean | number | undefined };
|
||||
@ -37,7 +37,7 @@ export function transformOasisInteractionDataOption(o: DiscordInteractionDataOpt
|
||||
return output;
|
||||
}
|
||||
|
||||
export interface CommandInteractionOption extends Omit<DiscordInteractionDataOption, 'value'> {
|
||||
export interface CommandInteractionOption extends Omit<DiscordInteractionDataOption, "value"> {
|
||||
Attachment?: string;
|
||||
Boolean?: boolean;
|
||||
User?: bigint;
|
||||
@ -97,7 +97,7 @@ export class CommandInteractionOptionResolver {
|
||||
}
|
||||
|
||||
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;
|
||||
@ -107,12 +107,12 @@ export class CommandInteractionOptionResolver {
|
||||
get(name: string | number, required: boolean): CommandInteractionOption | undefined;
|
||||
get(name: string | number, required?: boolean) {
|
||||
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 (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;
|
||||
@ -125,7 +125,7 @@ export class CommandInteractionOptionResolver {
|
||||
getString(name: string | number, required: true): string;
|
||||
getString(name: string | number, required?: boolean): string | undefined;
|
||||
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;
|
||||
}
|
||||
@ -134,7 +134,7 @@ export class CommandInteractionOptionResolver {
|
||||
getNumber(name: string | number, required: true): number;
|
||||
getNumber(name: string | number, required?: boolean): number | undefined;
|
||||
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;
|
||||
}
|
||||
@ -143,7 +143,7 @@ export class CommandInteractionOptionResolver {
|
||||
getInteger(name: string | number, required: true): number;
|
||||
getInteger(name: string | number, required?: boolean): number | undefined;
|
||||
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;
|
||||
}
|
||||
@ -152,7 +152,7 @@ export class CommandInteractionOptionResolver {
|
||||
getBoolean(name: string | number, required: true): boolean;
|
||||
getBoolean(name: string | number, required?: boolean): boolean | undefined;
|
||||
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;
|
||||
}
|
||||
@ -161,7 +161,7 @@ export class CommandInteractionOptionResolver {
|
||||
getUser(name: string | number, required: true): bigint;
|
||||
getUser(name: string | number, required?: boolean): bigint | undefined;
|
||||
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;
|
||||
}
|
||||
@ -170,7 +170,7 @@ export class CommandInteractionOptionResolver {
|
||||
getChannel(name: string | number, required: true): bigint;
|
||||
getChannel(name: string | number, required?: boolean): bigint | undefined;
|
||||
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;
|
||||
}
|
||||
@ -179,7 +179,7 @@ export class CommandInteractionOptionResolver {
|
||||
getMentionable(name: string | number, required: true): string;
|
||||
getMentionable(name: string | number, required?: boolean): string | undefined;
|
||||
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;
|
||||
}
|
||||
@ -188,7 +188,7 @@ export class CommandInteractionOptionResolver {
|
||||
getRole(name: string | number, required: true): bigint;
|
||||
getRole(name: string | number, required?: boolean): bigint | undefined;
|
||||
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;
|
||||
}
|
||||
@ -197,7 +197,7 @@ export class CommandInteractionOptionResolver {
|
||||
getAttachment(name: string | number, required: true): string;
|
||||
getAttachment(name: string | number, required?: boolean): string | undefined;
|
||||
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;
|
||||
}
|
||||
@ -207,7 +207,7 @@ export class CommandInteractionOptionResolver {
|
||||
const focusedOption = this.hoistedOptions.find((option) => option.focused);
|
||||
|
||||
if (!focusedOption) {
|
||||
throw new TypeError('No option found');
|
||||
throw new TypeError("No option found");
|
||||
}
|
||||
|
||||
return full ? focusedOption : focusedOption.Otherwise;
|
||||
@ -215,7 +215,7 @@ export class CommandInteractionOptionResolver {
|
||||
|
||||
getSubCommand(required = true) {
|
||||
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];
|
||||
@ -223,7 +223,7 @@ export class CommandInteractionOptionResolver {
|
||||
|
||||
getSubCommandGroup(required = false) {
|
||||
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];
|
||||
|
@ -1,8 +1,12 @@
|
||||
|
||||
import type { Model } from "../Base.ts";
|
||||
import type { Snowflake } from "../../util/Snowflake.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 Message from "../Message.ts";
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
import type { Model } from "../Base.ts";
|
||||
import type { Snowflake } from "../../util/Snowflake.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),
|
||||
{
|
||||
type: InteractionResponseTypes.Pong,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
9
util/permissions.ts
Normal file
9
util/permissions.ts
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user