catto.js 0.9.0 → 0.9.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/Server.js +11 -1
- package/TelegramBot.js +11 -17
- package/TelegramChannel.js +3 -3
- package/TelegramInteraction.js +5 -6
- package/TelegramMessage.js +9 -2
- package/package.json +4 -12
- package/request.js +20 -11
package/Server.js
CHANGED
|
@@ -181,10 +181,20 @@ class Server extends EventEmitter {
|
|
|
181
181
|
}
|
|
182
182
|
return context.__output;
|
|
183
183
|
}
|
|
184
|
-
static injectCJS(app) {
|
|
184
|
+
static injectCJS(app, nows) {
|
|
185
185
|
app.engine("cjs", Server.renderCJS.bind(null, app)).set("view engine", "cjs").get("/_cattojs/cjs_client.js", (req, res) => {
|
|
186
186
|
res.sendFile(path.join(__dirname, "cjs_client.js"));
|
|
187
187
|
});
|
|
188
|
+
if (!nows && !app.ws) {
|
|
189
|
+
expressWs(app);
|
|
190
|
+
app._cjs_sdynamic = [];
|
|
191
|
+
app.ws("/_cattojs/cjs_sdynamic", (ws, req) => {
|
|
192
|
+
app._cjs_sdynamic.push(ws);
|
|
193
|
+
ws.on("close", () => {
|
|
194
|
+
app._cjs_sdynamic = app._cjs_sdynamic.filter(client => client !== ws);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
188
198
|
}
|
|
189
199
|
static fa(text) {
|
|
190
200
|
return (req,res) => {
|
package/TelegramBot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var events = require("events");
|
|
2
2
|
var crypto = require("crypto");
|
|
3
|
-
var
|
|
3
|
+
var { Telegraf } = require("telegraf");
|
|
4
4
|
var TelegramMessage = require("./TelegramMessage");
|
|
5
5
|
var TelegramInteraction = require("./TelegramInteraction");
|
|
6
6
|
var TelegramUser = require("./TelegramUser");
|
|
@@ -11,19 +11,13 @@ module.exports = class extends EventEmitter {
|
|
|
11
11
|
constructor(options, client) {
|
|
12
12
|
super();
|
|
13
13
|
this.options = Object.assign({
|
|
14
|
-
"speed": 300,
|
|
15
14
|
"token": "",
|
|
16
15
|
"debug": !1
|
|
17
16
|
}, options || {});
|
|
18
17
|
if (client) {
|
|
19
18
|
this.client = client;
|
|
20
19
|
} else {
|
|
21
|
-
this.client = new
|
|
22
|
-
"polling": {
|
|
23
|
-
"interval": this.options.speed,
|
|
24
|
-
"autoStart": !1
|
|
25
|
-
}
|
|
26
|
-
});
|
|
20
|
+
this.client = new Telegraf(this.options.token);
|
|
27
21
|
}
|
|
28
22
|
this.commands = new Map();
|
|
29
23
|
this.slashCommands = new Map();
|
|
@@ -84,8 +78,8 @@ module.exports = class extends EventEmitter {
|
|
|
84
78
|
this.menubtn = { target, label, link };
|
|
85
79
|
return this;
|
|
86
80
|
}
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
run() {
|
|
82
|
+
this.client.launch();
|
|
89
83
|
var commands = [];
|
|
90
84
|
for (var cmd of this.slashCommands.values()) {
|
|
91
85
|
commands.push({
|
|
@@ -93,10 +87,10 @@ module.exports = class extends EventEmitter {
|
|
|
93
87
|
"description": cmd.description
|
|
94
88
|
});
|
|
95
89
|
}
|
|
96
|
-
this.client.setMyCommands(commands);
|
|
90
|
+
this.client.telegram.setMyCommands(commands);
|
|
97
91
|
if (this.menubtn.target == "web") {
|
|
98
|
-
this.client.setChatMenuButton({
|
|
99
|
-
"
|
|
92
|
+
this.client.telegram.setChatMenuButton({
|
|
93
|
+
"menuButton": JSON.stringify({
|
|
100
94
|
"type": "web_app",
|
|
101
95
|
"text": this.menubtn.label,
|
|
102
96
|
"web_app": {
|
|
@@ -105,8 +99,8 @@ module.exports = class extends EventEmitter {
|
|
|
105
99
|
})
|
|
106
100
|
});
|
|
107
101
|
} else {
|
|
108
|
-
this.client.setChatMenuButton({
|
|
109
|
-
"
|
|
102
|
+
this.client.telegram.setChatMenuButton({
|
|
103
|
+
"menuButton": JSON.stringify({
|
|
110
104
|
"type": "commands"
|
|
111
105
|
})
|
|
112
106
|
});
|
|
@@ -128,8 +122,8 @@ module.exports = class extends EventEmitter {
|
|
|
128
122
|
var checkHash = crypto.createHmac("sha256", secretKey).update(dcs).digest("hex");
|
|
129
123
|
return (checkHash === hash ? new TelegramUser(JSON.parse(dcs.split("\n").find(a => a.startsWith("user=")).split("=")[1]), this) : null);
|
|
130
124
|
}
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
stop() {
|
|
126
|
+
this.client.bot("SIGINT");
|
|
133
127
|
return this;
|
|
134
128
|
}
|
|
135
129
|
};
|
package/TelegramChannel.js
CHANGED
|
@@ -9,11 +9,11 @@ module.exports = class {
|
|
|
9
9
|
return this.data.id;
|
|
10
10
|
}
|
|
11
11
|
async type() {
|
|
12
|
-
await this.bot.client.sendChatAction(this.id, "typing");
|
|
12
|
+
await this.bot.client.telegram.sendChatAction(this.id, "typing");
|
|
13
13
|
}
|
|
14
14
|
async startTyping() {
|
|
15
15
|
if (this.typingLoop === null) {
|
|
16
|
-
await this.
|
|
16
|
+
await this.type();
|
|
17
17
|
this.typingLoop = setInterval(() => this.type(), 4e3);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -30,7 +30,7 @@ module.exports = class {
|
|
|
30
30
|
if (data instanceof TelegramMessageBuilder) {
|
|
31
31
|
data = data.data;
|
|
32
32
|
}
|
|
33
|
-
await this.bot.client.sendMessage(this.id, data.content, {
|
|
33
|
+
await this.bot.client.telegram.sendMessage(this.id, data.content, {
|
|
34
34
|
"reply_parameters": data.replyParameters ? {
|
|
35
35
|
"message_id": data.replyParameters.message.id,
|
|
36
36
|
"chat_id": (data.replyParameters.channel ? data.replyParameters.channel.id : this.id),
|
package/TelegramInteraction.js
CHANGED
|
@@ -3,20 +3,19 @@ module.exports = class {
|
|
|
3
3
|
constructor(data, bot) {
|
|
4
4
|
this._data = data;
|
|
5
5
|
this.bot = bot;
|
|
6
|
-
this.message = new TelegramMessage(this._data.message, bot);
|
|
6
|
+
this.message = new TelegramMessage(this._data.callbackQuery.message, bot);
|
|
7
7
|
}
|
|
8
8
|
get id() {
|
|
9
|
-
return this._data.id;
|
|
9
|
+
return this._data.callbackQuery.id;
|
|
10
10
|
}
|
|
11
11
|
get data() {
|
|
12
|
-
return this._data.data;
|
|
12
|
+
return this._data.callbackQuery.data;
|
|
13
13
|
}
|
|
14
14
|
async notify(text) {
|
|
15
|
-
await this.bot.client.
|
|
15
|
+
await this.bot.client.telegram.answerCbQuery(this.id, text);
|
|
16
16
|
}
|
|
17
17
|
async modal(text) {
|
|
18
|
-
await this.bot.client.
|
|
19
|
-
text,
|
|
18
|
+
await this.bot.client.telegram.answerCbQuery(this.id, text, {
|
|
20
19
|
"show_alert": !0
|
|
21
20
|
});
|
|
22
21
|
}
|
package/TelegramMessage.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var TelegramChannel = require("./TelegramChannel");
|
|
2
2
|
var TelegramUser = require("./TelegramUser");
|
|
3
|
+
var TelegramMessageBuilder = require("./TelegramMessageBuilder");
|
|
3
4
|
module.exports = class {
|
|
4
5
|
constructor(data, bot) {
|
|
5
6
|
this.data = data;
|
|
@@ -10,10 +11,10 @@ module.exports = class {
|
|
|
10
11
|
this.bot.users.set(this.user.id, this.user);
|
|
11
12
|
}
|
|
12
13
|
get id() {
|
|
13
|
-
return this.data.message_id;
|
|
14
|
+
return this.data.message.message_id;
|
|
14
15
|
}
|
|
15
16
|
get content() {
|
|
16
|
-
return this.data.text;
|
|
17
|
+
return this.data.message.text;
|
|
17
18
|
}
|
|
18
19
|
reply(data) {
|
|
19
20
|
if (typeof data !== "object") {
|
|
@@ -21,6 +22,12 @@ module.exports = class {
|
|
|
21
22
|
"content": data
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
if (data instanceof TelegramMessageBuilder) {
|
|
26
|
+
data.data.replyParameters = {
|
|
27
|
+
"message": this
|
|
28
|
+
};
|
|
29
|
+
return this.channel.send(data);
|
|
30
|
+
}
|
|
24
31
|
return this.channel.send(Object.assign({
|
|
25
32
|
"replyParameters": {
|
|
26
33
|
"message": this
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catto.js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Universal module for everything.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,17 +49,9 @@
|
|
|
49
49
|
"express": "^4.19.2",
|
|
50
50
|
"express-session": "^1.18.0",
|
|
51
51
|
"express-ws": "^5.0.2",
|
|
52
|
-
"node-
|
|
53
|
-
"request": "^2.88.2",
|
|
52
|
+
"node-fetch": "^2.7.0",
|
|
54
53
|
"session-file-store": "^1.5.0",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"tough-cookie": "next"
|
|
58
|
-
},
|
|
59
|
-
"overrides": {
|
|
60
|
-
"uri-js": {
|
|
61
|
-
"uri-js-replace": "^1.0.0"
|
|
62
|
-
},
|
|
63
|
-
"tough-cookie": "next"
|
|
54
|
+
"telegraf": "^4.16.3",
|
|
55
|
+
"tweetnacl": "^1.0.3"
|
|
64
56
|
}
|
|
65
57
|
}
|
package/request.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
/** @module request */
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var { default: fetch, Headers, Request, Response } = require("node-fetch");
|
|
4
|
+
|
|
5
|
+
if (!globalThis.fetch) {
|
|
6
|
+
globalThis.fetch = fetch;
|
|
7
|
+
globalThis.Headers = Headers;
|
|
8
|
+
globalThis.Request = Request;
|
|
9
|
+
globalThis.Response = Response;
|
|
10
|
+
}
|
|
4
11
|
|
|
5
12
|
function wrap(method, options) {
|
|
13
|
+
var options2 = Object.assign({}, options);
|
|
14
|
+
var url = options2.url;
|
|
15
|
+
delete options2.url;
|
|
6
16
|
return new Promise((res, rej) => {
|
|
7
|
-
request[method](
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
response, body
|
|
17
|
+
request[method](url, options2).then(response => {
|
|
18
|
+
response.text().then(body => {
|
|
19
|
+
try {
|
|
20
|
+
body = JSON.parse(body);
|
|
21
|
+
} catch {}
|
|
22
|
+
res({
|
|
23
|
+
response, body
|
|
24
|
+
});
|
|
16
25
|
});
|
|
17
|
-
});
|
|
26
|
+
}).catch(rej);
|
|
18
27
|
});
|
|
19
28
|
}
|
|
20
29
|
|