rubika 1.2.1 → 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 +8 -13
- package/bot/methods/files/_sendFile.ts +5 -2
- package/bot/methods/files/uploadFile.ts +5 -2
- 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 +4 -3
- 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 +8 -6
- 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/network/api.ts +1 -1
- 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
package/utils/parser.ts
CHANGED
|
@@ -1,173 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
type MarkdownEntity = {
|
|
2
|
+
type: string;
|
|
3
|
+
from_index: number;
|
|
4
|
+
length: number;
|
|
5
|
+
language?: string;
|
|
6
|
+
mention_text_user_id?: string;
|
|
7
|
+
mention_text_object_guid?: string;
|
|
8
|
+
mention_text_object_type?: string;
|
|
9
|
+
link?: { type: string; hyperlink_data: { url: string } };
|
|
8
10
|
};
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
["[", ["Link", 8]],
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
export default class Markdown {
|
|
36
|
-
static toMetadata(text: string): MetadataResult {
|
|
37
|
-
const metaDataParts: MetaDataPart[] = [];
|
|
38
|
-
let currentText = text;
|
|
12
|
+
class Markdown {
|
|
13
|
+
static markdownRegExp =
|
|
14
|
+
/(^|\s|\n)(````?)([\s\S]+?)(````?)([\s\n.,:?!;]|$)|(^|\s)(`|\*\*|__|~~|--|\|\||\^\^)([^\n]+?)\7([\s.,:?!;]|$)|@([a-zA-Z0-9]+)\s*\((.+?)\)|\[(.+?)\]\((.+?)\)/m;
|
|
15
|
+
|
|
16
|
+
static markdownEntities: Record<string, string> = {
|
|
17
|
+
"`": "Mono",
|
|
18
|
+
"**": "Bold",
|
|
19
|
+
__: "Italic",
|
|
20
|
+
"||": "Spoiler",
|
|
21
|
+
"~~": "Strike",
|
|
22
|
+
"--": "Underline",
|
|
23
|
+
"^^": "Quote",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static toMetadata(text: string): {
|
|
27
|
+
text: string;
|
|
28
|
+
metadata?: { meta_data_parts: MarkdownEntity[] };
|
|
29
|
+
} {
|
|
30
|
+
const entities: MarkdownEntity[] = [];
|
|
31
|
+
let match: RegExpMatchArray | null;
|
|
32
|
+
let remainingText = text;
|
|
33
|
+
const parsedTextParts: string[] = [];
|
|
39
34
|
let offset = 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
contentLength = Markdown.getUtf16Length(content);
|
|
93
|
-
charContentLength = content.length;
|
|
94
|
-
|
|
95
|
-
if (innerMeta.metadata) {
|
|
96
|
-
for (const part of innerMeta.metadata.meta_data_parts) {
|
|
97
|
-
part.from_index += adjustedStart;
|
|
98
|
-
metaDataParts.push(part);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
content = "";
|
|
104
|
-
contentLength = 0;
|
|
105
|
-
charContentLength = 0;
|
|
106
|
-
}
|
|
35
|
+
|
|
36
|
+
while ((match = remainingText.match(this.markdownRegExp))) {
|
|
37
|
+
const matchIndex = offset + (match.index || 0);
|
|
38
|
+
parsedTextParts.push(remainingText.substring(0, match.index!));
|
|
39
|
+
let matchedContent = match[3] || match[8] || match[11] || match[13];
|
|
40
|
+
|
|
41
|
+
if (matchedContent) {
|
|
42
|
+
offset -= matchedContent.length;
|
|
43
|
+
matchedContent = matchedContent.trim();
|
|
44
|
+
offset += matchedContent.length;
|
|
45
|
+
|
|
46
|
+
if (/^`*$/.test(matchedContent)) {
|
|
47
|
+
parsedTextParts.push(match[0]);
|
|
48
|
+
} else if (match[3]) {
|
|
49
|
+
if (match[5] === "\n") {
|
|
50
|
+
match[5] = "";
|
|
51
|
+
offset -= 1;
|
|
52
|
+
}
|
|
53
|
+
parsedTextParts.push(match[1] + matchedContent + match[5]);
|
|
54
|
+
entities.push({
|
|
55
|
+
type: "Pre",
|
|
56
|
+
language: "",
|
|
57
|
+
from_index: matchIndex + match[1].length,
|
|
58
|
+
length: matchedContent.length,
|
|
59
|
+
});
|
|
60
|
+
offset -= match[2].length + match[4].length;
|
|
61
|
+
} else if (match[7]) {
|
|
62
|
+
parsedTextParts.push(match[6] + matchedContent + match[9]);
|
|
63
|
+
entities.push({
|
|
64
|
+
type: this.markdownEntities[match[7]],
|
|
65
|
+
from_index: matchIndex + match[6].length,
|
|
66
|
+
length: matchedContent.length,
|
|
67
|
+
});
|
|
68
|
+
offset -= 2 * match[7].length;
|
|
69
|
+
} else if (match[11]) {
|
|
70
|
+
parsedTextParts.push(matchedContent);
|
|
71
|
+
entities.push({
|
|
72
|
+
type: "MentionText",
|
|
73
|
+
mention_text_object_guid: match[10],
|
|
74
|
+
from_index: matchIndex,
|
|
75
|
+
length: matchedContent.length,
|
|
76
|
+
mention_text_object_type: "User",
|
|
77
|
+
});
|
|
78
|
+
offset -= match[0].length - matchedContent.length;
|
|
79
|
+
} else if (match[12]) {
|
|
80
|
+
const [label, url] = [match[12], match[13]];
|
|
81
|
+
|
|
82
|
+
let mentionType: string | undefined;
|
|
83
|
+
if (url.length === 32) {
|
|
84
|
+
if (url.startsWith("u")) mentionType = "User";
|
|
85
|
+
else if (url.startsWith("g")) mentionType = "Group";
|
|
86
|
+
else if (url.startsWith("c")) mentionType = "Channel";
|
|
107
87
|
}
|
|
108
88
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
89
|
+
parsedTextParts.push(label);
|
|
90
|
+
const metaDataPart: MarkdownEntity = {
|
|
91
|
+
type: mentionType ? "MentionText" : "Link",
|
|
92
|
+
from_index: matchIndex,
|
|
93
|
+
length: label.length,
|
|
113
94
|
};
|
|
114
95
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
metaDataPart.
|
|
121
|
-
if (language) {
|
|
122
|
-
content = lines.slice(1).join("\n");
|
|
123
|
-
contentLength = Markdown.getUtf16Length(content);
|
|
124
|
-
charContentLength = content.length;
|
|
125
|
-
}
|
|
126
|
-
} else if (mdType === "Link") {
|
|
127
|
-
const url = match[9];
|
|
128
|
-
const mentionType = MENTION_PREFIX_TYPES[url?.[0]] || "hyperlink";
|
|
129
|
-
|
|
130
|
-
if (mentionType === "hyperlink") {
|
|
131
|
-
metaDataPart.link_url = url;
|
|
132
|
-
metaDataPart.link = {
|
|
133
|
-
type: mentionType,
|
|
134
|
-
hyperlink_data: { url },
|
|
135
|
-
};
|
|
136
|
-
} else {
|
|
137
|
-
metaDataPart.type = "MentionText";
|
|
138
|
-
metaDataPart.mention_text_object_guid = url;
|
|
139
|
-
metaDataPart.mention_text_user_id = url;
|
|
140
|
-
metaDataPart.mention_text_object_type = mentionType;
|
|
141
|
-
}
|
|
96
|
+
if (mentionType) {
|
|
97
|
+
metaDataPart.mention_text_object_guid = url;
|
|
98
|
+
metaDataPart.mention_text_user_id = url;
|
|
99
|
+
metaDataPart.mention_text_object_type = mentionType;
|
|
100
|
+
} else {
|
|
101
|
+
metaDataPart.link = { type: "hyperlink", hyperlink_data: { url } };
|
|
142
102
|
}
|
|
143
103
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
currentText.slice(0, adjustedCharStart) +
|
|
147
|
-
content +
|
|
148
|
-
currentText.slice(end - charOffset);
|
|
149
|
-
|
|
150
|
-
const markupLength = utf16Prefix[end] - utf16Prefix[start];
|
|
151
|
-
const charMarkupLength = end - start;
|
|
152
|
-
offset += markupLength - contentLength;
|
|
153
|
-
charOffset += charMarkupLength - charContentLength;
|
|
154
|
-
|
|
155
|
-
break;
|
|
104
|
+
entities.push(metaDataPart);
|
|
105
|
+
offset -= match[0].length - label.length;
|
|
156
106
|
}
|
|
107
|
+
|
|
108
|
+
remainingText = remainingText.substring(match.index! + match[0].length);
|
|
109
|
+
offset += match.index! + match[0].length;
|
|
157
110
|
}
|
|
158
111
|
}
|
|
159
112
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
113
|
+
parsedTextParts.push(remainingText);
|
|
114
|
+
let resultText = parsedTextParts.join("");
|
|
115
|
+
if (!resultText.replace(/\s+/g, "").length) {
|
|
116
|
+
resultText = text;
|
|
117
|
+
entities.splice(0, entities.length);
|
|
118
|
+
}
|
|
119
|
+
if (!entities.length) {
|
|
120
|
+
resultText = resultText.trim();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const returnData: {
|
|
124
|
+
text: string;
|
|
125
|
+
metadata?: { meta_data_parts: MarkdownEntity[] };
|
|
126
|
+
} = {
|
|
127
|
+
text: resultText,
|
|
165
128
|
};
|
|
166
|
-
}
|
|
167
129
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
130
|
+
if (entities.length > 0)
|
|
131
|
+
returnData.metadata = { meta_data_parts: entities };
|
|
132
|
+
|
|
133
|
+
return returnData;
|
|
172
134
|
}
|
|
173
135
|
}
|
|
136
|
+
|
|
137
|
+
export default Markdown;
|
package/utils/errors.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import checkFilters from "./checkFilter";
|
|
2
|
-
|
|
3
|
-
class Logger<T> {
|
|
4
|
-
constructor(
|
|
5
|
-
private errors: any,
|
|
6
|
-
private bot: T,
|
|
7
|
-
) {}
|
|
8
|
-
|
|
9
|
-
async error(text: string, type: "error" | "warn") {
|
|
10
|
-
const time = new Date();
|
|
11
|
-
for (let { filters, handler } of this.errors) {
|
|
12
|
-
const error = {
|
|
13
|
-
message: `${time.toISOString()} | ⟮ ${type} ⟯ ----> ${text}\n`,
|
|
14
|
-
bot: this.bot,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const passed = await checkFilters(text, filters);
|
|
18
|
-
|
|
19
|
-
if (passed) {
|
|
20
|
-
await handler(error);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default Logger;
|