mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
feat(helpers): Permissions util
This commit is contained in:
parent
490898a56f
commit
fa32071d4e
@ -1,7 +1,7 @@
|
|||||||
import { MakeRequired, Options } from '@biscuitland/common';
|
import { MakeRequired, Options } from "@biscuitland/common";
|
||||||
import { type Session, Handler } from '@biscuitland/core';
|
import { Handler, type Session } from "@biscuitland/core";
|
||||||
import { GatewayEvents } from '@biscuitland/ws';
|
import { GatewayEvents } from "@biscuitland/ws";
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from "node:events";
|
||||||
|
|
||||||
interface CollectorOptions<E extends keyof GatewayEvents> {
|
interface CollectorOptions<E extends keyof GatewayEvents> {
|
||||||
event: `${E}`;
|
event: `${E}`;
|
||||||
@ -13,19 +13,19 @@ interface CollectorOptions<E extends keyof GatewayEvents> {
|
|||||||
|
|
||||||
export const DEFAULT_OPTIONS = {
|
export const DEFAULT_OPTIONS = {
|
||||||
filter: () => true,
|
filter: () => true,
|
||||||
max: -1
|
max: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum CollectorStatus {
|
export enum CollectorStatus {
|
||||||
Idle = 0,
|
Idle = 0,
|
||||||
Started = 1,
|
Started = 1,
|
||||||
Ended = 2
|
Ended = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventCollector<E extends keyof GatewayEvents> extends EventEmitter {
|
export class EventCollector<E extends keyof GatewayEvents> extends EventEmitter {
|
||||||
collected = new Set<Parameters<Handler[E]>[0]>();
|
collected = new Set<Parameters<Handler[E]>[0]>();
|
||||||
status: CollectorStatus = CollectorStatus.Idle;
|
status: CollectorStatus = CollectorStatus.Idle;
|
||||||
options: MakeRequired<CollectorOptions<E>, 'filter' | 'max'>;
|
options: MakeRequired<CollectorOptions<E>, "filter" | "max">;
|
||||||
private timeout: NodeJS.Timeout | null = null;
|
private timeout: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
constructor(readonly session: Session, rawOptions: CollectorOptions<E>) {
|
constructor(readonly session: Session, rawOptions: CollectorOptions<E>) {
|
||||||
@ -36,24 +36,24 @@ export class EventCollector<E extends keyof GatewayEvents> extends EventEmitter
|
|||||||
start() {
|
start() {
|
||||||
this.session.setMaxListeners(this.session.getMaxListeners() + 1);
|
this.session.setMaxListeners(this.session.getMaxListeners() + 1);
|
||||||
this.session.on(this.options.event, (...args: unknown[]) => this.collect(...(args as Parameters<Handler[E]>)));
|
this.session.on(this.options.event, (...args: unknown[]) => this.collect(...(args as Parameters<Handler[E]>)));
|
||||||
this.timeout = setTimeout(() => this.stop('time'), this.options.idle ?? this.options.time);
|
this.timeout = setTimeout(() => this.stop("time"), this.options.idle ?? this.options.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
private collect(...args: Parameters<Handler[E]>) {
|
private collect(...args: Parameters<Handler[E]>) {
|
||||||
if (this.options.filter?.(...args)) {
|
if (this.options.filter?.(...args)) {
|
||||||
this.collected.add(args[0]);
|
this.collected.add(args[0]);
|
||||||
this.emit('collect', ...args);
|
this.emit("collect", ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.idle) {
|
if (this.options.idle) {
|
||||||
if (this.timeout) clearTimeout(this.timeout);
|
if (this.timeout) clearTimeout(this.timeout);
|
||||||
this.timeout = setTimeout(() => this.stop('time'), this.options.idle);
|
this.timeout = setTimeout(() => this.stop("time"), this.options.idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.collected.size >= this.options.max!) this.stop('max');
|
if (this.collected.size >= this.options.max!) this.stop("max");
|
||||||
}
|
}
|
||||||
|
|
||||||
stop(reason = 'User stopped') {
|
stop(reason = "User stopped") {
|
||||||
if (this.status === CollectorStatus.Ended) return;
|
if (this.status === CollectorStatus.Ended) return;
|
||||||
|
|
||||||
if (this.timeout) clearTimeout(this.timeout);
|
if (this.timeout) clearTimeout(this.timeout);
|
||||||
@ -62,17 +62,17 @@ export class EventCollector<E extends keyof GatewayEvents> extends EventEmitter
|
|||||||
this.session.setMaxListeners(this.session.getMaxListeners() - 1);
|
this.session.setMaxListeners(this.session.getMaxListeners() - 1);
|
||||||
|
|
||||||
this.status = CollectorStatus.Ended;
|
this.status = CollectorStatus.Ended;
|
||||||
this.emit('end', reason, this.collected);
|
this.emit("end", reason, this.collected);
|
||||||
}
|
}
|
||||||
|
|
||||||
on(event: 'collect', listener: (...args: Parameters<Handler[E]>) => unknown): this;
|
on(event: "collect", listener: (...args: Parameters<Handler[E]>) => unknown): this;
|
||||||
on(event: 'end', listener: (reason: string | null | undefined, collected: Set<Parameters<Handler[E]>[0]>) => void): this;
|
on(event: "end", listener: (reason: string | null | undefined, collected: Set<Parameters<Handler[E]>[0]>) => void): this;
|
||||||
on(event: string, listener: unknown): this {
|
on(event: string, listener: unknown): this {
|
||||||
return super.on(event, listener as () => unknown);
|
return super.on(event, listener as () => unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
once(event: 'collect', listener: (...args: Parameters<Handler[E]>) => unknown): this;
|
once(event: "collect", listener: (...args: Parameters<Handler[E]>) => unknown): this;
|
||||||
once(event: 'end', listener: (reason: string | null | undefined, collected: Set<Parameters<Handler[E]>[0]>) => void): this;
|
once(event: "end", listener: (reason: string | null | undefined, collected: Set<Parameters<Handler[E]>[0]>) => void): this;
|
||||||
once(event: string, listener: unknown): this {
|
once(event: string, listener: unknown): this {
|
||||||
return super.once(event, listener as () => unknown);
|
return super.once(event, listener as () => unknown);
|
||||||
}
|
}
|
||||||
|
132
packages/helpers/src/Permissions.ts
Normal file
132
packages/helpers/src/Permissions.ts
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
import { PermissionFlagsBits } from "@biscuitland/common";
|
||||||
|
|
||||||
|
export type PermissionsStrings = keyof typeof PermissionFlagsBits;
|
||||||
|
export type PermissionResolvable = bigint | PermissionsStrings | PermissionsStrings[] | PermissionsStrings | PermissionsStrings[];
|
||||||
|
|
||||||
|
export class Permissions {
|
||||||
|
/** Stores a reference to BitwisePermissionFlags */
|
||||||
|
static Flags = PermissionFlagsBits;
|
||||||
|
|
||||||
|
/** Falsy; Stores the lack of permissions*/
|
||||||
|
static None = 0n;
|
||||||
|
|
||||||
|
/** Stores all entity permissions */
|
||||||
|
bitfield: bigint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wheter to grant all other permissions to the administrator
|
||||||
|
* **Not to get confused with Permissions#admin**
|
||||||
|
*/
|
||||||
|
__admin__ = true;
|
||||||
|
|
||||||
|
constructor(bitfield: PermissionResolvable) {
|
||||||
|
this.bitfield = Permissions.resolve(bitfield);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wheter the bitfield has the administrator flag */
|
||||||
|
get admin(): boolean {
|
||||||
|
return this.has(Permissions.Flags.Administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
get array(): PermissionsStrings[] {
|
||||||
|
// unsafe cast, do not edit
|
||||||
|
const permissions = Object.keys(Permissions.Flags) as PermissionsStrings[];
|
||||||
|
return permissions.filter((bit) => this.has(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
add(...bits: PermissionResolvable[]): this {
|
||||||
|
let reduced = 0n;
|
||||||
|
for (const bit of bits) {
|
||||||
|
reduced |= Permissions.resolve(bit);
|
||||||
|
}
|
||||||
|
this.bitfield |= reduced;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(...bits: PermissionResolvable[]): this {
|
||||||
|
let reduced = 0n;
|
||||||
|
for (const bit of bits) {
|
||||||
|
reduced |= Permissions.resolve(bit);
|
||||||
|
}
|
||||||
|
this.bitfield &= ~reduced;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
has(bit: PermissionResolvable): boolean {
|
||||||
|
const bbit = Permissions.resolve(bit);
|
||||||
|
|
||||||
|
if (this.__admin__ && this.bitfield & BigInt(Permissions.Flags.Administrator)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.bitfield & bbit) === bbit;
|
||||||
|
}
|
||||||
|
|
||||||
|
any(bit: PermissionResolvable): boolean {
|
||||||
|
const bbit = Permissions.resolve(bit);
|
||||||
|
|
||||||
|
if (this.__admin__ && this.bitfield & BigInt(Permissions.Flags.Administrator)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.bitfield & bbit) !== Permissions.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
equals(bit: PermissionResolvable): boolean {
|
||||||
|
return !!(this.bitfield & Permissions.resolve(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets all permissions */
|
||||||
|
static get All(): bigint {
|
||||||
|
let reduced = 0n;
|
||||||
|
for (const key in PermissionFlagsBits) {
|
||||||
|
const perm = PermissionFlagsBits[key];
|
||||||
|
|
||||||
|
reduced = reduced | perm;
|
||||||
|
}
|
||||||
|
return reduced;
|
||||||
|
}
|
||||||
|
|
||||||
|
static resolve(bit: PermissionResolvable): bigint {
|
||||||
|
switch (typeof bit) {
|
||||||
|
case "bigint":
|
||||||
|
return bit;
|
||||||
|
case "number":
|
||||||
|
return BigInt(bit);
|
||||||
|
case "string":
|
||||||
|
return BigInt(Permissions.Flags[bit]);
|
||||||
|
case "object":
|
||||||
|
return Permissions.resolve(
|
||||||
|
bit
|
||||||
|
.map((p) => (typeof p === "string" ? BigInt(Permissions.Flags[p]) : BigInt(p)))
|
||||||
|
.reduce((acc, cur) => acc | cur, Permissions.None),
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
throw new TypeError(`Cannot resolve permission: ${bit}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static sum(permissions: (bigint | number)[]) {
|
||||||
|
return permissions.reduce((y, x) => BigInt(y) | BigInt(x), Permissions.None);
|
||||||
|
}
|
||||||
|
|
||||||
|
static reduce(permissions: PermissionResolvable[]): Permissions {
|
||||||
|
const solved = permissions.map(Permissions.resolve);
|
||||||
|
|
||||||
|
return new Permissions(solved.reduce((y, x) => y | x, Permissions.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
*[Symbol.iterator]() {
|
||||||
|
yield* this.array;
|
||||||
|
}
|
||||||
|
|
||||||
|
valueOf() {
|
||||||
|
return this.bitfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON(): { fields: string[] } {
|
||||||
|
const fields = Object.keys(Permissions.Flags).filter((bit) => typeof bit === "number" && this.has(bit));
|
||||||
|
|
||||||
|
return { fields };
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { APIMessageActionRowComponent, APIModalActionRowComponent, ComponentType, PermissionFlagsBits } from '@biscuitland/common';
|
import { APIMessageActionRowComponent, APIModalActionRowComponent, ComponentType } from "@biscuitland/common";
|
||||||
import {
|
import {
|
||||||
ChannelSelectMenu,
|
ChannelSelectMenu,
|
||||||
MentionableSelectMenu,
|
MentionableSelectMenu,
|
||||||
@ -6,9 +6,9 @@ import {
|
|||||||
ModalTextInput,
|
ModalTextInput,
|
||||||
RoleSelectMenu,
|
RoleSelectMenu,
|
||||||
StringSelectMenu,
|
StringSelectMenu,
|
||||||
UserSelectMenu
|
UserSelectMenu,
|
||||||
} from './components';
|
} from "./components";
|
||||||
import { BaseComponent } from './components/BaseComponent';
|
import { BaseComponent } from "./components/BaseComponent";
|
||||||
|
|
||||||
export function createComponent(data: APIMessageActionRowComponent): HelperComponents;
|
export function createComponent(data: APIMessageActionRowComponent): HelperComponents;
|
||||||
export function createComponent(data: APIModalActionRowComponent): HelperComponents;
|
export function createComponent(data: APIModalActionRowComponent): HelperComponents;
|
||||||
@ -36,7 +36,6 @@ export function createComponent(data: HelperComponents | APIMessageActionRowComp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PermissionsStrings = `${keyof typeof PermissionFlagsBits}`;
|
|
||||||
export type OptionValuesLength = { max: number; min: number };
|
export type OptionValuesLength = { max: number; min: number };
|
||||||
export type MessageSelectMenus = RoleSelectMenu | UserSelectMenu | StringSelectMenu | ChannelSelectMenu | MentionableSelectMenu;
|
export type MessageSelectMenus = RoleSelectMenu | UserSelectMenu | StringSelectMenu | ChannelSelectMenu | MentionableSelectMenu;
|
||||||
export type MessageComponents = MessageButton | MessageSelectMenus;
|
export type MessageComponents = MessageButton | MessageSelectMenus;
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import {
|
import { ApplicationCommandType, LocalizationMap, RESTPostAPIContextMenuApplicationCommandsJSONBody } from "@biscuitland/common";
|
||||||
LocalizationMap,
|
import { PermissionResolvable, Permissions } from "../../Permissions";
|
||||||
ApplicationCommandType,
|
|
||||||
Permissions,
|
|
||||||
PermissionFlagsBits,
|
|
||||||
RESTPostAPIContextMenuApplicationCommandsJSONBody
|
|
||||||
} from '@biscuitland/common';
|
|
||||||
import { PermissionsStrings } from '../../Utils';
|
|
||||||
|
|
||||||
export type ContextCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;
|
export type ContextCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;
|
||||||
|
|
||||||
@ -14,7 +8,7 @@ export class ContextCommand {
|
|||||||
name_localizations?: LocalizationMap;
|
name_localizations?: LocalizationMap;
|
||||||
type: ContextCommandType = undefined!;
|
type: ContextCommandType = undefined!;
|
||||||
default_permission: boolean | undefined = undefined;
|
default_permission: boolean | undefined = undefined;
|
||||||
default_member_permissions: Permissions | null | undefined = undefined;
|
default_member_permissions: string | undefined = undefined;
|
||||||
dm_permission: boolean | undefined = undefined;
|
dm_permission: boolean | undefined = undefined;
|
||||||
|
|
||||||
setName(name: string): this {
|
setName(name: string): this {
|
||||||
@ -38,8 +32,8 @@ export class ContextCommand {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefautlMemberPermissions(permissions: PermissionsStrings[]): this {
|
setDefautlMemberPermissions(permissions: PermissionResolvable[]): this {
|
||||||
this.default_member_permissions = `$${permissions.reduce((y, x) => y | PermissionFlagsBits[x], 0n)}`;
|
this.default_member_permissions = Permissions.reduce(permissions).bitfield.toString();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
export * from './slash/SlashCommand';
|
export * from "./contextMenu/ContextCommand";
|
||||||
export * from './slash/SlashCommandOption';
|
export * from "./slash/SlashCommand";
|
||||||
export * from './contextMenu/ContextCommand';
|
export * from "./slash/SlashCommandOption";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ApplicationCommandType, PermissionFlagsBits, RESTPostAPIChatInputApplicationCommandsJSONBody } from '@biscuitland/common';
|
import { ApplicationCommandType, RESTPostAPIChatInputApplicationCommandsJSONBody } from "@biscuitland/common";
|
||||||
import { AllSlashOptions, SlashSubcommandGroupOption, SlashSubcommandOption } from './SlashCommandOption';
|
import { Mixin } from "ts-mixer";
|
||||||
import { PermissionsStrings } from '../../Utils';
|
import { PermissionResolvable, Permissions } from "../../Permissions";
|
||||||
import { Mixin } from 'ts-mixer';
|
import { AllSlashOptions, SlashSubcommandGroupOption, SlashSubcommandOption } from "./SlashCommandOption";
|
||||||
|
|
||||||
class SlashCommandB {
|
class SlashCommandB {
|
||||||
constructor(public data: Partial<RESTPostAPIChatInputApplicationCommandsJSONBody> = {}) {}
|
constructor(public data: Partial<RESTPostAPIChatInputApplicationCommandsJSONBody> = {}) {}
|
||||||
@ -16,8 +16,8 @@ class SlashCommandB {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefautlMemberPermissions(permissions: PermissionsStrings[]): this {
|
setDefautlMemberPermissions(permissions: PermissionResolvable[]): this {
|
||||||
this.data.default_member_permissions = `$${permissions.reduce((y, x) => y | PermissionFlagsBits[x], 0n)}`;
|
this.data.default_member_permissions = Permissions.reduce(permissions).bitfield.toString();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class SlashCommandB {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
addRawOption(option: ReturnType<AllSlashOptions['toJSON']>) {
|
addRawOption(option: ReturnType<AllSlashOptions["toJSON"]>) {
|
||||||
this.data.options ??= [];
|
this.data.options ??= [];
|
||||||
// @ts-expect-error discord-api-types bad typing, again
|
// @ts-expect-error discord-api-types bad typing, again
|
||||||
this.data.options.push(option);
|
this.data.options.push(option);
|
||||||
@ -42,7 +42,7 @@ class SlashCommandB {
|
|||||||
toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
|
toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
|
||||||
return {
|
return {
|
||||||
...this.data,
|
...this.data,
|
||||||
type: ApplicationCommandType.ChatInput
|
type: ApplicationCommandType.ChatInput,
|
||||||
} as RESTPostAPIChatInputApplicationCommandsJSONBody & {
|
} as RESTPostAPIChatInputApplicationCommandsJSONBody & {
|
||||||
type: ApplicationCommandType.ChatInput;
|
type: ApplicationCommandType.ChatInput;
|
||||||
};
|
};
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
import {
|
import {
|
||||||
APIApplicationCommandOption,
|
APIApplicationCommandIntegerOption as AACIO,
|
||||||
APIApplicationCommandOptionChoice,
|
APIApplicationCommandNumberOption as AACNO,
|
||||||
ApplicationCommandOptionType,
|
APIApplicationCommandSubcommandOption as AACSCO,
|
||||||
|
APIApplicationCommandSubcommandGroupOption as AACSGO,
|
||||||
APIApplicationCommandStringOption as AACSO,
|
APIApplicationCommandStringOption as AACSO,
|
||||||
|
APIApplicationCommandAttachmentOption,
|
||||||
|
APIApplicationCommandBooleanOption,
|
||||||
|
APIApplicationCommandChannelOption,
|
||||||
|
APIApplicationCommandMentionableOption,
|
||||||
|
APIApplicationCommandOption,
|
||||||
APIApplicationCommandOptionBase,
|
APIApplicationCommandOptionBase,
|
||||||
|
APIApplicationCommandOptionChoice,
|
||||||
|
APIApplicationCommandRoleOption,
|
||||||
|
APIApplicationCommandUserOption,
|
||||||
|
ApplicationCommandOptionType,
|
||||||
|
ChannelType,
|
||||||
LocalizationMap,
|
LocalizationMap,
|
||||||
RestToKeys,
|
RestToKeys,
|
||||||
TypeArray,
|
TypeArray,
|
||||||
When,
|
When,
|
||||||
APIApplicationCommandNumberOption as AACNO,
|
} from "@biscuitland/common";
|
||||||
APIApplicationCommandIntegerOption as AACIO,
|
import { OptionValuesLength } from "../../";
|
||||||
APIApplicationCommandSubcommandGroupOption as AACSGO,
|
|
||||||
APIApplicationCommandSubcommandOption as AACSCO,
|
|
||||||
APIApplicationCommandUserOption,
|
|
||||||
APIApplicationCommandChannelOption,
|
|
||||||
ChannelType,
|
|
||||||
APIApplicationCommandRoleOption,
|
|
||||||
APIApplicationCommandMentionableOption,
|
|
||||||
APIApplicationCommandAttachmentOption,
|
|
||||||
APIApplicationCommandBooleanOption
|
|
||||||
} from '@biscuitland/common';
|
|
||||||
import { OptionValuesLength } from '../../';
|
|
||||||
|
|
||||||
export type SlashBaseOptionTypes =
|
export type SlashBaseOptionTypes =
|
||||||
| Exclude<APIApplicationCommandOption, AACSO | AACNO | AACIO | AACSCO>
|
| Exclude<APIApplicationCommandOption, AACSO | AACNO | AACIO | AACSCO>
|
||||||
@ -53,7 +53,7 @@ export abstract class SlashBaseOption<DataType extends SlashBaseOptionTypes> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
addLocalizations(locals: RestToKeys<[LocalizationMap, 'name', 'description']>): this {
|
addLocalizations(locals: RestToKeys<[LocalizationMap, "name", "description"]>): this {
|
||||||
this.data.name_localizations = locals.name;
|
this.data.name_localizations = locals.name;
|
||||||
this.data.description_localizations = locals.description;
|
this.data.description_localizations = locals.description;
|
||||||
return this;
|
return this;
|
||||||
@ -333,7 +333,7 @@ export class SlashSubcommandGroupOption extends SlashBaseOption<APIApplicationCo
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
addRawOption(option: ReturnType<SlashSubcommandOption['toJSON']>) {
|
addRawOption(option: ReturnType<SlashSubcommandOption["toJSON"]>) {
|
||||||
this.data.options ??= [];
|
this.data.options ??= [];
|
||||||
this.data.options.push(option);
|
this.data.options.push(option);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { APIActionRowComponent, APIMessageActionRowComponent, ComponentType, TypeArray } from '@biscuitland/common';
|
import { APIActionRowComponent, APIMessageActionRowComponent, ComponentType, TypeArray } from "@biscuitland/common";
|
||||||
import { MessageComponents, createComponent } from '../Utils';
|
import { MessageComponents, createComponent } from "../Utils";
|
||||||
import { BaseComponent } from './BaseComponent';
|
import { BaseComponent } from "./BaseComponent";
|
||||||
|
|
||||||
export class MessageActionRow<T extends MessageComponents> extends BaseComponent<APIActionRowComponent<APIMessageActionRowComponent>> {
|
export class MessageActionRow<T extends MessageComponents> extends BaseComponent<APIActionRowComponent<APIMessageActionRowComponent>> {
|
||||||
constructor({ components, ...data }: Partial<APIActionRowComponent<APIMessageActionRowComponent>>) {
|
constructor({ components, ...data }: Partial<APIActionRowComponent<APIMessageActionRowComponent>>) {
|
||||||
@ -22,7 +22,7 @@ export class MessageActionRow<T extends MessageComponents> extends BaseComponent
|
|||||||
toJSON(): APIActionRowComponent<APIMessageActionRowComponent> {
|
toJSON(): APIActionRowComponent<APIMessageActionRowComponent> {
|
||||||
return {
|
return {
|
||||||
...this.data,
|
...this.data,
|
||||||
components: this.components.map((c) => c.toJSON())
|
components: this.components.map((c) => c.toJSON()),
|
||||||
} as APIActionRowComponent<ReturnType<T['toJSON']>>;
|
} as APIActionRowComponent<ReturnType<T["toJSON"]>>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { APIBaseComponent, ComponentType } from '@biscuitland/common';
|
import { APIBaseComponent, ComponentType } from "@biscuitland/common";
|
||||||
|
|
||||||
export abstract class BaseComponent<TYPE extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,> {
|
export abstract class BaseComponent<TYPE extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,> {
|
||||||
constructor(public data: Partial<TYPE>) {}
|
constructor(public data: Partial<TYPE>) {}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { APIButtonComponentBase, APIMessageComponentEmoji, ButtonStyle, ComponentType, When } from '@biscuitland/common';
|
import { APIButtonComponentBase, APIMessageComponentEmoji, ButtonStyle, ComponentType, When } from "@biscuitland/common";
|
||||||
import { BaseComponent } from './BaseComponent';
|
import { BaseComponent } from "./BaseComponent";
|
||||||
|
|
||||||
export type ButtonStylesForID = Exclude<ButtonStyle, ButtonStyle.Link>;
|
export type ButtonStylesForID = Exclude<ButtonStyle, ButtonStyle.Link>;
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ import {
|
|||||||
APIUserSelectComponent,
|
APIUserSelectComponent,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
ComponentType,
|
ComponentType,
|
||||||
TypeArray
|
TypeArray,
|
||||||
} from '@biscuitland/common';
|
} from "@biscuitland/common";
|
||||||
import { BaseComponent } from './BaseComponent';
|
import { OptionValuesLength } from "..";
|
||||||
import { OptionValuesLength } from '..';
|
import { BaseComponent } from "./BaseComponent";
|
||||||
|
|
||||||
class SelectMenu<Select extends APISelectMenuComponent = APISelectMenuComponent,> extends BaseComponent<Select> {
|
class SelectMenu<Select extends APISelectMenuComponent = APISelectMenuComponent,> extends BaseComponent<Select> {
|
||||||
setCustomId(id: string): this {
|
setCustomId(id: string): this {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { APITextInputComponent, ComponentType, TextInputStyle } from '@biscuitland/common';
|
import { APITextInputComponent, ComponentType, TextInputStyle } from "@biscuitland/common";
|
||||||
import { BaseComponent } from './BaseComponent';
|
import { OptionValuesLength } from "..";
|
||||||
import { OptionValuesLength } from '..';
|
import { BaseComponent } from "./BaseComponent";
|
||||||
|
|
||||||
export class ModalTextInput extends BaseComponent<APITextInputComponent> {
|
export class ModalTextInput extends BaseComponent<APITextInputComponent> {
|
||||||
constructor(data: Partial<APITextInputComponent> = {}) {
|
constructor(data: Partial<APITextInputComponent> = {}) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export * from './ActionRow';
|
export * from "./ActionRow";
|
||||||
export * from './MessageButton';
|
export * from "./BaseComponent";
|
||||||
export * from './SelectMenu';
|
export * from "./MessageButton";
|
||||||
export * from './TextInput';
|
export * from "./SelectMenu";
|
||||||
export * from './BaseComponent';
|
export * from "./TextInput";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export * from './MessageEmbed';
|
export * from "./MessageEmbed";
|
||||||
export * from './components/index';
|
export * from "./Permissions";
|
||||||
export * from './Utils';
|
export * from "./Utils";
|
||||||
export * from './commands';
|
export * from "./commands";
|
||||||
|
export * from "./components";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user