rubika 1.2.0 → 1.2.1
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/client/client.ts +1 -1
- package/client/contexts/contextConstructors.ts +14 -11
- package/client/methods/advanced/builder.ts +25 -25
- package/client/methods/index.ts +1238 -1241
- package/client/network/api.ts +1 -1
- 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/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
|
) {
|
|
@@ -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;
|