mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
* chore: builders to helpers * fix: readme
This commit is contained in:
parent
18bcc32868
commit
1ebe2e6858
12
README.md
12
README.md
@ -29,17 +29,17 @@ that you should not make software that does things it is not supposed to do.
|
||||
## Example bot (TS/JS)
|
||||
|
||||
```js
|
||||
import { ChatInputApplicationCommandBuilder, Session } from '@biscuitland/core';
|
||||
import { Session } from '@biscuitland/core';
|
||||
import { GatewayIntents } from '@biscuitland/api-types';
|
||||
|
||||
const session = new Session({ token: 'your token', intents: GatewayIntents.Guilds });
|
||||
|
||||
const commands = [
|
||||
new ChatInputApplicationCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with pong!')
|
||||
.toJSON()
|
||||
]
|
||||
{
|
||||
name: 'ping',
|
||||
description: 'Replies with pong!'
|
||||
}
|
||||
];
|
||||
|
||||
session.events.on('ready', async ({ user }) => {
|
||||
console.log('Logged in as:', user.username);
|
||||
|
@ -1,115 +0,0 @@
|
||||
import type { Localization, PermissionStrings } from '@biscuitland/api-types';
|
||||
import type { CreateApplicationCommand } from '../../biscuit';
|
||||
import { ApplicationCommandTypes } from '@biscuitland/api-types';
|
||||
import { OptionBased } from './ApplicationCommandOption';
|
||||
|
||||
export abstract class ApplicationCommandBuilder {
|
||||
constructor(
|
||||
type: ApplicationCommandTypes = ApplicationCommandTypes.ChatInput,
|
||||
name: string = '',
|
||||
description: string = '',
|
||||
defaultMemberPermissions?: PermissionStrings[],
|
||||
nameLocalizations?: Localization,
|
||||
descriptionLocalizations?: Localization,
|
||||
dmPermission: boolean = true,
|
||||
) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultMemberPermissions = defaultMemberPermissions;
|
||||
this.nameLocalizations = nameLocalizations;
|
||||
this.descriptionLocalizations = descriptionLocalizations;
|
||||
this.dmPermission = dmPermission;
|
||||
}
|
||||
type: ApplicationCommandTypes;
|
||||
name: string;
|
||||
description: string;
|
||||
defaultMemberPermissions?: PermissionStrings[];
|
||||
nameLocalizations?: Localization;
|
||||
descriptionLocalizations?: Localization;
|
||||
dmPermission: boolean;
|
||||
|
||||
setType(type: ApplicationCommandTypes): this {
|
||||
return (this.type = type), this;
|
||||
}
|
||||
|
||||
setName(name: string): this {
|
||||
return (this.name = name), this;
|
||||
}
|
||||
|
||||
setDescription(description: string): this {
|
||||
return (this.description = description), this;
|
||||
}
|
||||
|
||||
setDefaultMemberPermission(perm: PermissionStrings[]): this {
|
||||
return (this.defaultMemberPermissions = perm), this;
|
||||
}
|
||||
|
||||
setNameLocalizations(l: Localization): this {
|
||||
return (this.nameLocalizations = l), this;
|
||||
}
|
||||
|
||||
setDescriptionLocalizations(l: Localization): this {
|
||||
return (this.descriptionLocalizations = l), this;
|
||||
}
|
||||
|
||||
setDmPermission(perm: boolean): this {
|
||||
return (this.dmPermission = perm), this;
|
||||
}
|
||||
}
|
||||
|
||||
export type MessageApplicationCommandBuilderJSON = { name: string; type: ApplicationCommandTypes.Message };
|
||||
|
||||
export class MessageApplicationCommandBuilder {
|
||||
type: ApplicationCommandTypes;
|
||||
name?: string;
|
||||
constructor(
|
||||
type?: ApplicationCommandTypes,
|
||||
name?: string,
|
||||
) {
|
||||
this.type = type ?? ApplicationCommandTypes.Message;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
setName(name: string): this {
|
||||
return (this.name = name), this;
|
||||
}
|
||||
|
||||
toJSON(): MessageApplicationCommandBuilderJSON {
|
||||
if (!this.name) throw new TypeError('Propety \'name\' is required');
|
||||
|
||||
return {
|
||||
type: ApplicationCommandTypes.Message,
|
||||
name: this.name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class ChatInputApplicationCommandBuilder extends ApplicationCommandBuilder {
|
||||
type: ApplicationCommandTypes.ChatInput = ApplicationCommandTypes.ChatInput;
|
||||
|
||||
toJSON(): CreateApplicationCommand {
|
||||
if (!this.type) throw new TypeError('Propety \'type\' is required');
|
||||
if (!this.name) throw new TypeError('Propety \'name\' is required');
|
||||
if (!this.description) {
|
||||
throw new TypeError('Propety \'description\' is required');
|
||||
}
|
||||
|
||||
return {
|
||||
type: ApplicationCommandTypes.ChatInput,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: this.options?.map((o) => o.toJSON()) ?? [],
|
||||
default_member_permissions: this.defaultMemberPermissions,
|
||||
name_localizations: this.nameLocalizations,
|
||||
description_localizations: this.descriptionLocalizations,
|
||||
dm_permission: this.dmPermission,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
OptionBased.applyTo(ChatInputApplicationCommandBuilder);
|
||||
|
||||
export interface ChatInputApplicationCommandBuilder extends ApplicationCommandBuilder, OptionBased {
|
||||
// pass
|
||||
}
|
@ -34,9 +34,9 @@ export * from './structures/components';
|
||||
export * from './structures/guilds';
|
||||
|
||||
// BUILDERS
|
||||
export * from './builders/components/InputTextBuilder';
|
||||
export * from './builders/components/MessageActionRowBuilder';
|
||||
export * from './builders/components/MessageButtonBuilder';
|
||||
export * from './builders/components/MessageSelectMenuBuilder';
|
||||
export * from './builders/slash/ApplicationCommand';
|
||||
export * from './builders/slash/ApplicationCommandOption';
|
||||
export * from '../../helpers/src/builders/components/InputTextBuilder';
|
||||
export * from '../../helpers/src/builders/components/MessageActionRowBuilder';
|
||||
export * from '../../helpers/src/builders/components/MessageButtonBuilder';
|
||||
export * from '../../helpers/src/builders/components/MessageSelectMenuBuilder';
|
||||
export * from '../../helpers/src/builders/slash/ApplicationCommand';
|
||||
export * from '../../helpers/src/builders/slash/ApplicationCommandOption';
|
||||
|
@ -1,6 +1,4 @@
|
||||
import type { ButtonBuilder } from '../builders/components/MessageButtonBuilder';
|
||||
import type { InputTextBuilder } from '../builders/components/InputTextBuilder';
|
||||
import type { SelectMenuBuilder } from '../builders/components/MessageSelectMenuBuilder';
|
||||
import type { SelectMenuBuilder, InputTextBuilder, ButtonBuilder } from '@biscuitland/helpers';
|
||||
import type { Permissions } from '../structures/special/permissions';
|
||||
import type { Snowflake } from '../snowflakes';
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import type { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from '@biscuitland/api-types';
|
||||
import { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from '@biscuitland/api-types';
|
||||
|
||||
export class InputTextBuilder {
|
||||
constructor() {
|
||||
this.#data = {} as DiscordInputTextComponent;
|
||||
this.type = 4;
|
||||
this.type = MessageComponentTypes.InputText;
|
||||
}
|
||||
#data: DiscordInputTextComponent;
|
||||
type: MessageComponentTypes.InputText;
|
@ -1,10 +1,10 @@
|
||||
import type { DiscordActionRow, MessageComponentTypes } from '@biscuitland/api-types';
|
||||
import type { ComponentBuilder } from '../../utils/util';
|
||||
import { DiscordActionRow, MessageComponentTypes } from '@biscuitland/api-types';
|
||||
import type { ComponentBuilder } from '../../../../core/src/utils/util';
|
||||
|
||||
export class ActionRowBuilder<T extends ComponentBuilder> {
|
||||
constructor() {
|
||||
this.components = [] as T[];
|
||||
this.type = 1;
|
||||
this.type = MessageComponentTypes.ActionRow;
|
||||
}
|
||||
components: T[];
|
||||
type: MessageComponentTypes.ActionRow;
|
@ -1,5 +1,5 @@
|
||||
import { ButtonStyles, DiscordButtonComponent, MessageComponentTypes } from '@biscuitland/api-types';
|
||||
import type { ComponentEmoji } from '../../utils/util';
|
||||
import type { ComponentEmoji } from '../../../../core/src/utils/util';
|
||||
|
||||
export class ButtonBuilder {
|
||||
constructor() {
|
@ -1,5 +1,5 @@
|
||||
import type { DiscordSelectOption, DiscordSelectMenuComponent, } from '@biscuitland/api-types';
|
||||
import type { ComponentEmoji } from '../../utils/util';
|
||||
import type { ComponentEmoji } from '../../../../core/src/utils/util';
|
||||
import { MessageComponentTypes } from '@biscuitland/api-types';
|
||||
|
||||
export class SelectMenuOptionBuilder {
|
@ -1,4 +1,4 @@
|
||||
import type { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from '@biscuitland/api-types';
|
||||
import { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from '@biscuitland/api-types';
|
||||
|
||||
export interface EmbedFooter {
|
||||
text: string;
|
120
packages/helpers/src/builders/slash/ApplicationCommand.ts
Normal file
120
packages/helpers/src/builders/slash/ApplicationCommand.ts
Normal file
@ -0,0 +1,120 @@
|
||||
import {
|
||||
Localization,
|
||||
PermissionStrings,
|
||||
ApplicationCommandTypes
|
||||
} from '@biscuitland/api-types';
|
||||
import { CreateApplicationCommand } from '@biscuitland/core';
|
||||
import { OptionBased } from './ApplicationCommandOption';
|
||||
|
||||
export abstract class ApplicationCommandBuilder {
|
||||
constructor(
|
||||
type: ApplicationCommandTypes = ApplicationCommandTypes.ChatInput,
|
||||
name: string = '',
|
||||
description: string = '',
|
||||
defaultMemberPermissions?: PermissionStrings[],
|
||||
nameLocalizations?: Localization,
|
||||
descriptionLocalizations?: Localization,
|
||||
dmPermission: boolean = true
|
||||
) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultMemberPermissions = defaultMemberPermissions;
|
||||
this.nameLocalizations = nameLocalizations;
|
||||
this.descriptionLocalizations = descriptionLocalizations;
|
||||
this.dmPermission = dmPermission;
|
||||
}
|
||||
type: ApplicationCommandTypes;
|
||||
name: string;
|
||||
description: string;
|
||||
defaultMemberPermissions?: PermissionStrings[];
|
||||
nameLocalizations?: Localization;
|
||||
descriptionLocalizations?: Localization;
|
||||
dmPermission: boolean;
|
||||
|
||||
setType(type: ApplicationCommandTypes): this {
|
||||
return (this.type = type), this;
|
||||
}
|
||||
|
||||
setName(name: string): this {
|
||||
return (this.name = name), this;
|
||||
}
|
||||
|
||||
setDescription(description: string): this {
|
||||
return (this.description = description), this;
|
||||
}
|
||||
|
||||
setDefaultMemberPermission(perm: PermissionStrings[]): this {
|
||||
return (this.defaultMemberPermissions = perm), this;
|
||||
}
|
||||
|
||||
setNameLocalizations(l: Localization): this {
|
||||
return (this.nameLocalizations = l), this;
|
||||
}
|
||||
|
||||
setDescriptionLocalizations(l: Localization): this {
|
||||
return (this.descriptionLocalizations = l), this;
|
||||
}
|
||||
|
||||
setDmPermission(perm: boolean): this {
|
||||
return (this.dmPermission = perm), this;
|
||||
}
|
||||
}
|
||||
|
||||
export type MessageApplicationCommandBuilderJSON = {
|
||||
name: string;
|
||||
type: ApplicationCommandTypes.Message;
|
||||
};
|
||||
|
||||
export class MessageApplicationCommandBuilder {
|
||||
type: ApplicationCommandTypes;
|
||||
name?: string;
|
||||
constructor(type?: ApplicationCommandTypes, name?: string) {
|
||||
this.type = type ?? ApplicationCommandTypes.Message;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
setName(name: string): this {
|
||||
return (this.name = name), this;
|
||||
}
|
||||
|
||||
toJSON(): MessageApplicationCommandBuilderJSON {
|
||||
if (!this.name) throw new TypeError("Propety 'name' is required");
|
||||
|
||||
return {
|
||||
type: ApplicationCommandTypes.Message,
|
||||
name: this.name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class ChatInputApplicationCommandBuilder extends ApplicationCommandBuilder {
|
||||
type: ApplicationCommandTypes.ChatInput = ApplicationCommandTypes.ChatInput;
|
||||
|
||||
toJSON(): CreateApplicationCommand {
|
||||
if (!this.type) throw new TypeError("Propety 'type' is required");
|
||||
if (!this.name) throw new TypeError("Propety 'name' is required");
|
||||
if (!this.description) {
|
||||
throw new TypeError("Propety 'description' is required");
|
||||
}
|
||||
|
||||
return {
|
||||
type: ApplicationCommandTypes.ChatInput,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: this.options?.map(o => o.toJSON()) ?? [],
|
||||
default_member_permissions: this.defaultMemberPermissions,
|
||||
name_localizations: this.nameLocalizations,
|
||||
description_localizations: this.descriptionLocalizations,
|
||||
dm_permission: this.dmPermission
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
OptionBased.applyTo(ChatInputApplicationCommandBuilder);
|
||||
|
||||
export interface ChatInputApplicationCommandBuilder
|
||||
extends ApplicationCommandBuilder,
|
||||
OptionBased {
|
||||
// pass
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import type { ChannelTypes, Localization, Locales } from '@biscuitland/api-types';
|
||||
import { ApplicationCommandOptionTypes } from '@biscuitland/api-types';
|
||||
import { ApplicationCommandOptionChoice } from '../../structures/interactions';
|
||||
import { ChannelTypes, Localization, Locales, ApplicationCommandOptionTypes } from '@biscuitland/api-types';
|
||||
import { ApplicationCommandOptionChoice } from '@biscuitland/core';
|
||||
|
||||
|
||||
export type Localizations = typeof Locales[keyof typeof Locales] & string;
|
@ -1 +1,16 @@
|
||||
export * from './collectors';
|
||||
export * from './collectors';
|
||||
|
||||
/** Builders */
|
||||
|
||||
// Components
|
||||
export * from './builders/components/InputTextBuilder';
|
||||
export * from './builders/components/MessageActionRowBuilder';
|
||||
export * from './builders/components/MessageButtonBuilder';
|
||||
export * from './builders/components/MessageSelectMenuBuilder';
|
||||
|
||||
// Slash
|
||||
export * from './builders/slash/ApplicationCommand';
|
||||
export * from './builders/slash/ApplicationCommandOption';
|
||||
|
||||
// Embed
|
||||
export * from './builders/embed-builder';
|
@ -17,7 +17,7 @@
|
||||
"@biscuitland/core#build": {
|
||||
"dependsOn": ["@biscuitland/api-types#build", "@biscuitland/rest#build", "@biscuitland/ws#build"]
|
||||
},
|
||||
"@biscuitland/extra#build": {
|
||||
"@biscuitland/helpers#build": {
|
||||
"dependsOn": ["@biscuitland/core#build"]
|
||||
},
|
||||
"clean": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user