catto.js 0.4.9 → 0.5.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/TelegramBot.js CHANGED
@@ -1,7 +1,9 @@
1
1
  var events = require("events");
2
+ var crypto = require("crypto");
2
3
  var Telegram = require("node-telegram-bot-api");
3
4
  var TelegramMessage = require("./TelegramMessage");
4
5
  var TelegramInteraction = require("./TelegramInteraction");
6
+ var TelegramUser = require("./TelegramUser");
5
7
  if (typeof EventEmitter === "undefined") {
6
8
  var { EventEmitter } = events;
7
9
  }
@@ -25,6 +27,7 @@ module.exports = class extends EventEmitter {
25
27
  }
26
28
  this.commands = new Map();
27
29
  this.slashCommands = new Map();
30
+ this.users = new Map();
28
31
  this.menubtn = "commands";
29
32
  if (this.options.debug) {
30
33
  this.client.on("polling_error", console.log);
@@ -110,6 +113,14 @@ module.exports = class extends EventEmitter {
110
113
  }
111
114
  return this;
112
115
  }
116
+ parseInitData(qs) {
117
+ var dcs = decodeURIComponent(qs).split("&").sort();
118
+ var hash = dcs.find(a => a.startsWith("hash=")).split("=")[1];
119
+ dcs = dcs.filter(a => !a.startsWith("hash=")).join("\n");
120
+ var secretKey = crypto.createHmac("sha256", "WebAppData").update("7198222939:AAH3IXLpmxhyRP2A_GOI7LR5UwA0ABLEWnQ").digest();
121
+ var checkHash = crypto.createHmac("sha256", secretKey).update(dcs).digest("hex");
122
+ return (checkHash === hash ? new TelegramUser(JSON.parse(dcs.split("\n").find(a => a.startsWith("user=")).split("=")[1]), this) : null);
123
+ }
113
124
  async stop() {
114
125
  await this.client.stopPolling();
115
126
  return this;
@@ -0,0 +1,22 @@
1
+ module.exports = class {
2
+ constructor(data, bot) {
3
+ this.data = data;
4
+ this.bot = bot;
5
+ this.path = null;
6
+ }
7
+ get id() {
8
+ return this.data.file_id;
9
+ }
10
+ get link() {
11
+ if (this.path) {
12
+ return `https://api.telegram.org/file/bot${this.bot.options.token}/${this.path}`;
13
+ } else {
14
+ return new Promise(res => {
15
+ this.bot.client.getFile(this.id).then(result => {
16
+ this.path = result.file_path;
17
+ res(this.link);
18
+ });
19
+ });
20
+ }
21
+ }
22
+ };
@@ -1,9 +1,13 @@
1
1
  var TelegramChannel = require("./TelegramChannel");
2
+ var TelegramUser = require("./TelegramUser");
2
3
  module.exports = class {
3
4
  constructor(data, bot) {
4
5
  this.data = data;
5
6
  this.bot = bot;
6
7
  this.channel = new TelegramChannel(this.data.chat, bot);
8
+ this.user = this.bot.users.get(this.data.from.id) || new TelegramUser(this.data.from, bot);
9
+ this.user.data = this.data.from;
10
+ this.bot.users.set(this.user.id, this.user);
7
11
  }
8
12
  get id() {
9
13
  return this.data.message_id;
@@ -0,0 +1,30 @@
1
+ var TelegramFile = require("./TelegramFile");
2
+ module.exports = class {
3
+ constructor(data, bot) {
4
+ this.data = data;
5
+ this.bot = bot;
6
+ }
7
+ get id() {
8
+ return this.data.id;
9
+ }
10
+ get isBot() {
11
+ return this.data.is_bot;
12
+ }
13
+ get firstName() {
14
+ return this.data.first_name;
15
+ }
16
+ get lastName() {
17
+ return this.data.last_name;
18
+ }
19
+ get username() {
20
+ return this.data.username;
21
+ }
22
+ get language() {
23
+ return this.data.language_code;
24
+ }
25
+ get avatars() {
26
+ return new Promise(res => {
27
+ this.bot.client.getUserProfilePhotos(this.id).then(result => res(result.photos.map(row => row.map(photo => new TelegramFile(photo, this.bot)))));
28
+ });
29
+ }
30
+ };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var mod = {};
2
- ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot", "Application", "MessageBuilder", "TelegramBot", "TelegramMessage", "TelegramChannel", "TelegramMessageBuilder", "TelegramInteraction"].forEach(part => {
2
+ ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot", "Application", "MessageBuilder", "TelegramBot", "TelegramMessage", "TelegramChannel", "TelegramMessageBuilder", "TelegramInteraction", "TelegramUser", "TelegramFile"].forEach(part => {
3
3
  mod[part] = require(`./${part}`);
4
4
  });
5
5
  module.exports = mod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.4.9",
3
+ "version": "0.5.1",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {