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 +20 -33
- package/bot/bot.ts +1 -1
- package/bot/methods/advanced/builder.ts +6 -6
- package/bot/methods/files/uploadFile.ts +1 -1
- package/bot/methods/utilities/webhook.ts +3 -1
- package/bot/network.ts +1 -1
- package/client/client.ts +3 -3
- package/client/contexts/contextConstructors.ts +14 -11
- package/client/methods/advanced/builder.ts +25 -25
- package/client/methods/auth/registerDevice.ts +1 -1
- package/client/methods/index.ts +1238 -1241
- package/client/methods/messages/sendMessage.ts +2 -2
- package/client/methods/utilities/start.ts +1 -1
- package/client/methods/utilities/thumbnail.ts +5 -5
- package/client/network/api.ts +2 -2
- package/client/network/file.ts +2 -2
- package/client/network/index.ts +3 -2
- package/client/network/utils.ts +24 -22
- package/client/network/websocket.ts +4 -4
- package/client/types/client.type.ts +7 -6
- package/client/types/methods.ts +224 -0
- package/package.json +1 -1
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
|
|
51
|
-
|
|
51
|
+
import Client from "rubika/bot";
|
|
52
52
|
|
|
53
|
-
const
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
@@ -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
|
|
18
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
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
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
|
-
|
|
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
|
-
|
|
111
|
+
return new Error("Invalid arguments for command()");
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Client from
|
|
3
|
-
import Activities from
|
|
4
|
-
import Chat from
|
|
5
|
-
import Message from
|
|
6
|
-
import Notifications from
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
2
|
-
import Crypto from
|
|
1
|
+
import Client from "../../client";
|
|
2
|
+
import Crypto from "../../crypto";
|
|
3
3
|
|
|
4
4
|
async function builder(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
this: Client,
|
|
6
|
+
name: string,
|
|
7
|
+
input: object,
|
|
8
|
+
tmp_session: boolean = false,
|
|
9
9
|
): Promise<any> {
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
let result = await this.network.send({
|
|
14
|
+
input,
|
|
15
|
+
tmp_session,
|
|
16
|
+
method: name,
|
|
17
|
+
});
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
26
|
+
const status = result.status;
|
|
27
|
+
const status_det = result.status_det;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
38
|
+
return new Error(`Cannot parse user-agent (${userAgent})`);
|
|
39
39
|
} else {
|
|
40
40
|
deviceModel = `${deviceModelMatch[1]} ${deviceModelMatch[2]}`;
|
|
41
41
|
}
|