@elara-services/packages 5.3.1 → 6.0.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/dist/package.json +44 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/interfaces/discord.d.ts +91 -0
- package/dist/src/interfaces/discord.js +2 -0
- package/dist/src/interfaces/index.d.ts +1 -0
- package/dist/src/interfaces/index.js +17 -0
- package/dist/src/lib/AES.d.ts +7 -0
- package/dist/src/lib/AES.js +71 -0
- package/dist/src/lib/discord.d.ts +136 -0
- package/dist/src/lib/discord.js +336 -0
- package/dist/src/lib/index.d.ts +8 -0
- package/dist/src/lib/index.js +24 -0
- package/dist/src/lib/languages.d.ts +110 -0
- package/{packages → dist/src/lib}/languages.js +123 -119
- package/dist/src/lib/minesweeper.d.ts +20 -0
- package/{packages → dist/src/lib}/minesweeper.js +67 -77
- package/dist/src/lib/misc.d.ts +1 -0
- package/dist/src/lib/misc.js +72 -0
- package/dist/src/lib/random.d.ts +16 -0
- package/dist/src/lib/random.js +326 -0
- package/dist/src/lib/tasks.d.ts +9 -0
- package/dist/src/lib/tasks.js +68 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AES.html +145 -0
- package/docs/classes/Minesweeper.html +206 -0
- package/docs/classes/Tasks.html +142 -0
- package/docs/functions/fetch.html +90 -0
- package/docs/functions/find.html +75 -0
- package/docs/functions/randomWeight.html +80 -0
- package/docs/functions/randomWords.html +75 -0
- package/docs/index.html +164 -0
- package/docs/interfaces/ButtonOptions.html +155 -0
- package/docs/interfaces/ModalOptions.html +125 -0
- package/docs/interfaces/RandomWord.html +154 -0
- package/docs/interfaces/SelectOptions.html +160 -0
- package/docs/interfaces/Slash.html +139 -0
- package/docs/interfaces/SlashOptions.html +188 -0
- package/docs/interfaces/TaskCreate.html +104 -0
- package/docs/interfaces/TextInputOptions.html +181 -0
- package/docs/modules.html +103 -0
- package/docs/types/ButtonNumberStyles.html +66 -0
- package/docs/types/ButtonStyles.html +66 -0
- package/docs/types/ChannelTypes.html +66 -0
- package/docs/types/Lang.html +66 -0
- package/docs/types/LangName.html +66 -0
- package/docs/variables/ButtonStyle.html +89 -0
- package/docs/variables/Duration.html +110 -0
- package/docs/variables/Interactions.html +160 -0
- package/docs/variables/SlashBuilder.html +239 -0
- package/docs/variables/langs.html +279 -0
- package/package.json +44 -10
- package/.github/renovate.json +0 -5
- package/CHANGELOG +0 -62
- package/index.d.ts +0 -247
- package/index.js +0 -11
- package/packages/Interactions.js +0 -76
- package/packages/SlashBuilder.js +0 -58
- package/packages/Tasks.js +0 -22
- package/packages/aes256.js +0 -62
- package/packages/duration.js +0 -74
- package/packages/fetch.js +0 -30
- package/packages/random/weight.js +0 -8
- package/packages/random/words.js +0 -300
package/index.d.ts
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
declare module "@elara-services/packages" {
|
2
|
-
type array = string[];
|
3
|
-
|
4
|
-
export class AES {
|
5
|
-
public constructor(key: string);
|
6
|
-
private key: string;
|
7
|
-
private header: string;
|
8
|
-
public encrypt(input: string): string
|
9
|
-
public decrypt(encrypted: string): string;
|
10
|
-
}
|
11
|
-
|
12
|
-
export const Languages: {
|
13
|
-
find(name: string): string | null;
|
14
|
-
langs: object
|
15
|
-
}
|
16
|
-
|
17
|
-
export class Minesweeper {
|
18
|
-
public constructor(options?: {
|
19
|
-
rows?: number;
|
20
|
-
columns?: number;
|
21
|
-
mines?: number;
|
22
|
-
emote?: string
|
23
|
-
});
|
24
|
-
|
25
|
-
public rows: number;
|
26
|
-
public columns: number;
|
27
|
-
public mines: number;
|
28
|
-
public matrix: array;
|
29
|
-
public types: {
|
30
|
-
mine: string;
|
31
|
-
numbers: array
|
32
|
-
};
|
33
|
-
|
34
|
-
public generateEmptyMatrix(): void;
|
35
|
-
public plantMines(): void;
|
36
|
-
public getNumberOfMines(x: number, y: number): string;
|
37
|
-
public start(): string | array[] | null;
|
38
|
-
}
|
39
|
-
|
40
|
-
export class Interactions extends null {
|
41
|
-
public static button(options: ButtonOptions): Button;
|
42
|
-
public static select(options: SelectOptions): Select;
|
43
|
-
public static modal(options: ModalOptions): Modal;
|
44
|
-
public static textInput(options: TextInputOptions, row?: boolean): TextInput | { type: number, components: [ TextInput ] };
|
45
|
-
}
|
46
|
-
|
47
|
-
export type ChannelTypes = 'GUILD_TEXT' | 'DM' | 'GUILD_VOICE' | 'GROUP_DM' | 'GUILD_CATEGORY' | 'GUILD_NEWS' | 'GUILD_STORE' | 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD' | 'GUILD_STAGE_VOICE';
|
48
|
-
|
49
|
-
export type TextInputOptions = {
|
50
|
-
id?: string;
|
51
|
-
type?: number;
|
52
|
-
title?: string;
|
53
|
-
style?: number;
|
54
|
-
min?: number;
|
55
|
-
max?: number;
|
56
|
-
holder?: string;
|
57
|
-
} & TextInput;
|
58
|
-
|
59
|
-
export type TextInput = {
|
60
|
-
custom_id?: string;
|
61
|
-
type?: number;
|
62
|
-
label?: string;
|
63
|
-
style?: number;
|
64
|
-
min_length?: number;
|
65
|
-
max_length?: number;
|
66
|
-
placeholder?: string;
|
67
|
-
value?: string;
|
68
|
-
required?: boolean;
|
69
|
-
}
|
70
|
-
|
71
|
-
export type SlashOptions = {
|
72
|
-
type: number;
|
73
|
-
name: string;
|
74
|
-
description: string;
|
75
|
-
required?: boolean;
|
76
|
-
channel_types?: ChannelTypes[];
|
77
|
-
autocomplete?: boolean;
|
78
|
-
min_value?: number;
|
79
|
-
max_value?: number;
|
80
|
-
min_length?: number;
|
81
|
-
max_length?: number;
|
82
|
-
choices?: { name: string, value: string }[];
|
83
|
-
options?: SlashOptions[];
|
84
|
-
locale?: {
|
85
|
-
names?: object;
|
86
|
-
descriptions?: object;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
export type Slash = {
|
91
|
-
type?: number;
|
92
|
-
|
93
|
-
dmPermission?: boolean;
|
94
|
-
dm_permission?: boolean;
|
95
|
-
|
96
|
-
defaultMemberPermissions?: string;
|
97
|
-
default_member_permissions?: string;
|
98
|
-
|
99
|
-
options?: SlashOptions[];
|
100
|
-
locale?: {
|
101
|
-
names?: object;
|
102
|
-
descriptions?: object;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
export class SlashBuilder {
|
107
|
-
|
108
|
-
public static TEXT_BASED_CHANNELS: number[];
|
109
|
-
|
110
|
-
public static types: {
|
111
|
-
sub_command: number,
|
112
|
-
sub_group: number,
|
113
|
-
string: number,
|
114
|
-
integer: number,
|
115
|
-
boolean: number,
|
116
|
-
user: number,
|
117
|
-
channel: number,
|
118
|
-
role: number,
|
119
|
-
mentionable: number,
|
120
|
-
number: number,
|
121
|
-
context: {
|
122
|
-
user: number;
|
123
|
-
message: number;
|
124
|
-
}
|
125
|
-
};
|
126
|
-
|
127
|
-
public static context: {
|
128
|
-
user(name: string, options?: Omit<Slash, "options"|"type">): Slash;
|
129
|
-
message(name: string, options?: Omit<Slash, "options"|"type">): Slash;
|
130
|
-
};
|
131
|
-
|
132
|
-
public static choice(name: string, value: string|number, name_localizations?: object): { name: string, value: string|number, name_localizations: object };
|
133
|
-
public static option(data: SlashOptions): Slash;
|
134
|
-
public static create(name: string, description: string, options: Slash): Slash;
|
135
|
-
}
|
136
|
-
|
137
|
-
export type Button = {
|
138
|
-
custom_id?: string;
|
139
|
-
label?: string;
|
140
|
-
type?: number;
|
141
|
-
style?: number;
|
142
|
-
disabled?: boolean;
|
143
|
-
emoji?: { name?: string, id?: string, animated?: boolean };
|
144
|
-
url?: string
|
145
|
-
}
|
146
|
-
|
147
|
-
export type ButtonOptions = {
|
148
|
-
id?: Button['custom_id'];
|
149
|
-
title?: Button['label'];
|
150
|
-
label?: Button['label'];
|
151
|
-
custom_id?: Button['custom_id'];
|
152
|
-
type?: Button['type'];
|
153
|
-
style?: ButtonStyles | Button['style'];
|
154
|
-
disabled?: Button['disabled'];
|
155
|
-
emoji?: Button['emoji'];
|
156
|
-
url?: Button['url']
|
157
|
-
}
|
158
|
-
|
159
|
-
export type ButtonStyles = 'PRIMARY' | 'BLURPLE' | 'SECONDARY' | 'GREY' | 'SUCCESS' | 'GREEN' | 'DANGER' | 'RED' | 'LINK' | 'URL'
|
160
|
-
|
161
|
-
export type Select = {
|
162
|
-
custom_id: string;
|
163
|
-
placeholder: string;
|
164
|
-
min_values: number;
|
165
|
-
max_values: number;
|
166
|
-
type: number;
|
167
|
-
disabled: boolean;
|
168
|
-
options: {
|
169
|
-
label: string;
|
170
|
-
value: string;
|
171
|
-
description?: string;
|
172
|
-
emoji?: Button['emoji'],
|
173
|
-
default?: boolean;
|
174
|
-
}[]
|
175
|
-
}
|
176
|
-
|
177
|
-
export type SelectOptions = {
|
178
|
-
id?: Select['custom_id'];
|
179
|
-
custom_id?: Select['custom_id'];
|
180
|
-
holder?: Select['placeholder'];
|
181
|
-
min?: Select['min_values'];
|
182
|
-
max?: Select['max_values'];
|
183
|
-
type?: Select['type'];
|
184
|
-
options: Select['options'];
|
185
|
-
disabled?: Select['disabled'];
|
186
|
-
}
|
187
|
-
|
188
|
-
export type Modal = {
|
189
|
-
title: string;
|
190
|
-
custom_id: string;
|
191
|
-
components: {
|
192
|
-
type: number,
|
193
|
-
components: {
|
194
|
-
type: number;
|
195
|
-
custom_id: string;
|
196
|
-
label: string;
|
197
|
-
style: 1 | 2 | number;
|
198
|
-
min_length?: number;
|
199
|
-
max_length?: number;
|
200
|
-
required?: boolean;
|
201
|
-
value?: string;
|
202
|
-
placeholder?: string;
|
203
|
-
}[]
|
204
|
-
}[]
|
205
|
-
}
|
206
|
-
|
207
|
-
export type ModalOptions = {
|
208
|
-
id?: Modal['custom_id'];
|
209
|
-
custom_id?: Modal['custom_id'];
|
210
|
-
title?: Modal['title'];
|
211
|
-
label?: Modal['title'];
|
212
|
-
components: Modal['components']
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
export function randomWeight(objects: object[]): object
|
217
|
-
export function randomWords(options?: {
|
218
|
-
exactly?: boolean;
|
219
|
-
maxLength?: number;
|
220
|
-
min?: number;
|
221
|
-
max?: number;
|
222
|
-
wordsPerString?: number;
|
223
|
-
formatter(word: string): void;
|
224
|
-
separator: string;
|
225
|
-
join: string;
|
226
|
-
}): string | string[]
|
227
|
-
|
228
|
-
export async function fetch(url: string, key?: string, body?: any, postRequest?: boolean, returnRaw?: boolean): Promise<object|string|null>;
|
229
|
-
|
230
|
-
|
231
|
-
export class Duration extends null {
|
232
|
-
static get timeIds(): Set<string>;
|
233
|
-
static validate(value: string): boolean;
|
234
|
-
static parse(value: string): number | null;
|
235
|
-
static determineTimeType(str: string): number;
|
236
|
-
};
|
237
|
-
|
238
|
-
export class Tasks extends null {
|
239
|
-
static create(options: {
|
240
|
-
id: string;
|
241
|
-
time: string;
|
242
|
-
shouldCancel?: boolean
|
243
|
-
}, run: Function): void;
|
244
|
-
|
245
|
-
static delete(id: string): void;
|
246
|
-
}
|
247
|
-
}
|
package/index.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
|
2
|
-
exports.AES = require("./packages/aes256");
|
3
|
-
exports.Minesweeper = require("./packages/minesweeper");
|
4
|
-
exports.randomWords = require("./packages/random/words");
|
5
|
-
exports.randomWeight = require("./packages/random/weight");
|
6
|
-
exports.Languages = require("./packages/languages");
|
7
|
-
exports.SlashBuilder = require("./packages/SlashBuilder");
|
8
|
-
exports.Interactions = require("./packages/Interactions");
|
9
|
-
exports.fetch = require("./packages/fetch");
|
10
|
-
exports.Duration = require("./packages/duration");
|
11
|
-
exports.Tasks = require("./packages/Tasks");
|
package/packages/Interactions.js
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
module.exports = class Interactions extends null {
|
2
|
-
static button(options = {}) {
|
3
|
-
if (typeof options.style === "string") {
|
4
|
-
let styles = { PRIMARY: 1, BLURPLE: 1, SECONDARY: 2, GREY: 2, SUCCESS: 3, GREEN: 3, DANGER: 4, RED: 4, LINK: 5, URL: 5 };
|
5
|
-
let style = styles[options.style?.toUpperCase()];
|
6
|
-
if (!style) options.style = 2;
|
7
|
-
else options.style = style;
|
8
|
-
};
|
9
|
-
if (typeof options.url === "string" && options.url.match(/(https?|discord):\/\//gi)) {
|
10
|
-
options.style = 5;
|
11
|
-
options.id = "";
|
12
|
-
}
|
13
|
-
return {
|
14
|
-
custom_id: options?.id ?? options?.custom_id ?? "",
|
15
|
-
label: options?.title ?? options?.label ?? "",
|
16
|
-
type: options?.type ?? 2,
|
17
|
-
style: options?.style ? options.style : 2,
|
18
|
-
disabled: Boolean(options.disabled),
|
19
|
-
emoji: options?.emoji ?? undefined,
|
20
|
-
url: options?.url ?? undefined
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
|
-
static select(options = {}) {
|
25
|
-
if (!options.options || !Array.isArray(options.options)) throw new Error(`[Dropdown#options]: isn't an array.`);
|
26
|
-
return {
|
27
|
-
custom_id: options?.id ?? options?.custom_id ?? "",
|
28
|
-
placeholder: options?.holder ?? "",
|
29
|
-
min_values: options?.min ?? 1,
|
30
|
-
max_values: options?.max ?? 1,
|
31
|
-
options: options?.options,
|
32
|
-
type: options?.type ?? 3,
|
33
|
-
disabled: typeof options?.disabled === "boolean" ? options.disabled : false
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
static modal(options = {}) {
|
38
|
-
if (!options.components || !Array.isArray(options.components)) throw new Error(`[Modal#components]: isn't an array!`);
|
39
|
-
return {
|
40
|
-
custom_id: options?.id ?? options?.custom_id,
|
41
|
-
title: options?.title ?? options?.label,
|
42
|
-
components: options.components
|
43
|
-
};
|
44
|
-
};
|
45
|
-
|
46
|
-
static textInput(options = {}, row = false) {
|
47
|
-
let data = {};
|
48
|
-
|
49
|
-
if (options.type) data.type = options.type;
|
50
|
-
else data.type = 4;
|
51
|
-
|
52
|
-
if (options.id) data.custom_id = options.id;
|
53
|
-
else if (options.custom_id) data.custom_id = options.custom_id;
|
54
|
-
|
55
|
-
if (options.label) data.label = options.label;
|
56
|
-
else if (options.title) data.label = options.title;
|
57
|
-
|
58
|
-
if (options.style) data.style = options.style;
|
59
|
-
else data.style = 1;
|
60
|
-
|
61
|
-
if (options.min) data.min_length = options.min;
|
62
|
-
else if (options.min_length) data.min_length = options.min_length;
|
63
|
-
|
64
|
-
if (options.max) data.max_length = options.max;
|
65
|
-
else if (options.max_length) data.max_length = options.max_length;
|
66
|
-
|
67
|
-
if (options.holder) data.placeholder = options.holder;
|
68
|
-
else if (options.placeholder) data.placeholder = options.placeholder;
|
69
|
-
|
70
|
-
if (typeof options.required === "boolean") data.required = options.required;
|
71
|
-
if (options.value) data.value = options.value;
|
72
|
-
|
73
|
-
if (row) return data;
|
74
|
-
return { type: 1, components: [ data ] };
|
75
|
-
};
|
76
|
-
};
|
package/packages/SlashBuilder.js
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module.exports = class SlashBuilder extends null {
|
2
|
-
static get TEXT_BASED_CHANNELS() {
|
3
|
-
return [ 0, 5, 11, 12 ]
|
4
|
-
}
|
5
|
-
|
6
|
-
static get types() {
|
7
|
-
return {
|
8
|
-
sub_command: 1,
|
9
|
-
sub_group: 2,
|
10
|
-
string: 3,
|
11
|
-
integer: 4,
|
12
|
-
boolean: 5,
|
13
|
-
user: 6,
|
14
|
-
channel: 7,
|
15
|
-
role: 8,
|
16
|
-
mentionable: 9,
|
17
|
-
number: 10,
|
18
|
-
context: {
|
19
|
-
user: 2,
|
20
|
-
message: 3
|
21
|
-
}
|
22
|
-
};
|
23
|
-
}
|
24
|
-
|
25
|
-
static get context() {
|
26
|
-
return {
|
27
|
-
user: (name, options) => this.create(name, "", { type: this.types.context.user, ...options }),
|
28
|
-
message: (name, options) => this.create(name, "", { type: this.types.context.message, ...options })
|
29
|
-
}
|
30
|
-
};
|
31
|
-
|
32
|
-
static choice(name, value, name_localizations) {
|
33
|
-
return { name, value, name_localizations };
|
34
|
-
};
|
35
|
-
|
36
|
-
static option(data) {
|
37
|
-
let _data = { ...data };
|
38
|
-
if (_data.locale?.names) _data.name_localizations = _data.locale.names;
|
39
|
-
if (_data.locale?.descriptions) _data.description_localizations = _data.locale.descriptions;
|
40
|
-
if ("locale" in _data) delete _data["locale"];
|
41
|
-
return _data;
|
42
|
-
};
|
43
|
-
|
44
|
-
static create(name, description, options = { }) {
|
45
|
-
let obj = { name, description };
|
46
|
-
if (options?.locale?.names) obj.name_localizations = options.locale.names;
|
47
|
-
if (options?.locale?.descriptions) obj.description_localizations = options.locale.descriptions;
|
48
|
-
if (options?.options?.length) obj.options = options.options;
|
49
|
-
if (options?.type) obj.type = options.type;
|
50
|
-
|
51
|
-
if ("dmPermission" in options) obj.dm_permission = options.dmPermission;
|
52
|
-
else if ("dm_permission" in options) obj.dm_permission = options.dm_permission;
|
53
|
-
|
54
|
-
if ("default_member_permissions" in options) obj.default_member_permissions = options.default_member_permissions;
|
55
|
-
else if ("defaultMemberPermissions" in options) obj.default_member_permissions = options.defaultMemberPermissions;
|
56
|
-
return obj;
|
57
|
-
};
|
58
|
-
};
|
package/packages/Tasks.js
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
let nodeSchedule;
|
2
|
-
|
3
|
-
try {
|
4
|
-
nodeSchedule = require("node-schedule");
|
5
|
-
} catch { };
|
6
|
-
|
7
|
-
module.exports = class Tasks extends null {
|
8
|
-
static create({ id = "", time = "", shouldCancel = true } = {}, run) {
|
9
|
-
if (!nodeSchedule) return `[Tasks:Create:ERROR]: I was unable to locate the 'node-schedule' package!`;
|
10
|
-
if (!id || !time || !run) return `[Tasks:Create:ERROR]: You didn't provide a valid ID, Time or Run function`;
|
11
|
-
if (nodeSchedule.scheduledJobs[id]) return `[Tasks:Create:ERROR]: Found (${id}) already in the scheduledJobs object.`;
|
12
|
-
return nodeSchedule.scheduleJob(id, time, () => {
|
13
|
-
run();
|
14
|
-
if (shouldCancel) return nodeSchedule.cancelJob(id);
|
15
|
-
});
|
16
|
-
};
|
17
|
-
|
18
|
-
static delete(id) {
|
19
|
-
if (!nodeSchedule) return null;
|
20
|
-
return nodeSchedule.cancelJob(id);
|
21
|
-
};
|
22
|
-
};
|
package/packages/aes256.js
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
const crypto = require("node:crypto"),
|
2
|
-
CIPHER_ALGORITHM = 'aes-256-ctr';
|
3
|
-
|
4
|
-
module.exports = class AES256 {
|
5
|
-
constructor(key) {
|
6
|
-
if (!key || typeof key !== "string") throw new Error(`${this.header} 'key' is invalid or not a string.`);
|
7
|
-
/** @private */
|
8
|
-
this.key = key;
|
9
|
-
};
|
10
|
-
/** @private */
|
11
|
-
get header() {
|
12
|
-
return `[SECURITY]:`;
|
13
|
-
};
|
14
|
-
|
15
|
-
encrypt(input) {
|
16
|
-
let isString = typeof input === 'string',
|
17
|
-
isBuffer = Buffer.isBuffer(input);
|
18
|
-
if (!(isString || isBuffer) || (isString && !input) || (isBuffer && !Buffer.byteLength(input))) {
|
19
|
-
throw new Error(`${this.header} Provided invalid 'input', must be a non-empty string or buffer.`);
|
20
|
-
};
|
21
|
-
|
22
|
-
let sha = crypto.createHash("sha256");
|
23
|
-
sha.update(this.key);
|
24
|
-
|
25
|
-
let iv = crypto.randomBytes(16),
|
26
|
-
cipher = crypto.createCipheriv(CIPHER_ALGORITHM, sha.digest(), iv),
|
27
|
-
buffer = input;
|
28
|
-
|
29
|
-
if (isString) buffer = Buffer.from(input);
|
30
|
-
let text = cipher.update(buffer),
|
31
|
-
encrypted = Buffer.concat([ iv, text, cipher.final() ]);
|
32
|
-
|
33
|
-
if (isString) encrypted = encrypted.toString('base64');
|
34
|
-
return encrypted;
|
35
|
-
};
|
36
|
-
|
37
|
-
decrypt(encrypted) {
|
38
|
-
let [ isString, isBuffer ] = [
|
39
|
-
typeof encrypted === 'string',
|
40
|
-
Buffer.isBuffer(encrypted)
|
41
|
-
];
|
42
|
-
if (!(isString || isBuffer) || (isString && !encrypted) || (isBuffer && !Buffer.byteLength(encrypted))) throw new Error(`${this.header} Provided "encrypted" must be a non-empty string or buffer`);
|
43
|
-
let sha256 = crypto.createHash('sha256');
|
44
|
-
sha256.update(this.key);
|
45
|
-
|
46
|
-
let input = encrypted;
|
47
|
-
if (isString) {
|
48
|
-
input = Buffer.from(encrypted, 'base64');
|
49
|
-
if (input.length < 17) throw new Error(`${this.header} Provided "encrypted" must decrypt to a non-empty string or buffer`);
|
50
|
-
} else {
|
51
|
-
if (Buffer.byteLength(encrypted) < 17) throw new Error(`${this.header} Provided "encrypted" must decrypt to a non-empty string or buffer`);
|
52
|
-
}
|
53
|
-
|
54
|
-
let iv = input.slice(0, 16),
|
55
|
-
decipher = crypto.createDecipheriv(CIPHER_ALGORITHM, sha256.digest(), iv),
|
56
|
-
ciphertext = input.slice(16),
|
57
|
-
output;
|
58
|
-
if (isString) output = decipher.update(ciphertext) + decipher.final();
|
59
|
-
else output = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
60
|
-
return output;
|
61
|
-
};
|
62
|
-
};
|
package/packages/duration.js
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
module.exports = class Duration extends null {
|
2
|
-
static parse(value) {
|
3
|
-
const MATCHES_ALL = value.match(/\d+\s*[A-Za-z]+/g);
|
4
|
-
if (MATCHES_ALL) {
|
5
|
-
let totalTime = 0;
|
6
|
-
for (const dur of MATCHES_ALL) {
|
7
|
-
const [ num, str ] = [
|
8
|
-
parseInt(dur.match(/\d+/g)[0]),
|
9
|
-
dur.match(/[A-Za-z]+/g)[0]
|
10
|
-
];
|
11
|
-
if (isNaN(num)) totalTime = 0;
|
12
|
-
else totalTime += num * module.exports.determineTimeType(str);
|
13
|
-
}
|
14
|
-
if (totalTime) return totalTime;
|
15
|
-
}
|
16
|
-
|
17
|
-
return null;
|
18
|
-
};
|
19
|
-
|
20
|
-
static determineTimeType(str) {
|
21
|
-
switch (str) {
|
22
|
-
case "ms": case "millisecond": case "milliseconds": return 1;
|
23
|
-
|
24
|
-
case "s": case "second": case "seconds": return 1000;
|
25
|
-
|
26
|
-
case "m": case "min": case "mins": case "minute": case "minutes": return 60 * 1000;
|
27
|
-
|
28
|
-
case "h": case "hr": case "hour": case "hours": return 60 * 60 * 1000;
|
29
|
-
|
30
|
-
case "d": case "day": case "days": return 24 * 60 * 60 * 1000;
|
31
|
-
|
32
|
-
case "w": case "week": case "weeks": return 7 * 24 * 60 * 60 * 1000;
|
33
|
-
|
34
|
-
case "mo": case "month": case "months": return 30 * 24 * 60 * 60 * 1000;
|
35
|
-
|
36
|
-
case "y": case "year": case "years": return 365 * 24 * 60 * 60 * 1000;
|
37
|
-
|
38
|
-
default: return 1;
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
static validate(value) {
|
43
|
-
const MATCHES_ALL = value.match(/\d+\s*[A-Za-z]+/g);
|
44
|
-
if (MATCHES_ALL) {
|
45
|
-
for (const match of MATCHES_ALL) {
|
46
|
-
let [ num, str ] = [
|
47
|
-
match.match(/\d+/g),
|
48
|
-
match.match(/[A-Za-z]+/g)
|
49
|
-
]
|
50
|
-
if (!num || (num.length !== 1)) return false;
|
51
|
-
if (!str || (str.length !== 1)) return false;
|
52
|
-
if (!Number.isInteger(parseInt(num[0]))) return false;
|
53
|
-
if (!module.exports.timeIds.has(str[0])) return false;
|
54
|
-
}
|
55
|
-
|
56
|
-
return true;
|
57
|
-
}
|
58
|
-
|
59
|
-
return false;
|
60
|
-
}
|
61
|
-
|
62
|
-
static get timeIds() {
|
63
|
-
return new Set([
|
64
|
-
"ms", "millisecond", "milliseconds",
|
65
|
-
"s", "second", "seconds",
|
66
|
-
"m", "min", "mins", "minute", "minutes",
|
67
|
-
"h", "hr", "hrs", "hour", "hours",
|
68
|
-
"d", "day", "days",
|
69
|
-
"w", "week", "weeks",
|
70
|
-
"mo", "month", "months",
|
71
|
-
"y", "year", "years"
|
72
|
-
])
|
73
|
-
}
|
74
|
-
}
|
package/packages/fetch.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
let fetch;
|
2
|
-
|
3
|
-
try {
|
4
|
-
fetch = require("@elara-services/fetch");
|
5
|
-
if ("fetch" in fetch) {
|
6
|
-
fetch = fetch.fetch;
|
7
|
-
}
|
8
|
-
} catch {
|
9
|
-
|
10
|
-
}
|
11
|
-
|
12
|
-
module.exports = async (url, key = "", body = undefined, postRequest = false, returnRaw = false) => {
|
13
|
-
if (!fetch) throw new Error(`Unable to find @elara-services/fetch package`);
|
14
|
-
try {
|
15
|
-
let headers = {
|
16
|
-
"User-Agent": `Services v${Math.floor(Math.random() * 999999)}`
|
17
|
-
};
|
18
|
-
if (key !== "" && key) headers.Authorization = key;
|
19
|
-
let res = await fetch(url, postRequest ? "POST" : "GET")
|
20
|
-
.header(headers)
|
21
|
-
.body(body, "json")
|
22
|
-
.send()
|
23
|
-
.catch(() => ({ statusCode: 500 }));
|
24
|
-
if (res.statusCode !== 200) return null;
|
25
|
-
if (returnRaw) return res.body;
|
26
|
-
return res.json();
|
27
|
-
} catch {
|
28
|
-
return null;
|
29
|
-
}
|
30
|
-
}
|