@aracna/telegram-bot 1.9.14 → 2.0.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/apis/telegram-api.d.ts +9 -0
- package/apis/telegram-api.js +55 -0
- package/apis/telegram-file-api.d.ts +7 -0
- package/apis/telegram-file-api.js +14 -0
- package/classes/client.d.ts +46 -0
- package/classes/client.js +409 -0
- package/definitions/constants.d.ts +10 -0
- package/definitions/constants.js +53 -1
- package/definitions/enums.d.ts +1 -20
- package/definitions/enums.js +2 -22
- package/definitions/interfaces.d.ts +83 -76
- package/definitions/telegram-api-definitions.d.ts +12 -0
- package/definitions/telegram-api-definitions.js +2 -0
- package/definitions/types.d.ts +3 -2
- package/index.d.ts +475 -438
- package/index.js +236 -20
- package/loggers/class-logger.d.ts +2 -0
- package/loggers/{module.logger.js → class-logger.js} +2 -2
- package/package.json +12 -3
- package/requests/add-requests.d.ts +3 -0
- package/requests/add-requests.js +14 -0
- package/requests/answer-requests.d.ts +7 -0
- package/requests/answer-requests.js +23 -0
- package/requests/approve-requests.d.ts +3 -0
- package/requests/approve-requests.js +7 -0
- package/requests/ban-requests.d.ts +4 -0
- package/requests/ban-requests.js +11 -0
- package/requests/close-requests.d.ts +4 -0
- package/requests/close-requests.js +11 -0
- package/requests/copy-requests.d.ts +4 -0
- package/requests/copy-requests.js +11 -0
- package/requests/create-requests.d.ts +7 -0
- package/requests/create-requests.js +30 -0
- package/requests/decline-requests.d.ts +3 -0
- package/requests/decline-requests.js +7 -0
- package/requests/delete-requests.d.ts +10 -0
- package/requests/delete-requests.js +35 -0
- package/requests/download-requests.d.ts +3 -0
- package/requests/download-requests.js +29 -0
- package/requests/edit-requests.d.ts +12 -0
- package/requests/edit-requests.js +46 -0
- package/requests/export-requests.d.ts +3 -0
- package/requests/export-requests.js +7 -0
- package/requests/forward-requests.d.ts +4 -0
- package/requests/forward-requests.js +11 -0
- package/requests/get-requests.d.ts +23 -0
- package/requests/get-requests.js +92 -0
- package/requests/hide-requests.d.ts +3 -0
- package/requests/hide-requests.js +7 -0
- package/requests/leave-requests.d.ts +3 -0
- package/requests/leave-requests.js +7 -0
- package/requests/log-requests.d.ts +2 -0
- package/requests/log-requests.js +7 -0
- package/requests/pin-requests.d.ts +3 -0
- package/requests/pin-requests.js +7 -0
- package/requests/promote-requests.d.ts +3 -0
- package/requests/promote-requests.js +7 -0
- package/requests/refund-requests.d.ts +3 -0
- package/requests/refund-requests.js +7 -0
- package/requests/reopen-requests.d.ts +4 -0
- package/requests/reopen-requests.js +11 -0
- package/requests/replace-requests.d.ts +3 -0
- package/requests/replace-requests.js +14 -0
- package/requests/restrict-requests.d.ts +3 -0
- package/requests/restrict-requests.js +7 -0
- package/requests/revoke-requests.d.ts +3 -0
- package/requests/revoke-requests.js +7 -0
- package/requests/send-requests.d.ts +24 -0
- package/requests/send-requests.js +102 -0
- package/requests/set-requests.d.ts +24 -0
- package/requests/set-requests.js +95 -0
- package/requests/stop-requests.d.ts +4 -0
- package/requests/stop-requests.js +11 -0
- package/requests/unban-requests.d.ts +4 -0
- package/requests/unban-requests.js +11 -0
- package/requests/unhide-requests.d.ts +3 -0
- package/requests/unhide-requests.js +7 -0
- package/requests/unpin-requests.d.ts +6 -0
- package/requests/unpin-requests.js +19 -0
- package/requests/upload-requests.d.ts +3 -0
- package/requests/upload-requests.js +7 -0
- package/requests/webhook-requests.d.ts +6 -0
- package/requests/webhook-requests.js +20 -0
- package/utils/callback-query-utils.d.ts +3 -0
- package/utils/callback-query-utils.js +25 -0
- package/utils/command-utils.d.ts +5 -0
- package/utils/command-utils.js +28 -0
- package/utils/context-utils.d.ts +11 -0
- package/utils/context-utils.js +42 -0
- package/utils/html-utils.d.ts +2 -0
- package/utils/html-utils.js +18 -0
- package/utils/inline-keyboard-utils.d.ts +12 -0
- package/utils/inline-keyboard-utils.js +43 -0
- package/utils/reply-to-message-utils.d.ts +6 -0
- package/utils/reply-to-message-utils.js +36 -0
- package/utils/start-message-utils.d.ts +6 -0
- package/utils/start-message-utils.js +40 -0
- package/builders/button.builder.d.ts +0 -11
- package/builders/button.builder.js +0 -31
- package/childs/add.d.ts +0 -6
- package/childs/add.js +0 -10
- package/childs/answer.d.ts +0 -10
- package/childs/answer.js +0 -22
- package/childs/approve.d.ts +0 -6
- package/childs/approve.js +0 -10
- package/childs/ban.d.ts +0 -7
- package/childs/ban.js +0 -13
- package/childs/close.d.ts +0 -7
- package/childs/close.js +0 -13
- package/childs/copy.d.ts +0 -7
- package/childs/copy.js +0 -13
- package/childs/create.d.ts +0 -10
- package/childs/create.js +0 -26
- package/childs/decline.d.ts +0 -6
- package/childs/decline.js +0 -10
- package/childs/delete.d.ts +0 -13
- package/childs/delete.js +0 -31
- package/childs/download.d.ts +0 -8
- package/childs/download.js +0 -32
- package/childs/edit.d.ts +0 -14
- package/childs/edit.js +0 -38
- package/childs/export.d.ts +0 -6
- package/childs/export.js +0 -10
- package/childs/forward.d.ts +0 -7
- package/childs/forward.js +0 -13
- package/childs/get.d.ts +0 -26
- package/childs/get.js +0 -73
- package/childs/hide.d.ts +0 -6
- package/childs/hide.js +0 -10
- package/childs/leave.d.ts +0 -6
- package/childs/leave.js +0 -10
- package/childs/log.d.ts +0 -5
- package/childs/log.js +0 -10
- package/childs/pin.d.ts +0 -6
- package/childs/pin.js +0 -10
- package/childs/polling.d.ts +0 -9
- package/childs/polling.js +0 -34
- package/childs/privates/send.private.d.ts +0 -8
- package/childs/privates/send.private.js +0 -19
- package/childs/promote.d.ts +0 -6
- package/childs/promote.js +0 -10
- package/childs/refund.d.ts +0 -6
- package/childs/refund.js +0 -14
- package/childs/reopen.d.ts +0 -7
- package/childs/reopen.js +0 -13
- package/childs/replace.d.ts +0 -6
- package/childs/replace.js +0 -10
- package/childs/restrict.d.ts +0 -6
- package/childs/restrict.js +0 -13
- package/childs/revoke.d.ts +0 -6
- package/childs/revoke.js +0 -10
- package/childs/send.d.ts +0 -32
- package/childs/send.js +0 -111
- package/childs/set.d.ts +0 -28
- package/childs/set.js +0 -82
- package/childs/stop.d.ts +0 -7
- package/childs/stop.js +0 -13
- package/childs/unban.d.ts +0 -7
- package/childs/unban.js +0 -13
- package/childs/unhide.d.ts +0 -6
- package/childs/unhide.js +0 -10
- package/childs/unpin.d.ts +0 -9
- package/childs/unpin.js +0 -23
- package/childs/upload.d.ts +0 -6
- package/childs/upload.js +0 -10
- package/childs/webhook.d.ts +0 -10
- package/childs/webhook.js +0 -28
- package/loggers/module.logger.d.ts +0 -2
- package/modules/api.d.ts +0 -5
- package/modules/api.js +0 -24
- package/modules/builder.d.ts +0 -4
- package/modules/builder.js +0 -8
- package/modules/child.d.ts +0 -5
- package/modules/child.js +0 -10
- package/modules/configuration.d.ts +0 -8
- package/modules/configuration.js +0 -10
- package/modules/dummy.d.ts +0 -9
- package/modules/dummy.js +0 -56
- package/modules/telegram.d.ts +0 -109
- package/modules/telegram.js +0 -391
- package/utils/callback.query.utils.d.ts +0 -5
- package/utils/callback.query.utils.js +0 -26
- package/utils/command.utils.d.ts +0 -7
- package/utils/command.utils.js +0 -29
- package/utils/context.utils.d.ts +0 -13
- package/utils/context.utils.js +0 -41
- package/utils/html.utils.d.ts +0 -5
- package/utils/html.utils.js +0 -20
- package/utils/inline.keyboard.utils.d.ts +0 -4
- package/utils/inline.keyboard.utils.js +0 -26
- package/utils/reply.to.message.utils.d.ts +0 -6
- package/utils/reply.to.message.utils.js +0 -27
- package/utils/start.utils.d.ts +0 -7
- package/utils/start.utils.js +0 -32
package/modules/dummy.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Dummy = void 0;
|
|
4
|
-
const enums_1 = require("../definitions/enums");
|
|
5
|
-
class Dummy {
|
|
6
|
-
static get callbackQueryBody() {
|
|
7
|
-
return {
|
|
8
|
-
c: undefined,
|
|
9
|
-
d: 0,
|
|
10
|
-
t: ''
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
static get configurationAPI() {
|
|
14
|
-
return {
|
|
15
|
-
post: {
|
|
16
|
-
callback: {
|
|
17
|
-
success: () => null
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
static get configurationDefault() {
|
|
23
|
-
return {
|
|
24
|
-
buttons: {
|
|
25
|
-
callback: async () => [],
|
|
26
|
-
game: async () => [],
|
|
27
|
-
login: async () => [],
|
|
28
|
-
pay: async () => [],
|
|
29
|
-
query: async () => [],
|
|
30
|
-
queryCurrentChat: async () => [],
|
|
31
|
-
text: async () => [],
|
|
32
|
-
url: async () => []
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
static get configurationHandler() {
|
|
37
|
-
return { send: { buttons: { empty: () => new Error() } } };
|
|
38
|
-
}
|
|
39
|
-
static get handler() {
|
|
40
|
-
return {
|
|
41
|
-
id: '',
|
|
42
|
-
key: '',
|
|
43
|
-
middleware: () => null,
|
|
44
|
-
options: {
|
|
45
|
-
deleteOnCallbackQuery: true,
|
|
46
|
-
deleteOnMessageStart: true,
|
|
47
|
-
deleteOnReply: true
|
|
48
|
-
},
|
|
49
|
-
type: enums_1.UpdateType.MESSAGE
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
static get messageBody() {
|
|
53
|
-
return { chatID: undefined, data: undefined, type: '' };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.Dummy = Dummy;
|
package/modules/telegram.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { BotCommand, CallbackQuery, ChatJoinRequest, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll, PollAnswer, PreCheckoutQuery, ShippingQuery, Update } from '@aracna/telegram-bot-types';
|
|
2
|
-
import { Add } from '../childs/add';
|
|
3
|
-
import { Answer } from '../childs/answer';
|
|
4
|
-
import { Approve } from '../childs/approve';
|
|
5
|
-
import { Ban } from '../childs/ban';
|
|
6
|
-
import { Close } from '../childs/close';
|
|
7
|
-
import { Copy } from '../childs/copy';
|
|
8
|
-
import { Create } from '../childs/create';
|
|
9
|
-
import { Decline } from '../childs/decline';
|
|
10
|
-
import { Delete } from '../childs/delete';
|
|
11
|
-
import { Download } from '../childs/download';
|
|
12
|
-
import { Edit } from '../childs/edit';
|
|
13
|
-
import { Export } from '../childs/export';
|
|
14
|
-
import { Forward } from '../childs/forward';
|
|
15
|
-
import { Get } from '../childs/get';
|
|
16
|
-
import { Hide } from '../childs/hide';
|
|
17
|
-
import { Leave } from '../childs/leave';
|
|
18
|
-
import { Log } from '../childs/log';
|
|
19
|
-
import { Pin } from '../childs/pin';
|
|
20
|
-
import { Polling } from '../childs/polling';
|
|
21
|
-
import { Promote } from '../childs/promote';
|
|
22
|
-
import { Refund } from '../childs/refund';
|
|
23
|
-
import { Reopen } from '../childs/reopen';
|
|
24
|
-
import { Replace } from '../childs/replace';
|
|
25
|
-
import { Restrict } from '../childs/restrict';
|
|
26
|
-
import { Revoke } from '../childs/revoke';
|
|
27
|
-
import { Send } from '../childs/send';
|
|
28
|
-
import { Set } from '../childs/set';
|
|
29
|
-
import { Stop } from '../childs/stop';
|
|
30
|
-
import { Unban } from '../childs/unban';
|
|
31
|
-
import { Unhide } from '../childs/unhide';
|
|
32
|
-
import { Unpin } from '../childs/unpin';
|
|
33
|
-
import { Upload } from '../childs/upload';
|
|
34
|
-
import { Webhook } from '../childs/webhook';
|
|
35
|
-
import { UpdateType } from '../definitions/enums';
|
|
36
|
-
import type { Handler, HandlerOptions, TelegramName } from '../definitions/interfaces';
|
|
37
|
-
import type { HandlerMiddleware } from '../definitions/types';
|
|
38
|
-
import { API } from './api';
|
|
39
|
-
import { Builder } from './builder';
|
|
40
|
-
export declare class Telegram {
|
|
41
|
-
/** INTERNAL */
|
|
42
|
-
api: API;
|
|
43
|
-
handlers: Handler[];
|
|
44
|
-
hostname: string;
|
|
45
|
-
id: bigint;
|
|
46
|
-
name: TelegramName;
|
|
47
|
-
port: number;
|
|
48
|
-
token: string;
|
|
49
|
-
username: string;
|
|
50
|
-
/** BUILDERS */
|
|
51
|
-
builder: Builder;
|
|
52
|
-
/** CHILDS */
|
|
53
|
-
add: Add;
|
|
54
|
-
answer: Answer;
|
|
55
|
-
approve: Approve;
|
|
56
|
-
ban: Ban;
|
|
57
|
-
close: Close;
|
|
58
|
-
copy: Copy;
|
|
59
|
-
create: Create;
|
|
60
|
-
decline: Decline;
|
|
61
|
-
delete: Delete;
|
|
62
|
-
download: Download;
|
|
63
|
-
edit: Edit;
|
|
64
|
-
export: Export;
|
|
65
|
-
forward: Forward;
|
|
66
|
-
get: Get;
|
|
67
|
-
hide: Hide;
|
|
68
|
-
leave: Leave;
|
|
69
|
-
log: Log;
|
|
70
|
-
pin: Pin;
|
|
71
|
-
polling: Polling;
|
|
72
|
-
promote: Promote;
|
|
73
|
-
refund: Refund;
|
|
74
|
-
reopen: Reopen;
|
|
75
|
-
replace: Replace;
|
|
76
|
-
restrict: Restrict;
|
|
77
|
-
revoke: Revoke;
|
|
78
|
-
send: Send;
|
|
79
|
-
set: Set;
|
|
80
|
-
stop: Stop;
|
|
81
|
-
unban: Unban;
|
|
82
|
-
unhide: Unhide;
|
|
83
|
-
unpin: Unpin;
|
|
84
|
-
upload: Upload;
|
|
85
|
-
webhook: Webhook;
|
|
86
|
-
constructor(token: string, hostname?: string, port?: number);
|
|
87
|
-
on<T extends UpdateType, U extends HandlerOptions>(type: T, middleware: HandlerMiddleware<T>, key?: string, description?: string, options?: U): void;
|
|
88
|
-
handle(update: Update): void;
|
|
89
|
-
handleCallbackQuery(query: CallbackQuery): Handler;
|
|
90
|
-
handleChannelPost(post: Message): Handler;
|
|
91
|
-
handleChatJoinRequest(request: ChatJoinRequest): Handler;
|
|
92
|
-
handleChatMember(member: ChatMemberUpdated): Handler;
|
|
93
|
-
handleChosenInlineResult(result: ChosenInlineResult): Handler;
|
|
94
|
-
handleDocument(document: Message): Handler;
|
|
95
|
-
handleEditedChannelPost(post: Message): Handler;
|
|
96
|
-
handleEditedMessage(message: Message): Handler;
|
|
97
|
-
handleInlineQuery(query: InlineQuery): Handler;
|
|
98
|
-
handleMessage(message: Message): Handler;
|
|
99
|
-
handleMyChatMember(member: ChatMemberUpdated): Handler;
|
|
100
|
-
handlePoll(poll: Poll): Handler;
|
|
101
|
-
handlePollAnswer(answer: PollAnswer): Handler;
|
|
102
|
-
handlePreCheckoutQuery(query: PreCheckoutQuery): Handler;
|
|
103
|
-
handleReplyToMessage(reply: Message): Handler;
|
|
104
|
-
handleShippingQuery(query: ShippingQuery): Handler;
|
|
105
|
-
handleStart(start: Message): Handler;
|
|
106
|
-
private findMatchingHandler;
|
|
107
|
-
get commands(): BotCommand[];
|
|
108
|
-
private get handlerIDs();
|
|
109
|
-
}
|
package/modules/telegram.js
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Telegram = void 0;
|
|
4
|
-
const core_1 = require("@aracna/core");
|
|
5
|
-
const add_1 = require("../childs/add");
|
|
6
|
-
const answer_1 = require("../childs/answer");
|
|
7
|
-
const approve_1 = require("../childs/approve");
|
|
8
|
-
const ban_1 = require("../childs/ban");
|
|
9
|
-
const close_1 = require("../childs/close");
|
|
10
|
-
const copy_1 = require("../childs/copy");
|
|
11
|
-
const create_1 = require("../childs/create");
|
|
12
|
-
const decline_1 = require("../childs/decline");
|
|
13
|
-
const delete_1 = require("../childs/delete");
|
|
14
|
-
const download_1 = require("../childs/download");
|
|
15
|
-
const edit_1 = require("../childs/edit");
|
|
16
|
-
const export_1 = require("../childs/export");
|
|
17
|
-
const forward_1 = require("../childs/forward");
|
|
18
|
-
const get_1 = require("../childs/get");
|
|
19
|
-
const hide_1 = require("../childs/hide");
|
|
20
|
-
const leave_1 = require("../childs/leave");
|
|
21
|
-
const log_1 = require("../childs/log");
|
|
22
|
-
const pin_1 = require("../childs/pin");
|
|
23
|
-
const polling_1 = require("../childs/polling");
|
|
24
|
-
const promote_1 = require("../childs/promote");
|
|
25
|
-
const refund_1 = require("../childs/refund");
|
|
26
|
-
const reopen_1 = require("../childs/reopen");
|
|
27
|
-
const replace_1 = require("../childs/replace");
|
|
28
|
-
const restrict_1 = require("../childs/restrict");
|
|
29
|
-
const revoke_1 = require("../childs/revoke");
|
|
30
|
-
const send_1 = require("../childs/send");
|
|
31
|
-
const set_1 = require("../childs/set");
|
|
32
|
-
const stop_1 = require("../childs/stop");
|
|
33
|
-
const unban_1 = require("../childs/unban");
|
|
34
|
-
const unhide_1 = require("../childs/unhide");
|
|
35
|
-
const unpin_1 = require("../childs/unpin");
|
|
36
|
-
const upload_1 = require("../childs/upload");
|
|
37
|
-
const webhook_1 = require("../childs/webhook");
|
|
38
|
-
const enums_1 = require("../definitions/enums");
|
|
39
|
-
const module_logger_1 = require("../loggers/module.logger");
|
|
40
|
-
const callback_query_utils_1 = require("../utils/callback.query.utils");
|
|
41
|
-
const command_utils_1 = require("../utils/command.utils");
|
|
42
|
-
const reply_to_message_utils_1 = require("../utils/reply.to.message.utils");
|
|
43
|
-
const start_utils_1 = require("../utils/start.utils");
|
|
44
|
-
const api_1 = require("./api");
|
|
45
|
-
const builder_1 = require("./builder");
|
|
46
|
-
const dummy_1 = require("./dummy");
|
|
47
|
-
class Telegram {
|
|
48
|
-
/** INTERNAL */
|
|
49
|
-
api;
|
|
50
|
-
handlers;
|
|
51
|
-
hostname;
|
|
52
|
-
id;
|
|
53
|
-
name;
|
|
54
|
-
port;
|
|
55
|
-
token;
|
|
56
|
-
username;
|
|
57
|
-
/** BUILDERS */
|
|
58
|
-
builder;
|
|
59
|
-
/** CHILDS */
|
|
60
|
-
add;
|
|
61
|
-
answer;
|
|
62
|
-
approve;
|
|
63
|
-
ban;
|
|
64
|
-
close;
|
|
65
|
-
copy;
|
|
66
|
-
create;
|
|
67
|
-
decline;
|
|
68
|
-
delete;
|
|
69
|
-
download;
|
|
70
|
-
edit;
|
|
71
|
-
export;
|
|
72
|
-
forward;
|
|
73
|
-
get;
|
|
74
|
-
hide;
|
|
75
|
-
leave;
|
|
76
|
-
log;
|
|
77
|
-
pin;
|
|
78
|
-
polling;
|
|
79
|
-
promote;
|
|
80
|
-
refund;
|
|
81
|
-
reopen;
|
|
82
|
-
replace;
|
|
83
|
-
restrict;
|
|
84
|
-
revoke;
|
|
85
|
-
send;
|
|
86
|
-
set;
|
|
87
|
-
stop;
|
|
88
|
-
unban;
|
|
89
|
-
unhide;
|
|
90
|
-
unpin;
|
|
91
|
-
upload;
|
|
92
|
-
webhook;
|
|
93
|
-
constructor(token, hostname = '', port = (0, core_1.parseNumber)(process.env.PORT)) {
|
|
94
|
-
this.api = new api_1.API('https://api.telegram.org/bot' + token + '/');
|
|
95
|
-
this.handlers = [];
|
|
96
|
-
this.hostname = hostname;
|
|
97
|
-
this.name = { first: '', last: '' };
|
|
98
|
-
this.id = 0n;
|
|
99
|
-
this.port = port;
|
|
100
|
-
this.token = token;
|
|
101
|
-
this.username = '';
|
|
102
|
-
this.builder = new builder_1.Builder();
|
|
103
|
-
this.add = new add_1.Add(this);
|
|
104
|
-
this.answer = new answer_1.Answer(this);
|
|
105
|
-
this.approve = new approve_1.Approve(this);
|
|
106
|
-
this.ban = new ban_1.Ban(this);
|
|
107
|
-
this.close = new close_1.Close(this);
|
|
108
|
-
this.copy = new copy_1.Copy(this);
|
|
109
|
-
this.create = new create_1.Create(this);
|
|
110
|
-
this.decline = new decline_1.Decline(this);
|
|
111
|
-
this.delete = new delete_1.Delete(this);
|
|
112
|
-
this.download = new download_1.Download(this);
|
|
113
|
-
this.edit = new edit_1.Edit(this);
|
|
114
|
-
this.export = new export_1.Export(this);
|
|
115
|
-
this.forward = new forward_1.Forward(this);
|
|
116
|
-
this.get = new get_1.Get(this);
|
|
117
|
-
this.hide = new hide_1.Hide(this);
|
|
118
|
-
this.leave = new leave_1.Leave(this);
|
|
119
|
-
this.log = new log_1.Log(this);
|
|
120
|
-
this.pin = new pin_1.Pin(this);
|
|
121
|
-
this.polling = new polling_1.Polling(this);
|
|
122
|
-
this.promote = new promote_1.Promote(this);
|
|
123
|
-
this.refund = new refund_1.Refund(this);
|
|
124
|
-
this.reopen = new reopen_1.Reopen(this);
|
|
125
|
-
this.replace = new replace_1.Replace(this);
|
|
126
|
-
this.restrict = new restrict_1.Restrict(this);
|
|
127
|
-
this.revoke = new revoke_1.Revoke(this);
|
|
128
|
-
this.send = new send_1.Send(this);
|
|
129
|
-
this.set = new set_1.Set(this);
|
|
130
|
-
this.stop = new stop_1.Stop(this);
|
|
131
|
-
this.unban = new unban_1.Unban(this);
|
|
132
|
-
this.unhide = new unhide_1.Unhide(this);
|
|
133
|
-
this.unpin = new unpin_1.Unpin(this);
|
|
134
|
-
this.upload = new upload_1.Upload(this);
|
|
135
|
-
this.webhook = new webhook_1.Webhook(this);
|
|
136
|
-
this.get.me().then((v) => {
|
|
137
|
-
if (v instanceof Error)
|
|
138
|
-
return;
|
|
139
|
-
this.id = v.id;
|
|
140
|
-
this.name.first = v.first_name;
|
|
141
|
-
this.name.last = v.last_name ?? '';
|
|
142
|
-
this.username = v.username ?? '';
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
on(type, middleware, key, description, options) {
|
|
146
|
-
let handler, potential;
|
|
147
|
-
handler = dummy_1.Dummy.handler;
|
|
148
|
-
handler.description = description;
|
|
149
|
-
handler.id = (0, core_1.generateRandomString)({ blacklist: this.handlerIDs });
|
|
150
|
-
handler.key = key;
|
|
151
|
-
handler.middleware = middleware;
|
|
152
|
-
handler.type = type;
|
|
153
|
-
handler.options = (0, core_1.mergeObjects)(handler.options, options ?? {});
|
|
154
|
-
potential = this.findMatchingHandler(handler.type, handler.key);
|
|
155
|
-
if (potential.id) {
|
|
156
|
-
potential.middleware = middleware;
|
|
157
|
-
module_logger_1.ModuleLogger.debug('Telegram', 'register', `The handler has been updated.`, handler);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
this.handlers.push(handler);
|
|
161
|
-
module_logger_1.ModuleLogger.debug('Telegram', 'register', `The handler has been registered.`, handler);
|
|
162
|
-
}
|
|
163
|
-
handle(update) {
|
|
164
|
-
let handler;
|
|
165
|
-
switch (true) {
|
|
166
|
-
case (0, core_1.hasObjectProperty)(update, 'callback_query.data'):
|
|
167
|
-
handler = this.handleCallbackQuery(update.callback_query);
|
|
168
|
-
break;
|
|
169
|
-
case (0, core_1.hasObjectProperty)(update, 'channel_post'):
|
|
170
|
-
handler = this.handleChannelPost(update.channel_post);
|
|
171
|
-
break;
|
|
172
|
-
case (0, core_1.hasObjectProperty)(update, 'chat_join_request'):
|
|
173
|
-
handler = this.handleChatJoinRequest(update.chat_join_request);
|
|
174
|
-
break;
|
|
175
|
-
case (0, core_1.hasObjectProperty)(update, 'chat_member'):
|
|
176
|
-
handler = this.handleChatMember(update.chat_member);
|
|
177
|
-
break;
|
|
178
|
-
case (0, core_1.hasObjectProperty)(update, 'chosen_inline_result'):
|
|
179
|
-
handler = this.handleChosenInlineResult(update.chosen_inline_result);
|
|
180
|
-
break;
|
|
181
|
-
case (0, core_1.hasObjectProperty)(update, 'edited_channel_post'):
|
|
182
|
-
handler = this.handleEditedChannelPost(update.edited_channel_post);
|
|
183
|
-
break;
|
|
184
|
-
case (0, core_1.hasObjectProperty)(update, 'edited_message'):
|
|
185
|
-
handler = this.handleEditedMessage(update.edited_message);
|
|
186
|
-
break;
|
|
187
|
-
case (0, core_1.hasObjectProperty)(update, 'inline_query'):
|
|
188
|
-
handler = this.handleInlineQuery(update.inline_query);
|
|
189
|
-
break;
|
|
190
|
-
case (0, core_1.getObjectProperty)(update, 'message.text', '').includes('/start') &&
|
|
191
|
-
(0, core_1.getObjectProperty)(update, 'message.text', '').replace('/start', '').trim().length > 0:
|
|
192
|
-
handler = this.handleStart(update.message);
|
|
193
|
-
break;
|
|
194
|
-
case (0, core_1.hasObjectProperty)(update, 'message') && (0, core_1.hasObjectProperty)(update, 'message.reply_to_message.text'):
|
|
195
|
-
handler = this.handleReplyToMessage(update.message);
|
|
196
|
-
break;
|
|
197
|
-
case (0, core_1.hasObjectProperty)(update, 'message.text'):
|
|
198
|
-
handler = this.handleMessage(update.message);
|
|
199
|
-
break;
|
|
200
|
-
case (0, core_1.hasObjectProperty)(update, 'message.document') && (0, core_1.hasObjectProperty)(update, 'message.caption'):
|
|
201
|
-
handler = this.handleDocument(update.message);
|
|
202
|
-
break;
|
|
203
|
-
case (0, core_1.hasObjectProperty)(update, 'my_chat_member'):
|
|
204
|
-
handler = this.handleMyChatMember(update.my_chat_member);
|
|
205
|
-
break;
|
|
206
|
-
case (0, core_1.hasObjectProperty)(update, 'poll'):
|
|
207
|
-
handler = this.handlePoll(update.poll);
|
|
208
|
-
break;
|
|
209
|
-
case (0, core_1.hasObjectProperty)(update, 'poll_answer'):
|
|
210
|
-
handler = this.handlePollAnswer(update.poll_answer);
|
|
211
|
-
break;
|
|
212
|
-
case (0, core_1.hasObjectProperty)(update, 'pre_checkout_query'):
|
|
213
|
-
handler = this.handlePreCheckoutQuery(update.pre_checkout_query);
|
|
214
|
-
break;
|
|
215
|
-
case (0, core_1.hasObjectProperty)(update, 'shipping_query'):
|
|
216
|
-
handler = this.handleShippingQuery(update.shipping_query);
|
|
217
|
-
break;
|
|
218
|
-
default:
|
|
219
|
-
module_logger_1.ModuleLogger.error('Telegram', 'handle', `Failed to handle the update.`, update);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
handler.id
|
|
223
|
-
? module_logger_1.ModuleLogger.debug('Telegram', 'handle', `A ${handler.type} update has been handled.`, update, handler)
|
|
224
|
-
: module_logger_1.ModuleLogger.warn('Telegram', 'handle', `Failed to find the matching handler.`, update);
|
|
225
|
-
}
|
|
226
|
-
handleCallbackQuery(query) {
|
|
227
|
-
let handler, body;
|
|
228
|
-
body = callback_query_utils_1.CallbackQueryUtils.decodeBody(query.data);
|
|
229
|
-
(0, core_1.setObjectProperty)(query, 'body', body);
|
|
230
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.CALLBACK_QUERY, body.t);
|
|
231
|
-
if (!handler.id)
|
|
232
|
-
return handler;
|
|
233
|
-
handler.middleware(query);
|
|
234
|
-
if (handler.options.deleteOnCallbackQuery && query.message) {
|
|
235
|
-
this.delete.message(body.c ? query.from.id : query.message.chat.id, query.message.message_id);
|
|
236
|
-
}
|
|
237
|
-
return handler;
|
|
238
|
-
}
|
|
239
|
-
handleChannelPost(post) {
|
|
240
|
-
let handler;
|
|
241
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.CHANNEL_POST);
|
|
242
|
-
if (!handler.id)
|
|
243
|
-
return handler;
|
|
244
|
-
handler.middleware(post);
|
|
245
|
-
module_logger_1.ModuleLogger.debug('Telegram', 'handleChannelPost', `A ${handler.type} update has been handled.`, post, handler);
|
|
246
|
-
return handler;
|
|
247
|
-
}
|
|
248
|
-
handleChatJoinRequest(request) {
|
|
249
|
-
let handler;
|
|
250
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.CHAT_JOIN_REQUEST);
|
|
251
|
-
if (!handler.id)
|
|
252
|
-
return handler;
|
|
253
|
-
handler.middleware(request);
|
|
254
|
-
return handler;
|
|
255
|
-
}
|
|
256
|
-
handleChatMember(member) {
|
|
257
|
-
let handler;
|
|
258
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.CHAT_MEMBER);
|
|
259
|
-
if (!handler.id)
|
|
260
|
-
return handler;
|
|
261
|
-
handler.middleware(member);
|
|
262
|
-
return handler;
|
|
263
|
-
}
|
|
264
|
-
handleChosenInlineResult(result) {
|
|
265
|
-
let handler;
|
|
266
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.CHOSEN_INLINE_RESULT);
|
|
267
|
-
if (!handler.id)
|
|
268
|
-
return handler;
|
|
269
|
-
handler.middleware(result);
|
|
270
|
-
return handler;
|
|
271
|
-
}
|
|
272
|
-
handleDocument(document) {
|
|
273
|
-
let handler;
|
|
274
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.DOCUMENT, command_utils_1.CommandUtils.get(document.caption));
|
|
275
|
-
if (!handler.id)
|
|
276
|
-
return handler;
|
|
277
|
-
handler.middleware(document);
|
|
278
|
-
return handler;
|
|
279
|
-
}
|
|
280
|
-
handleEditedChannelPost(post) {
|
|
281
|
-
let handler;
|
|
282
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.EDITED_CHANNEL_POST);
|
|
283
|
-
if (!handler.id)
|
|
284
|
-
return handler;
|
|
285
|
-
handler.middleware(post);
|
|
286
|
-
return handler;
|
|
287
|
-
}
|
|
288
|
-
handleEditedMessage(message) {
|
|
289
|
-
let handler;
|
|
290
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.EDITED_MESSAGE);
|
|
291
|
-
if (!handler.id)
|
|
292
|
-
return handler;
|
|
293
|
-
handler.middleware(message);
|
|
294
|
-
return handler;
|
|
295
|
-
}
|
|
296
|
-
handleInlineQuery(query) {
|
|
297
|
-
let handler;
|
|
298
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.INLINE_QUERY);
|
|
299
|
-
if (!handler.id)
|
|
300
|
-
return handler;
|
|
301
|
-
handler.middleware(query);
|
|
302
|
-
return handler;
|
|
303
|
-
}
|
|
304
|
-
handleMessage(message) {
|
|
305
|
-
let handler;
|
|
306
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.MESSAGE, command_utils_1.CommandUtils.get(message.text));
|
|
307
|
-
if (!handler.id)
|
|
308
|
-
return handler;
|
|
309
|
-
handler.middleware(message);
|
|
310
|
-
return handler;
|
|
311
|
-
}
|
|
312
|
-
handleMyChatMember(member) {
|
|
313
|
-
let handler;
|
|
314
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.MY_CHAT_MEMBER);
|
|
315
|
-
if (!handler.id)
|
|
316
|
-
return handler;
|
|
317
|
-
handler.middleware(member);
|
|
318
|
-
return handler;
|
|
319
|
-
}
|
|
320
|
-
handlePoll(poll) {
|
|
321
|
-
let handler;
|
|
322
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.POLL);
|
|
323
|
-
if (!handler.id)
|
|
324
|
-
return handler;
|
|
325
|
-
handler.middleware(poll);
|
|
326
|
-
return handler;
|
|
327
|
-
}
|
|
328
|
-
handlePollAnswer(answer) {
|
|
329
|
-
let handler;
|
|
330
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.POLL_ANSWER);
|
|
331
|
-
if (!handler.id)
|
|
332
|
-
return handler;
|
|
333
|
-
handler.middleware(answer);
|
|
334
|
-
return handler;
|
|
335
|
-
}
|
|
336
|
-
handlePreCheckoutQuery(query) {
|
|
337
|
-
let handler;
|
|
338
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.PRE_CHECKOUT_QUERY);
|
|
339
|
-
if (!handler.id)
|
|
340
|
-
return handler;
|
|
341
|
-
handler.middleware(query);
|
|
342
|
-
return handler;
|
|
343
|
-
}
|
|
344
|
-
handleReplyToMessage(reply) {
|
|
345
|
-
let body, handler;
|
|
346
|
-
body = reply_to_message_utils_1.ReplyToMessageUtils.decodeBody(reply.reply_to_message?.entities ?? []);
|
|
347
|
-
(0, core_1.setObjectProperty)(reply, 'body', body);
|
|
348
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.REPLY_TO_MESSAGE, body.type);
|
|
349
|
-
if (!handler.id)
|
|
350
|
-
return handler;
|
|
351
|
-
handler.middleware(reply);
|
|
352
|
-
if (handler.id.length > 0 && handler.options.deleteOnReply && reply.from && reply.reply_to_message) {
|
|
353
|
-
this.delete.message(reply.from.id, reply.message_id);
|
|
354
|
-
this.delete.message(reply.from.id, reply.reply_to_message.message_id);
|
|
355
|
-
}
|
|
356
|
-
return handler;
|
|
357
|
-
}
|
|
358
|
-
handleShippingQuery(query) {
|
|
359
|
-
let handler;
|
|
360
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.SHIPPING_QUERY);
|
|
361
|
-
if (!handler.id)
|
|
362
|
-
return handler;
|
|
363
|
-
handler.middleware(query);
|
|
364
|
-
return handler;
|
|
365
|
-
}
|
|
366
|
-
handleStart(start) {
|
|
367
|
-
let handler, body;
|
|
368
|
-
body = start_utils_1.StartUtils.decodeBody(start.text);
|
|
369
|
-
(0, core_1.setObjectProperty)(start, 'body', body);
|
|
370
|
-
handler = this.findMatchingHandler(enums_1.UpdateType.START, body.type);
|
|
371
|
-
if (!handler.id)
|
|
372
|
-
return handler;
|
|
373
|
-
handler.middleware(start);
|
|
374
|
-
if (handler.id.length > 0 && handler.options.deleteOnMessageStart) {
|
|
375
|
-
this.delete.message(body.chatID ? start.from?.id ?? 0n : start.chat.id, start.message_id);
|
|
376
|
-
}
|
|
377
|
-
return handler;
|
|
378
|
-
}
|
|
379
|
-
findMatchingHandler(type, key = '') {
|
|
380
|
-
return this.handlers.find((v) => v.key === key && v.type === type) ?? dummy_1.Dummy.handler;
|
|
381
|
-
}
|
|
382
|
-
get commands() {
|
|
383
|
-
return this.handlers
|
|
384
|
-
.filter((v) => v.key && v.type === enums_1.UpdateType.MESSAGE)
|
|
385
|
-
.map((v) => ({ command: v.key ?? '', description: v.description ?? '' }));
|
|
386
|
-
}
|
|
387
|
-
get handlerIDs() {
|
|
388
|
-
return this.handlers.reduce((r, v) => [...r, v.id], []);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
exports.Telegram = Telegram;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CallbackQueryUtils = void 0;
|
|
4
|
-
const core_1 = require("@aracna/core");
|
|
5
|
-
const dummy_1 = require("../modules/dummy");
|
|
6
|
-
class CallbackQueryUtils {
|
|
7
|
-
static decodeBody(data) {
|
|
8
|
-
let body;
|
|
9
|
-
if (!data) {
|
|
10
|
-
return dummy_1.Dummy.callbackQueryBody;
|
|
11
|
-
}
|
|
12
|
-
body = (0, core_1.tc)(() => JSON.parse(Buffer.from(data, 'base64').toString()));
|
|
13
|
-
if (body instanceof Error)
|
|
14
|
-
return dummy_1.Dummy.callbackQueryBody;
|
|
15
|
-
return body;
|
|
16
|
-
}
|
|
17
|
-
static encodeBody(data, type, chatID) {
|
|
18
|
-
let body;
|
|
19
|
-
body = dummy_1.Dummy.callbackQueryBody;
|
|
20
|
-
body.c = chatID;
|
|
21
|
-
body.d = data;
|
|
22
|
-
body.t = type;
|
|
23
|
-
return Buffer.from(JSON.stringify(body)).toString('base64');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.CallbackQueryUtils = CallbackQueryUtils;
|
package/utils/command.utils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'vm';
|
|
2
|
-
import type { UpdateType } from '../definitions/enums';
|
|
3
|
-
export declare class CommandUtils {
|
|
4
|
-
static getByContext<T extends UpdateType>(context: Context[T]): string;
|
|
5
|
-
static get(string?: string): string;
|
|
6
|
-
static omit(string: string): string;
|
|
7
|
-
}
|
package/utils/command.utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandUtils = void 0;
|
|
4
|
-
const core_1 = require("@aracna/core");
|
|
5
|
-
const constants_1 = require("../definitions/constants");
|
|
6
|
-
class CommandUtils {
|
|
7
|
-
static getByContext(context) {
|
|
8
|
-
let string;
|
|
9
|
-
switch (true) {
|
|
10
|
-
case (0, core_1.hasObjectProperty)(context, 'caption'):
|
|
11
|
-
string = (0, core_1.getObjectProperty)(context, 'caption', '');
|
|
12
|
-
break;
|
|
13
|
-
case (0, core_1.hasObjectProperty)(context, 'text'):
|
|
14
|
-
string = (0, core_1.getObjectProperty)(context, 'caption', '');
|
|
15
|
-
break;
|
|
16
|
-
default:
|
|
17
|
-
string = '';
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
return this.get(string);
|
|
21
|
-
}
|
|
22
|
-
static get(string) {
|
|
23
|
-
return (constants_1.REGEXP_COMMAND.exec(string?.slice(0, 512) ?? '') ?? [''])[0].slice(1);
|
|
24
|
-
}
|
|
25
|
-
static omit(string) {
|
|
26
|
-
return string.replace(constants_1.REGEXP_COMMAND_WITH_USERNAME, '').trim();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.CommandUtils = CommandUtils;
|
package/utils/context.utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Chat, User } from '@aracna/telegram-bot-types';
|
|
2
|
-
import type { UpdateType } from '../definitions/enums';
|
|
3
|
-
import type { Context } from '../definitions/interfaces';
|
|
4
|
-
export declare class ContextUtils {
|
|
5
|
-
static getChatID<T extends UpdateType>(context: Context[T]): bigint;
|
|
6
|
-
static getChatType<T extends UpdateType>(context: Context[T]): string;
|
|
7
|
-
static getChat<T extends UpdateType>(context: Context[T]): Chat;
|
|
8
|
-
static getUserID<T extends UpdateType>(context: Context[T]): bigint;
|
|
9
|
-
static getUserFirstName<T extends UpdateType>(context: Context[T]): string;
|
|
10
|
-
static getUserLastName<T extends UpdateType>(context: Context[T]): string;
|
|
11
|
-
static getUserUsername<T extends UpdateType>(context: Context[T]): string;
|
|
12
|
-
static getUser<T extends UpdateType>(context: Context[T]): User;
|
|
13
|
-
}
|
package/utils/context.utils.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContextUtils = void 0;
|
|
4
|
-
const core_1 = require("@aracna/core");
|
|
5
|
-
class ContextUtils {
|
|
6
|
-
static getChatID(context) {
|
|
7
|
-
return this.getChat(context).id;
|
|
8
|
-
}
|
|
9
|
-
static getChatType(context) {
|
|
10
|
-
return this.getChat(context).type;
|
|
11
|
-
}
|
|
12
|
-
static getChat(context) {
|
|
13
|
-
switch (true) {
|
|
14
|
-
case (0, core_1.hasObjectProperty)(context, 'chat'):
|
|
15
|
-
return (0, core_1.getObjectProperty)(context, 'chat', { id: 0n, type: '' });
|
|
16
|
-
case (0, core_1.hasObjectProperty)(context, 'message.chat'):
|
|
17
|
-
return (0, core_1.getObjectProperty)(context, 'chat', { id: 0n, type: '' });
|
|
18
|
-
default:
|
|
19
|
-
return { id: 0n, type: '' };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
static getUserID(context) {
|
|
23
|
-
return this.getUser(context).id;
|
|
24
|
-
}
|
|
25
|
-
static getUserFirstName(context) {
|
|
26
|
-
return this.getUser(context).first_name;
|
|
27
|
-
}
|
|
28
|
-
static getUserLastName(context) {
|
|
29
|
-
return this.getUser(context).last_name ?? '';
|
|
30
|
-
}
|
|
31
|
-
static getUserUsername(context) {
|
|
32
|
-
return this.getUser(context).username ?? '';
|
|
33
|
-
}
|
|
34
|
-
static getUser(context) {
|
|
35
|
-
if ((0, core_1.hasObjectProperty)(context, 'from')) {
|
|
36
|
-
return (0, core_1.getObjectProperty)(context, 'from', { first_name: '', id: 0n, is_bot: false, username: '' });
|
|
37
|
-
}
|
|
38
|
-
return { first_name: '', id: 0n, is_bot: false, username: '' };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.ContextUtils = ContextUtils;
|