@fallencodes/seyfert-utils 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { Container, ContainerBuilderComponents, Section, Separator, TextDisplay } from 'seyfert';
2
- import { ButtonStyle, Spacing } from 'seyfert/lib/types/index.js';
1
+ import { ActionBuilderComponents, ActionRow, Button, Container, ContainerBuilderComponents, FixedComponents, Section, Separator, TextDisplay } from 'seyfert';
2
+ import { APIMessageComponentEmoji, ButtonStyle, Spacing } from 'seyfert/lib/types/index.js';
3
3
  export declare function createTextDisplay(content: string): TextDisplay;
4
4
  type SectionAccessory = ({
5
5
  url?: string;
@@ -22,5 +22,16 @@ interface ContainerOptions {
22
22
  spoiler?: boolean;
23
23
  }
24
24
  export declare function createContainer(components: ContainerBuilderComponents[], options?: ContainerOptions): Container;
25
+ export declare function createActionRow<T extends ActionBuilderComponents>(...components: FixedComponents<T>[]): ActionRow<T>;
26
+ interface ButtonData {
27
+ url?: string;
28
+ label: string;
29
+ skuId?: string;
30
+ customId: string;
31
+ style: ButtonStyle;
32
+ disabled?: boolean;
33
+ emoji?: APIMessageComponentEmoji;
34
+ }
35
+ export declare function createButton(data: ButtonData): Button;
25
36
  export {};
26
- //# sourceMappingURL=components.d.ts.map
37
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/components/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,0BAA0B,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAa,MAAM,SAAS,CAAC;AACzK,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE5F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAE9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ACpC;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAIrD"}
@@ -1,4 +1,4 @@
1
- import { Button, Container, Section, Separator, TextDisplay, Thumbnail } from 'seyfert';
1
+ import { ActionRow, Button, Container, Section, Separator, TextDisplay, Thumbnail } from 'seyfert';
2
2
  export function createTextDisplay(content) {
3
3
  return new TextDisplay({ content });
4
4
  }
@@ -46,3 +46,14 @@ export function createContainer(components, options) {
46
46
  return container;
47
47
  }
48
48
  ;
49
+ export function createActionRow(...components) {
50
+ return new ActionRow().setComponents(components);
51
+ }
52
+ ;
53
+ export function createButton(data) {
54
+ const button = new Button(data).setCustomId(data.customId);
55
+ if (data.skuId)
56
+ button.setSKUId(data.skuId);
57
+ return button;
58
+ }
59
+ ;
@@ -0,0 +1,33 @@
1
+ import { Label, Modal } from 'seyfert';
2
+ import { TextInputStyle, APISelectMenuOption } from 'seyfert/lib/types/index.js';
3
+ interface ModalData {
4
+ title: string;
5
+ customId: string;
6
+ components: Label[];
7
+ }
8
+ export declare function createModal(data: ModalData): Modal;
9
+ interface ModalTextInputData {
10
+ label?: string;
11
+ value?: string;
12
+ customId: string;
13
+ required?: boolean;
14
+ minLength?: number;
15
+ maxLength?: number;
16
+ description?: string;
17
+ placeholder?: string;
18
+ style: TextInputStyle;
19
+ }
20
+ export declare function createModalTextInput(data: ModalTextInputData): Label;
21
+ interface ModalStringSelectMenuData {
22
+ label?: string;
23
+ customId: string;
24
+ required?: boolean;
25
+ minValues?: number;
26
+ maxValues?: number;
27
+ description?: string;
28
+ placeholder?: string;
29
+ options: APISelectMenuOption[];
30
+ }
31
+ export declare function createModalStringSelectMenu(data: ModalStringSelectMenuData): Label;
32
+ export {};
33
+ //# sourceMappingURL=modal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../src/components/modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAA+B,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjF,UAAU,SAAS;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,KAAK,EAAE,CAAC;CACvB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,SAE1C;AAED,UAAU,kBAAkB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,cAAc,CAAC;CACzB;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,SAa5D;AAED,UAAU,yBAAyB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAClC;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,yBAAyB,SAY1E"}
@@ -0,0 +1,35 @@
1
+ import { Label, Modal, StringSelectMenu, TextInput } from 'seyfert';
2
+ export function createModal(data) {
3
+ return new Modal({ title: data.title, custom_id: data.customId }).setComponents(data.components);
4
+ }
5
+ ;
6
+ ;
7
+ export function createModalTextInput(data) {
8
+ return new Label({
9
+ label: data.label,
10
+ description: data.description
11
+ }).setComponent(new TextInput({
12
+ value: data.value,
13
+ style: data.style,
14
+ required: data.required,
15
+ custom_id: data.customId,
16
+ min_length: data.minLength,
17
+ max_length: data.maxLength,
18
+ placeholder: data.placeholder
19
+ }));
20
+ }
21
+ ;
22
+ export function createModalStringSelectMenu(data) {
23
+ return new Label({
24
+ label: data.label,
25
+ description: data.description,
26
+ }).setComponent(new StringSelectMenu({
27
+ options: data.options,
28
+ required: data.required,
29
+ custom_id: data.customId,
30
+ min_values: data.minValues,
31
+ max_values: data.maxValues,
32
+ placeholder: data.placeholder
33
+ }));
34
+ }
35
+ ;
@@ -0,0 +1,5 @@
1
+ import { ModalSubmitInteraction, ComponentInteraction } from 'seyfert';
2
+ import { HandleCommand } from 'seyfert/lib/commands/handle.js';
3
+ export declare function handleModal(this: HandleCommand, interaction: ModalSubmitInteraction): Promise<void>;
4
+ export declare function messageComponent(this: HandleCommand, interaction: ComponentInteraction): Promise<void>;
5
+ //# sourceMappingURL=handleCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleCommand.d.ts","sourceRoot":"","sources":["../src/handleCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAwE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC7I,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG/D,wBAAsB,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,iBAgBzF;AAGD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,oBAAoB,iBAkB5F"}
@@ -0,0 +1,37 @@
1
+ import { ModalContext, InteractionCommandType } from 'seyfert';
2
+ /* My custom modal handler to support advanced custom IDs. */
3
+ export async function handleModal(interaction) {
4
+ const context = new ModalContext(this.client, interaction);
5
+ const extended = this.client.options.context?.(interaction) ?? {};
6
+ Object.assign(context, extended);
7
+ const modal = this.client.components.commands.find((component) => (component.type === InteractionCommandType.MODAL &&
8
+ component.customId === interaction.customId.split(':')[0]));
9
+ try {
10
+ context.command = modal;
11
+ await this.client.components.execute(modal, context);
12
+ }
13
+ catch (error) {
14
+ this.client.components.onFail(error);
15
+ }
16
+ ;
17
+ }
18
+ ;
19
+ /* My custom message component handler to support advanced custom IDs. */
20
+ export async function messageComponent(interaction) {
21
+ // @ts-expect-error
22
+ const context = new ComponentContext(this.client, interaction);
23
+ const extended = this.client.options.context?.(interaction) ?? {};
24
+ Object.assign(context, extended);
25
+ const component = this.client.components.commands.find((component) => (component.type === InteractionCommandType.COMPONENT &&
26
+ component.cType === interaction.componentType &&
27
+ component.customId === interaction.customId.split(':')[0]));
28
+ try {
29
+ context.command = component;
30
+ await this.client.components.execute(component, context);
31
+ }
32
+ catch (error) {
33
+ await this.client.components.onFail(error);
34
+ }
35
+ ;
36
+ }
37
+ ;
package/build/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './utilities.js';
2
- export * from './components.js';
2
+ export * from './variables.js';
3
+ export * from './components/modal.js';
4
+ export * from './components/message.js';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
package/build/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './utilities.js';
2
- export * from './components.js';
2
+ export * from './variables.js';
3
+ export * from './components/modal.js';
4
+ export * from './components/message.js';
@@ -6,5 +6,7 @@ export declare function isValidSnowflake(snowflake: string): boolean;
6
6
  export declare function truncateString(string: string, maxLength?: number): string;
7
7
  type NameType = 'display' | 'display-s' | 'display-username' | 'display-username-s' | 'username-id' | 'username-id-s';
8
8
  export declare function name(user: User | GuildMember, type?: NameType): string;
9
+ export declare function reviver(_key: string, value: any): any;
10
+ export declare function replacer(_key: string, value: any): any;
9
11
  export {};
10
12
  //# sourceMappingURL=utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG5C,wBAAgB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzC;AAGD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C;AAGD,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnD;AAGD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI3D;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAI9E;AAED,KAAK,QAAQ,GACX,SAAS,GACT,WAAW,GACX,kBAAkB,GAClB,oBAAoB,GACpB,aAAa,GACb,eAAe,CAAA;AAGjB,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAWjF"}
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG5C,wBAAgB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzC;AAGD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C;AAGD,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnD;AAGD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI3D;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAI9E;AAED,KAAK,QAAQ,GACX,SAAS,GACT,WAAW,GACX,kBAAkB,GAClB,oBAAoB,GACpB,aAAa,GACb,eAAe,CAAA;AAGjB,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAWjF;AAGD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAG/C;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAIhD"}
@@ -47,3 +47,20 @@ export function name(user, type = 'display') {
47
47
  ;
48
48
  }
49
49
  ;
50
+ /* Custom reviver function for JSON.parse to handle Maps. */
51
+ export function reviver(_key, value) {
52
+ if (typeof value === 'object' && value !== null)
53
+ if (value.dataType === 'Map')
54
+ return new Map(value.value);
55
+ return value;
56
+ }
57
+ ;
58
+ /* Custom replacer function for JSON.stringify to handle Maps. */
59
+ export function replacer(_key, value) {
60
+ if (typeof value === 'bigint')
61
+ return value.toString();
62
+ if (value instanceof Map)
63
+ return { dataType: 'Map', value: [...value] };
64
+ return value;
65
+ }
66
+ ;
@@ -0,0 +1,5 @@
1
+ export declare const trueOrFalse: {
2
+ name: string;
3
+ value: string;
4
+ }[];
5
+ //# sourceMappingURL=variables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;GAGvB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /* A generic true or false choice array for string command options. */
2
+ export const trueOrFalse = [
3
+ { name: 'Yes', value: 'true' },
4
+ { name: 'No', value: 'false' }
5
+ ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fallencodes/seyfert-utils",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "description": "A collection of various utility/helper code I use in my Seyfert projects.",
7
7
  "main": "build/index.js",
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAE,0BAA0B,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAa,MAAM,SAAS,CAAC;AACpH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAElE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAE9D;AAED,KAAK,gBAAgB,GAAG,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC,GAAG,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC,CAAA;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAqBvF;AAED,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,aAEnE;AAED,UAAU,gBAAgB;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,0BAA0B,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAW/G"}