mrmBot-Matrix/commands/music/play.js

21 lines
921 B
JavaScript
Raw Normal View History

import { play } from "../../utils/soundplayer.js";
import MusicCommand from "../../classes/musicCommand.js";
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
const searchRegex = /^ytsearch:/;
class PlayCommand extends MusicCommand {
async run() {
if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
if (!this.args[0]) return "You need to provide what you want to play!";
const query = this.args.join(" ").trim();
const search = urlRegex.test(query) ? query : (searchRegex.test(query) ? query : `ytsearch:${query}`);
return await play(this.client, encodeURIComponent(search), this.message, true);
}
static description = "Plays a song or adds it to the queue";
static aliases = ["p"];
static arguments = ["[url]"];
}
export default PlayCommand;