rubjs 3.1.5 → 3.2.0
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 +3 -0
- package/lib/core/bot/bot.d.ts +2 -2
- package/lib/core/bot/bot.js +3 -3
- package/lib/core/bot/contexts/message.context.d.ts +3 -3
- package/lib/core/bot/contexts/message.context.js +2 -2
- package/lib/core/bot/contexts/update.context.d.ts +17 -0
- package/lib/core/bot/contexts/update.context.js +39 -0
- package/lib/core/bot/filters.d.ts +1 -1
- package/lib/core/bot/methods/utilities/handleUpdates.js +3 -3
- package/lib/core/bot/types/bot.type.d.ts +2 -2
- package/lib/index.d.ts +5 -2
- package/lib/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,9 @@ bot.run();
|
|
|
72
72
|
### ابزارهای داخلی توسعه
|
|
73
73
|
مثل `Utils.Bold`, `Utils.Italic` و ... برای زیباتر کردن پاسخها به کاربر.
|
|
74
74
|
|
|
75
|
+
### راه اندازی وبسایت همزمان با ربات
|
|
76
|
+
با rubjs میتوانید ربات را همزمان با وبسایت استقرار کنید | [اموزش](https://hadi-rostami.github.io/rubjs-docs/blog/running-website-and-bot-simultaneously-with-rubjs)
|
|
77
|
+
|
|
75
78
|
|
|
76
79
|
</div>
|
|
77
80
|
|
package/lib/core/bot/bot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import SessionManager from '../../utils/session';
|
|
2
|
-
import Message from './contexts/
|
|
2
|
+
import Message from './contexts/update.context';
|
|
3
3
|
import Methods from './methods';
|
|
4
4
|
import Network from './network';
|
|
5
5
|
import { BotType, ContextMap, Handler, NestedFilter, SessionType } from './types/bot.type';
|
|
@@ -20,6 +20,6 @@ declare class Bot extends Methods {
|
|
|
20
20
|
on<T extends keyof typeof this.handlers>(type: T, handler: (ctx: ContextMap[T]) => Promise<void>): void;
|
|
21
21
|
on<T extends keyof typeof this.handlers>(type: T, filters: NestedFilter<ContextMap[T]>, handler: (ctx: ContextMap[T]) => Promise<void>): void;
|
|
22
22
|
command(prefix: string | RegExp, handler: (ctx: Message) => Promise<void>): void;
|
|
23
|
-
command(prefix: string | RegExp, filters: NestedFilter<ContextMap['
|
|
23
|
+
command(prefix: string | RegExp, filters: NestedFilter<ContextMap['update']>, handler: (ctx: Message) => Promise<void>): void;
|
|
24
24
|
}
|
|
25
25
|
export default Bot;
|
package/lib/core/bot/bot.js
CHANGED
|
@@ -14,7 +14,7 @@ class Bot extends methods_1.default {
|
|
|
14
14
|
this.BASE_URL = `https://botapi.rubika.ir/v3`;
|
|
15
15
|
this.initialize = false;
|
|
16
16
|
this.sendToken = '';
|
|
17
|
-
this.handlers = { inline: [],
|
|
17
|
+
this.handlers = { inline: [], update: [] };
|
|
18
18
|
this.sessionDB = new session_1.default(token, undefined, 'BOT');
|
|
19
19
|
this.network = new network_1.default(this);
|
|
20
20
|
this.server = (0, fastify_1.default)();
|
|
@@ -36,14 +36,14 @@ class Bot extends methods_1.default {
|
|
|
36
36
|
}
|
|
37
37
|
command(prefix, filtersOrHandler, maybeHandler) {
|
|
38
38
|
if (typeof filtersOrHandler === 'function') {
|
|
39
|
-
this.handlers.
|
|
39
|
+
this.handlers.update.push({
|
|
40
40
|
filters: [],
|
|
41
41
|
handler: filtersOrHandler,
|
|
42
42
|
prefix,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
else if (Array.isArray(filtersOrHandler) && maybeHandler) {
|
|
46
|
-
this.handlers.
|
|
46
|
+
this.handlers.update.push({
|
|
47
47
|
filters: filtersOrHandler,
|
|
48
48
|
handler: maybeHandler,
|
|
49
49
|
prefix,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bot } from '../../..';
|
|
2
|
-
import { PaymentStatus, Update, UpdateTypeEnum, Message as MessageUpdate, Keypad, ChatKeypadTypeEnum, InlineKeypad } from '../types/models';
|
|
3
|
-
declare class
|
|
2
|
+
import { PaymentStatus, Update as UpdateMessage, UpdateTypeEnum, Message as MessageUpdate, Keypad, ChatKeypadTypeEnum, InlineKeypad } from '../types/models';
|
|
3
|
+
declare class Update implements UpdateMessage {
|
|
4
4
|
type: UpdateTypeEnum;
|
|
5
5
|
chat_id: string;
|
|
6
6
|
removed_message_id?: string;
|
|
@@ -14,4 +14,4 @@ declare class Message implements Update {
|
|
|
14
14
|
forward(to_chat_id: string, disable_notification?: boolean): Promise<import("../types/models").SendMessage | undefined>;
|
|
15
15
|
delete(): Promise<import("../types/models").SendMessage | undefined>;
|
|
16
16
|
}
|
|
17
|
-
export default
|
|
17
|
+
export default Update;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class
|
|
3
|
+
class Update {
|
|
4
4
|
constructor(bot, update) {
|
|
5
5
|
this.store = {};
|
|
6
6
|
Object.defineProperty(this, 'bot', {
|
|
@@ -36,4 +36,4 @@ class Message {
|
|
|
36
36
|
return await this.bot.deleteMessage(this.chat_id, message_id);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
exports.default =
|
|
39
|
+
exports.default = Update;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Bot } from '../../..';
|
|
2
|
+
import { PaymentStatus, Update as UpdateMessage, UpdateTypeEnum, Message as MessageUpdate, Keypad, ChatKeypadTypeEnum, InlineKeypad } from '../types/models';
|
|
3
|
+
declare class Update implements UpdateMessage {
|
|
4
|
+
type: UpdateTypeEnum;
|
|
5
|
+
chat_id: string;
|
|
6
|
+
removed_message_id?: string;
|
|
7
|
+
new_message?: MessageUpdate;
|
|
8
|
+
updated_message?: MessageUpdate;
|
|
9
|
+
updated_payment?: PaymentStatus;
|
|
10
|
+
store: Record<string, any>;
|
|
11
|
+
bot: Bot;
|
|
12
|
+
constructor(bot: Bot, update: Update);
|
|
13
|
+
reply(text: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../types/models").SendMessage>;
|
|
14
|
+
forward(to_chat_id: string, disable_notification?: boolean): Promise<import("../types/models").SendMessage | undefined>;
|
|
15
|
+
delete(): Promise<import("../types/models").SendMessage | undefined>;
|
|
16
|
+
}
|
|
17
|
+
export default Update;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Update {
|
|
4
|
+
constructor(bot, update) {
|
|
5
|
+
this.store = {};
|
|
6
|
+
Object.defineProperty(this, 'bot', {
|
|
7
|
+
value: bot,
|
|
8
|
+
enumerable: false,
|
|
9
|
+
writable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
});
|
|
12
|
+
this.type = update.type;
|
|
13
|
+
this.chat_id = update.chat_id;
|
|
14
|
+
if (update?.new_message)
|
|
15
|
+
this.new_message = update?.new_message;
|
|
16
|
+
if (update?.updated_message)
|
|
17
|
+
this.updated_message = update?.updated_message;
|
|
18
|
+
if (update?.updated_payment)
|
|
19
|
+
this.updated_payment = update?.updated_payment;
|
|
20
|
+
if (update.removed_message_id)
|
|
21
|
+
this.removed_message_id = update.removed_message_id;
|
|
22
|
+
}
|
|
23
|
+
async reply(text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
24
|
+
return await this.bot.sendMessage(this.chat_id, text, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
25
|
+
}
|
|
26
|
+
async forward(to_chat_id, disable_notification = false) {
|
|
27
|
+
const message_id = this.new_message?.message_id || this.updated_message?.message_id;
|
|
28
|
+
if (!message_id)
|
|
29
|
+
return;
|
|
30
|
+
return await this.bot.forwardMessage(this.chat_id, message_id, to_chat_id, disable_notification);
|
|
31
|
+
}
|
|
32
|
+
async delete() {
|
|
33
|
+
const message_id = this.new_message?.message_id || this.updated_message?.message_id;
|
|
34
|
+
if (!message_id)
|
|
35
|
+
return;
|
|
36
|
+
return await this.bot.deleteMessage(this.chat_id, message_id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = Update;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const update_context_1 = __importDefault(require("../../contexts/update.context"));
|
|
7
7
|
const inline_context_1 = __importDefault(require("../../contexts/inline.context"));
|
|
8
8
|
const models_1 = require("../../types/models");
|
|
9
9
|
const checkFilters_1 = require("../../../../utils/checkFilters");
|
|
@@ -11,8 +11,8 @@ const checkTypes = [models_1.UpdateTypeEnum.UpdatedMessage, models_1.UpdateTypeE
|
|
|
11
11
|
async function handleUpdates(req, res) {
|
|
12
12
|
const data = req.body;
|
|
13
13
|
if (data?.update) {
|
|
14
|
-
for (let { prefix, filters, handler } of this.handlers.
|
|
15
|
-
const ctx = new
|
|
14
|
+
for (let { prefix, filters, handler } of this.handlers.update) {
|
|
15
|
+
const ctx = new update_context_1.default(this, data.update);
|
|
16
16
|
const passed = await (0, checkFilters_1.checkFilters)(ctx, filters);
|
|
17
17
|
if (passed) {
|
|
18
18
|
if (prefix) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import InlineMessage from '../contexts/inline.context';
|
|
2
|
-
import
|
|
2
|
+
import Update from '../contexts/update.context';
|
|
3
3
|
export interface Session {
|
|
4
4
|
iv: string;
|
|
5
5
|
enData: string;
|
|
@@ -16,7 +16,7 @@ export interface BotType {
|
|
|
16
16
|
start_message: string;
|
|
17
17
|
}
|
|
18
18
|
export interface ContextMap {
|
|
19
|
-
|
|
19
|
+
update: Update;
|
|
20
20
|
inline: InlineMessage;
|
|
21
21
|
}
|
|
22
22
|
export type FilterFn<T> = (ctx: T) => boolean | Promise<boolean>;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ import ClientFilters from './core/client/filters';
|
|
|
3
3
|
import ClientUtils from './utils/utils';
|
|
4
4
|
import Bot from './core/bot/bot';
|
|
5
5
|
import BotFilters from './core/bot/filters';
|
|
6
|
-
import { RubPlugin } from './core/client/types/client.type';
|
|
6
|
+
import type { RubPlugin } from './core/client/types/client.type';
|
|
7
7
|
import type MessageType from './core/client/contexts/message.type';
|
|
8
8
|
import type ActivitiesType from './core/client/contexts/activities.type';
|
|
9
9
|
import type ChatType from './core/client/contexts/chat.type';
|
|
10
10
|
import type NotificationsType from './core/client/contexts/notifications.type';
|
|
11
|
+
import type InlineMessageType from './core/bot/contexts/inline.context';
|
|
12
|
+
import type UpdateType from './core/bot/contexts/update.context';
|
|
11
13
|
import * as Clients from './clients';
|
|
12
|
-
export { Client, ClientFilters, ClientUtils, Bot, BotFilters,
|
|
14
|
+
export { Client, ClientFilters, ClientUtils, Bot, BotFilters, Clients };
|
|
15
|
+
export type { ChatType, MessageType, ActivitiesType, NotificationsType, RubPlugin, InlineMessageType, UpdateType, };
|
|
13
16
|
export default Client;
|
package/lib/index.js
CHANGED