@fallencodes/seyfert-utils 1.4.2 → 1.5.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.
- package/build/logger.d.ts.map +1 -1
- package/build/logger.js +1 -0
- package/build/options.d.ts +2 -1
- package/build/options.d.ts.map +1 -1
- package/build/options.js +71 -0
- package/package.json +3 -2
package/build/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,UAAU,eAAe,SAkBtC"}
|
package/build/logger.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import { Logger } from 'seyfert';
|
|
3
3
|
import { red, LogLevels, cyan, dim, yellow, bgRed, gray, bold } from 'seyfert/lib/common/index.js';
|
|
4
|
+
/* My custom logger with more compact information. */
|
|
4
5
|
export default function customizeLogger() {
|
|
5
6
|
Logger.customize((_, level, args) => {
|
|
6
7
|
let color = red;
|
package/build/options.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OKFunction, GuildRole, StopFunction, AllGuildChannels, CommandContext, User } from 'seyfert';
|
|
1
|
+
import { OKFunction, GuildRole, StopFunction, AllGuildChannels, CommandContext, User, OnOptionsReturnObject } from 'seyfert';
|
|
2
2
|
interface StringOption {
|
|
3
3
|
value: string;
|
|
4
4
|
context: CommandContext;
|
|
@@ -10,5 +10,6 @@ export declare function relativeTimeOptionValue({ value }: StringOption, ok: OKF
|
|
|
10
10
|
export declare function rolesOptionValue({ value: values, context }: StringOption, ok: OKFunction<[GuildRole, ...GuildRole[]]>, fail: StopFunction): Promise<void>;
|
|
11
11
|
export declare function channelsOptionValue({ value: values, context }: StringOption, ok: OKFunction<[AllGuildChannels, ...AllGuildChannels[]]>, fail: StopFunction): Promise<void>;
|
|
12
12
|
export declare function usersOptionValue({ value: values, context }: StringOption, ok: OKFunction<[User, ...User[]]>, fail: StopFunction): Promise<void>;
|
|
13
|
+
export declare function validateOptions(metadata: OnOptionsReturnObject): Promise<string[]>;
|
|
13
14
|
export {};
|
|
14
15
|
//# sourceMappingURL=options.d.ts.map
|
package/build/options.d.ts.map
CHANGED
|
@@ -1 +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,IAAI,EAAE,MAAM,SAAS,CAAC;
|
|
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,IAAI,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAS7H,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;AAGD,wBAAsB,gBAAgB,CAClC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,YAAY,EACxC,EAAE,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,EACjC,IAAI,EAAE,YAAY,iBAkBrB;AAGD,wBAAsB,eAAe,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAmDxF"}
|
package/build/options.js
CHANGED
|
@@ -3,6 +3,8 @@ import dayjs from 'dayjs';
|
|
|
3
3
|
import ms from 'ms';
|
|
4
4
|
import fuzzy from 'fuzzysort';
|
|
5
5
|
import { channelMentionRegex, hexRegex, roleMentionRegex, userMentionRegex } from './variables.js';
|
|
6
|
+
import { ChannelType } from 'seyfert/lib/types/index.js';
|
|
7
|
+
import { noCase } from 'change-case';
|
|
6
8
|
/* Returns a valid string snowflake value. */
|
|
7
9
|
export const snowflakeOptionValue = ({ value }, ok, fail) => {
|
|
8
10
|
if (isValidSnowflake(value))
|
|
@@ -106,6 +108,7 @@ export async function channelsOptionValue({ value: values, context }, ok, fail)
|
|
|
106
108
|
ok(resolvedChannels);
|
|
107
109
|
}
|
|
108
110
|
;
|
|
111
|
+
/* Returns an array of users from the provided string value. */
|
|
109
112
|
export async function usersOptionValue({ value: values, context }, ok, fail) {
|
|
110
113
|
const resolvedUsers = [];
|
|
111
114
|
for await (const value of values.split(',').map((value) => value.trim())) {
|
|
@@ -127,3 +130,71 @@ export async function usersOptionValue({ value: values, context }, ok, fail) {
|
|
|
127
130
|
ok(resolvedUsers);
|
|
128
131
|
}
|
|
129
132
|
;
|
|
133
|
+
/* Checks the provided options for validation errors and returns user friendly error messages. */
|
|
134
|
+
export async function validateOptions(metadata) {
|
|
135
|
+
const errorMessages = [];
|
|
136
|
+
for (const [option, error] of Object.entries(metadata)) {
|
|
137
|
+
if (!error.failed)
|
|
138
|
+
continue;
|
|
139
|
+
let errorMessage;
|
|
140
|
+
if (error.value.includes('is required but returned no value')) {
|
|
141
|
+
errorMessage = "is required but wasn't provided";
|
|
142
|
+
}
|
|
143
|
+
;
|
|
144
|
+
if (error.value.includes('Unknown Role 10011'))
|
|
145
|
+
errorMessage = "isn't a valid role mention or ID";
|
|
146
|
+
if (error.value.includes('Unknown User 10013'))
|
|
147
|
+
errorMessage = "isn't a valid user mention or ID";
|
|
148
|
+
if (error.value.includes('Unknown Channel 10003'))
|
|
149
|
+
errorMessage = "isn't a valid channel mention or ID";
|
|
150
|
+
const parseError = error.parseError?.[0];
|
|
151
|
+
const parseErrorValue = error.parseError?.[1];
|
|
152
|
+
switch (parseError) {
|
|
153
|
+
case 'NUMBER_NAN':
|
|
154
|
+
errorMessage = `isn't a valid number.`;
|
|
155
|
+
break;
|
|
156
|
+
case 'NUMBER_MAX_VALUE':
|
|
157
|
+
errorMessage = `must be less than or equal to ${parseErrorValue}`;
|
|
158
|
+
break;
|
|
159
|
+
case 'NUMBER_MIN_VALUE':
|
|
160
|
+
errorMessage = `must be greater than or equal to ${parseErrorValue}`;
|
|
161
|
+
break;
|
|
162
|
+
case 'STRING_MAX_LENGTH':
|
|
163
|
+
errorMessage = `must be less than or equal to ${parseErrorValue} characters long`;
|
|
164
|
+
break;
|
|
165
|
+
case 'STRING_MIN_LENGTH':
|
|
166
|
+
errorMessage = `must be greater than or equal to ${parseErrorValue} characters long`;
|
|
167
|
+
break;
|
|
168
|
+
case 'NUMBER_INVALID_CHOICE':
|
|
169
|
+
case 'STRING_INVALID_CHOICE':
|
|
170
|
+
errorMessage = `must be equal to ${listFormat(parseErrorValue)}`;
|
|
171
|
+
break;
|
|
172
|
+
case 'CHANNEL_TYPES':
|
|
173
|
+
errorMessage = `must be a ${channelTypeFormat(parseErrorValue)} channel mention or ID`;
|
|
174
|
+
break;
|
|
175
|
+
case 'UNKNOWN':
|
|
176
|
+
case 'OPTION_REQUIRED':
|
|
177
|
+
errorMessage = `was provided but isn't valid`;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
;
|
|
181
|
+
if (!errorMessage)
|
|
182
|
+
errorMessage = error.value.replace(`${option} `, '');
|
|
183
|
+
errorMessages.push(`The option "${option}" ${errorMessage}.`);
|
|
184
|
+
}
|
|
185
|
+
;
|
|
186
|
+
return errorMessages;
|
|
187
|
+
}
|
|
188
|
+
;
|
|
189
|
+
function listFormat(options) {
|
|
190
|
+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' });
|
|
191
|
+
const mappedOptions = options.map((option) => {
|
|
192
|
+
return typeof option === 'string' ? option.toLowerCase() : option.value.toString().toLowerCase();
|
|
193
|
+
});
|
|
194
|
+
return formatter.format(mappedOptions);
|
|
195
|
+
}
|
|
196
|
+
;
|
|
197
|
+
function channelTypeFormat(types) {
|
|
198
|
+
return listFormat(types.map((type) => noCase(ChannelType[type] ?? '').replace('guild ', '')));
|
|
199
|
+
}
|
|
200
|
+
;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fallencodes/seyfert-utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.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",
|
|
@@ -34,12 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@sapphire/snowflake": "^3.5.5",
|
|
37
|
+
"change-case": "^5.4.4",
|
|
37
38
|
"dayjs": "^1.11.19",
|
|
38
39
|
"fuzzysort": "^3.1.0",
|
|
39
40
|
"ms": "^2.1.3",
|
|
40
41
|
"multibyte": "^1.0.5",
|
|
41
42
|
"nanoid": "^5.1.6",
|
|
42
|
-
"seyfert": "4.1
|
|
43
|
+
"seyfert": "4.2.1"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@types/ms": "^2.1.0",
|