catto.js 0.9.9 → 1.0.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.
Files changed (2) hide show
  1. package/Bot.js +54 -13
  2. package/package.json +1 -1
package/Bot.js CHANGED
@@ -62,7 +62,8 @@ module.exports = class extends EventEmitter {
62
62
  this.client.on("debug", console.log);
63
63
  }
64
64
  this.client.on("ready", () => {
65
- var cmds = [];
65
+ var gcmds = [];
66
+ var scmds = [];
66
67
  for (var cmd of this.slashCommands.values()) {
67
68
  var cmdo = new Discord.SlashCommandBuilder();
68
69
  cmdo.setName(cmd.name).setDescription(cmd.description).setDMPermission(cmd.dm);
@@ -168,29 +169,69 @@ module.exports = class extends EventEmitter {
168
169
  if (cmd.user) {
169
170
  contexts.push(2);
170
171
  }
171
- cmds.push(Object.assign(cmdo.toJSON(), {
172
- integration_types, contexts
173
- }));
172
+ if (cmd.servers) {
173
+ cmd.servers.forEach(id => {
174
+ if (!scmds[id]) {
175
+ scmds[id] = [];
176
+ }
177
+ scmds[id].push(Object.assign(cmdo.toJSON(), {
178
+ integration_types, contexts
179
+ }));
180
+ });
181
+ } else {
182
+ gcmds.push(Object.assign(cmdo.toJSON(), {
183
+ integration_types, contexts
184
+ }));
185
+ }
174
186
  }
175
187
  for (var cmd of this.userContexts.values()) {
176
188
  var cmdo = new Discord.ContextMenuCommandBuilder();
177
189
  cmdo.setType(2).setName(cmd.name).setDMPermission(cmd.dm);
178
- cmds.push(Object.assign(cmdo.toJSON(), {
179
- "integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
180
- "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
181
- }));
190
+ if (cmd.servers) {
191
+ cmd.servers.forEach(id => {
192
+ if (!scmds[id]) {
193
+ scmds[id] = [];
194
+ }
195
+ scmds[id].push(Object.assign(cmdo.toJSON(), {
196
+ "integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
197
+ "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
198
+ }));
199
+ });
200
+ } else {
201
+ gcmds.push(Object.assign(cmdo.toJSON(), {
202
+ "integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
203
+ "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
204
+ }));
205
+ }
182
206
  }
183
207
  for (var cmd of this.messageContexts.values()) {
184
208
  var cmdo = new Discord.ContextMenuCommandBuilder();
185
209
  cmdo.setType(3).setName(cmd.name).setDMPermission(cmd.dm);
186
- cmds.push(Object.assign(cmdo.toJSON(), {
187
- "integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
188
- "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
189
- }));
210
+ if (cmd.servers) {
211
+ cmd.servers.forEach(id => {
212
+ if (!scmds[id]) {
213
+ scmds[id] = [];
214
+ }
215
+ scmds[id].push(Object.assign(cmdo.toJSON(), {
216
+ "integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
217
+ "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
218
+ }));
219
+ });
220
+ } else {
221
+ gcmds.push(Object.assign(cmdo.toJSON(), {
222
+ "integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
223
+ "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
224
+ }));
225
+ }
190
226
  }
191
227
  if (this.options.slashListener) {
192
228
  this.client.rest.put(`/applications/${this.client.application.id}/commands`, {
193
- "body": cmds
229
+ "body": gcmds
230
+ });
231
+ Object.keys(scmds).forEach(id => {
232
+ this.client.rest.put(`/applications/${this.client.application.id}/guilds/${id}/commands`, {
233
+ "body": scmds[id]
234
+ });
194
235
  });
195
236
  }
196
237
  this.emit("running", { Discord });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.9.9",
3
+ "version": "1.0.0",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {