rubika 1.2.1 → 1.2.3

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/bot/bot.ts CHANGED
@@ -204,7 +204,7 @@ class Bot extends Methods {
204
204
  prefix,
205
205
  });
206
206
  } else {
207
- throw this.logger.error("Invalid arguments for command()", "warn");
207
+ return this.logger.error("Invalid arguments for command()", "warn");
208
208
  }
209
209
  }
210
210
  }
@@ -14,14 +14,14 @@ async function builder(
14
14
 
15
15
  const response: any = await this.network.request(method, input);
16
16
 
17
- if (response?.status !== "OK") {
18
- throw this.logger.error(
19
- `[builder] error in request ${method}:\n ${JSON.stringify(response, null, 2)}`,
20
- "error",
21
- );
17
+ if (response?.status === "OK") {
18
+ return response.data;
22
19
  }
23
20
 
24
- return response.data;
21
+ this.logger.error(
22
+ `[builder] error in request ${method}:\n ${JSON.stringify(response, null, 2)}`,
23
+ "error",
24
+ );
25
25
  }
26
26
 
27
27
  export default builder;
@@ -67,7 +67,7 @@ async function uploadFile(
67
67
  throw this.logger.error(`HTTP ${res.status}: ${text}`, "warn");
68
68
  }
69
69
 
70
- const response = await res.json();
70
+ const response: any = await res.json();
71
71
 
72
72
  if (response.status !== "OK") {
73
73
  throw this.logger.error(
@@ -38,12 +38,14 @@ async function setupWebhook(
38
38
  },
39
39
  });
40
40
 
41
+ await new Promise((resolve) => setTimeout(resolve, 3000));
42
+
41
43
  // set-endpoints
42
44
  for (const update of updates) {
43
45
  const res = await this.updateBotEndpoints(url, update);
44
46
 
45
47
  if (res.status !== "Done") {
46
- throw this.logger.error(
48
+ this.logger.error(
47
49
  `[setupWebhook] status updateBotEndpoints is ${res.status} for update: ${update}`,
48
50
  "warn",
49
51
  );
package/bot/network.ts CHANGED
@@ -35,7 +35,7 @@ export default class Network {
35
35
  await this.delay(1000);
36
36
  }
37
37
 
38
- throw new Error(
38
+ return new Error(
39
39
  `[request] Failed after ${this.MAX_ATTEMPTS} attempts: ${method}`
40
40
  );
41
41
  }
package/client/client.ts CHANGED
@@ -73,7 +73,7 @@ export default class Client extends Methods {
73
73
  handler: maybeHandler,
74
74
  });
75
75
  } else {
76
- throw new Error("Invalid arguments for on()");
76
+ return new Error("Invalid arguments for on()");
77
77
  }
78
78
  }
79
79
 
@@ -108,7 +108,7 @@ export default class Client extends Methods {
108
108
  prefix,
109
109
  });
110
110
  } else {
111
- throw new Error("Invalid arguments for command()");
111
+ return new Error("Invalid arguments for command()");
112
112
  }
113
113
  }
114
114
  }
@@ -35,7 +35,7 @@ async function getBrowser(
35
35
  let deviceModel = "Unknown";
36
36
 
37
37
  if (!deviceModelMatch) {
38
- throw new Error(`Cannot parse user-agent (${userAgent})`);
38
+ return new Error(`Cannot parse user-agent (${userAgent})`);
39
39
  } else {
40
40
  deviceModel = `${deviceModelMatch[1]} ${deviceModelMatch[2]}`;
41
41
  }
@@ -48,7 +48,7 @@ async function sendMessage(
48
48
  }
49
49
  file_inline = await fs.promises.readFile(fileName);
50
50
  } else if (!Buffer.isBuffer(file_inline)) {
51
- throw this.logger.error(
51
+ return this.logger.error(
52
52
  "File argument must be a file path or bytes",
53
53
  "warn",
54
54
  );
@@ -70,7 +70,7 @@ async function sendMessage(
70
70
  thumb = false;
71
71
  if (audio_info) {
72
72
  if (!optionalMusicMetadata) {
73
- throw new Error(
73
+ return new Error(
74
74
  "music-metadata module is not installed. Some features may be disabled.",
75
75
  );
76
76
  }
@@ -16,7 +16,7 @@ async function start(this: Client): Promise<void> {
16
16
  }
17
17
 
18
18
  try {
19
- if (!this.auth) throw Error("[start] Error auth is not set");
19
+ if (!this.auth) return Error("[start] Error auth is not set");
20
20
  this.key = Buffer.from(Crypto.passphrase(this.auth), "utf8");
21
21
  this.decode_auth = Crypto.decode_auth(this.auth);
22
22
  const result = await this.getUserInfo();
@@ -8,7 +8,7 @@ const ffmpeg = optionalImport<typeof import("fluent-ffmpeg")>("fluent-ffmpeg");
8
8
  class ThumbnailGenerator {
9
9
  static async getTime(videoPath: string): Promise<number> {
10
10
  if (!ffmpeg) {
11
- throw new Error(
11
+ return new Error(
12
12
  "fluent-ffmpeg module is not installed. Some features may be disabled.",
13
13
  );
14
14
  }
@@ -28,7 +28,7 @@ class ThumbnailGenerator {
28
28
 
29
29
  static async fromVideo(videoPath: string): Promise<string> {
30
30
  if (!ffmpeg) {
31
- throw new Error(
31
+ return new Error(
32
32
  "fluent-ffmpeg module is not installed. Some features may be disabled.",
33
33
  );
34
34
  }
@@ -57,7 +57,7 @@ class ThumbnailGenerator {
57
57
  return base64Thumbnail;
58
58
  } catch (error) {
59
59
  console.error("Error generating video thumbnail:", error);
60
- throw error;
60
+ return error;
61
61
  }
62
62
  }
63
63
 
@@ -66,7 +66,7 @@ class ThumbnailGenerator {
66
66
  width: number = 320,
67
67
  ): Promise<string> {
68
68
  if (!sharp) {
69
- throw new Error(
69
+ return new Error(
70
70
  "sharp module is not installed. Some features may be disabled.",
71
71
  );
72
72
  }
@@ -76,7 +76,7 @@ class ThumbnailGenerator {
76
76
  return buffer.toString("base64");
77
77
  } catch (error) {
78
78
  console.error("Error generating image thumbnail:", error);
79
- throw error;
79
+ return error;
80
80
  }
81
81
  }
82
82
  }
@@ -86,7 +86,7 @@ export async function sendRequest(network: Network, url: string, data: any) {
86
86
 
87
87
  await network.delay(1000);
88
88
  }
89
- throw network.client.logger.error(
89
+ return network.client.logger.error(
90
90
  `[request] Failed after ${MAX_ATTEMPTS} attempts: ${url}`,
91
91
  "warn",
92
92
  );
@@ -8,7 +8,7 @@ export async function uploadFile(
8
8
  chunkSize: number = 1048576,
9
9
  ): Promise<any> {
10
10
  if (!fs.existsSync(filePath))
11
- throw new Error("File not found in the given path");
11
+ return new Error("File not found in the given path");
12
12
 
13
13
  const stat = await fs.promises.stat(filePath);
14
14
  const fileSize = stat.size;
@@ -81,7 +81,7 @@ export async function uploadFile(
81
81
  }
82
82
  }
83
83
 
84
- throw new Error("Upload failed completely.");
84
+ return new Error("Upload failed completely.");
85
85
  }
86
86
 
87
87
  export async function download(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubika",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "author": "Hadi Rostami",
5
5
  "main": "index.ts",
6
6
  "description": "A modern library for Rubika built with Bun.",