1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 01:21:56 +00:00

update 3.0.5

This commit is contained in:
MatteZ02 2020-03-24 12:02:07 +02:00
parent 11cea679d1
commit e20d0e18e0
61 changed files with 81 additions and 109 deletions

View File

@ -1,4 +1,4 @@
const config = require("./src/struct/config/config.js");
const config = require("./src/struct/config/config.ts");
if (config.devMode) {
config.token = config.devToken;
@ -6,7 +6,7 @@ if (config.devMode) {
}
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/bot.js', { token: config.token, respawn: config.respawn, totalShards: config.shards });
const manager = new ShardingManager('./src/bot.ts', { token: config.token, respawn: config.respawn, totalShards: config.shards });
console.log('Launching shards...');
manager.spawn(config.shards, config.shardDelay, config.shardTimeout);

View File

@ -1,6 +1,6 @@
{
"name": "musix",
"version": "3.0.4",
"version": "3.0.5",
"description": "V3 for Musix the discord music bot",
"main": "./index.js",
"scripts": {

View File

@ -1,2 +0,0 @@
const MusicClient = require('./struct/client.js');
const client = new MusicClient({});

2
src/bot.ts Normal file
View File

@ -0,0 +1,2 @@
const MusicClient = require('./struct/client.ts');
const client = new MusicClient({});

View File

@ -35,20 +35,11 @@ module.exports = {
client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
return lmsg.edit(client.messages.playlistAdded);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
search(searchString, function (err, res) {
if (err) return console.log(err);
if (res.videos.length === 0) {
msg.channel.send(client.messages.noResults);
} else {
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false);
}
})
return;
}
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
search(searchString, function (err, res) {
if (err) return console.log(err);
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false);
})
}
}
};

View File

@ -1,71 +0,0 @@
const YouTube = require("simple-youtube-api");
const he = require('he');
module.exports = {
name: 'search',
alias: 'sr',
usage: '<search word(s)>',
description: 'Search the top 10 queryes and choose one.',
onlyDev: false,
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, command) {
const youtube = new YouTube(client.config.api_key);
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const queue = client.queue.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
if (!queue) {
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
} else {
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
}
if (!args[1]) return msg.channel.send(client.messages.noQuery);
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
}
let message;
message = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
return lmsg.edit(message);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.songSelection)
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
.setFooter(client.messages.provideANumber)
.setColor(client.config.embedColor)
msg.channel.send(embed);
try {
var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, {
max: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
console.error(err);
return msg.channel.send(client.messages.cancellingVideoSelection);
}
const videoIndex = parseInt(response.first().content);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) {
console.error(err);
return msg.channel.send(client.messages.noResults);
}
}
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
}
}
};

51
src/commands/search.ts Normal file
View File

@ -0,0 +1,51 @@
const yts = require('yt-search');
const he = require('he');
module.exports = {
name: 'search',
alias: 'sr',
usage: '<search word(s)>',
description: 'Search the top 10 queryes and choose one.',
onlyDev: false,
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, command) {
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const queue = client.queue.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
if (!queue) {
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
} else {
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
}
if (!args[1]) return msg.channel.send(client.messages.noQuery);
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
yts(searchString, async function (err, res) {
if (err) return console.log(err);
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
const videos = res.videos.slice(0, 10);
let index = 0;
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.songSelection)
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
.setFooter(client.messages.provideANumber)
.setColor(client.config.embedColor)
msg.channel.send(embed);
try {
var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, {
max: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
console.error(err);
return msg.channel.send(client.messages.cancellingVideoSelection);
}
const videoIndex = parseInt(response.first().content) - 1;
return client.funcs.handleVideo(videos[videoIndex], msg, voiceChannel, client, false);
})
}
};

View File

@ -10,7 +10,8 @@ module.exports = {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``);
const point = parseInt(args[1] - 1);
let point = parseInt(args[1]);
point = point - 1;
if (isNaN(point)) return msg.channel.send(client.messages.validNumber);
if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs);
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent);

View File

@ -2,16 +2,16 @@ module.exports = function (client) {
const Discord = require('discord.js');
const events = './clientEvents/';
client.on('ready', () => {
require(`${events}ready`).execute(client, Discord);
require(`${events}ready.ts`).execute(client, Discord);
});
client.on('message', (msg) => {
require(`${events}msg`).execute(client, msg, Discord);
require(`${events}msg.ts`).execute(client, msg, Discord);
});
client.on('guildCreate', (guild) => {
require(`${events}guildCreate`).execute(client, guild);
require(`${events}guildCreate.ts`).execute(client, guild);
});
client.on('voiceStateUpdate', (oldState, newState) => {
require(`${events}voiceStateUpdate`).execute(client, oldState, newState);
require(`${events}voiceStateUpdate.ts`).execute(client, oldState, newState);
});
client.on('error', (error) => {
client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${client.shard}`);

View File

@ -3,7 +3,7 @@ const admin = require('firebase-admin');
const serviceAccount = require('./config/serviceAccount.json');
const fs = require('fs');
const path = require('path');
const events = require('../events/events.js');
const events = require('../events/events.ts');
module.exports = class extends Client {
constructor() {
@ -21,12 +21,12 @@ module.exports = class extends Client {
this.queue = new Map();
this.funcs = {};
this.dispatcher = {};
this.config = require('./config/config.js');
this.messages = require('./config/messages.js');
this.config = require('./config/config.ts');
this.messages = require('./config/messages.ts');
this.db = admin.firestore();
this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
this.dispatcher.finish = require('../events/dispatcherEvents/finish.js');
this.dispatcher.error = require('../events/dispatcherEvents/error.js');
this.dispatcher.finish = require('../events/dispatcherEvents/finish.ts');
this.dispatcher.error = require('../events/dispatcherEvents/error.ts');
this.global = {
db: {
guilds: {},
@ -37,14 +37,14 @@ module.exports = class extends Client {
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`);
});
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.ts'));
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
command.uses = 0;
this.commands.set(command.name, command);
this.commandAliases.set(command.alias, command);
}
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.js'));
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.ts'));
for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option);

View File

@ -13,7 +13,7 @@ module.exports = {
embedColor: "#b50002",
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
supportServer: "https://discord.gg/rvHuJtB",
devMode: false,
devMode: true,
dblApi: false,
saveDB: true,
respawn: true,

View File

@ -16,7 +16,7 @@ module.exports = async function (video, msg, voiceChannel, client, playlist = fa
return msg.channel.send(message);
}
const construct = require("../config/queueConfig.js");
const construct = require("../config/queueConfig.ts");
construct.textChannel = msg.channel;
construct.voiceChannel = voiceChannel;

View File

@ -1,8 +1,8 @@
module.exports = function msToTime(duration, format) {
var seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24);
hours = Math.floor((duration / (1000 * 60 * 60)) % 24),
days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24);
days = (days < 10) ? "0" + days : days;
hours = (hours < 10) ? "0" + hours : hours;

View File

@ -1,7 +1,7 @@
module.exports = async function (guild, song, client, seek, play) {
const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const streamConfig = require("../config/streamConfig.js");
const streamConfig = require("../config/streamConfig.ts");
const getThumb = require('video-thumbnail-url');
const prism = require('prism-media');
@ -20,7 +20,7 @@ module.exports = async function (guild, song, client, seek, play) {
"-f", "s16le",
"-ar", "48000",
"-ac", "2",
"-af", `bass=g=${queue.bass}`
"-af", `bass=g=${queue.bass}`,
];
const transcoder = new prism.FFmpeg({ args: ffmpegArgs });