@elara-services/packages 4.5.0 → 4.7.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/CHANGELOG +4 -0
- package/index.d.ts +20 -2
- package/index.js +2 -1
- package/package.json +1 -1
- package/packages/SlashBuilder.js +9 -3
- package/packages/Tasks.js +22 -0
- package/packages/duration.js +2 -2
package/CHANGELOG
CHANGED
package/index.d.ts
CHANGED
@@ -56,6 +56,10 @@ declare module "@elara-services/packages" {
|
|
56
56
|
max_value?: number;
|
57
57
|
choices?: { name: string, value: string }[];
|
58
58
|
options?: SlashOptions[];
|
59
|
+
locale?: {
|
60
|
+
names?: object;
|
61
|
+
descriptions?: object;
|
62
|
+
}
|
59
63
|
}
|
60
64
|
|
61
65
|
export type Slash = {
|
@@ -63,6 +67,10 @@ declare module "@elara-services/packages" {
|
|
63
67
|
defaultPermission?: boolean;
|
64
68
|
default_permission?: boolean;
|
65
69
|
options?: SlashOptions[];
|
70
|
+
locale?: {
|
71
|
+
names?: object;
|
72
|
+
descriptions?: object;
|
73
|
+
}
|
66
74
|
}
|
67
75
|
|
68
76
|
export class SlashBuilder {
|
@@ -87,8 +95,8 @@ declare module "@elara-services/packages" {
|
|
87
95
|
};
|
88
96
|
|
89
97
|
public static context: {
|
90
|
-
user(name: string): Slash;
|
91
|
-
message(name: string): Slash;
|
98
|
+
user(name: string, locale?: { names?: object }): Slash;
|
99
|
+
message(name: string, locale?: { names?: object }): Slash;
|
92
100
|
};
|
93
101
|
|
94
102
|
public static choice(name: string, value: string|number): { name: string, value: string|number };
|
@@ -191,5 +199,15 @@ declare module "@elara-services/packages" {
|
|
191
199
|
static validate(value: string): boolean;
|
192
200
|
static parse(value: string): number | null;
|
193
201
|
static determineTimeType(str: string): number;
|
202
|
+
};
|
203
|
+
|
204
|
+
export class Tasks extends null {
|
205
|
+
static create(options: {
|
206
|
+
id: string;
|
207
|
+
time: string;
|
208
|
+
shouldCancel?: boolean
|
209
|
+
}, run: Function): void;
|
210
|
+
|
211
|
+
static delete(id: string): void;
|
194
212
|
}
|
195
213
|
}
|
package/index.js
CHANGED
@@ -7,4 +7,5 @@ exports.Languages = require("./packages/languages");
|
|
7
7
|
exports.SlashBuilder = require("./packages/SlashBuilder");
|
8
8
|
exports.Interactions = require("./packages/Interactions");
|
9
9
|
exports.fetch = require("./packages/fetch");
|
10
|
-
exports.Duration = require("./packages/duration");
|
10
|
+
exports.Duration = require("./packages/duration");
|
11
|
+
exports.Tasks = require("./packages/Tasks");
|
package/package.json
CHANGED
package/packages/SlashBuilder.js
CHANGED
@@ -24,8 +24,8 @@ module.exports = class SlashBuilder extends null {
|
|
24
24
|
|
25
25
|
static get context() {
|
26
26
|
return {
|
27
|
-
user: (name) => this.create(name, "", { type: 2 }),
|
28
|
-
message: (name) => this.create(name, "", { type: 3 })
|
27
|
+
user: (name, locale) => this.create(name, "", { type: 2, locale }),
|
28
|
+
message: (name, locale) => this.create(name, "", { type: 3, locale })
|
29
29
|
}
|
30
30
|
};
|
31
31
|
|
@@ -34,11 +34,17 @@ module.exports = class SlashBuilder extends null {
|
|
34
34
|
};
|
35
35
|
|
36
36
|
static option(data) {
|
37
|
-
|
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;
|
38
42
|
};
|
39
43
|
|
40
44
|
static create(name, description, options = { }) {
|
41
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;
|
42
48
|
if (options?.options?.length) obj.options = options.options;
|
43
49
|
if (options.type) obj.type = options.type;
|
44
50
|
if (typeof options.defaultPermission === "boolean") obj.default_permission = options.defaultPermission;
|
@@ -0,0 +1,22 @@
|
|
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/duration.js
CHANGED
@@ -9,7 +9,7 @@ module.exports = class Duration extends null {
|
|
9
9
|
dur.match(/[A-Za-z]+/g)[0]
|
10
10
|
];
|
11
11
|
if (isNaN(num)) totalTime = 0;
|
12
|
-
else totalTime += num *
|
12
|
+
else totalTime += num * module.exports.determineTimeType(str);
|
13
13
|
}
|
14
14
|
if (totalTime) return totalTime;
|
15
15
|
}
|
@@ -50,7 +50,7 @@ module.exports = class Duration extends null {
|
|
50
50
|
if (!num || (num.length !== 1)) return false;
|
51
51
|
if (!str || (str.length !== 1)) return false;
|
52
52
|
if (!Number.isInteger(parseInt(num[0]))) return false;
|
53
|
-
if (!
|
53
|
+
if (!module.exports.timeIds.has(str[0])) return false;
|
54
54
|
}
|
55
55
|
|
56
56
|
return true;
|