catto.js 0.4.5 → 0.4.7

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/Application.js CHANGED
@@ -144,7 +144,7 @@ module.exports = class {
144
144
  null,
145
145
  null,
146
146
  null,
147
- null,
147
+ "APPLICATION_AUTO_MODERATION_RULE_CREATE_BADGE",
148
148
  null,
149
149
  null,
150
150
  null,
@@ -201,10 +201,17 @@ module.exports = class {
201
201
  return this.badges.has("EMBEDDED");
202
202
  }
203
203
  /**
204
- * Gets a boolean indicating if the application supports the slash command.
205
- * @returns {boolean} A boolean indicating if the application supports the slash command.
204
+ * Gets a boolean indicating if the application supports the slash commands.
205
+ * @returns {boolean} A boolean indicating if the application supports the slash commands.
206
206
  */
207
207
  get supportsSlash() {
208
208
  return this.badges.has("APPLICATION_COMMAND_BADGE");
209
209
  }
210
+ /**
211
+ * Gets a boolean indicating if the application uses automod.
212
+ * @returns {boolean} A boolean indicating if the application uses automod.
213
+ */
214
+ get supportsAutomod() {
215
+ return this.badges.has("APPLICATION_AUTO_MODERATION_RULE_CREATE_BADGE");
216
+ }
210
217
  };
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  ![Contributors](https://img.shields.io/github/contributors/BoryaGames/catto.js)
5
5
  ![Chat on Discord](https://img.shields.io/discord/916772281747931198?logo=discord)
6
6
 
7
- ✨ catto.js is a new version of universal catto package, which allows easy web server making, random generation and Discord authorization. ✨
7
+ ✨ catto.js is a new version of universal catto package, which allows easy web server making, random generation, Discord authorization and Discord/Telegram bots. ✨
8
8
  ## Features
9
9
  - Creating web server.
10
10
  - Adding SSL certificate and key to your web server.
@@ -13,6 +13,7 @@
13
13
  - Authorizing users using Discord API OAuth2.
14
14
  - Generating random numbers and booleans.
15
15
  - Easy removing elements from Arrays.
16
+ - Creating Discord and Telegram bots using simple API.
16
17
 
17
18
  ## Installation
18
19
  ```sh
package/TelegramBot.js ADDED
@@ -0,0 +1,92 @@
1
+ var events = require("events");
2
+ var Telegram = require("node-telegram-bot-api");
3
+ var TelegramMessage = require("./TelegramMessage");
4
+ if (typeof EventEmitter === "undefined") {
5
+ var { EventEmitter } = events;
6
+ }
7
+ module.exports = class extends EventEmitter {
8
+ constructor(options, client) {
9
+ super();
10
+ this.options = Object.assign({
11
+ "speed": 300,
12
+ "token": "",
13
+ "debug": !1
14
+ }, options || {});
15
+ if (client) {
16
+ this.client = client;
17
+ } else {
18
+ this.client = new Telegram(this.options.token, {
19
+ "polling": {
20
+ "interval": this.options.speed,
21
+ "autoStart": !1
22
+ }
23
+ });
24
+ }
25
+ this.commands = new Map();
26
+ this.slashCommands = new Map();
27
+ if (this.options.debug) {
28
+ this.client.on("polling_error", console.log);
29
+ this.client.on("webhook_error", console.log);
30
+ this.client.on("error", console.log);
31
+ } else {
32
+ this.client.on("polling_error", () => {});
33
+ this.client.on("webhook_error", () => {});
34
+ this.client.on("error", () => {});
35
+ }
36
+ this.client.on("message", message => {
37
+ message = new TelegramMessage(message, this);
38
+ var args = message.content.split(" ");
39
+ var cmd = args.shift();
40
+ var command = this.slashCommands.get(cmd) || this.commands.get(cmd);
41
+ if (command) {
42
+ try {
43
+ command.execute({
44
+ message,
45
+ cmd,
46
+ args,
47
+ "bot": this
48
+ });
49
+ } catch(e) {
50
+ console.log(e);
51
+ }
52
+ }
53
+ this.emit("message", message);
54
+ });
55
+ }
56
+ command(basic, executor) {
57
+ if (typeof basic === "string") {
58
+ basic = {
59
+ "name": basic
60
+ };
61
+ }
62
+ this.commands.set(basic.name, Object.assign(basic, {
63
+ "execute": executor
64
+ }));
65
+ return this;
66
+ }
67
+ slashCommand(basic, executor) {
68
+ if (!basic.name.startsWith("/")) {
69
+ throw new Error("Slash command starts with /.");
70
+ }
71
+ this.slashCommands.set(basic.name, Object.assign(basic, {
72
+ "execute": executor
73
+ }));
74
+ return this;
75
+ }
76
+ async run() {
77
+ await this.client.startPolling();
78
+ var commands = [];
79
+ for (var cmd of this.slashCommands.values()) {
80
+ commands.push({
81
+ "command": cmd.name.replace("/", ""),
82
+ "description": cmd.description
83
+ });
84
+ }
85
+ this.client.setMyCommands(commands);
86
+ return this;
87
+ }
88
+ async stop() {
89
+ await this.client.stopPolling();
90
+ return this;
91
+ }
92
+ };
@@ -0,0 +1,43 @@
1
+ module.exports = class {
2
+ constructor(data, bot) {
3
+ this.data = data;
4
+ this.bot = bot;
5
+ this.typingLoop = null;
6
+ }
7
+ get id() {
8
+ return this.data.id;
9
+ }
10
+ async type() {
11
+ await this.bot.client.sendChatAction(this.id, "typing");
12
+ }
13
+ async startTyping() {
14
+ if (this.typingLoop === null) {
15
+ await this.bot.client.sendChatAction(this.id, "typing");
16
+ this.typingLoop = setInterval(() => this.type(), 4e3);
17
+ }
18
+ }
19
+ stopTyping() {
20
+ clearInterval(this.typingLoop);
21
+ this.typingLoop = null;
22
+ }
23
+ async send(data) {
24
+ if (typeof data !== "object") {
25
+ data = {
26
+ "content": data
27
+ };
28
+ }
29
+ await this.bot.client.sendMessage(this.id, data.content, {
30
+ "reply_parameters": data.replyParameters ? {
31
+ "message_id": data.replyParameters.message.id,
32
+ "chat_id": (data.replyParameters.channel ? data.replyParameters.channel.id : this.id),
33
+ "allow_sending_without_reply": !1
34
+ } : void 0,
35
+ "reply_markup": data.replyMarkup ? data.replyMarkup : {
36
+ "remove_keyboard": !0
37
+ }
38
+ });
39
+ if (this.typingLoop !== null) {
40
+ await this.type();
41
+ }
42
+ }
43
+ };
@@ -0,0 +1,26 @@
1
+ var TelegramChannel = require("./TelegramChannel");
2
+ module.exports = class {
3
+ constructor(data, bot) {
4
+ this.data = data;
5
+ this.bot = bot;
6
+ this.channel = new TelegramChannel(this.data.chat, bot);
7
+ }
8
+ get id() {
9
+ return this.data.message_id;
10
+ }
11
+ get content() {
12
+ return this.data.text;
13
+ }
14
+ reply(data) {
15
+ if (typeof data !== "object") {
16
+ data = {
17
+ "content": data
18
+ };
19
+ }
20
+ return this.channel.send(Object.assign({
21
+ "replyParameters": {
22
+ "message": this
23
+ }
24
+ }, data));
25
+ }
26
+ };
package/User.js CHANGED
@@ -82,7 +82,7 @@ module.exports = class {
82
82
  }
83
83
  get badges() {
84
84
  var i = 23;
85
- var p = (this.options.flags ? (this.options.flags.bitfield ? this.options.flags.bitfield : this.options.flags) : (this.options.public_flags.bitfield ? this.options.public_flags.bitfield : this.options.public_flags));
85
+ var p = (this.options.flags ? (this.options.flags.bitfield ? this.options.flags.bitfield : this.options.flags) : (this.options.publicFlags.bitfield ? this.options.publicFlags.bitfield : this.options.publicFlags));
86
86
  var f = [];
87
87
  while (--i > -1) {
88
88
  if (![21, 20, 15, 13, 12, 11, 5, 4].includes(i) && p >= (1 << i)) {
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"].forEach(part => {
2
+ ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot", "Application", "MessageBuilder", "TelegramBot", "TelegramMessage", "TelegramChannel"].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.5",
3
+ "version": "0.4.7",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,7 +27,10 @@
27
27
  "cattoes",
28
28
  "easy",
29
29
  "slash",
30
- "random"
30
+ "random",
31
+ "telegram",
32
+ "api",
33
+ "telegraf"
31
34
  ],
32
35
  "author": "cat1234",
33
36
  "license": "ISC",
@@ -45,6 +48,7 @@
45
48
  "express": "^4.18.2",
46
49
  "express-session": "^1.18.0",
47
50
  "express-ws": "^5.0.2",
51
+ "node-telegram-bot-api": "^0.65.1",
48
52
  "request": "^2.88.2",
49
53
  "session-file-store": "^1.5.0",
50
54
  "tweetnacl": "^1.0.3"