1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 08:10:18 +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) { if (config.devMode) {
config.token = config.devToken; config.token = config.devToken;
@ -6,7 +6,7 @@ if (config.devMode) {
} }
const { ShardingManager } = require('discord.js'); 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...'); console.log('Launching shards...');
manager.spawn(config.shards, config.shardDelay, config.shardTimeout); manager.spawn(config.shards, config.shardDelay, config.shardTimeout);

View File

@ -1,6 +1,6 @@
{ {
"name": "musix", "name": "musix",
"version": "3.0.4", "version": "3.0.5",
"description": "V3 for Musix the discord music bot", "description": "V3 for Musix the discord music bot",
"main": "./index.js", "main": "./index.js",
"scripts": { "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); client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
return lmsg.edit(client.messages.playlistAdded); return lmsg.edit(client.messages.playlistAdded);
} else { } else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
search(searchString, function (err, res) { search(searchString, function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (res.videos.length === 0) { if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
msg.channel.send(client.messages.noResults);
} else {
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false); client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false);
}
}) })
return;
}
return client.funcs.handleVideo(video, 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); const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) { if (client.funcs.check(client, msg, command)) {
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``); 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 (isNaN(point)) return msg.channel.send(client.messages.validNumber);
if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs); if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs);
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent); 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 Discord = require('discord.js');
const events = './clientEvents/'; const events = './clientEvents/';
client.on('ready', () => { client.on('ready', () => {
require(`${events}ready`).execute(client, Discord); require(`${events}ready.ts`).execute(client, Discord);
}); });
client.on('message', (msg) => { client.on('message', (msg) => {
require(`${events}msg`).execute(client, msg, Discord); require(`${events}msg.ts`).execute(client, msg, Discord);
}); });
client.on('guildCreate', (guild) => { client.on('guildCreate', (guild) => {
require(`${events}guildCreate`).execute(client, guild); require(`${events}guildCreate.ts`).execute(client, guild);
}); });
client.on('voiceStateUpdate', (oldState, newState) => { 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.on('error', (error) => {
client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${client.shard}`); 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 serviceAccount = require('./config/serviceAccount.json');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const events = require('../events/events.js'); const events = require('../events/events.ts');
module.exports = class extends Client { module.exports = class extends Client {
constructor() { constructor() {
@ -21,12 +21,12 @@ module.exports = class extends Client {
this.queue = new Map(); this.queue = new Map();
this.funcs = {}; this.funcs = {};
this.dispatcher = {}; this.dispatcher = {};
this.config = require('./config/config.js'); this.config = require('./config/config.ts');
this.messages = require('./config/messages.js'); this.messages = require('./config/messages.ts');
this.db = admin.firestore(); this.db = admin.firestore();
this.db.FieldValue = require('firebase-admin').firestore.FieldValue; this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
this.dispatcher.finish = require('../events/dispatcherEvents/finish.js'); this.dispatcher.finish = require('../events/dispatcherEvents/finish.ts');
this.dispatcher.error = require('../events/dispatcherEvents/error.js'); this.dispatcher.error = require('../events/dispatcherEvents/error.ts');
this.global = { this.global = {
db: { db: {
guilds: {}, guilds: {},
@ -37,14 +37,14 @@ module.exports = class extends Client {
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`); 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) { for (const file of commandFiles) {
const command = require(`../commands/${file}`); const command = require(`../commands/${file}`);
command.uses = 0; command.uses = 0;
this.commands.set(command.name, command); this.commands.set(command.name, command);
this.commandAliases.set(command.alias, 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) { for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`); const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option); this.settingCmd.set(option.name, option);

View File

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

View File

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

View File

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

View File

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