summaryrefslogtreecommitdiff
path: root/server/src/commands/voice/Play.ts
blob: 9ea335d22fbaced0d816d08b79cd414ae02fd384 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Command } from 'discord-akairo';
import { Message } from 'discord.js';
import request from 'node-superfetch';

export default class PlayVoice extends Command {
    public constructor() {
        super('play', {
            aliases: ['play'],
            category: 'voice',
            description: {
                content: 'Gives you the bot\'s IP address.',
                usage: '[song url/ name]',
                examples: [
                    ''
                ]
            },
            ratelimit: 3,
            args: [
                {
                    id: 'song',
                    type: 'string'
                }
            ]
        });
    }
    
    public async exec(msg: Message, { song }): Promise<Message> {
        const { channel } = msg.member.voice;
        
        const serverQueue = this.client.queue.get(msg.guild.id);
        if (!channel) return msg.reply('You need to join a voice channel first!'); //error
        if (serverQueue && channel !== msg.guild.me.voice.channel)
            return msg.reply(`You must be in the same channel as ${this.client.user}`); //error
            
        const permissions = channel.permissionsFor(msg.client.user);
        if (!permissions.has('CONNECT'))
            return msg.reply('Cannot connect to voice channel, missing permissions.');
        if (!permissions.has('SPEAK'))
            return msg.reply('I cannto speak in this voice channel, make sure I have the proper permissions!');
            
        const search = song;
        const videoPattern = /^(https?:\/\/)?(www\.)?(m\.)?(youtube\.com|youtu\.?be)\/.+$/gi;
        const playlistPattern = /^.*(list=)([^#\&\?]*).*/gi;
        const scRegex = /^https?:\/\/(soundcloud\.com)\/(.*)$/;
        const url = song;
        const urlValid = videoPattern.test(song);
        
        if (!videoPattern.test(song) && playlistPattern.test(song)) {
            return this.client.commandHandler.commandUtil.
        }
    }
}