@elara-services/packages 3.0.3 → 4.0.2

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 CHANGED
@@ -1,3 +1,18 @@
1
+ # v4.0.2
2
+ Added
3
+ - fetch (useful with `@elara-services/fetch`)
4
+
5
+ # v4.0.1
6
+ Added
7
+ - Languages.find
8
+ - Languages.langs
9
+
10
+ # v4.0.0
11
+ __Breaking Change__
12
+ The following functions & methods for `SlashBuilder` was moved to `static`
13
+ > So you no longer need to do `new (require("@elara-services/packages").SlashBuilder)()`
14
+
15
+
1
16
  # v3.0.3
2
17
  Added 'types.context.user', 'types.context.message' and the typings for SlashBuilder
3
18
 
package/index.d.ts CHANGED
@@ -9,7 +9,11 @@ declare module "@elara-services/packages" {
9
9
  public decrypt(encrypted: string): string;
10
10
  }
11
11
 
12
- export const Languages: object;
12
+ export const Languages: {
13
+ find(name: string): string | null;
14
+ langs: object
15
+ }
16
+
13
17
  export class Minesweeper {
14
18
  public constructor(options?: {
15
19
  rows?: number;
@@ -62,8 +66,10 @@ declare module "@elara-services/packages" {
62
66
  }
63
67
 
64
68
  export class SlashBuilder {
65
- public constructor();
66
- public types: {
69
+
70
+ public static TEXT_BASED_CHANNELS: number[];
71
+
72
+ public static types: {
67
73
  sub_command: number,
68
74
  sub_group: number,
69
75
  string: number,
@@ -80,14 +86,14 @@ declare module "@elara-services/packages" {
80
86
  }
81
87
  };
82
88
 
83
- public context: {
89
+ public static context: {
84
90
  user(name: string): Slash;
85
91
  message(name: string): Slash;
86
92
  };
87
93
 
88
- public choice(name: string, value: string|number): { name: string, value: string|number };
89
- public option(data: SlashOptions): Slash;
90
- public create(name: string, description: string, options: Slash): Slash;
94
+ public static choice(name: string, value: string|number): { name: string, value: string|number };
95
+ public static option(data: SlashOptions): Slash;
96
+ public static create(name: string, description: string, options: Slash): Slash;
91
97
  }
92
98
 
93
99
  export type Button = {
@@ -176,4 +182,6 @@ declare module "@elara-services/packages" {
176
182
  separator: string;
177
183
  join: string;
178
184
  }): string | string[]
185
+
186
+ export async function fetch(url: string, key?: string, body?: any, postRequest?: boolean, returnRaw?: boolean): Promise<object|string|null>;
179
187
  }
package/index.js CHANGED
@@ -5,4 +5,5 @@ exports.randomWords = require("./packages/random/words");
5
5
  exports.randomWeight = require("./packages/random/weight");
6
6
  exports.Languages = require("./packages/languages");
7
7
  exports.SlashBuilder = require("./packages/SlashBuilder");
8
- exports.Interactions = require("./packages/Interactions");
8
+ exports.Interactions = require("./packages/Interactions");
9
+ exports.fetch = require("./packages/fetch");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/packages",
3
- "version": "3.0.3",
3
+ "version": "4.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "./index.d.ts",
@@ -1,9 +1,9 @@
1
- module.exports = class SlashBuilder {
2
- constructor() {
3
- this.TEXT_BASED_CHANNELS = [ 0, 5, 11, 12 ];
4
- };
1
+ module.exports = class SlashBuilder extends null {
2
+ static get TEXT_BASED_CHANNELS() {
3
+ return [ 0, 5, 11, 12 ]
4
+ }
5
5
 
6
- get types() {
6
+ static get types() {
7
7
  return {
8
8
  sub_command: 1,
9
9
  sub_group: 2,
@@ -22,22 +22,22 @@ module.exports = class SlashBuilder {
22
22
  };
23
23
  }
24
24
 
25
- get context() {
25
+ static get context() {
26
26
  return {
27
27
  user: (name) => this.create(name, "", { type: 2 }),
28
28
  message: (name) => this.create(name, "", { type: 3 })
29
29
  }
30
30
  };
31
31
 
32
- choice(name, value) {
32
+ static choice(name, value) {
33
33
  return { name, value };
34
34
  };
35
35
 
36
- option(data) {
36
+ static option(data) {
37
37
  return data;
38
38
  };
39
39
 
40
- create(name, description, options = { }) {
40
+ static create(name, description, options = { }) {
41
41
  let obj = { name, description };
42
42
  if (options?.options?.length) obj.options = options.options;
43
43
  if (options.type) obj.type = options.type;
@@ -0,0 +1,27 @@
1
+ let fetch;
2
+
3
+ try {
4
+ fetch = require("@elara-services/fetch");
5
+ } catch {
6
+
7
+ }
8
+
9
+ module.exports = (url, key = "", body = undefined, postRequest = false, returnRaw = false) => {
10
+ if (!fetch) throw new Error(`Unable to find @elara-services/fetch package`);
11
+ try {
12
+ let headers = {
13
+ "User-Agent": `Services v${Math.floor(Math.random() * 999999)}`
14
+ };
15
+ if (key !== "" && key) headers.Authorization = key;
16
+ let res = await fetch(url, postRequest ? "POST" : "GET")
17
+ .header(headers)
18
+ .body(body, "json")
19
+ .send()
20
+ .catch(() => ({ statusCode: 500 }));
21
+ if (res.statusCode !== 200) return null;
22
+ if (returnRaw) return res.body;
23
+ return res.json();
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ const langs = {
2
2
  'en': 'English',
3
3
  'fr': 'French',
4
4
  'es': 'Spanish',
@@ -105,4 +105,15 @@ module.exports = {
105
105
  'yi': 'Yiddish',
106
106
  'yo': 'Yoruba',
107
107
  'zu': 'Zulu'
108
- };
108
+ };
109
+ /** @deprecated */
110
+ module.exports = langs;
111
+ module.exports.langs = langs;
112
+
113
+ module.exports.find = (name) => {
114
+ for (const key of Object.keys(langs)) {
115
+ if (key === name) return key;
116
+ if (langs[key] === name) return key;
117
+ }
118
+ return null;
119
+ }