rubika 1.2.3 → 1.2.4
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/bot/bot.ts +34 -28
- package/bot/contexts/inline.ts +15 -14
- package/bot/contexts/update.ts +20 -21
- package/bot/filters.ts +32 -30
- package/bot/index.ts +4 -2
- package/bot/methods/advanced/builder.ts +7 -12
- package/bot/methods/files/_sendFile.ts +5 -2
- package/bot/methods/files/uploadFile.ts +4 -1
- package/bot/methods/index.ts +10 -10
- package/bot/methods/messages/deleteMessage.ts +6 -10
- package/bot/methods/messages/sendContact.ts +5 -3
- package/bot/methods/messages/sendFile.ts +1 -1
- package/bot/methods/messages/sendGif.ts +23 -23
- package/bot/methods/messages/sendImage.ts +23 -23
- package/bot/methods/messages/sendLocation.ts +6 -3
- package/bot/methods/messages/sendMessage.ts +6 -2
- package/bot/methods/messages/sendMusic.ts +23 -23
- package/bot/methods/messages/sendPoll.ts +6 -3
- package/bot/methods/messages/sendSticker.ts +8 -4
- package/bot/methods/messages/sendVideo.ts +23 -23
- package/bot/methods/messages/sendVoice.ts +23 -23
- package/bot/methods/utilities/getUpdates.ts +1 -1
- package/bot/methods/utilities/handleUpdates.ts +14 -14
- package/bot/methods/utilities/polling.ts +57 -32
- package/bot/methods/utilities/run.ts +2 -2
- package/bot/methods/utilities/start.ts +5 -2
- package/bot/methods/utilities/webhook.ts +1 -2
- package/bot/network.ts +43 -15
- package/bot/types/handlers.ts +3 -3
- package/bot/types/interfaces.ts +44 -4
- package/bot/types/utils.ts +6 -1
- package/bot/utils/antiSpam.ts +1 -1
- package/client/client.ts +35 -33
- package/client/contexts/activities.type.ts +2 -2
- package/client/contexts/chat.type.ts +2 -2
- package/client/contexts/message.type.ts +10 -3
- package/client/contexts/notifications.type.ts +2 -2
- package/client/crypto.ts +2 -2
- package/client/filters.ts +31 -31
- package/client/index.ts +5 -1
- package/client/methods/advanced/builder.ts +3 -1
- package/client/methods/auth/registerDevice.ts +8 -6
- package/client/methods/channels/addChannel.ts +1 -1
- package/client/methods/channels/editChannelInfo.ts +3 -3
- package/client/methods/channels/setChannelVoiceChatSetting.ts +1 -1
- package/client/methods/chats/editJoinLink.ts +1 -1
- package/client/methods/chats/seenChats.ts +1 -1
- package/client/methods/extras/deleteMessagebyCount.ts +40 -38
- package/client/methods/extras/onEditMessages.ts +1 -1
- package/client/methods/extras/userIsAdmin.ts +2 -2
- package/client/methods/groups/editGroupInfo.ts +13 -1
- package/client/methods/groups/setGroupVoiceChatSetting.ts +1 -1
- package/client/methods/messages/sendDocument.ts +3 -2
- package/client/methods/messages/sendFileInline.ts +1 -1
- package/client/methods/messages/sendGif.ts +4 -3
- package/client/methods/messages/sendMessage.ts +7 -5
- package/client/methods/messages/sendMessageAPICall.ts +18 -0
- package/client/methods/messages/sendMusic.ts +3 -2
- package/client/methods/messages/sendPhoto.ts +3 -2
- package/client/methods/messages/sendText.ts +4 -2
- package/client/methods/messages/sendVideo.ts +3 -2
- package/client/methods/messages/sendVideoMessage.ts +3 -2
- package/client/methods/messages/sendVoice.ts +3 -2
- package/client/methods/settings/updateProfile.ts +1 -1
- package/client/methods/utilities/start.ts +7 -4
- package/client/methods/utilities/thumbnail.ts +5 -5
- package/client/network/file.ts +13 -7
- package/client/network/websocket.ts +32 -15
- package/client/types/client.type.ts +10 -10
- package/client/utils/session.ts +1 -1
- package/index.ts +1 -0
- package/package.json +1 -7
- package/utils/formater.ts +1 -1
- package/utils/index.ts +2 -1
- package/utils/logger.ts +28 -0
- package/utils/parser.ts +120 -156
- package/utils/errors.ts +0 -26
|
@@ -1,64 +1,89 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import Bot from "../../bot";
|
|
3
|
-
import { checkFilters } from "../../../utils";
|
|
4
1
|
import { UpdateTypeEnum } from "../../types/enums";
|
|
2
|
+
import { checkFilters } from "../../../utils";
|
|
5
3
|
import Update from "../../contexts/update";
|
|
4
|
+
import Bot from "../../bot";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import { Filters } from "../../../client";
|
|
8
|
+
|
|
9
|
+
const checkTypes = [
|
|
10
|
+
UpdateTypeEnum.UpdatedMessage,
|
|
11
|
+
UpdateTypeEnum.NewMessage,
|
|
12
|
+
UpdateTypeEnum.RemovedMessage,
|
|
13
|
+
UpdateTypeEnum.UpdatedPayment,
|
|
14
|
+
UpdateTypeEnum.StoppedBot,
|
|
15
|
+
UpdateTypeEnum.StartedBot,
|
|
16
|
+
];
|
|
6
17
|
|
|
7
|
-
const
|
|
18
|
+
const OFFSET_FILE_PATH = path.join(
|
|
19
|
+
process.cwd(),
|
|
20
|
+
process.env.OFFSET_PATH || "offset.json",
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const sleep = async (time: number) =>
|
|
24
|
+
await new Promise((res) => setTimeout(res, time));
|
|
8
25
|
|
|
9
26
|
export default async function polling(this: Bot) {
|
|
10
27
|
console.log("✔ Start Robot... [ polling mode ]");
|
|
11
28
|
|
|
12
29
|
let next_offset_id: string | undefined = loadOffset();
|
|
13
30
|
|
|
14
|
-
|
|
31
|
+
while (true) {
|
|
15
32
|
try {
|
|
16
|
-
const res = await this.getUpdates(next_offset_id);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
const res = await this.getUpdates(next_offset_id, 100);
|
|
34
|
+
|
|
35
|
+
if (res.status_message !== "OK") {
|
|
36
|
+
await sleep(500);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
22
39
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const passed = await checkFilters(ctx, filters);
|
|
40
|
+
for (const m of res.updates) {
|
|
41
|
+
if (!checkTypes.includes(m.type)) continue;
|
|
42
|
+
const time = m.update_time - Math.floor(Date.now() / 1000);
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
if (time > 10 || time < -10) continue;
|
|
45
|
+
for (const { prefix, filters, handler } of this.handlers.update) {
|
|
46
|
+
const ctx = new Update(m, this);
|
|
47
|
+
const passed = await checkFilters(ctx, filters);
|
|
31
48
|
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
if (passed) {
|
|
50
|
+
if (prefix) {
|
|
51
|
+
const text = Filters.findKey(m, "text") || null;
|
|
34
52
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
if (!text) continue;
|
|
54
|
+
if (typeof prefix === "string" && text !== prefix) continue;
|
|
55
|
+
if (prefix instanceof RegExp && !prefix.test(text)) continue;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await handler(ctx);
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
41
61
|
}
|
|
42
62
|
}
|
|
43
63
|
}
|
|
44
64
|
}
|
|
45
|
-
|
|
46
65
|
if (res.next_offset_id) {
|
|
47
66
|
next_offset_id = res.next_offset_id;
|
|
48
67
|
saveOffset(next_offset_id as string);
|
|
49
68
|
}
|
|
50
69
|
} catch (e) {
|
|
51
|
-
|
|
70
|
+
console.log(e);
|
|
52
71
|
}
|
|
53
|
-
|
|
72
|
+
|
|
73
|
+
await sleep(500);
|
|
74
|
+
}
|
|
54
75
|
}
|
|
55
76
|
|
|
56
77
|
function saveOffset(offset: string) {
|
|
57
|
-
|
|
78
|
+
const dir = path.dirname(OFFSET_FILE_PATH);
|
|
79
|
+
if (!fs.existsSync(dir)) {
|
|
80
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
fs.writeFileSync(OFFSET_FILE_PATH, JSON.stringify({ offset }));
|
|
58
83
|
}
|
|
59
84
|
|
|
60
85
|
function loadOffset(): string | undefined {
|
|
61
|
-
if (!fs.existsSync(
|
|
62
|
-
const data = fs.readFileSync(
|
|
86
|
+
if (!fs.existsSync(OFFSET_FILE_PATH)) return undefined;
|
|
87
|
+
const data = fs.readFileSync(OFFSET_FILE_PATH, "utf8");
|
|
63
88
|
return JSON.parse(data).offset;
|
|
64
89
|
}
|
|
@@ -17,8 +17,8 @@ async function run(
|
|
|
17
17
|
while (!this.initialize) {
|
|
18
18
|
await this.network.delay(2000);
|
|
19
19
|
}
|
|
20
|
-
if (url) await this.
|
|
21
|
-
else await this.
|
|
20
|
+
if (url) await this.setupWebhook(url, host, port, updates);
|
|
21
|
+
else await this.polling();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export default run;
|
|
@@ -6,15 +6,18 @@ async function start(this: Bot, token?: string) {
|
|
|
6
6
|
if (token) this.token = token;
|
|
7
7
|
else {
|
|
8
8
|
const token = await prompt("[start] Please enter your bot token: ");
|
|
9
|
-
|
|
9
|
+
await this.start(token);
|
|
10
|
+
return;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
try {
|
|
14
15
|
const res = await this.getMe();
|
|
15
16
|
this.bot = res.bot;
|
|
17
|
+
|
|
16
18
|
} catch (err) {
|
|
17
|
-
|
|
19
|
+
await this.logger.error(`[start] error in token maby:${await err}`, "warn");
|
|
20
|
+
return
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
this.initialize = true;
|
|
@@ -13,7 +13,6 @@ async function setupWebhook(
|
|
|
13
13
|
port: number = 3000,
|
|
14
14
|
updates: UpdateEndpointTypeEnum[] = [],
|
|
15
15
|
) {
|
|
16
|
-
// create server
|
|
17
16
|
Bun.serve({
|
|
18
17
|
port,
|
|
19
18
|
hostname: host,
|
|
@@ -44,7 +43,7 @@ async function setupWebhook(
|
|
|
44
43
|
for (const update of updates) {
|
|
45
44
|
const res = await this.updateBotEndpoints(url, update);
|
|
46
45
|
|
|
47
|
-
if (res.status !== "Done") {
|
|
46
|
+
if (res.status_message !== "OK" && res.status !== "Done") {
|
|
48
47
|
this.logger.error(
|
|
49
48
|
`[setupWebhook] status updateBotEndpoints is ${res.status} for update: ${update}`,
|
|
50
49
|
"warn",
|
package/bot/network.ts
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
|
+
import { Logger } from "../utils";
|
|
2
|
+
import Bot from "./bot";
|
|
3
|
+
|
|
1
4
|
export default class Network {
|
|
2
|
-
|
|
5
|
+
constructor(
|
|
6
|
+
public base_url: string,
|
|
7
|
+
public logger: Logger<Bot>,
|
|
8
|
+
public retryCount: number = 3,
|
|
9
|
+
public timeout: number = 10000,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
stringifyBigInts = (obj: object): object => {
|
|
13
|
+
if (Array.isArray(obj)) {
|
|
14
|
+
return obj.map(this.stringifyBigInts);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (obj !== null && typeof obj === "object") {
|
|
18
|
+
const result: Record<string, unknown> = {};
|
|
19
|
+
for (const key in obj) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
21
|
+
result[key] = this.stringifyBigInts(obj[key as keyof typeof obj]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
3
26
|
|
|
4
|
-
|
|
27
|
+
return obj;
|
|
28
|
+
};
|
|
5
29
|
|
|
6
30
|
async request(method: string, data: object) {
|
|
7
|
-
const url =
|
|
31
|
+
const url = this.base_url + "/" + method;
|
|
8
32
|
|
|
9
|
-
for (let attempt = 1; attempt <= this.
|
|
33
|
+
for (let attempt = 1; attempt <= this.retryCount; attempt++) {
|
|
10
34
|
try {
|
|
11
35
|
const res = await fetch(url, {
|
|
12
36
|
method: "POST",
|
|
@@ -15,29 +39,33 @@ export default class Network {
|
|
|
15
39
|
},
|
|
16
40
|
body: JSON.stringify(data),
|
|
17
41
|
});
|
|
42
|
+
|
|
18
43
|
if (res.status === 200) {
|
|
19
44
|
const responseData = await res.json();
|
|
20
45
|
|
|
21
|
-
return
|
|
22
|
-
JSON.stringify(responseData, (_, v) =>
|
|
23
|
-
typeof v === "bigint" ? v.toString() : v
|
|
24
|
-
)
|
|
25
|
-
);
|
|
46
|
+
return responseData;
|
|
26
47
|
} else {
|
|
27
|
-
|
|
28
|
-
`[request]
|
|
48
|
+
this.logger.error(
|
|
49
|
+
`[request] attempt ${attempt}: ${res.statusText} ${res.status}`,
|
|
50
|
+
"error",
|
|
29
51
|
);
|
|
30
52
|
}
|
|
31
|
-
} catch
|
|
32
|
-
|
|
53
|
+
} catch {
|
|
54
|
+
this.logger.error(
|
|
55
|
+
`[request] attempt ${attempt} message: you dont have access to the internet.`,
|
|
56
|
+
"error",
|
|
57
|
+
);
|
|
33
58
|
}
|
|
34
59
|
|
|
35
60
|
await this.delay(1000);
|
|
36
61
|
}
|
|
37
62
|
|
|
38
|
-
|
|
39
|
-
`[request]
|
|
63
|
+
this.logger.error(
|
|
64
|
+
`[request] failed after ${this.retryCount} attempts { method: ${method} }`,
|
|
65
|
+
"error",
|
|
40
66
|
);
|
|
67
|
+
|
|
68
|
+
return false;
|
|
41
69
|
}
|
|
42
70
|
|
|
43
71
|
delay(ms: number) {
|
package/bot/types/handlers.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Bot from "..";
|
|
2
2
|
import { Update, Inline } from "../contexts";
|
|
3
3
|
|
|
4
|
-
export interface ContextMap {
|
|
5
|
-
update: Update
|
|
6
|
-
inline: Inline
|
|
4
|
+
export interface ContextMap<T> {
|
|
5
|
+
update: Update<T>;
|
|
6
|
+
inline: Inline<T>;
|
|
7
7
|
error: {
|
|
8
8
|
message: string;
|
|
9
9
|
bot: Bot;
|
package/bot/types/interfaces.ts
CHANGED
|
@@ -14,7 +14,16 @@ import {
|
|
|
14
14
|
UpdateTypeEnum,
|
|
15
15
|
} from "./enums";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
interface STATUS_MESSAGE {
|
|
18
|
+
status_message:
|
|
19
|
+
| "OK"
|
|
20
|
+
| "INVALID_ACCESS"
|
|
21
|
+
| "TOO_REQUESTS"
|
|
22
|
+
| "NETWORK_ERROR"
|
|
23
|
+
| "INVALID_TOKEN";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface Chat extends STATUS_MESSAGE {
|
|
18
27
|
chat: {
|
|
19
28
|
chat_id: string;
|
|
20
29
|
chat_type: ChatTypeEnum;
|
|
@@ -25,6 +34,9 @@ export interface Chat {
|
|
|
25
34
|
username: string;
|
|
26
35
|
};
|
|
27
36
|
}
|
|
37
|
+
export interface UpdateBotEndpoints extends STATUS_MESSAGE {
|
|
38
|
+
status: string;
|
|
39
|
+
}
|
|
28
40
|
|
|
29
41
|
export interface File {
|
|
30
42
|
file_id: string;
|
|
@@ -49,7 +61,7 @@ export interface MessageTextUpdate {
|
|
|
49
61
|
text: string;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
|
-
export interface Bot {
|
|
64
|
+
export interface Bot extends STATUS_MESSAGE {
|
|
53
65
|
bot: {
|
|
54
66
|
bot_id: string;
|
|
55
67
|
bot_title: string;
|
|
@@ -61,6 +73,10 @@ export interface Bot {
|
|
|
61
73
|
};
|
|
62
74
|
}
|
|
63
75
|
|
|
76
|
+
export interface REQUEST_SEND_FILE extends STATUS_MESSAGE {
|
|
77
|
+
upload_url: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
export interface BotCommand {
|
|
65
81
|
command: string;
|
|
66
82
|
description: string;
|
|
@@ -224,6 +240,30 @@ export interface Message {
|
|
|
224
240
|
live_location?: LiveLocation;
|
|
225
241
|
}
|
|
226
242
|
|
|
243
|
+
export interface UpdateMessage {
|
|
244
|
+
chat_id: string;
|
|
245
|
+
update_time: number;
|
|
246
|
+
type: UpdateTypeEnum;
|
|
247
|
+
new_message?: Message;
|
|
248
|
+
updated_message?: Message;
|
|
249
|
+
removed_message_id?: string;
|
|
250
|
+
updated_payment?: PaymentStatus;
|
|
251
|
+
}
|
|
252
|
+
export interface InlineMessage {
|
|
253
|
+
sender_id: string;
|
|
254
|
+
text: string;
|
|
255
|
+
file?: File;
|
|
256
|
+
location?: Location;
|
|
257
|
+
aux_data?: AuxData;
|
|
258
|
+
message_id: string;
|
|
259
|
+
chat_id: string;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface GetUpdates extends STATUS_MESSAGE {
|
|
263
|
+
updates: UpdateMessage[];
|
|
264
|
+
next_offset_id: string;
|
|
265
|
+
}
|
|
266
|
+
|
|
227
267
|
export interface BotInfo {
|
|
228
268
|
bot_id: string;
|
|
229
269
|
bot_title: string;
|
|
@@ -233,11 +273,11 @@ export interface BotInfo {
|
|
|
233
273
|
start_message: string;
|
|
234
274
|
}
|
|
235
275
|
|
|
236
|
-
export interface SendMessage {
|
|
276
|
+
export interface SendMessage extends STATUS_MESSAGE {
|
|
237
277
|
message_id: string;
|
|
238
278
|
}
|
|
239
279
|
|
|
240
|
-
export interface UploadFile {
|
|
280
|
+
export interface UploadFile extends STATUS_MESSAGE {
|
|
241
281
|
status: string;
|
|
242
282
|
status_det: string;
|
|
243
283
|
data: { file_id: string };
|
package/bot/types/utils.ts
CHANGED
|
@@ -35,8 +35,13 @@ export interface MetadataResult {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// antiSpam
|
|
38
|
-
export type SpamCallbackType = (ctx: Update) => Promise<void>;
|
|
38
|
+
export type SpamCallbackType = (ctx: Update<unknown>) => Promise<void>;
|
|
39
39
|
export type OptionSpamType = {
|
|
40
40
|
spam_time: number;
|
|
41
41
|
spam_limit: number;
|
|
42
42
|
};
|
|
43
|
+
|
|
44
|
+
export type BotConfig = {
|
|
45
|
+
timeout: number;
|
|
46
|
+
retryCount: number;
|
|
47
|
+
};
|
package/bot/utils/antiSpam.ts
CHANGED
package/client/client.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import Network from "./network";
|
|
2
2
|
import Methods from "./methods";
|
|
3
|
+
import { Logger } from "../utils";
|
|
3
4
|
import { SessionManager } from "./utils";
|
|
4
5
|
import Message from "./contexts/message.type";
|
|
5
|
-
import
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
ContextMap,
|
|
8
|
+
RubPlugin,
|
|
9
|
+
Handler,
|
|
10
|
+
SessionType,
|
|
11
|
+
PlatformType,
|
|
12
|
+
} from "./types/client.type";
|
|
7
13
|
|
|
8
14
|
export default class Client extends Methods {
|
|
9
15
|
public initialize = false;
|
|
@@ -13,12 +19,10 @@ export default class Client extends Methods {
|
|
|
13
19
|
public auth?: string;
|
|
14
20
|
public sessionDb: SessionManager;
|
|
15
21
|
public network: Network;
|
|
16
|
-
public plugins:
|
|
22
|
+
public plugins: RubPlugin[] = [];
|
|
17
23
|
public userGuid?: string;
|
|
18
24
|
public handlers: {
|
|
19
|
-
[K in keyof
|
|
20
|
-
ClientTypes.ContextMap[K]
|
|
21
|
-
>[];
|
|
25
|
+
[K in keyof ContextMap<unknown>]: Handler<ContextMap<unknown>[K]>[];
|
|
22
26
|
} = {
|
|
23
27
|
error: [],
|
|
24
28
|
chat: [],
|
|
@@ -30,9 +34,9 @@ export default class Client extends Methods {
|
|
|
30
34
|
public logger = new Logger<Client>(this.handlers.error, this);
|
|
31
35
|
|
|
32
36
|
constructor(
|
|
33
|
-
private session:
|
|
37
|
+
private session: SessionType,
|
|
34
38
|
public application: "Shad" | "Rubika" = "Rubika",
|
|
35
|
-
public platform:
|
|
39
|
+
public platform: PlatformType = "Web",
|
|
36
40
|
public timeout: number = 5000,
|
|
37
41
|
) {
|
|
38
42
|
super();
|
|
@@ -42,25 +46,23 @@ export default class Client extends Methods {
|
|
|
42
46
|
this.start();
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
on<T extends keyof typeof this.handlers>(
|
|
46
|
-
type:
|
|
47
|
-
handler: (ctx:
|
|
49
|
+
on<T, K extends keyof typeof this.handlers>(
|
|
50
|
+
type: K,
|
|
51
|
+
handler: (ctx: ContextMap<T>[K]) => Promise<void>,
|
|
48
52
|
): void;
|
|
49
53
|
|
|
50
|
-
on<T extends keyof typeof this.handlers>(
|
|
51
|
-
type:
|
|
52
|
-
filters: Array<
|
|
53
|
-
|
|
54
|
-
>,
|
|
55
|
-
handler: (ctx: ClientTypes.ContextMap[T]) => Promise<void>,
|
|
54
|
+
on<T, K extends keyof typeof this.handlers>(
|
|
55
|
+
type: K,
|
|
56
|
+
filters: Array<(ctx: ContextMap<T>[K]) => boolean | Promise<boolean>>,
|
|
57
|
+
handler: (ctx: ContextMap<T>[K]) => Promise<void>,
|
|
56
58
|
): void;
|
|
57
59
|
|
|
58
|
-
on<T extends keyof typeof this.handlers>(
|
|
59
|
-
type:
|
|
60
|
+
on<T, K extends keyof typeof this.handlers>(
|
|
61
|
+
type: K,
|
|
60
62
|
filtersOrHandler:
|
|
61
|
-
| Array<(ctx:
|
|
62
|
-
| ((ctx:
|
|
63
|
-
maybeHandler?: (ctx:
|
|
63
|
+
| Array<(ctx: ContextMap<T>[K]) => boolean | Promise<boolean>>
|
|
64
|
+
| ((ctx: ContextMap<T>[K]) => Promise<void>),
|
|
65
|
+
maybeHandler?: (ctx: ContextMap<T>[K]) => Promise<void>,
|
|
64
66
|
) {
|
|
65
67
|
if (typeof filtersOrHandler === "function") {
|
|
66
68
|
this.handlers[type].push({
|
|
@@ -73,27 +75,27 @@ export default class Client extends Methods {
|
|
|
73
75
|
handler: maybeHandler,
|
|
74
76
|
});
|
|
75
77
|
} else {
|
|
76
|
-
|
|
78
|
+
new Error("Invalid arguments for on()");
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
command(
|
|
82
|
+
command<T>(
|
|
81
83
|
prefix: string | RegExp,
|
|
82
|
-
handler: (ctx: Message) => Promise<void>,
|
|
84
|
+
handler: (ctx: Message<T>) => Promise<void>,
|
|
83
85
|
): void;
|
|
84
86
|
|
|
85
|
-
command(
|
|
87
|
+
command<T>(
|
|
86
88
|
prefix: string | RegExp,
|
|
87
|
-
filters: Array<(ctx: Message) => boolean | Promise<boolean>>,
|
|
88
|
-
handler: (ctx: Message) => Promise<void>,
|
|
89
|
+
filters: Array<(ctx: Message<T>) => boolean | Promise<boolean>>,
|
|
90
|
+
handler: (ctx: Message<T>) => Promise<void>,
|
|
89
91
|
): void;
|
|
90
92
|
|
|
91
|
-
command(
|
|
93
|
+
command<T>(
|
|
92
94
|
prefix: string | RegExp,
|
|
93
95
|
filtersOrHandler:
|
|
94
|
-
| Array<(ctx: Message) => boolean | Promise<boolean>>
|
|
95
|
-
| ((ctx: Message) => Promise<void>),
|
|
96
|
-
maybeHandler?: (ctx: Message) => Promise<void>,
|
|
96
|
+
| Array<(ctx: Message<T>) => boolean | Promise<boolean>>
|
|
97
|
+
| ((ctx: Message<T>) => Promise<void>),
|
|
98
|
+
maybeHandler?: (ctx: Message<T>) => Promise<void>,
|
|
97
99
|
) {
|
|
98
100
|
if (typeof filtersOrHandler === "function") {
|
|
99
101
|
this.handlers["message"].push({
|
|
@@ -108,7 +110,7 @@ export default class Client extends Methods {
|
|
|
108
110
|
prefix,
|
|
109
111
|
});
|
|
110
112
|
} else {
|
|
111
|
-
|
|
113
|
+
new Error("Invalid arguments for command()");
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
}
|
|
@@ -2,12 +2,12 @@ import { inspect } from "util";
|
|
|
2
2
|
import { Client } from "../../..";
|
|
3
3
|
import { DecoratorsTypes } from "../types/index.type";
|
|
4
4
|
|
|
5
|
-
class Activities implements DecoratorsTypes.ShowActivities {
|
|
5
|
+
class Activities<T> implements DecoratorsTypes.ShowActivities {
|
|
6
6
|
type: string;
|
|
7
7
|
object_guid: string;
|
|
8
8
|
object_type: string;
|
|
9
9
|
user_activity_guid: string;
|
|
10
|
-
store:
|
|
10
|
+
store: Partial<T> = {};
|
|
11
11
|
|
|
12
12
|
declare client: Client;
|
|
13
13
|
|
|
@@ -2,14 +2,14 @@ import { inspect } from "util";
|
|
|
2
2
|
import { Client } from "../../..";
|
|
3
3
|
import { DecoratorsTypes } from "../types/index.type";
|
|
4
4
|
|
|
5
|
-
class Chat implements DecoratorsTypes.ChatUpdates {
|
|
5
|
+
class Chat<T> implements DecoratorsTypes.ChatUpdates {
|
|
6
6
|
object_guid: string;
|
|
7
7
|
action: string;
|
|
8
8
|
chat: DecoratorsTypes.Chat;
|
|
9
9
|
updated_parameters: string[];
|
|
10
10
|
timestamp: string;
|
|
11
11
|
type: string;
|
|
12
|
-
store:
|
|
12
|
+
store: Partial<T> = {};
|
|
13
13
|
|
|
14
14
|
declare client: Client;
|
|
15
15
|
|
|
@@ -18,11 +18,11 @@ const getOriginalType = (message: any) => {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
class Message implements DecoratorsTypes.MessageUpdate {
|
|
21
|
+
class Message<T> implements DecoratorsTypes.MessageUpdate {
|
|
22
22
|
message_id: string;
|
|
23
23
|
action: string;
|
|
24
24
|
message: DecoratorsTypes.Message;
|
|
25
|
-
updated_parameters:
|
|
25
|
+
updated_parameters: string[];
|
|
26
26
|
timestamp: string;
|
|
27
27
|
prev_message_id: string;
|
|
28
28
|
object_guid: string;
|
|
@@ -30,7 +30,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
30
30
|
state: string;
|
|
31
31
|
client_guid: string;
|
|
32
32
|
is_scheduled: boolean;
|
|
33
|
-
store:
|
|
33
|
+
store: Partial<T> = {};
|
|
34
34
|
|
|
35
35
|
declare client: Client;
|
|
36
36
|
declare originalType: string;
|
|
@@ -59,6 +59,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
59
59
|
object_guid?: string,
|
|
60
60
|
message_id?: string,
|
|
61
61
|
auto_delete?: number,
|
|
62
|
+
aux_data?: { button_id: string },
|
|
62
63
|
file_inline?: string | Buffer<ArrayBufferLike>,
|
|
63
64
|
type?: string,
|
|
64
65
|
is_spoil?: boolean,
|
|
@@ -70,6 +71,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
70
71
|
text,
|
|
71
72
|
message_id || this.message_id,
|
|
72
73
|
file_inline,
|
|
74
|
+
aux_data,
|
|
73
75
|
type,
|
|
74
76
|
is_spoil,
|
|
75
77
|
thumb,
|
|
@@ -107,6 +109,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
107
109
|
object_guid,
|
|
108
110
|
reply_to_message_id,
|
|
109
111
|
auto_delete,
|
|
112
|
+
undefined,
|
|
110
113
|
image,
|
|
111
114
|
"Image",
|
|
112
115
|
is_spoil,
|
|
@@ -128,6 +131,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
128
131
|
object_guid,
|
|
129
132
|
reply_to_message_id,
|
|
130
133
|
auto_delete,
|
|
134
|
+
undefined,
|
|
131
135
|
video,
|
|
132
136
|
"Video",
|
|
133
137
|
is_spoil,
|
|
@@ -149,6 +153,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
149
153
|
object_guid,
|
|
150
154
|
reply_to_message_id,
|
|
151
155
|
auto_delete,
|
|
156
|
+
undefined,
|
|
152
157
|
gif,
|
|
153
158
|
"Gif",
|
|
154
159
|
is_spoil,
|
|
@@ -170,6 +175,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
170
175
|
object_guid,
|
|
171
176
|
reply_to_message_id,
|
|
172
177
|
auto_delete,
|
|
178
|
+
undefined,
|
|
173
179
|
music,
|
|
174
180
|
"Music",
|
|
175
181
|
is_spoil,
|
|
@@ -191,6 +197,7 @@ class Message implements DecoratorsTypes.MessageUpdate {
|
|
|
191
197
|
object_guid,
|
|
192
198
|
reply_to_message_id,
|
|
193
199
|
auto_delete,
|
|
200
|
+
undefined,
|
|
194
201
|
voice,
|
|
195
202
|
"Voice",
|
|
196
203
|
is_spoil,
|
|
@@ -2,14 +2,14 @@ import { inspect } from "util";
|
|
|
2
2
|
import { Client } from "../../..";
|
|
3
3
|
import { DecoratorsTypes } from "../types/index.type";
|
|
4
4
|
|
|
5
|
-
class Notifications implements DecoratorsTypes.ShowNotifications {
|
|
5
|
+
class Notifications<T> implements DecoratorsTypes.ShowNotifications {
|
|
6
6
|
notification_id: string;
|
|
7
7
|
type: string;
|
|
8
8
|
title: string;
|
|
9
9
|
text: string;
|
|
10
10
|
image_file_id?: number;
|
|
11
11
|
message_data: DecoratorsTypes.MessageData;
|
|
12
|
-
store:
|
|
12
|
+
store: Partial<T> = {};
|
|
13
13
|
|
|
14
14
|
declare client: Client;
|
|
15
15
|
|
package/client/crypto.ts
CHANGED
|
@@ -93,12 +93,12 @@ class Crypto {
|
|
|
93
93
|
const keyPair = new NodeRSA({
|
|
94
94
|
b: 1024,
|
|
95
95
|
});
|
|
96
|
-
|
|
96
|
+
const publicKey = Crypto.decode_auth(
|
|
97
97
|
Buffer.from(keyPair.exportKey('pkcs1-public-pem'), 'binary').toString(
|
|
98
98
|
'base64',
|
|
99
99
|
),
|
|
100
100
|
);
|
|
101
|
-
|
|
101
|
+
const privateKey = keyPair.exportKey('pkcs1-private-pem');
|
|
102
102
|
return [publicKey, privateKey];
|
|
103
103
|
}
|
|
104
104
|
|