catto.js 0.1.3 → 0.1.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/Application.js CHANGED
@@ -58,7 +58,7 @@ module.exports = class {
58
58
  var p = this.options.flags;
59
59
  var f = [];
60
60
  while (--i > -1) {
61
- if (![22, 21, 20, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0].includes(i) && p >= (1 << i)) {
61
+ if (p >= (1 << i)) {
62
62
  p -= (1 << i);
63
63
  f.push(i);
64
64
  }
@@ -89,7 +89,7 @@ module.exports = class {
89
89
  null,
90
90
  "APPLICATION_COMMAND_BADGE"
91
91
  ];
92
- return f.map(n => fl[n]);
92
+ return f.map(n => fl[n]).filter(n => n);
93
93
  }
94
94
  get tags() {
95
95
  return this.options.tags;
package/Bot.js CHANGED
@@ -121,9 +121,9 @@ module.exports = class extends EventEmitter {
121
121
  });
122
122
  this.client.on("interactionCreate", interaction => {
123
123
  if (interaction.isChatInputCommand()) {
124
- interaction.user = new User(interaction.user);
124
+ interaction.user = new User(interaction.user, this);
125
125
  if (interaction.member) {
126
- interaction.member.user = new User(interaction.member.user);
126
+ interaction.member.user = new User(interaction.member.user, this);
127
127
  }
128
128
  var command = this.slashCommands.get(interaction.commandName);
129
129
  if (command) {
@@ -141,9 +141,9 @@ module.exports = class extends EventEmitter {
141
141
  }
142
142
  });
143
143
  this.client.on("messageCreate", message => {
144
- message.author = new User(message.author);
144
+ message.author = new User(message.author, this);
145
145
  if (message.member) {
146
- message.member.user = new User(message.member.user);
146
+ message.member.user = new User(message.member.user, this);
147
147
  }
148
148
  var args = message.content.split(" ");
149
149
  var cmd = args.shift();
package/User.js CHANGED
@@ -1,9 +1,8 @@
1
1
  var request = require("./request");
2
2
  var Application = require("./Application");
3
3
  module.exports = class {
4
- constructor(options) {
4
+ constructor(options, bot) {
5
5
  this.options = Object.assign({
6
- "client": null,
7
6
  "id": "",
8
7
  "username": "",
9
8
  "avatar": "",
@@ -21,8 +20,14 @@ module.exports = class {
21
20
  "bot": !1,
22
21
  "system": !1
23
22
  }, options || {});
23
+ this.bot = bot;
24
24
  if (this.isBot) {
25
- request.get(`https://discord.com/api/v${(this.options.client ? this.options.client.rest.version.toString() : "10")}/oauth2/applications/${this.id}/rpc`).then(application => {
25
+ request.get({
26
+ "url": `https://discord.com/api/v${(this.bot ? (this.bot.client.rest.version ? this.bot.client.rest.version.toString() : "10") : "10")}/oauth2/applications/${this.id}/rpc`,
27
+ "headers": {
28
+ "Authorization": `Bot ${this.bot.client.token}`
29
+ }
30
+ }).then(application => {
26
31
  this.application = new Application(application.body);
27
32
  });
28
33
  }
@@ -38,7 +43,7 @@ module.exports = class {
38
43
  }
39
44
  get avatar() {
40
45
  var avataru = this.avatarHash;
41
- if (avataru.startsWith("a_")) {
46
+ if (avataru && avataru.startsWith("a_")) {
42
47
  avataru = `https://cdn.discordapp.com/avatars/${this.id}/${avataru}.gif?size=4096`;
43
48
  } else if (avataru) {
44
49
  avataru = `https://cdn.discordapp.com/avatars/${this.id}/${avataru}.webp?size=4096`;
@@ -98,7 +103,7 @@ module.exports = class {
98
103
  }
99
104
  get banner() {
100
105
  var banneru = this.bannerHash;
101
- if (banneru.startsWith("a_")) {
106
+ if (banneru && banneru.startsWith("a_")) {
102
107
  banneru = `https://cdn.discordapp.com/banners/${this.id}/${banneru}.gif?size=4096`;
103
108
  } else if (banneru) {
104
109
  banneru = `https://cdn.discordapp.com/banners/${this.id}/${banneru}.webp?size=4096`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {