More slash command work

This commit is contained in:
Essem 2022-03-31 14:53:22 -05:00
parent 77913618d6
commit c821d91254
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
26 changed files with 188 additions and 62 deletions

View file

@ -28,6 +28,7 @@ class AvatarCommand extends Command {
static description = "Gets a user's avatar";
static aliases = ["pfp", "ava"];
static arguments = ["{mention/id}"];
static slashAllowed = false;
}
export default AvatarCommand;

View file

@ -28,6 +28,7 @@ class BannerCommand extends Command {
static description = "Gets a user's banner";
static aliases = ["userbanner"];
static arguments = ["{mention/id}"];
static slashAllowed = false;
}
export default BannerCommand;

View file

@ -6,8 +6,9 @@ class BroadcastCommand extends Command {
return new Promise((resolve) => {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can broadcast messages!";
if (this.args.length !== 0) {
this.ipc.broadcast("playbroadcast", this.args.join(" "));
const message = this.type === "classic" ? this.args.join(" ") : this.options.message;
if (message && message.trim()) {
this.ipc.broadcast("playbroadcast", message);
this.ipc.register("broadcastSuccess", () => {
this.ipc.unregister("broadcastSuccess");
resolve("Successfully broadcasted message.");
@ -22,6 +23,12 @@ class BroadcastCommand extends Command {
});
}
static flags = [{
name: "message",
type: 3,
description: "The message to broadcast"
}];
static description = "Broadcasts a playing message until the command is run again or the bot restarts";
}

View file

@ -39,7 +39,7 @@ class CountCommand extends Command {
}]
});
}
return paginator(this.client, this.message, embeds);
return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, embeds);
}
static description = "Gets how many times every command was used";

View file

@ -5,7 +5,8 @@ class EvalCommand extends Command {
async run() {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can use eval!";
const code = this.args.join(" ");
await this.acknowledge();
const code = this.type === "classic" ? this.args.join(" ") : this.options.code;
try {
const evaled = eval(code);
const cleaned = await clean(evaled);
@ -24,6 +25,13 @@ class EvalCommand extends Command {
}
}
static flags = [{
name: "code",
type: 3,
description: "The code to execute",
required: true
}];
static description = "Executes JavaScript code";
static aliases = ["run"];
static arguments = ["[code]"];

View file

@ -25,6 +25,7 @@ class EvalRawCommand extends Command {
static description = "Executes JavaScript code (with raw output)";
static aliases = ["run"];
static arguments = ["[code]"];
static slashAllowed = false;
}
export default EvalRawCommand;

View file

@ -8,7 +8,8 @@ class ExecCommand extends Command {
async run() {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can use exec!";
const code = this.args.join(" ");
await this.acknowledge();
const code = this.type === "classic" ? this.args.join(" ") : this.options.cmd;
try {
const execed = await exec(code);
if (execed.stderr) return `\`ERROR\` \`\`\`xl\n${await clean(execed.stderr)}\n\`\`\``;
@ -28,6 +29,13 @@ class ExecCommand extends Command {
}
}
static flags = [{
name: "cmd",
type: 3,
description: "The command to execute",
required: true
}];
static description = "Executes a shell command";
static aliases = ["runcmd"];
static arguments = ["[command]"];

View file

@ -93,7 +93,7 @@ class HelpCommand extends Command {
}]
});
}
return paginator(this.client, this.message, embeds);
return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, embeds);
}
}

View file

@ -8,10 +8,11 @@ import Command from "../../classes/command.js";
class ImageSearchCommand extends Command {
async run() {
if (this.channel.guild && !this.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
if (this.args.length === 0) return "You need to provide something to search for!";
const query = this.type === "classic" ? this.args.join(" ") : this.options.query;
if (!query || !query.trim()) return "You need to provide something to search for!";
this.acknowledge();
const embeds = [];
const rawImages = await fetch(`${random(searx)}/search?format=json&safesearch=2&categories=images&q=!goi%20!ddi%20${encodeURIComponent(this.args.join(" "))}`).then(res => res.json());
const rawImages = await fetch(`${random(searx)}/search?format=json&safesearch=2&categories=images&q=!goi%20!ddi%20${encodeURIComponent(query)}`).then(res => res.json());
if (rawImages.results.length === 0) return "I couldn't find any results!";
const images = rawImages.results.filter((val) => !val.img_src.startsWith("data:"));
for (const [i, value] of images.entries()) {
@ -33,9 +34,16 @@ class ImageSearchCommand extends Command {
}]
});
}
return paginator(this.client, this.message, embeds);
return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, embeds);
}
static flags = [{
name: "query",
type: 3,
description: "The query you want to search for",
required: true
}];
static description = "Searches for images across the web";
static aliases = ["im", "photo", "img"];
static arguments = ["[query]"];

View file

@ -6,12 +6,14 @@ class ReloadCommand extends Command {
return new Promise((resolve) => {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return resolve("Only the bot owner can reload commands!");
if (this.args.length === 0) return resolve("You need to provide a command to reload!");
this.ipc.broadcast("reload", this.args[0]);
const commandName = this.type === "classic" ? this.args.join(" ") : this.options.cmd;
if (!commandName || !commandName.trim()) return resolve("You need to provide a command to reload!");
this.acknowledge();
this.ipc.broadcast("reload", commandName);
this.ipc.register("reloadSuccess", () => {
this.ipc.unregister("reloadSuccess");
this.ipc.unregister("reloadFail");
resolve(`The command \`${this.args[0]}\` has been reloaded.`);
resolve(`The command \`${commandName}\` has been reloaded.`);
});
this.ipc.register("reloadFail", (message) => {
this.ipc.unregister("reloadSuccess");
@ -21,6 +23,13 @@ class ReloadCommand extends Command {
});
}
static flags = [{
name: "cmd",
type: 3,
description: "The command to reload",
required: true
}];
static description = "Reloads a command";
static arguments = ["[command]"];
}

View file

@ -58,6 +58,7 @@ class UserInfoCommand extends Command {
static description = "Gets info about a user";
static aliases = ["user"];
static arguments = ["[mention/id]"];
static slashAllowed = false;
}
export default UserInfoCommand;

View file

@ -7,17 +7,25 @@ import Command from "../../classes/command.js";
class YouTubeCommand extends Command {
async run() {
if (this.args.length === 0) return "You need to provide something to search for!";
const query = this.type === "classic" ? this.args.join(" ") : this.options.query;
if (!query || !query.trim()) return "You need to provide something to search for!";
this.acknowledge();
const messages = [];
const videos = await fetch(`${random(searx)}/search?format=json&safesearch=1&categories=videos&q=!youtube%20${encodeURIComponent(this.args.join(" "))}`).then(res => res.json());
const videos = await fetch(`${random(searx)}/search?format=json&safesearch=1&categories=videos&q=!youtube%20${encodeURIComponent(query)}`).then(res => res.json());
if (videos.results.length === 0) return "I couldn't find any results!";
for (const [i, value] of videos.results.entries()) {
messages.push({ content: `Page ${i + 1} of ${videos.results.length}\n<:youtube:637020823005167626> **${value.title.replaceAll("*", "\\*")}**\nUploaded by **${value.author.replaceAll("*", "\\*")}**\n${value.url}` });
}
return paginator(this.client, this.message, messages);
return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, messages);
}
static flags = [{
name: "query",
type: 3,
description: "The query you want to search for",
required: true
}];
static description = "Searches YouTube";
static aliases = ["yt", "video", "ytsearch"];
static arguments = ["[query]"];