rubika 1.2.0 → 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/README.md CHANGED
@@ -44,50 +44,37 @@ bot.on("error", async (err) => {
44
44
 
45
45
  bot.run();
46
46
  ```
47
+
47
48
  ## › نمونه کد ساده سلف (self)
48
49
 
49
50
  ```ts
50
- import Client, { Filters } from "rubika/client";
51
-
51
+ import Client from "rubika/bot";
52
52
 
53
- const client = new Client("rubika");
54
-
55
- client.command("/start", async (ctx) => {
56
- await ctx.reply("🤖 ربات استارت شد");
57
- });
53
+ const shad_client = new Client("shad", "Shad");
54
+ const rubika_client = new Client("rubika", "Rubika");
58
55
 
59
- client.on("message", [Filters.isText], async (ctx) => {
60
- await ctx.reply("سلام 😎");
61
- });
56
+ // Shad
57
+ shad_client.on("message", async (ctx) => console.log(ctx));
58
+ shad_client.on("error", async (err) => console.log(err));
62
59
 
63
- client.on("activities", async (ctx) => {
64
- console.log(ctx);
65
- });
66
-
67
- client.on("chat", async (ctx) => {
68
- console.log(ctx);
69
- });
70
-
71
- client.on("notifications", async (ctx) => {
72
- console.log(ctx);
73
- });
74
-
75
- client.on("error", async (err) => {
76
- await err.client.sendMessage("CHAT_ID", err.message);
77
- console.log(err.message);
78
- });
60
+ // Rubika
61
+ rubika_client.on("message", async (ctx) => console.log(ctx));
62
+ rubika_client.on("error", async (err) => console.log(err));
79
63
 
80
- client.run();
64
+ // start (self)-bots
65
+ shad_client.run();
66
+ rubika_client.run();
81
67
  ```
82
68
 
83
69
  ## › ویژگی‌های کلیدی
84
70
 
85
- | ویژگی | توضیح |
86
- | -------------- | ---------------------------------------------- |
87
- | ⚡ Super-Speed | استفاده از معماری غیرهمزمان برای پاسخ‌دهی سریع |
88
- | 🛡️ Type-Safe | کمک به جلوگیری از خطاهای متداول جاوااسکریپت |
89
- | 🔧 Filter-Base | سیستم فیلترینگ قدرتمند برای مدیریت پیام‌ها |
90
- | 📂 Modular | ساختار ماژولار و قابل گسترش |
71
+ | ویژگی | توضیح |
72
+ | -------------------- | ---------------------------------------------- |
73
+ | ⚡ Super-Speed | استفاده از معماری غیرهمزمان برای پاسخ‌دهی سریع |
74
+ | 🛡️ Type-Safe | کمک به جلوگیری از خطاهای متداول جاوااسکریپت |
75
+ | 🔧 Filter-Base | سیستم فیلترینگ قدرتمند برای مدیریت پیام‌ها |
76
+ | 📂 Modular | ساختار ماژولار و قابل گسترش |
77
+ | 🈸 Multi Application | ساخت ربات های روبیکایی و شاد |
91
78
 
92
79
  ## 🌐 لینک‌های مهم
93
80
 
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
@@ -14,7 +14,6 @@ export default class Client extends Methods {
14
14
  public sessionDb: SessionManager;
15
15
  public network: Network;
16
16
  public plugins: ClientTypes.RubPlugin[] = [];
17
- public errorMiddlewares: ClientTypes.ErrorMiddleware[] = [];
18
17
  public userGuid?: string;
19
18
  public handlers: {
20
19
  [K in keyof ClientTypes.ContextMap]: ClientTypes.Handler<
@@ -32,6 +31,7 @@ export default class Client extends Methods {
32
31
 
33
32
  constructor(
34
33
  private session: ClientTypes.SessionType,
34
+ public application: "Shad" | "Rubika" = "Rubika",
35
35
  public platform: ClientTypes.PlatformType = "Web",
36
36
  public timeout: number = 5000,
37
37
  ) {
@@ -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
  }
@@ -1,13 +1,16 @@
1
- import { ContextMap } from '../types/client.type';
2
- import Client from '../client';
3
- import Activities from './activities.type';
4
- import Chat from './chat.type';
5
- import Message from './message.type';
6
- import Notifications from './notifications.type';
1
+ import { ContextMapCon } from "../types/client.type";
2
+ import Client from "../client";
3
+ import Activities from "./activities.type";
4
+ import Chat from "./chat.type";
5
+ import Message from "./message.type";
6
+ import Notifications from "./notifications.type";
7
7
 
8
8
  export const ContextConstructors = {
9
- message: Message,
10
- chat: Chat,
11
- activities: Activities,
12
- notifications: Notifications,
13
- } satisfies Record<keyof ContextMap, new (client: Client, update: any) => any>;
9
+ message: Message,
10
+ chat: Chat,
11
+ activities: Activities,
12
+ notifications: Notifications,
13
+ } satisfies Record<
14
+ keyof ContextMapCon,
15
+ new (client: Client, update: any) => any
16
+ >;
@@ -1,35 +1,35 @@
1
- import Client from '../../client';
2
- import Crypto from '../../crypto';
1
+ import Client from "../../client";
2
+ import Crypto from "../../crypto";
3
3
 
4
4
  async function builder(
5
- this: Client,
6
- name: string,
7
- input: object,
8
- tmp_session: boolean = false,
5
+ this: Client,
6
+ name: string,
7
+ input: object,
8
+ tmp_session: boolean = false,
9
9
  ): Promise<any> {
10
- if (!this.auth) this.auth = Crypto.secret(32);
11
- if (!this.key) this.key = Buffer.from(Crypto.passphrase(this.auth), 'utf8');
10
+ if (!this.auth) this.auth = Crypto.secret(32);
11
+ if (!this.key) this.key = Buffer.from(Crypto.passphrase(this.auth), "utf8");
12
12
 
13
- let result = await this.network.send({
14
- input,
15
- tmp_session,
16
- method: name,
17
- });
13
+ let result = await this.network.send({
14
+ input,
15
+ tmp_session,
16
+ method: name,
17
+ });
18
18
 
19
- if (result) {
20
- const data_enc = result.data_enc;
21
- if (data_enc) {
22
- const decrypted = Crypto.decrypt(data_enc, this.key);
23
- result = JSON.parse(decrypted);
24
- }
19
+ if (result) {
20
+ const data_enc = result.data_enc;
21
+ if (data_enc) {
22
+ const decrypted = Crypto.decrypt(data_enc, this.key);
23
+ result = JSON.parse(decrypted);
24
+ }
25
25
 
26
- const status = result.status;
27
- const status_det = result.status_det;
26
+ const status = result.status;
27
+ const status_det = result.status_det;
28
28
 
29
- if (status == 'OK' && status_det == 'OK') {
30
- return result.data;
31
- }
32
- }
29
+ if (status == "OK" && status_det == "OK") {
30
+ return result.data;
31
+ }
32
+ }
33
33
  }
34
34
 
35
35
  export default builder;
@@ -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
  }