catto.js 0.4.8 → 0.5.0

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,6 +1,7 @@
1
1
  var events = require("events");
2
2
  var Telegram = require("node-telegram-bot-api");
3
3
  var TelegramMessage = require("./TelegramMessage");
4
+ var TelegramInteraction = require("./TelegramInteraction");
4
5
  if (typeof EventEmitter === "undefined") {
5
6
  var { EventEmitter } = events;
6
7
  }
@@ -52,6 +53,9 @@ module.exports = class extends EventEmitter {
52
53
  }
53
54
  this.emit("message", message);
54
55
  });
56
+ this.client.on("callback_query", interaction => {
57
+ this.emit("interaction", new TelegramInteraction(interaction, this));
58
+ });
55
59
  }
56
60
  command(basic, executor) {
57
61
  if (typeof basic === "string") {
@@ -1,3 +1,4 @@
1
+ var TelegramMessageBuilder = require("./TelegramMessageBuilder");
1
2
  module.exports = class {
2
3
  constructor(data, bot) {
3
4
  this.data = data;
@@ -21,11 +22,14 @@ module.exports = class {
21
22
  this.typingLoop = null;
22
23
  }
23
24
  async send(data) {
24
- if (typeof data !== "object") {
25
+ if (typeof data === "string") {
25
26
  data = {
26
27
  "content": data
27
28
  };
28
29
  }
30
+ if (data instanceof TelegramMessageBuilder) {
31
+ data = data.data;
32
+ }
29
33
  await this.bot.client.sendMessage(this.id, data.content, {
30
34
  "reply_parameters": data.replyParameters ? {
31
35
  "message_id": data.replyParameters.message.id,
@@ -0,0 +1,23 @@
1
+ var TelegramMessage = require("./TelegramMessage");
2
+ module.exports = class {
3
+ constructor(data, bot) {
4
+ this._data = data;
5
+ this.bot = bot;
6
+ this.message = new TelegramMessage(this._data.message, bot);
7
+ }
8
+ get id() {
9
+ return this._data.id;
10
+ }
11
+ get data() {
12
+ return this._data.data;
13
+ }
14
+ async notify(text) {
15
+ await this.bot.client.answerCallbackQuery(this.id, { text });
16
+ }
17
+ async modal(text) {
18
+ await this.bot.client.answerCallbackQuery(this.id, {
19
+ text,
20
+ "show_alert": !0
21
+ });
22
+ }
23
+ };
@@ -1,9 +1,11 @@
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 = new TelegramUser(this.data.from, bot);
7
9
  }
8
10
  get id() {
9
11
  return this.data.message_id;
@@ -0,0 +1,68 @@
1
+ module.exports = class {
2
+ constructor() {
3
+ this.data = {};
4
+ }
5
+ text(data) {
6
+ if (!this.data.content) {
7
+ this.data.content = data;
8
+ } else {
9
+ this.data.content += ` ${data}`;
10
+ }
11
+ return this;
12
+ }
13
+ buttons(rows) {
14
+ this.data.replyMarkup = {
15
+ "inline_keyboard": rows.map(row => row.map(btn => {
16
+ switch(btn.type) {
17
+ case "web":
18
+ return {
19
+ "text": btn.label,
20
+ "url": btn.link
21
+ };
22
+ break;
23
+ case "webapp":
24
+ return {
25
+ "text": btn.label,
26
+ "web_app": {
27
+ "url": btn.link
28
+ }
29
+ };
30
+ break;
31
+ case "interaction":
32
+ return {
33
+ "text": btn.label,
34
+ "callback_data": btn.data
35
+ };
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+ }).filter(btn => btn))
41
+ };
42
+ return this;
43
+ }
44
+ keyboard(rows) {
45
+ this.data.replyMarkup = {
46
+ "keyboard": rows.map(row => row.map(btn => {
47
+ switch(btn.type) {
48
+ case "answer":
49
+ return {
50
+ "text": btn.label
51
+ };
52
+ break;
53
+ case "webapp":
54
+ return {
55
+ "text": btn.label,
56
+ "web_app": {
57
+ "url": btn.link
58
+ }
59
+ };
60
+ break;
61
+ default:
62
+ break;
63
+ }
64
+ }).filter(btn => btn))
65
+ };
66
+ return this;
67
+ }
68
+ };
@@ -0,0 +1,24 @@
1
+ module.exports = class {
2
+ constructor(data, bot) {
3
+ this.data = data;
4
+ this.bot = bot;
5
+ }
6
+ get id() {
7
+ return this.data.id;
8
+ }
9
+ get isBot() {
10
+ return this.data.is_bot;
11
+ }
12
+ get firstName() {
13
+ return this.data.first_name;
14
+ }
15
+ get lastName() {
16
+ return this.data.last_name;
17
+ }
18
+ get username() {
19
+ return this.data.username;
20
+ }
21
+ get language() {
22
+ return this.data.language_code;
23
+ }
24
+ };
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"].forEach(part => {
2
+ ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot", "Application", "MessageBuilder", "TelegramBot", "TelegramMessage", "TelegramChannel", "TelegramMessageBuilder", "TelegramInteraction", "TelegramUser"].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.8",
3
+ "version": "0.5.0",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {