Some music fixes, merge decode and encode into a single command

This commit is contained in:
Essem 2022-04-10 11:20:52 -05:00
parent c37a8a5fcf
commit dd7bd6b4cc
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
9 changed files with 55 additions and 38 deletions

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class WikihowCommand extends Command {
async run() {
await this.acknowledge();
if (!this.interaction.acknowledged) await this.acknowledge();
const request = await fetch("https://www.wikihow.com/api.php?action=query&generator=random&prop=imageinfo&format=json&iiprop=url&grnnamespace=6");
const json = await request.json();
const id = Object.keys(json.query.pages)[0];

View file

@ -0,0 +1,46 @@
import Command from "../../classes/command.js";
import { clean } from "../../utils/misc.js";
class Base64Command extends Command {
async run() {
if (this.type === "classic" && this.args.length === 0) return "You need to provide whether you want to encode or decode the text!";
const command = this.type === "classic" ? this.args[0].toLowerCase() : this.optionsArray[0].name.toLowerCase();
if (command !== "decode" && command !== "encode") return "You need to provide whether you want to encode or decode the text!";
const string = this.type === "classic" ? this.args.slice(1).join(" ") : this.options.text;
if (!string || !string.trim()) return `You need to provide a string to ${command}!`;
if (command === "decode") {
const b64Decoded = Buffer.from(string, "base64").toString("utf8");
return `\`\`\`\n${await clean(b64Decoded)}\`\`\``;
} else if (command === "encode") {
const b64Encoded = Buffer.from(string, "utf8").toString("base64");
return `\`\`\`\n${b64Encoded}\`\`\``;
}
}
static flags = [{
name: "decode",
type: 1,
description: "Decodes a Base64 string",
options: [{
name: "text",
type: 3,
description: "The text to decode",
required: true
}]
}, {
name: "encode",
type: 1,
description: "Encodes a Base64 string",
options: [{
name: "text",
type: 3,
description: "The text to encode",
required: true
}]
}];
static description = "Encodes/decodes a Base64 string";
static arguments = ["[encode/decode]", "[text]"];
}
export default Base64Command;

View file

@ -1,16 +0,0 @@
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
class DecodeCommand extends Command {
async run() {
if (this.args.length === 0) return "You need to provide a string to decode!";
const b64Decoded = Buffer.from(this.args.join(" "), "base64").toString("utf8");
return `\`\`\`\n${await clean(b64Decoded)}\`\`\``;
}
static description = "Decodes a Base64 string";
static aliases = ["b64decode", "base64decode"];
static arguments = ["[text]"];
}
export default DecodeCommand;

View file

@ -1,15 +0,0 @@
import Command from "../../classes/command.js";
class EncodeCommand extends Command {
async run() {
if (this.args.length === 0) return "You need to provide a string to encode!";
const b64Encoded = Buffer.from(this.args.join(" "), "utf8").toString("base64");
return `\`\`\`\n${b64Encoded}\`\`\``;
}
static description = "Encodes a Base64 string";
static aliases = ["b64encode", "base64encode"];
static arguments = ["[text]"];
}
export default EncodeCommand;

View file

@ -5,7 +5,7 @@ import { commands, aliases, info, categories } from "../../utils/collections.js"
class MusicAIOCommand extends Command {
async run() {
let cmd = this.type === "classic" ? this.args[0] : this.optionsArray[0].name;
if (cmd === "music" || this.constructor.aliases.includes(cmd)) return "How dare you recurse me!";
if (cmd === "music" || this.constructor.aliases.includes(cmd)) return "https://media.discordapp.net/attachments/322114245632327703/941958748874887178/robot_dance-trans.gif";
if (this.type === "classic") {
this.origOptions.args.shift();
} else {

View file

@ -6,7 +6,7 @@ class PlayCommand extends MusicCommand {
const input = this.type === "classic" ? this.args.join(" ") : this.options.query;
if (!input && (this.type === "classic" ? (!this.message || this.message.attachments.length <= 0) : !this.options.file)) return "You need to provide what you want to play!";
let query = input ? input.trim() : "";
const attachment = this.type === "classic" ? this.message.attachments[0] : this.interaction.data.resolved.attachments[this.options.file];
const attachment = this.type === "classic" ? this.message.attachments[0] : (this.options.file ? this.interaction.data.resolved.attachments[this.options.file] : null);
if (query.startsWith("||") && query.endsWith("||")) {
query = query.substring(2, query.length - 2);
}
@ -15,10 +15,10 @@ class PlayCommand extends MusicCommand {
}
try {
const url = new URL(query);
return await play(this.client, url, { channel: this.channel, author: this.author, member: this.member, type: this.type, interaction: this.interaction }, true);
return await play(this.client, url, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true);
} catch {
const search = query.startsWith("ytsearch:") ? query : !query && attachment ? attachment.url : `ytsearch:${query}`;
return await play(this.client, search, { channel: this.channel, author: this.author, member: this.member, type: this.type, interaction: this.interaction }, true);
return await play(this.client, search, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true);
}
}

View file

@ -18,12 +18,14 @@ class SkipCommand extends MusicCommand {
if (votes.count + 1 === votes.max) {
await player.player.stop(this.channel.guild.id);
skipVotes.set(this.channel.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) });
if (this.type === "application") return "🔊 The current song has been skipped.";
} else {
skipVotes.set(this.channel.guild.id, newObject);
return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`;
}
} else {
await player.player.stop(this.channel.guild.id);
if (this.type === "application") return "🔊 The current song has been skipped.";
return;
}
}

View file

@ -8,7 +8,7 @@ class SoundboardAIOCommand extends Command {
const soundName = this.type === "classic" ? this.args[0] : this.optionsArray[0].name;
if (!sounds.has(soundName)) return "You need to provide a sound to play!";
const name = sounds.get(soundName);
return await play(this.client, name, { channel: this.channel, author: this.author, type: this.type, interaction: this.interaction });
return await play(this.client, name, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction });
}
static postInit() {

View file

@ -92,7 +92,7 @@ export async function play(client, sound, options, music = false) {
if (oldQueue && oldQueue.length !== 0 && music) {
return `Your ${playlistInfo.name ? "playlist" : "tune"} \`${playlistInfo.name ? playlistInfo.name.trim() : (tracks[0].info.title !== "" ? tracks[0].info.title.trim() : "(blank)")}\` has been added to the queue!`;
} else {
nextSong(client, options, connection, tracks[0].track, tracks[0].info, music, voiceChannel, player ? player.host : options.author.id, player ? player.loop : false, player ? player.shuffle : false);
nextSong(client, options, connection, tracks[0].track, tracks[0].info, music, voiceChannel, player ? player.host : options.member.id, player ? player.loop : false, player ? player.shuffle : false);
return;
}
}