Lots of slash command work, added workaround for eris-fleet request debugging
This commit is contained in:
parent
b8aeb6625a
commit
2cffdf6628
61 changed files with 417 additions and 244 deletions
|
@ -8,21 +8,33 @@ class Command {
|
|||
this.args = options.args;
|
||||
if (options.type === "classic") {
|
||||
this.message = options.message;
|
||||
this.channel = options.message.channel;
|
||||
this.author = options.message.author;
|
||||
this.content = options.content;
|
||||
this.specialArgs = options.specialArgs;
|
||||
this.reference = {
|
||||
messageReference: {
|
||||
channelID: this.message.channel.id,
|
||||
channelID: this.channel.id,
|
||||
messageID: this.message.id,
|
||||
guildID: this.message.channel.guild ? this.message.channel.guild.id : undefined,
|
||||
guildID: this.channel.guild ? this.channel.guild.id : undefined,
|
||||
failIfNotExists: false
|
||||
},
|
||||
allowedMentions: {
|
||||
repliedUser: false
|
||||
}
|
||||
};
|
||||
} else {
|
||||
} else if (options.type === "application") {
|
||||
this.interaction = options.interaction;
|
||||
this.channel = options.interaction.channel;
|
||||
this.author = options.interaction.guildID ? options.interaction.member : options.interaction.user;
|
||||
if (options.interaction.data.options) {
|
||||
this.specialArgs = this.options = options.interaction.data.options.reduce((obj, item) => {
|
||||
obj[item.name] = item.value;
|
||||
return obj;
|
||||
}, {});
|
||||
} else {
|
||||
this.specialArgs = this.options = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +44,7 @@ class Command {
|
|||
|
||||
async acknowledge() {
|
||||
if (this.type === "classic") {
|
||||
await this.message.channel.sendTyping();
|
||||
await this.client.sendChannelTyping(this.channel.id);
|
||||
} else {
|
||||
await this.interaction.acknowledge();
|
||||
}
|
||||
|
|
|
@ -33,19 +33,44 @@ class ImageCommand extends Command {
|
|||
]
|
||||
};*/
|
||||
|
||||
constructor(client, cluster, worker, ipc, options) {
|
||||
super(client, cluster, worker, ipc, options);
|
||||
this.flags = [];
|
||||
if (this.constructor.requiresText || this.constructor.textOptional) {
|
||||
this.flags.push({
|
||||
name: "text",
|
||||
type: 3,
|
||||
description: "The text to put on the image",
|
||||
required: !this.constructor.textOptional
|
||||
});
|
||||
}
|
||||
if (this.constructor.requiresImage) {
|
||||
this.flags.push({
|
||||
name: "image",
|
||||
type: 11,
|
||||
description: "An image/GIF attachment"
|
||||
}, {
|
||||
name: "link",
|
||||
type: 3,
|
||||
description: "An image/GIF URL"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async criteria() {
|
||||
return true;
|
||||
}
|
||||
|
||||
async run() {
|
||||
const timestamp = this.type === "classic" ? this.message.createdAt : Math.floor((this.interaction.id / 4194304) + 1420070400000);
|
||||
// check if this command has already been run in this channel with the same arguments, and we are awaiting its result
|
||||
// if so, don't re-run it
|
||||
if (runningCommands.has(this.message.author.id) && (new Date(runningCommands.get(this.message.author.id)) - new Date(this.message.createdAt)) < 5000) {
|
||||
if (runningCommands.has(this.author.id) && (new Date(runningCommands.get(this.author.id)) - new Date(timestamp)) < 5000) {
|
||||
return "Please slow down a bit.";
|
||||
}
|
||||
// before awaiting the command result, add this command to the set of running commands
|
||||
runningCommands.set(this.message.author.id, this.message.createdAt);
|
||||
|
||||
runningCommands.set(this.author.id, timestamp);
|
||||
|
||||
const magickParams = {
|
||||
cmd: this.constructor.command,
|
||||
params: {}
|
||||
|
@ -53,15 +78,15 @@ class ImageCommand extends Command {
|
|||
|
||||
if (this.constructor.requiresImage) {
|
||||
try {
|
||||
const image = await imageDetect(this.client, this.message, true);
|
||||
const image = await imageDetect(this.client, this.message, this.interaction, this.options, true);
|
||||
if (image === undefined) {
|
||||
runningCommands.delete(this.message.author.id);
|
||||
runningCommands.delete(this.author.id);
|
||||
return this.constructor.noImage;
|
||||
} else if (image.type === "large") {
|
||||
runningCommands.delete(this.message.author.id);
|
||||
runningCommands.delete(this.author.id);
|
||||
return "That image is too large (>= 25MB)! Try using a smaller image.";
|
||||
} else if (image.type === "tenorlimit") {
|
||||
runningCommands.delete(this.message.author.id);
|
||||
runningCommands.delete(this.author.id);
|
||||
return "I've been rate-limited by Tenor. Please try uploading your GIF elsewhere.";
|
||||
}
|
||||
magickParams.path = image.path;
|
||||
|
@ -70,15 +95,16 @@ class ImageCommand extends Command {
|
|||
magickParams.params.delay = image.delay ?? 0;
|
||||
if (this.constructor.requiresGIF) magickParams.onlyGIF = true;
|
||||
} catch (e) {
|
||||
runningCommands.delete(this.message.author.id);
|
||||
runningCommands.delete(this.author.id);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (this.constructor.requiresText) {
|
||||
if (this.args.length === 0 || !await this.criteria(this.args)) {
|
||||
runningCommands.delete(this.message.author.id);
|
||||
const text = this.type === "classic" ? this.args : this.options.text;
|
||||
if (text.length === 0 || !await this.criteria(text)) {
|
||||
runningCommands.delete(this.author.id);
|
||||
return this.constructor.noText;
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +119,7 @@ class ImageCommand extends Command {
|
|||
}
|
||||
|
||||
let status;
|
||||
if (magickParams.params.type === "image/gif") {
|
||||
if (magickParams.params.type === "image/gif" && this.type === "classic") {
|
||||
status = await this.processMessage(this.message);
|
||||
} else {
|
||||
this.acknowledge();
|
||||
|
@ -113,9 +139,9 @@ class ImageCommand extends Command {
|
|||
throw e;
|
||||
} finally {
|
||||
if (status && (status.channel.messages ? status.channel.messages.has(status.id) : await this.client.getMessage(status.channel.id, status.id).catch(() => undefined))) await status.delete();
|
||||
runningCommands.delete(this.message.author.id);
|
||||
runningCommands.delete(this.author.id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
processMessage(message) {
|
||||
|
@ -124,6 +150,7 @@ class ImageCommand extends Command {
|
|||
|
||||
static requiresImage = true;
|
||||
static requiresText = false;
|
||||
static textOptional = false;
|
||||
static requiresGIF = false;
|
||||
static noImage = "You need to provide an image/GIF!";
|
||||
static noText = "You need to provide some text!";
|
||||
|
|
|
@ -2,10 +2,10 @@ import Command from "./command.js";
|
|||
import { players, queues } from "../utils/soundplayer.js";
|
||||
|
||||
class MusicCommand extends Command {
|
||||
constructor(client, cluster, worker, ipc, message, args, content, specialArgs) {
|
||||
super(client, cluster, worker, ipc, message, args, content, specialArgs);
|
||||
this.connection = players.get(message.channel.guild.id);
|
||||
this.queue = queues.get(message.channel.guild.id);
|
||||
constructor(client, cluster, worker, ipc, options) {
|
||||
super(client, cluster, worker, ipc, options);
|
||||
this.connection = players.get(options.message.channel.guild.id);
|
||||
this.queue = queues.get(options.message.channel.guild.id);
|
||||
}
|
||||
|
||||
static requires = ["sound"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue