@fallencodes/seyfert-utils 1.2.8 → 1.3.1

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.
@@ -23,15 +23,21 @@ interface ContainerOptions {
23
23
  }
24
24
  export declare function createContainer(components: ContainerBuilderComponents[], options?: ContainerOptions): Container;
25
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;
26
+ interface BaseButtonData {
27
+ label?: string;
32
28
  disabled?: boolean;
33
29
  emoji?: APIMessageComponentEmoji;
34
30
  }
31
+ type ButtonData = (BaseButtonData & {
32
+ url: string;
33
+ style: ButtonStyle.Link;
34
+ }) | (BaseButtonData & {
35
+ skuId: string;
36
+ style: ButtonStyle.Premium;
37
+ }) | (BaseButtonData & {
38
+ customId: string;
39
+ style: ButtonStyle;
40
+ });
35
41
  export declare function createButton(data: ButtonData): Button;
36
42
  export {};
37
43
  //# sourceMappingURL=message.d.ts.map
@@ -1 +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,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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H;AAED,UAAU,cAAc;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,wBAAwB,CAAC;CACpC;AAED,KAAK,UAAU,GAAG,CAAC,cAAc,GAAG;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC;CAC3B,CAAC,GAAG,CAAC,cAAc,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC;CAC9B,CAAC,GAAG,CAAC,cAAc,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,WAAW,CAAC;CACtB,CAAC,CAAA;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAKrD"}
@@ -51,8 +51,10 @@ export function createActionRow(...components) {
51
51
  }
52
52
  ;
53
53
  export function createButton(data) {
54
- const button = new Button(data).setCustomId(data.customId);
55
- if (data.skuId)
54
+ const button = new Button(data);
55
+ if ('customId' in data)
56
+ button.setCustomId(data.customId);
57
+ if ('skuId' in data)
56
58
  button.setSKUId(data.skuId);
57
59
  return button;
58
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
package/build/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import dayjs from 'dayjs';
2
+ import utcPlugin from 'dayjs/plugin/utc.js';
3
+ dayjs.extend(utcPlugin);
1
4
  export * from './utilities.js';
2
5
  export * from './variables.js';
3
6
  // export * from './components/modal.js';
@@ -0,0 +1,13 @@
1
+ import { OKFunction, GuildRole, StopFunction, AllGuildChannels, CommandContext } from 'seyfert';
2
+ interface StringOption {
3
+ value: string;
4
+ context: CommandContext;
5
+ }
6
+ export declare const snowflakeOptionValue: ({ value }: StringOption, ok: OKFunction<string>, fail: StopFunction) => void;
7
+ export declare const colorHexOptionValue: ({ value }: StringOption, ok: OKFunction<number>, fail: StopFunction) => void;
8
+ export declare function dateOptionValue({ value }: StringOption, ok: OKFunction<Date>, fail: StopFunction): void;
9
+ export declare function relativeTimeOptionValue({ value }: StringOption, ok: OKFunction<number>, fail: StopFunction): void;
10
+ export declare function rolesOptionValue({ value: values, context }: StringOption, ok: OKFunction<[GuildRole, ...GuildRole[]]>, fail: StopFunction): Promise<void>;
11
+ export declare function channelsOptionValue({ value: values, context }: StringOption, ok: OKFunction<[AllGuildChannels, ...AllGuildChannels[]]>, fail: StopFunction): Promise<void>;
12
+ export {};
13
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAOhG,UAAU,YAAY;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,cAAc,CAAC;CAC3B;AAGD,eAAO,MAAM,oBAAoB,GAAI,WAAW,YAAY,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,YAAY,SAGvG,CAAC;AAGF,eAAO,MAAM,mBAAmB,GAAI,WAAW,YAAY,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,YAAY,SAStG,CAAC;AAGF,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,QAIhG;AAGD,wBAAgB,uBAAuB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,QAI1G;AAGD,wBAAsB,gBAAgB,CAClC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,YAAY,EACxC,EAAE,EAAE,UAAU,CAAC,CAAC,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,EAC3C,IAAI,EAAE,YAAY,iBA4BrB;AAGD,wBAAsB,mBAAmB,CACrC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,YAAY,EACxC,EAAE,EAAE,UAAU,CAAC,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAC,EACzD,IAAI,EAAE,YAAY,iBA8BrB"}
@@ -0,0 +1,108 @@
1
+ import { isValidSnowflake } from './utilities.js';
2
+ import dayjs from 'dayjs';
3
+ import ms from 'ms';
4
+ import fuzzy from 'fuzzysort';
5
+ import { channelMentionRegex, hexRegex, roleMentionRegex } from './variables.js';
6
+ /* Returns a valid string snowflake value. */
7
+ export const snowflakeOptionValue = ({ value }, ok, fail) => {
8
+ if (isValidSnowflake(value))
9
+ return ok(value);
10
+ return fail(`The provided string isn't a valid snowflake.`);
11
+ };
12
+ /* Returns a valid numerical color code for the Discord API. */
13
+ export const colorHexOptionValue = ({ value }, ok, fail) => {
14
+ if (!value.startsWith('#'))
15
+ value = `#${value}`;
16
+ if (value.match(hexRegex)) {
17
+ if (value === '#000000')
18
+ value = '#000001';
19
+ return ok(parseInt(value.replace('#', '0x')));
20
+ }
21
+ ;
22
+ return fail(`The specified color "${value}" isn't a valid HEX code (format: #faff6d).`);
23
+ };
24
+ /* Returns a valid date object from the provided string value. */
25
+ export function dateOptionValue({ value }, ok, fail) {
26
+ const date = dayjs.utc(value);
27
+ if (date.isValid())
28
+ return ok(date.toDate());
29
+ else
30
+ return fail(`The specified date "${date}" isn't a valid date.`);
31
+ }
32
+ ;
33
+ /* Returns a valid date object from the provided string value. */
34
+ export function relativeTimeOptionValue({ value }, ok, fail) {
35
+ const relativeMs = ms(value);
36
+ if (isNaN(relativeMs))
37
+ return fail(`The provided time value isn't a valid amount of time.`);
38
+ return ok(relativeMs);
39
+ }
40
+ ;
41
+ /* Returns an array of roles from the provided string value. */
42
+ export async function rolesOptionValue({ value: values, context }, ok, fail) {
43
+ const guild = await context.guild();
44
+ if (!guild)
45
+ return fail("The guild this command was used in wasn't found.");
46
+ const resolvedRoles = [];
47
+ const roles = await guild.roles.list();
48
+ for (const value of values.split(',').map((value) => value.trim())) {
49
+ let role;
50
+ const mentionMatch = roleMentionRegex.exec(value)?.[1];
51
+ if (mentionMatch)
52
+ role = roles.find(({ id }) => mentionMatch === id);
53
+ if (!role && isValidSnowflake(value))
54
+ role = roles.find(({ id }) => value === id);
55
+ if (!role) {
56
+ const formattedRoles = roles.map(({ id, name }) => ({ id: id, name: fuzzy.prepare(name) }));
57
+ const match = fuzzy.go(value, formattedRoles, { key: 'name' })[0];
58
+ if (match)
59
+ role = roles.find(({ id }) => match.obj.id === id);
60
+ }
61
+ ;
62
+ if (role)
63
+ resolvedRoles.push(role);
64
+ else
65
+ return fail(`Hold up! | The specified role "${value}" wasn't found.`);
66
+ }
67
+ ;
68
+ if (resolvedRoles.length < 1)
69
+ return fail(`Hold up! | You didn't specify any valid roles.`);
70
+ // @ts-expect-error
71
+ ok(resolvedRoles);
72
+ }
73
+ ;
74
+ /* Returns an array of channels from the provided string value. */
75
+ export async function channelsOptionValue({ value: values, context }, ok, fail) {
76
+ const guild = await context.guild();
77
+ if (!guild)
78
+ return fail("The guild this command was used in wasn't found.");
79
+ const resolvedChannels = [];
80
+ let channels = (await guild.channels.list());
81
+ channels = channels.filter((ch) => !ch.isThread() && ('name' in ch));
82
+ for (const value of values.split(',').map((value) => value.trim())) {
83
+ let channel;
84
+ const mentionMatch = channelMentionRegex.exec(value)?.[1];
85
+ if (mentionMatch)
86
+ channel = channels.find(({ id }) => mentionMatch === id);
87
+ if (!channel && isValidSnowflake(value))
88
+ channel = channels.find(({ id }) => value === id);
89
+ if (!channel) {
90
+ // @ts-expect-error
91
+ const formattedChannels = channels.map(({ id, name }) => ({ id: id, name: fuzzy.prepare(name) }));
92
+ const match = fuzzy.go(value, formattedChannels, { key: 'name' })[0];
93
+ if (match)
94
+ channel = channels.find(({ id }) => match.obj.id === id);
95
+ }
96
+ ;
97
+ if (channel)
98
+ resolvedChannels.push(channel);
99
+ else
100
+ return fail(`Hold up! | The specified channel "${channel}" wasn't found.`);
101
+ }
102
+ ;
103
+ if (resolvedChannels.length < 1)
104
+ return fail(`Hold up! | You didn't specify any valid channels.`);
105
+ // @ts-expect-error
106
+ ok(resolvedChannels);
107
+ }
108
+ ;
@@ -2,4 +2,8 @@ export declare const trueOrFalse: {
2
2
  name: string;
3
3
  value: string;
4
4
  }[];
5
+ export declare const hexRegex: RegExp;
6
+ export declare const userMentionRegex: RegExp;
7
+ export declare const roleMentionRegex: RegExp;
8
+ export declare const channelMentionRegex: RegExp;
5
9
  //# sourceMappingURL=variables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;GAGvB,CAAC"}
1
+ {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;GAGvB,CAAC;AAGF,eAAO,MAAM,QAAQ,QAA2B,CAAC;AAGjD,eAAO,MAAM,gBAAgB,QAAwB,CAAC;AAGtD,eAAO,MAAM,gBAAgB,QAAyB,CAAC;AAGvD,eAAO,MAAM,mBAAmB,QAAwB,CAAC"}
@@ -3,3 +3,11 @@ export const trueOrFalse = [
3
3
  { name: 'Yes', value: 'true' },
4
4
  { name: 'No', value: 'false' }
5
5
  ];
6
+ /* A regex that matches HEX color codes. */
7
+ export const hexRegex = /^#([0-9A-F]{3}){1,2}$/i;
8
+ /* A regex that matches user mentions. */
9
+ export const userMentionRegex = /<@(?<id>\d{17,20})>/;
10
+ /* A regex that matches role mentions */
11
+ export const roleMentionRegex = /<@&(?<id>\d{17,20})>/;
12
+ /* A regex that matches channel mentions. */
13
+ export const channelMentionRegex = /<#(?<id>\d{17,20})>/;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fallencodes/seyfert-utils",
3
3
  "type": "module",
4
- "version": "1.2.8",
4
+ "version": "1.3.1",
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",
@@ -28,17 +28,21 @@
28
28
  "exports": {
29
29
  ".": "./build/index.js",
30
30
  "./logger": "./build/logger.js",
31
+ "./options": "./build/options.js",
31
32
  "./components/*": "./build/components/*.js",
32
33
  "./handleCommand": "./build/handleCommand.js"
33
34
  },
34
35
  "dependencies": {
35
36
  "@sapphire/snowflake": "^3.5.5",
36
37
  "dayjs": "^1.11.19",
38
+ "fuzzysort": "^3.1.0",
39
+ "ms": "^2.1.3",
37
40
  "multibyte": "^1.0.5",
38
41
  "nanoid": "^5.1.6",
39
42
  "seyfert": "4.0.1-dev-21273098940.0"
40
43
  },
41
44
  "devDependencies": {
45
+ "@types/ms": "^2.1.0",
42
46
  "@types/node": "^25.0.8",
43
47
  "typescript": "^5.9.3"
44
48
  },