rubika 1.1.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 +47 -17
- package/{bot.ts → bot/bot.ts} +2 -2
- package/{contexts → bot/contexts}/inline.ts +14 -14
- package/{contexts → bot/contexts}/update.ts +7 -12
- package/bot/index.ts +10 -0
- package/bot/methods/chat/getChatAdministrators.ts +9 -0
- package/bot/methods/chat/getChatMemberCount.ts +9 -0
- package/bot/methods/chat/index.ts +13 -0
- package/{methods → bot/methods}/files/_sendFile.ts +1 -1
- package/{methods → bot/methods}/index.ts +21 -0
- package/bot/methods/messages/index.ts +37 -0
- package/bot/methods/messages/pinChatMessage.ts +16 -0
- package/{methods → bot/methods}/messages/sendMessage.ts +1 -1
- package/{methods → bot/methods}/utilities/handleUpdates.ts +1 -1
- package/{methods → bot/methods}/utilities/polling.ts +4 -3
- package/{methods → bot/methods}/utilities/start.ts +1 -1
- package/{types → bot/types}/handlers.ts +5 -1
- package/bot/utils/index.ts +3 -0
- package/client/client.ts +114 -0
- package/client/contexts/activities.type.ts +31 -0
- package/client/contexts/chat.type.ts +32 -0
- package/client/contexts/contextConstructors.ts +16 -0
- package/client/contexts/index.ts +6 -0
- package/client/contexts/message.type.ts +256 -0
- package/client/contexts/notifications.type.ts +35 -0
- package/client/crypto.ts +112 -0
- package/client/filters.ts +184 -0
- package/client/index.ts +5 -0
- package/client/methods/advanced/builder.ts +35 -0
- package/client/methods/advanced/index.ts +3 -0
- package/client/methods/auth/index.ts +7 -0
- package/client/methods/auth/logout.ts +7 -0
- package/client/methods/auth/registerDevice.ts +77 -0
- package/client/methods/auth/sendCode.ts +28 -0
- package/client/methods/auth/signIn.ts +21 -0
- package/client/methods/channels/addChannel.ts +30 -0
- package/client/methods/channels/addChannelMembers.ts +16 -0
- package/client/methods/channels/banChannelMember.ts +25 -0
- package/client/methods/channels/cancelChangeObjectOwner.ts +7 -0
- package/client/methods/channels/channelPreviewByJoinLink.ts +9 -0
- package/client/methods/channels/checkChannelUsername.ts +9 -0
- package/client/methods/channels/createChannelVoiceChat.ts +7 -0
- package/client/methods/channels/discardChannelVoiceChat.ts +14 -0
- package/client/methods/channels/editChannelInfo.ts +73 -0
- package/client/methods/channels/getBannedChannelMembers.ts +14 -0
- package/client/methods/channels/getChannelAdminAccessList.ts +14 -0
- package/client/methods/channels/getChannelAdminMembers.ts +14 -0
- package/client/methods/channels/getChannelAllMembers.ts +16 -0
- package/client/methods/channels/getChannelInfo.ts +7 -0
- package/client/methods/channels/getChannelLink.ts +7 -0
- package/client/methods/channels/getPendingObjectOwner.ts +7 -0
- package/client/methods/channels/index.ts +53 -0
- package/client/methods/channels/joinChannelAction.ts +20 -0
- package/client/methods/channels/joinChannelByLink.ts +8 -0
- package/client/methods/channels/leaveChannelVoiceChat.ts +14 -0
- package/client/methods/channels/removeChannel.ts +7 -0
- package/client/methods/channels/requestChangeObjectOwner.ts +14 -0
- package/client/methods/channels/seenChannelMessages.ts +16 -0
- package/client/methods/channels/setChannelLink.ts +7 -0
- package/client/methods/channels/setChannelVoiceChatSetting.ts +30 -0
- package/client/methods/channels/updateChannelUsername.ts +14 -0
- package/client/methods/chats/actionOnJoinRequest.ts +18 -0
- package/client/methods/chats/addLiveComment.ts +12 -0
- package/client/methods/chats/clickMessageUrl.ts +12 -0
- package/client/methods/chats/createJoinLink.ts +20 -0
- package/client/methods/chats/deleteAvatar.ts +11 -0
- package/client/methods/chats/deleteChatHistory.ts +14 -0
- package/client/methods/chats/editJoinLink.ts +46 -0
- package/client/methods/chats/getAbsObjects.ts +9 -0
- package/client/methods/chats/getAvatars.ts +7 -0
- package/client/methods/chats/getChatReaction.ts +12 -0
- package/client/methods/chats/getChats.ts +7 -0
- package/client/methods/chats/getChatsUpdates.ts +10 -0
- package/client/methods/chats/getJoinLinks.ts +7 -0
- package/client/methods/chats/getJoinRequests.ts +7 -0
- package/client/methods/chats/getLinkFromAppUrl.ts +7 -0
- package/client/methods/chats/getLiveComments.ts +11 -0
- package/client/methods/chats/getLivePlayUrl.ts +11 -0
- package/client/methods/chats/getLiveStatus.ts +12 -0
- package/client/methods/chats/getObjectInfoByUsername.ts +9 -0
- package/client/methods/chats/getTopChatUsers.ts +7 -0
- package/client/methods/chats/index.ts +59 -0
- package/client/methods/chats/removeFromTopChatUsers.ts +7 -0
- package/client/methods/chats/removeJoinLink.ts +13 -0
- package/client/methods/chats/searchChatMessages.ts +24 -0
- package/client/methods/chats/searchGlobalMessages.ts +11 -0
- package/client/methods/chats/seenChats.ts +7 -0
- package/client/methods/chats/sendChatActivity.ts +19 -0
- package/client/methods/chats/sendLive.ts +22 -0
- package/client/methods/chats/setActionChat.ts +19 -0
- package/client/methods/chats/uploadAvatar.ts +19 -0
- package/client/methods/contacts/addAddressBook.ts +12 -0
- package/client/methods/contacts/deleteContact.ts +7 -0
- package/client/methods/contacts/getContacts.ts +7 -0
- package/client/methods/contacts/getContactsLastOnline.ts +7 -0
- package/client/methods/contacts/getContactsUpdates.ts +10 -0
- package/client/methods/contacts/index.ts +15 -0
- package/client/methods/contacts/resetContacts.ts +7 -0
- package/client/methods/extras/banMember.ts +15 -0
- package/client/methods/extras/deleteMessagebyCount.ts +49 -0
- package/client/methods/extras/getInfo.ts +17 -0
- package/client/methods/extras/getObjectByUsername.ts +9 -0
- package/client/methods/extras/getProfileLinkItems.ts +7 -0
- package/client/methods/extras/getRelatedObjects.ts +7 -0
- package/client/methods/extras/getTranscription.ts +14 -0
- package/client/methods/extras/index.ts +37 -0
- package/client/methods/extras/join.ts +9 -0
- package/client/methods/extras/joinVoiceChat.ts +20 -0
- package/client/methods/extras/leaveChat.ts +9 -0
- package/client/methods/extras/onEditMessages.ts +39 -0
- package/client/methods/extras/reportObject.ts +34 -0
- package/client/methods/extras/searchGlobalObjects.ts +7 -0
- package/client/methods/extras/sendVoiceChatActivity.ts +23 -0
- package/client/methods/extras/setVoiceChatState.ts +21 -0
- package/client/methods/extras/transcribeVoice.ts +11 -0
- package/client/methods/extras/userIsAdmin.ts +26 -0
- package/client/methods/gif/addToMyGifSet.ts +11 -0
- package/client/methods/gif/getMyGifSet.ts +7 -0
- package/client/methods/gif/index.ts +6 -0
- package/client/methods/gif/removeFromMyGifSet.ts +7 -0
- package/client/methods/groups/addGroup.ts +14 -0
- package/client/methods/groups/addGroupMembers.ts +13 -0
- package/client/methods/groups/banGroupMember.ts +24 -0
- package/client/methods/groups/createGroupVoiceChat.ts +7 -0
- package/client/methods/groups/deleteNoAccessGroupChat.ts +7 -0
- package/client/methods/groups/discardGroupVoiceChat.ts +10 -0
- package/client/methods/groups/editGroupInfo.ts +67 -0
- package/client/methods/groups/getBannedGroupMembers.ts +11 -0
- package/client/methods/groups/getGroupAdminAccessList.ts +14 -0
- package/client/methods/groups/getGroupAdminMembers.ts +11 -0
- package/client/methods/groups/getGroupAllMembers.ts +16 -0
- package/client/methods/groups/getGroupDefaultAccess.ts +7 -0
- package/client/methods/groups/getGroupInfo.ts +7 -0
- package/client/methods/groups/getGroupLink.ts +7 -0
- package/client/methods/groups/getGroupMentionList.ts +14 -0
- package/client/methods/groups/getGroupOnlineCount.ts +7 -0
- package/client/methods/groups/getGroupVoiceChatParticipants.ts +7 -0
- package/client/methods/groups/getGroupVoiceChatUpdates.ts +16 -0
- package/client/methods/groups/groupPreviewByJoinLink.ts +9 -0
- package/client/methods/groups/index.ts +61 -0
- package/client/methods/groups/joinGroup.ts +10 -0
- package/client/methods/groups/joinGroupVoiceChat.ts +18 -0
- package/client/methods/groups/leaveGroup.ts +7 -0
- package/client/methods/groups/leaveGroupVoiceChat.ts +14 -0
- package/client/methods/groups/removeGroup.ts +7 -0
- package/client/methods/groups/seenGroupMessages.ts +16 -0
- package/client/methods/groups/setGroupAdmin.ts +40 -0
- package/client/methods/groups/setGroupDefaultAccess.ts +34 -0
- package/client/methods/groups/setGroupLink.ts +7 -0
- package/client/methods/groups/setGroupVoiceChatSetting.ts +30 -0
- package/client/methods/index.ts +1241 -0
- package/client/methods/messages/actionOnMessageReaction.ts +22 -0
- package/client/methods/messages/createPoll.ts +64 -0
- package/client/methods/messages/deleteMessages.ts +29 -0
- package/client/methods/messages/editMessage.ts +19 -0
- package/client/methods/messages/forwardMessages.ts +35 -0
- package/client/methods/messages/getMessageShareUrl.ts +11 -0
- package/client/methods/messages/getMessages.ts +28 -0
- package/client/methods/messages/getMessagesByID.ts +15 -0
- package/client/methods/messages/getMessagesInterval.ts +13 -0
- package/client/methods/messages/getMessagesUpdates.ts +11 -0
- package/client/methods/messages/getPollOptionVoters.ts +16 -0
- package/client/methods/messages/getPollStatus.ts +7 -0
- package/client/methods/messages/index.ts +54 -0
- package/client/methods/messages/sendDocument.ts +24 -0
- package/client/methods/messages/sendFileInline.ts +51 -0
- package/client/methods/messages/sendGif.ts +24 -0
- package/client/methods/messages/sendMessage.ts +137 -0
- package/client/methods/messages/sendMusic.ts +26 -0
- package/client/methods/messages/sendPhoto.ts +25 -0
- package/client/methods/messages/sendSticker.ts +7 -0
- package/client/methods/messages/sendText.ts +23 -0
- package/client/methods/messages/sendVideo.ts +26 -0
- package/client/methods/messages/sendVideoMessage.ts +25 -0
- package/client/methods/messages/sendVoice.ts +24 -0
- package/client/methods/messages/setPinMessage.ts +24 -0
- package/client/methods/messages/votePoll.ts +11 -0
- package/client/methods/settings/changePassword.ts +12 -0
- package/client/methods/settings/checkTwoStepPasscode.ts +7 -0
- package/client/methods/settings/deleteFolder.ts +7 -0
- package/client/methods/settings/getBlockedUsers.ts +7 -0
- package/client/methods/settings/getFolders.ts +10 -0
- package/client/methods/settings/getMySessions.ts +7 -0
- package/client/methods/settings/getPrivacySetting.ts +7 -0
- package/client/methods/settings/getSuggestedFolders.ts +7 -0
- package/client/methods/settings/getTwoPasscodeStatus.ts +7 -0
- package/client/methods/settings/index.ts +39 -0
- package/client/methods/settings/requestRecoveryEmail.ts +14 -0
- package/client/methods/settings/setSetting.ts +99 -0
- package/client/methods/settings/setupTwoStepVerification.ts +16 -0
- package/client/methods/settings/terminateOtherSessions.ts +7 -0
- package/client/methods/settings/terminateSession.ts +7 -0
- package/client/methods/settings/turnOffTwoStep.ts +7 -0
- package/client/methods/settings/updateProfile.ts +38 -0
- package/client/methods/settings/updateUsername.ts +7 -0
- package/client/methods/settings/verifyRecoveryEmail.ts +11 -0
- package/client/methods/stickers/actionOnStickerSet.ts +19 -0
- package/client/methods/stickers/getMyStickerSets.ts +7 -0
- package/client/methods/stickers/getStickerSetByID.ts +7 -0
- package/client/methods/stickers/getStickersByEmoji.ts +11 -0
- package/client/methods/stickers/getStickersBySetIds.ts +9 -0
- package/client/methods/stickers/getTrendStickerSets.ts +10 -0
- package/client/methods/stickers/index.ts +10 -0
- package/client/methods/stickers/searchStickers.ts +11 -0
- package/client/methods/users/checkUserUsername.ts +7 -0
- package/client/methods/users/deleteUserChat.ts +14 -0
- package/client/methods/users/getMe.ts +7 -0
- package/client/methods/users/getUserInfo.ts +15 -0
- package/client/methods/users/index.ts +8 -0
- package/client/methods/users/setBlockUser.ts +18 -0
- package/client/methods/utilities/download.ts +18 -0
- package/client/methods/utilities/downloadProfilePicture.ts +29 -0
- package/client/methods/utilities/index.ts +18 -0
- package/client/methods/utilities/requestSendFile.ts +17 -0
- package/client/methods/utilities/run.ts +11 -0
- package/client/methods/utilities/start.ts +89 -0
- package/client/methods/utilities/thumbnail.ts +84 -0
- package/client/methods/utilities/usePlugin.ts +38 -0
- package/client/network/api.ts +128 -0
- package/client/network/file.ts +143 -0
- package/client/network/index.ts +45 -0
- package/client/network/utils.ts +32 -0
- package/client/network/websocket.ts +198 -0
- package/client/types/client.type.ts +51 -0
- package/client/types/decorators.type.ts +197 -0
- package/client/types/index.type.ts +12 -0
- package/client/types/methods.ts +224 -0
- package/client/types/network.type.ts +7 -0
- package/client/types/session.type.ts +7 -0
- package/client/utils/index.ts +4 -0
- package/client/utils/optionalImport.ts +8 -0
- package/client/utils/session.ts +46 -0
- package/index.ts +3 -7
- package/package.json +7 -3
- package/utils/errors.ts +10 -4
- package/utils/index.ts +4 -4
- package/utils/parser.ts +1 -1
- package/methods/chat/index.ts +0 -6
- package/methods/messages/index.ts +0 -36
- /package/{contexts → bot/contexts}/index.ts +0 -0
- /package/{filters.ts → bot/filters.ts} +0 -0
- /package/{methods → bot/methods}/advanced/builder.ts +0 -0
- /package/{methods → bot/methods}/advanced/index.ts +0 -0
- /package/{methods → bot/methods}/bot/getMe.ts +0 -0
- /package/{methods → bot/methods}/bot/index.ts +0 -0
- /package/{methods → bot/methods}/chat/banChatMember.ts +0 -0
- /package/{methods → bot/methods}/chat/getChat.ts +0 -0
- /package/{methods → bot/methods}/chat/unbanChatMember.ts +0 -0
- /package/{methods → bot/methods}/files/getFile.ts +0 -0
- /package/{methods → bot/methods}/files/index.ts +0 -0
- /package/{methods → bot/methods}/files/requestSendFile.ts +0 -0
- /package/{methods → bot/methods}/files/uploadFile.ts +0 -0
- /package/{methods → bot/methods}/messages/deleteMessage.ts +0 -0
- /package/{methods → bot/methods}/messages/editChatKeypad.ts +0 -0
- /package/{methods → bot/methods}/messages/editMessageKeypad.ts +0 -0
- /package/{methods → bot/methods}/messages/editMessageText.ts +0 -0
- /package/{methods → bot/methods}/messages/forwardMessage.ts +0 -0
- /package/{methods → bot/methods}/messages/sendContact.ts +0 -0
- /package/{methods → bot/methods}/messages/sendFile.ts +0 -0
- /package/{methods → bot/methods}/messages/sendGif.ts +0 -0
- /package/{methods → bot/methods}/messages/sendImage.ts +0 -0
- /package/{methods → bot/methods}/messages/sendLocation.ts +0 -0
- /package/{methods → bot/methods}/messages/sendMusic.ts +0 -0
- /package/{methods → bot/methods}/messages/sendPoll.ts +0 -0
- /package/{methods → bot/methods}/messages/sendSticker.ts +0 -0
- /package/{methods → bot/methods}/messages/sendVideo.ts +0 -0
- /package/{methods → bot/methods}/messages/sendVoice.ts +0 -0
- /package/{methods → bot/methods}/settings/index.ts +0 -0
- /package/{methods → bot/methods}/settings/setCommands.ts +0 -0
- /package/{methods → bot/methods}/settings/updateBotEndpoints.ts +0 -0
- /package/{methods → bot/methods}/utilities/getUpdates.ts +0 -0
- /package/{methods → bot/methods}/utilities/index.ts +0 -0
- /package/{methods → bot/methods}/utilities/run.ts +0 -0
- /package/{methods → bot/methods}/utilities/webhook.ts +0 -0
- /package/{network.ts → bot/network.ts} +0 -0
- /package/{types → bot/types}/enums.ts +0 -0
- /package/{types → bot/types}/interfaces.ts +0 -0
- /package/{types → bot/types}/methods.ts +0 -0
- /package/{types → bot/types}/utils.ts +0 -0
- /package/{utils → bot/utils}/antiSpam.ts +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<h1 style="color:#fff;">› rubika Framework</h1>
|
|
3
|
-
<p><b>فریمورک قدرتمند و پرسرعت جاوااسکریپت برای
|
|
3
|
+
<p><b>فریمورک قدرتمند و پرسرعت جاوااسکریپت برای ربات/سلفهای روبیکا</b></p>
|
|
4
4
|
</p>
|
|
5
5
|
|
|
6
6
|
---
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
**rubika** یک فریمورک سبک، مدرن و کاملاً **غیرهمزمان** برای توسعه رباتهای روبیکا است.
|
|
11
11
|
با معماری **Filter-Base** و **Type-Safe**، شما میتوانید:
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
- سیستم فرماندهی و مدیریت پیام حرفهای داشته
|
|
15
|
-
- با قابلیت **اسکِیبل و قابل گسترش**، پروژههای بزرگ هم مدیریت
|
|
13
|
+
- ربات/سلف هایی سریع و کمحجم بسازید.
|
|
14
|
+
- سیستم فرماندهی و مدیریت پیام حرفهای داشته باشید.
|
|
15
|
+
- با قابلیت **اسکِیبل و قابل گسترش**، پروژههای بزرگ هم مدیریت کنید.
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
@@ -22,33 +22,63 @@
|
|
|
22
22
|
bun add rubika
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
## › نمونه کد ساده
|
|
25
|
+
## › نمونه کد ساده ربات
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
import Bot, { Filters } from "rubika";
|
|
28
|
+
import Bot, { Filters } from "rubika/bot";
|
|
29
29
|
|
|
30
|
-
const bot = new Bot("
|
|
30
|
+
const bot = new Bot("TOKEN_BOT");
|
|
31
31
|
|
|
32
|
-
bot.command("/start", async (ctx
|
|
33
|
-
await
|
|
32
|
+
bot.command("/start", async (ctx) => {
|
|
33
|
+
await ctx.reply("🤖 ربات استارت شد");
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
bot.on("update", [Filters.isText], async (ctx
|
|
37
|
-
await
|
|
36
|
+
bot.on("update", [Filters.isText], async (ctx) => {
|
|
37
|
+
await ctx.reply("سلام 😎");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
bot.on("error", async (err) => {
|
|
41
|
+
await err.bot.sendMessage("CHAT_ID", err.message);
|
|
42
|
+
console.log(err.message);
|
|
38
43
|
});
|
|
39
44
|
|
|
40
45
|
bot.run();
|
|
41
46
|
```
|
|
42
47
|
|
|
48
|
+
## › نمونه کد ساده سلف (self)
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import Client from "rubika/bot";
|
|
52
|
+
|
|
53
|
+
const shad_client = new Client("shad", "Shad");
|
|
54
|
+
const rubika_client = new Client("rubika", "Rubika");
|
|
55
|
+
|
|
56
|
+
// Shad
|
|
57
|
+
shad_client.on("message", async (ctx) => console.log(ctx));
|
|
58
|
+
shad_client.on("error", async (err) => console.log(err));
|
|
59
|
+
|
|
60
|
+
// Rubika
|
|
61
|
+
rubika_client.on("message", async (ctx) => console.log(ctx));
|
|
62
|
+
rubika_client.on("error", async (err) => console.log(err));
|
|
63
|
+
|
|
64
|
+
// start (self)-bots
|
|
65
|
+
shad_client.run();
|
|
66
|
+
rubika_client.run();
|
|
67
|
+
```
|
|
68
|
+
|
|
43
69
|
## › ویژگیهای کلیدی
|
|
44
70
|
|
|
45
|
-
| ویژگی
|
|
46
|
-
|
|
|
47
|
-
| ⚡ Super-Speed
|
|
48
|
-
| 🛡️ Type-Safe
|
|
49
|
-
| 🔧 Filter-Base
|
|
50
|
-
| 📂 Modular
|
|
71
|
+
| ویژگی | توضیح |
|
|
72
|
+
| -------------------- | ---------------------------------------------- |
|
|
73
|
+
| ⚡ Super-Speed | استفاده از معماری غیرهمزمان برای پاسخدهی سریع |
|
|
74
|
+
| 🛡️ Type-Safe | کمک به جلوگیری از خطاهای متداول جاوااسکریپت |
|
|
75
|
+
| 🔧 Filter-Base | سیستم فیلترینگ قدرتمند برای مدیریت پیامها |
|
|
76
|
+
| 📂 Modular | ساختار ماژولار و قابل گسترش |
|
|
77
|
+
| 🈸 Multi Application | ساخت ربات های روبیکایی و شاد |
|
|
51
78
|
|
|
52
79
|
## 🌐 لینکهای مهم
|
|
53
80
|
|
|
54
81
|
- [لینک گیتهاب](https://github.com/hadi-rostami/rubika-bot)
|
|
82
|
+
- [لینک npm](https://www.npmjs.com/package/rubika)
|
|
83
|
+
- [تلگرام](https://t.me/rubikajs_channel)
|
|
84
|
+
- [روبیکا](https://rubika.ir/rubika_js)
|
package/{bot.ts → bot/bot.ts}
RENAMED
|
@@ -3,7 +3,7 @@ import Methods from "./methods";
|
|
|
3
3
|
import type { BotInfo } from "./types/interfaces";
|
|
4
4
|
import type { ContextMap, Handler, NestedFilter } from "./types/handlers";
|
|
5
5
|
import Update from "./contexts/update";
|
|
6
|
-
import Logger from "
|
|
6
|
+
import { Logger } from "../utils";
|
|
7
7
|
|
|
8
8
|
class Bot extends Methods {
|
|
9
9
|
protected initialize: boolean = false;
|
|
@@ -15,7 +15,7 @@ class Bot extends Methods {
|
|
|
15
15
|
[K in keyof ContextMap]: Handler<ContextMap[K]>[];
|
|
16
16
|
} = { inline: [], update: [], error: [] };
|
|
17
17
|
|
|
18
|
-
public logger = new Logger(this.handlers.error);
|
|
18
|
+
public logger = new Logger<Bot>(this.handlers.error, this);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* نمونهای از کلاس ربات را ایجاد میکند.
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import Bot from "..";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { inspect } from "util";
|
|
3
|
+
import {
|
|
4
|
+
AuxData,
|
|
5
|
+
File,
|
|
6
|
+
InlineKeypad,
|
|
7
|
+
Keypad,
|
|
8
|
+
Location,
|
|
9
|
+
} from "../types/interfaces";
|
|
4
10
|
import { ChatKeypadTypeEnum } from "../types/enums";
|
|
5
11
|
import { FileSource } from "../types/methods";
|
|
6
12
|
|
|
@@ -16,7 +22,10 @@ class Inline {
|
|
|
16
22
|
|
|
17
23
|
declare bot: Bot;
|
|
18
24
|
|
|
19
|
-
constructor(
|
|
25
|
+
constructor(
|
|
26
|
+
private ctx: any,
|
|
27
|
+
bot: Bot,
|
|
28
|
+
) {
|
|
20
29
|
this.sender_id = ctx.sender_id;
|
|
21
30
|
this.text = ctx.text;
|
|
22
31
|
this.file = ctx.file;
|
|
@@ -285,17 +294,8 @@ class Inline {
|
|
|
285
294
|
);
|
|
286
295
|
};
|
|
287
296
|
|
|
288
|
-
[
|
|
289
|
-
return
|
|
290
|
-
sender_id: this.sender_id,
|
|
291
|
-
text: this.text,
|
|
292
|
-
file: this.file,
|
|
293
|
-
location: this.location,
|
|
294
|
-
aux_data: this.aux_data,
|
|
295
|
-
message_id: this.message_id,
|
|
296
|
-
chat_id: this.chat_id,
|
|
297
|
-
store: this.store,
|
|
298
|
-
};
|
|
297
|
+
[inspect.custom]() {
|
|
298
|
+
return this.ctx;
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Bot from "..";
|
|
2
|
-
import
|
|
2
|
+
import { inspect } from "util";
|
|
3
3
|
import { ChatKeypadTypeEnum, UpdateTypeEnum } from "../types/enums";
|
|
4
4
|
import { FileSource } from "../types/methods";
|
|
5
5
|
import {
|
|
@@ -19,7 +19,10 @@ class Update {
|
|
|
19
19
|
store: Record<string, any> = {};
|
|
20
20
|
declare bot: Bot;
|
|
21
21
|
|
|
22
|
-
constructor(
|
|
22
|
+
constructor(
|
|
23
|
+
private ctx: any,
|
|
24
|
+
bot: Bot,
|
|
25
|
+
) {
|
|
23
26
|
this.type = ctx.type;
|
|
24
27
|
this.chat_id = ctx.chat_id;
|
|
25
28
|
this.removed_message_id = ctx.removed_message_id;
|
|
@@ -335,16 +338,8 @@ class Update {
|
|
|
335
338
|
return isId ? msg.sender_id : msg.message_id;
|
|
336
339
|
}
|
|
337
340
|
|
|
338
|
-
[
|
|
339
|
-
return
|
|
340
|
-
type: this.type,
|
|
341
|
-
chat_id: this.chat_id,
|
|
342
|
-
removed_message_id: this.removed_message_id,
|
|
343
|
-
new_message: this.new_message,
|
|
344
|
-
updated_message: this.updated_message,
|
|
345
|
-
updated_payment: this.updated_payment,
|
|
346
|
-
store: this.store,
|
|
347
|
-
};
|
|
341
|
+
[inspect.custom]() {
|
|
342
|
+
return this.ctx;
|
|
348
343
|
}
|
|
349
344
|
}
|
|
350
345
|
|
package/bot/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Bot from "./bot";
|
|
2
|
+
import { AntiSpam } from "./utils";
|
|
3
|
+
import Filters from "./filters";
|
|
4
|
+
import Utils from "../utils/formater";
|
|
5
|
+
import type * as Enums from "./types/enums";
|
|
6
|
+
import { Update, Inline } from "./contexts/index";
|
|
7
|
+
|
|
8
|
+
export default Bot;
|
|
9
|
+
export { Bot, Filters, Utils, AntiSpam };
|
|
10
|
+
export type { Enums, Update, Inline };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import banChatMember from "./banChatMember";
|
|
2
|
+
import getChat from "./getChat";
|
|
3
|
+
import getChatAdministrators from "./getChatAdministrators";
|
|
4
|
+
import getChatMemberCount from "./getChatMemberCount";
|
|
5
|
+
import unbanChatMember from "./unbanChatMember";
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
getChat,
|
|
9
|
+
banChatMember,
|
|
10
|
+
unbanChatMember,
|
|
11
|
+
getChatAdministrators,
|
|
12
|
+
getChatMemberCount,
|
|
13
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Bot from "../..";
|
|
2
|
-
import { Markdown } from "
|
|
2
|
+
import { Markdown } from "../../../utils";
|
|
3
3
|
import { FileSource, SendType } from "../../types/methods";
|
|
4
4
|
import { InlineKeypad, Keypad } from "../../types/interfaces";
|
|
5
5
|
import { ChatKeypadTypeEnum, FileTypeEnum } from "../../types/enums";
|
|
@@ -162,6 +162,13 @@ export default class Methods {
|
|
|
162
162
|
return Messages.editChatKeypad.apply(this, args);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
// async pinChatMessage(
|
|
166
|
+
// this: Bot,
|
|
167
|
+
// ...args: Parameters<typeof Messages.pinChatMessage>
|
|
168
|
+
// ): Promise<Types.SendMessage> {
|
|
169
|
+
// return Messages.pinChatMessage.apply(this, args);
|
|
170
|
+
// }
|
|
171
|
+
|
|
165
172
|
// chat
|
|
166
173
|
async getChat(
|
|
167
174
|
this: Bot,
|
|
@@ -184,6 +191,20 @@ export default class Methods {
|
|
|
184
191
|
return Chat.unbanChatMember.apply(this, args);
|
|
185
192
|
}
|
|
186
193
|
|
|
194
|
+
// async getChatAdministrators(
|
|
195
|
+
// this: Bot,
|
|
196
|
+
// ...args: Parameters<typeof Chat.getChatAdministrators>
|
|
197
|
+
// ): Promise<Types.SendMessage> {
|
|
198
|
+
// return Chat.getChatAdministrators.apply(this, args);
|
|
199
|
+
// }
|
|
200
|
+
|
|
201
|
+
// async getChatMemberCount(
|
|
202
|
+
// this: Bot,
|
|
203
|
+
// ...args: Parameters<typeof Chat.getChatMemberCount>
|
|
204
|
+
// ): Promise<Types.SendMessage> {
|
|
205
|
+
// return Chat.getChatMemberCount.apply(this, args);
|
|
206
|
+
// }
|
|
207
|
+
|
|
187
208
|
// utilities
|
|
188
209
|
async start(
|
|
189
210
|
this: Bot,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import deleteMessage from "./deleteMessage";
|
|
2
|
+
import editChatKeypad from "./editChatKeypad";
|
|
3
|
+
import editMessageKeypad from "./editMessageKeypad";
|
|
4
|
+
import editMessageText from "./editMessageText";
|
|
5
|
+
import forwardMessage from "./forwardMessage";
|
|
6
|
+
import pinChatMessage from "./pinChatMessage";
|
|
7
|
+
import sendContact from "./sendContact";
|
|
8
|
+
import sendFile from "./sendFile";
|
|
9
|
+
import sendGif from "./sendGif";
|
|
10
|
+
import sendImage from "./sendImage";
|
|
11
|
+
import sendLocation from "./sendLocation";
|
|
12
|
+
import sendMessage from "./sendMessage";
|
|
13
|
+
import sendMusic from "./sendMusic";
|
|
14
|
+
import sendPoll from "./sendPoll";
|
|
15
|
+
import sendSticker from "./sendSticker";
|
|
16
|
+
import sendVideo from "./sendVideo";
|
|
17
|
+
import sendVoice from "./sendVoice";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
sendMessage,
|
|
21
|
+
sendPoll,
|
|
22
|
+
sendLocation,
|
|
23
|
+
sendContact,
|
|
24
|
+
forwardMessage,
|
|
25
|
+
editMessageText,
|
|
26
|
+
deleteMessage,
|
|
27
|
+
editMessageKeypad,
|
|
28
|
+
editChatKeypad,
|
|
29
|
+
sendMusic,
|
|
30
|
+
sendFile,
|
|
31
|
+
sendGif,
|
|
32
|
+
sendImage,
|
|
33
|
+
sendSticker,
|
|
34
|
+
sendVideo,
|
|
35
|
+
sendVoice,
|
|
36
|
+
pinChatMessage,
|
|
37
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Bot from "../..";
|
|
2
|
+
|
|
3
|
+
async function pinChatMessage(
|
|
4
|
+
this: Bot,
|
|
5
|
+
chat_id: string,
|
|
6
|
+
message_id: string,
|
|
7
|
+
disable_notification = false,
|
|
8
|
+
) {
|
|
9
|
+
return await this.builder("pinChatMessage", {
|
|
10
|
+
chat_id,
|
|
11
|
+
message_id,
|
|
12
|
+
disable_notification,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default pinChatMessage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Bot from "../..";
|
|
2
|
-
import { Markdown } from "
|
|
2
|
+
import { Markdown } from "../../../utils";
|
|
3
3
|
import { SendType } from "../../types/methods";
|
|
4
4
|
import { ChatKeypadTypeEnum } from "../../types/enums";
|
|
5
5
|
import { InlineKeypad, Keypad } from "../../types/interfaces";
|
|
@@ -2,7 +2,7 @@ import Bot from "../../bot";
|
|
|
2
2
|
import Inline from "../../contexts/inline";
|
|
3
3
|
import Update from "../../contexts/update";
|
|
4
4
|
import { UpdateTypeEnum } from "../../types/enums";
|
|
5
|
-
import { checkFilters } from "
|
|
5
|
+
import { checkFilters } from "../../../utils";
|
|
6
6
|
|
|
7
7
|
const checkTypes = [UpdateTypeEnum.UpdatedMessage, UpdateTypeEnum.NewMessage];
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import Bot from "../../bot";
|
|
3
|
-
import { checkFilters } from "
|
|
3
|
+
import { checkFilters } from "../../../utils";
|
|
4
4
|
import { UpdateTypeEnum } from "../../types/enums";
|
|
5
5
|
import Update from "../../contexts/update";
|
|
6
6
|
|
|
@@ -35,8 +35,9 @@ export default async function polling(this: Bot) {
|
|
|
35
35
|
if (typeof prefix === "string" && text !== prefix) continue;
|
|
36
36
|
if (prefix instanceof RegExp && !prefix.test(text)) continue;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
try {
|
|
39
|
+
await handler(ctx);
|
|
40
|
+
} catch {}
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import Bot from "..";
|
|
1
2
|
import { Update, Inline } from "../contexts";
|
|
2
3
|
|
|
3
4
|
export interface ContextMap {
|
|
4
5
|
update: Update;
|
|
5
6
|
inline: Inline;
|
|
6
|
-
error:
|
|
7
|
+
error: {
|
|
8
|
+
message: string;
|
|
9
|
+
bot: Bot;
|
|
10
|
+
};
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
export type FilterFn<T> = (ctx: T) => boolean | Promise<boolean>;
|
package/client/client.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Network from "./network";
|
|
2
|
+
import Methods from "./methods";
|
|
3
|
+
import { SessionManager } from "./utils";
|
|
4
|
+
import Message from "./contexts/message.type";
|
|
5
|
+
import * as ClientTypes from "./types/client.type";
|
|
6
|
+
import { Logger } from "../utils";
|
|
7
|
+
|
|
8
|
+
export default class Client extends Methods {
|
|
9
|
+
public initialize = false;
|
|
10
|
+
public key?: Buffer<ArrayBuffer>;
|
|
11
|
+
public privateKey?: string;
|
|
12
|
+
public decode_auth?: string;
|
|
13
|
+
public auth?: string;
|
|
14
|
+
public sessionDb: SessionManager;
|
|
15
|
+
public network: Network;
|
|
16
|
+
public plugins: ClientTypes.RubPlugin[] = [];
|
|
17
|
+
public userGuid?: string;
|
|
18
|
+
public handlers: {
|
|
19
|
+
[K in keyof ClientTypes.ContextMap]: ClientTypes.Handler<
|
|
20
|
+
ClientTypes.ContextMap[K]
|
|
21
|
+
>[];
|
|
22
|
+
} = {
|
|
23
|
+
error: [],
|
|
24
|
+
chat: [],
|
|
25
|
+
message: [],
|
|
26
|
+
activities: [],
|
|
27
|
+
notifications: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
public logger = new Logger<Client>(this.handlers.error, this);
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
private session: ClientTypes.SessionType,
|
|
34
|
+
public application: "Shad" | "Rubika" = "Rubika",
|
|
35
|
+
public platform: ClientTypes.PlatformType = "Web",
|
|
36
|
+
public timeout: number = 5000,
|
|
37
|
+
) {
|
|
38
|
+
super();
|
|
39
|
+
this.sessionDb = new SessionManager(this.session);
|
|
40
|
+
this.network = new Network(this);
|
|
41
|
+
|
|
42
|
+
this.start();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
on<T extends keyof typeof this.handlers>(
|
|
46
|
+
type: T,
|
|
47
|
+
handler: (ctx: ClientTypes.ContextMap[T]) => Promise<void>,
|
|
48
|
+
): void;
|
|
49
|
+
|
|
50
|
+
on<T extends keyof typeof this.handlers>(
|
|
51
|
+
type: T,
|
|
52
|
+
filters: Array<
|
|
53
|
+
(ctx: ClientTypes.ContextMap[T]) => boolean | Promise<boolean>
|
|
54
|
+
>,
|
|
55
|
+
handler: (ctx: ClientTypes.ContextMap[T]) => Promise<void>,
|
|
56
|
+
): void;
|
|
57
|
+
|
|
58
|
+
on<T extends keyof typeof this.handlers>(
|
|
59
|
+
type: T,
|
|
60
|
+
filtersOrHandler:
|
|
61
|
+
| Array<(ctx: ClientTypes.ContextMap[T]) => boolean | Promise<boolean>>
|
|
62
|
+
| ((ctx: ClientTypes.ContextMap[T]) => Promise<void>),
|
|
63
|
+
maybeHandler?: (ctx: ClientTypes.ContextMap[T]) => Promise<void>,
|
|
64
|
+
) {
|
|
65
|
+
if (typeof filtersOrHandler === "function") {
|
|
66
|
+
this.handlers[type].push({
|
|
67
|
+
filters: [],
|
|
68
|
+
handler: filtersOrHandler,
|
|
69
|
+
});
|
|
70
|
+
} else if (Array.isArray(filtersOrHandler) && maybeHandler) {
|
|
71
|
+
this.handlers[type].push({
|
|
72
|
+
filters: filtersOrHandler,
|
|
73
|
+
handler: maybeHandler,
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
throw new Error("Invalid arguments for on()");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
command(
|
|
81
|
+
prefix: string | RegExp,
|
|
82
|
+
handler: (ctx: Message) => Promise<void>,
|
|
83
|
+
): void;
|
|
84
|
+
|
|
85
|
+
command(
|
|
86
|
+
prefix: string | RegExp,
|
|
87
|
+
filters: Array<(ctx: Message) => boolean | Promise<boolean>>,
|
|
88
|
+
handler: (ctx: Message) => Promise<void>,
|
|
89
|
+
): void;
|
|
90
|
+
|
|
91
|
+
command(
|
|
92
|
+
prefix: string | RegExp,
|
|
93
|
+
filtersOrHandler:
|
|
94
|
+
| Array<(ctx: Message) => boolean | Promise<boolean>>
|
|
95
|
+
| ((ctx: Message) => Promise<void>),
|
|
96
|
+
maybeHandler?: (ctx: Message) => Promise<void>,
|
|
97
|
+
) {
|
|
98
|
+
if (typeof filtersOrHandler === "function") {
|
|
99
|
+
this.handlers["message"].push({
|
|
100
|
+
filters: [],
|
|
101
|
+
handler: filtersOrHandler,
|
|
102
|
+
prefix,
|
|
103
|
+
});
|
|
104
|
+
} else if (Array.isArray(filtersOrHandler) && maybeHandler) {
|
|
105
|
+
this.handlers["message"].push({
|
|
106
|
+
filters: filtersOrHandler,
|
|
107
|
+
handler: maybeHandler,
|
|
108
|
+
prefix,
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
throw new Error("Invalid arguments for command()");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { inspect } from "util";
|
|
2
|
+
import { Client } from "../../..";
|
|
3
|
+
import { DecoratorsTypes } from "../types/index.type";
|
|
4
|
+
|
|
5
|
+
class Activities implements DecoratorsTypes.ShowActivities {
|
|
6
|
+
type: string;
|
|
7
|
+
object_guid: string;
|
|
8
|
+
object_type: string;
|
|
9
|
+
user_activity_guid: string;
|
|
10
|
+
store: Record<string, any> = {};
|
|
11
|
+
|
|
12
|
+
declare client: Client;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
client: Client,
|
|
16
|
+
private update: DecoratorsTypes.ShowActivities,
|
|
17
|
+
) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
|
|
20
|
+
this.type = update.type;
|
|
21
|
+
this.object_guid = update.object_guid;
|
|
22
|
+
this.object_type = update.object_type;
|
|
23
|
+
this.user_activity_guid = update.user_activity_guid;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[inspect.custom]() {
|
|
27
|
+
return this.update;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default Activities;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { inspect } from "util";
|
|
2
|
+
import { Client } from "../../..";
|
|
3
|
+
import { DecoratorsTypes } from "../types/index.type";
|
|
4
|
+
|
|
5
|
+
class Chat implements DecoratorsTypes.ChatUpdates {
|
|
6
|
+
object_guid: string;
|
|
7
|
+
action: string;
|
|
8
|
+
chat: DecoratorsTypes.Chat;
|
|
9
|
+
updated_parameters: string[];
|
|
10
|
+
timestamp: string;
|
|
11
|
+
type: string;
|
|
12
|
+
store: Record<string, any> = {};
|
|
13
|
+
|
|
14
|
+
declare client: Client;
|
|
15
|
+
|
|
16
|
+
constructor(client: Client, private update: DecoratorsTypes.ChatUpdates) {
|
|
17
|
+
this.client = client;
|
|
18
|
+
|
|
19
|
+
this.object_guid = update.object_guid;
|
|
20
|
+
this.action = update.action;
|
|
21
|
+
this.chat = update.chat;
|
|
22
|
+
this.updated_parameters = update.updated_parameters;
|
|
23
|
+
this.timestamp = update.timestamp;
|
|
24
|
+
this.type = update.type;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
[inspect.custom]() {
|
|
28
|
+
return this.update
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default Chat;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
8
|
+
export const ContextConstructors = {
|
|
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
|
+
>;
|