mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Remove play, resume, pause, stop
This commit is contained in:
@@ -9,7 +9,7 @@ module.exports = class JoinCommand extends Command {
|
||||
super(client, {
|
||||
name: 'join',
|
||||
aliases: ['join-voice-channel', 'join-vc', 'join-voice', 'join-channel', 'connect'],
|
||||
group: 'util-voice',
|
||||
group: 'util',
|
||||
description: 'Joins your voice channel.',
|
||||
guildOnly: true,
|
||||
guarded: true,
|
||||
@@ -6,7 +6,7 @@ module.exports = class LeaveCommand extends Command {
|
||||
super(client, {
|
||||
name: 'leave',
|
||||
aliases: ['leave-voice-channel', 'leave-vc', 'leave-voice', 'leave-channel', 'disconnect'],
|
||||
group: 'util-voice',
|
||||
group: 'util',
|
||||
description: 'Leaves the current voice channel.',
|
||||
guildOnly: true,
|
||||
guarded: true
|
||||
@@ -1,28 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { PermissionFlagsBits } = require('discord.js');
|
||||
|
||||
module.exports = class PauseCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'pause',
|
||||
aliases: ['pause-voice-channel', 'pause-vc', 'pause-voice', 'pause-music', 'pause-playing'],
|
||||
group: 'util-voice',
|
||||
description: 'Pauses the current audio playing.',
|
||||
guildOnly: true,
|
||||
guarded: true
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (connection.canPlay) {
|
||||
return msg.reply('I am not currently playing audio in this server.');
|
||||
}
|
||||
if (!connection.channel.permissionsFor(msg.author).has(PermissionFlagsBits.MoveMembers)) {
|
||||
return msg.reply(`You need the "MOVE_MEMBERS" permission to use the \`${this.name}\` command.`);
|
||||
}
|
||||
connection.pause();
|
||||
return msg.reply('Paused playing.');
|
||||
}
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { PermissionFlagsBits } = require('discord.js');
|
||||
|
||||
module.exports = class ResumeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'resume',
|
||||
aliases: ['resume-voice-channel', 'resume-vc', 'resume-voice', 'resume-music', 'resume-playing'],
|
||||
group: 'util-voice',
|
||||
description: 'Resume the current audio playing.',
|
||||
guildOnly: true,
|
||||
guarded: true
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (connection.canPlay) {
|
||||
return msg.reply('I am not currently playing audio in this server.');
|
||||
}
|
||||
if (!connection.channel.permissionsFor(msg.author).has(PermissionFlagsBits.MoveMembers)) {
|
||||
return msg.reply(`You need the "MOVE_MEMBERS" permission to use the \`${this.name}\` command.`);
|
||||
}
|
||||
connection.unpause();
|
||||
return msg.reply('Resumed playing.');
|
||||
}
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { PermissionFlagsBits } = require('discord.js');
|
||||
|
||||
module.exports = class StopCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'stop',
|
||||
aliases: ['stop-voice-channel', 'stop-vc', 'stop-voice', 'stop-music', 'stop-playing'],
|
||||
group: 'util-voice',
|
||||
description: 'Stops the current audio playing.',
|
||||
guildOnly: true,
|
||||
guarded: true
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (connection.canPlay) {
|
||||
return msg.reply('I am not currently playing audio in this server.');
|
||||
}
|
||||
if (!connection.channel.permissionsFor(msg.author).has(PermissionFlagsBits.MoveMembers)) {
|
||||
return msg.reply(`You need the "MOVE_MEMBERS" permission to use the \`${this.name}\` command.`);
|
||||
}
|
||||
connection.stop();
|
||||
return msg.reply('Stopped playing.');
|
||||
}
|
||||
};
|
||||
@@ -1,98 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { EmbedBuilder, PermissionFlagsBits } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const ytdl = require('@distube/ytdl-core');
|
||||
const { shorten, verify } = require('../../util/Util');
|
||||
const logos = require('../../assets/json/logos');
|
||||
const { GOOGLE_KEY } = process.env;
|
||||
|
||||
module.exports = class PlayCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'play',
|
||||
aliases: ['play-music', 'music'],
|
||||
group: 'voice',
|
||||
description: 'Plays a YouTube video in your voice channel.',
|
||||
guildOnly: true,
|
||||
throttling: {
|
||||
usages: 2,
|
||||
duration: 60
|
||||
},
|
||||
userPermissions: [PermissionFlagsBits.Connect, PermissionFlagsBits.Speak],
|
||||
credit: [
|
||||
{
|
||||
name: 'Google',
|
||||
url: 'https://www.google.com/',
|
||||
reason: 'YouTube Data API',
|
||||
reasonURL: 'https://developers.google.com/youtube/v3/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
|
||||
const result = await this.searchForVideo(query, msg.channel.nsfw || false);
|
||||
if (!result) return msg.reply('Could not find any results for your query.');
|
||||
const data = await ytdl.getInfo(result);
|
||||
const canPlay = this.canUseVideo(data, msg.channel.nsfw || false);
|
||||
if (!canPlay) return msg.reply('I cannot play this video.');
|
||||
if (canPlay === 'length') return msg.reply('This video is longer than 15 minutes, so I can\'t play it.');
|
||||
await msg.reply('Is this the video you want to play? Reply with **[y]es** or **[n]o**.', {
|
||||
embeds: [this.generateEmbed(data)]
|
||||
});
|
||||
const verification = await verify(msg.channel, msg.author);
|
||||
if (!verification) return msg.reply('Aborting playback.');
|
||||
connection.play(ytdl(result, { filter: 'audioonly' }));
|
||||
return msg.reply(`🔉 Now playing **${shorten(data.videoDetails.title, 70)}**!`);
|
||||
}
|
||||
|
||||
async searchForVideo(query, nsfw) {
|
||||
if (ytdl.validateURL(query)) return ytdl.getURLVideoID(query);
|
||||
if (ytdl.validateID(query)) return query;
|
||||
if (!GOOGLE_KEY) return null;
|
||||
const { body } = await request
|
||||
.get('https://www.googleapis.com/youtube/v3/search')
|
||||
.query({
|
||||
part: 'snippet',
|
||||
type: 'video',
|
||||
maxResults: 1,
|
||||
q: query,
|
||||
safeSearch: nsfw ? 'none' : 'strict',
|
||||
key: GOOGLE_KEY
|
||||
});
|
||||
if (!body.items.length) return null;
|
||||
const data = body.items[0];
|
||||
return data.id.videoId;
|
||||
}
|
||||
|
||||
canUseVideo(data, nsfw) {
|
||||
if (data.videoDetails.isPrivate || data.videoDetails.isLiveContent) return false;
|
||||
if (data.videoDetails.age_restricted && nsfw) return false;
|
||||
if (Number.parseInt(data.videoDetails.lengthSeconds, 10) > 900) return 'length';
|
||||
return true;
|
||||
}
|
||||
|
||||
generateEmbed(data) {
|
||||
return new EmbedBuilder()
|
||||
.setColor(0xDD2825)
|
||||
.setTitle(shorten(data.videoDetails.title, 70))
|
||||
.setDescription(shorten(data.videoDetails.description, 100))
|
||||
.setAuthor({ name: 'YouTube', iconURL: logos.youtube, url: 'https://www.youtube.com/' })
|
||||
.setURL(data.videoDetails.video_url)
|
||||
.setThumbnail(data.videoDetails.thumbnails.length ? data.videoDetails.thumbnails[0].url : null)
|
||||
.addField('❯ ID', data.videoDetails.videoId, true)
|
||||
.addField('❯ Publish Date', data.videoDetails.publishDate, true);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user