1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-16 18:56:00 +00:00

removed src

This commit is contained in:
MatteZ02
2020-02-10 21:08:46 +02:00
parent f28c2fcd77
commit ee246734aa
48 changed files with 12 additions and 0 deletions

74
struct/client.js Normal file
View File

@ -0,0 +1,74 @@
const { Client, Collection } = require('discord.js');
const Discord = require('discord.js');
const admin = require('firebase-admin');
const serviceAccount = require('./config/serviceAccount.json');
const fs = require('fs');
const path = require('path')
const events = '../events/';
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START']
});
this.commands = new Collection();
this.commandAliases = new Collection();
this.settingCmd = new Collection();
this.queue = new Map();
this.funcs = {};
this.dispatcher = {};
this.config = require('./config/config.js');
this.dispatcher.finish = require('../events/dispatcher/finish.js');
fs.readdirSync(path.join(__dirname, 'funcs')).forEach(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'));
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'));
for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option);
}
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
this.db = admin.firestore();
this.global = {
db: {
guilds: {},
},
};
this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
if (this.config.devMode) {
this.config.token = this.config.devToken;
}
this.on('ready', () => {
require(`${events}ready`).execute(this, Discord);
});
this.on('message', (msg) => {
require(`${events}msg`).execute(this, msg, Discord);
});
this.on('guildCreate', (guild) => {
require(`${events}guildCreate`).execute(this, guild);
});
this.on('voiceStateUpdate', (newMember) => {
require(`${events}voiceStateUpdate`).execute(this, newMember);
});
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
}
};

28
struct/config/config.js Normal file
View File

@ -0,0 +1,28 @@
require('dotenv/config');
module.exports = {
//credentials
token: process.env.TOKEN,
devToken: process.env.DEVTOKEN,
dblKey: process.env.DBLKEY,
api_key: process.env.GOOGLE_API_KEY,
//channels
debug_channel: "634718645188034560",
primary_test_channel: "617633098296721409",
secondary_test_channel: "570531724002328577",
devId: "360363051792203779",
//misc
embedColor: "#B127CD",
invite: "https://discordapp.com/api/oauth2/authorize?client_id=649252971690983446&permissions=8&redirect_uri=https%3A%2F%2Fdiscordapp.com%2Foauth2%2Fauthorize%3Fclient_id%3D649252971690983446%26%3Bscope%3Dbot%26%3Bpermissions%3D0&scope=bot",
//Settings
devMode: false,
dblApi: false,
saveDB: false,
//db values
prefix: "*",
defaultVolume: 5,
permissions: false,
dj: false,
djrole: null,
startPlaying: true,
}

View File

@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "musix-canary",
"private_key_id": "a57304e5072095b259f2a2f8d415857a3c8aa2ca",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDcHdNxXUldc+sO\nuQLKh5cwzc60IwENBD4K3bhqBBxePrvFozRlFB3/EN8d5dak5Vq+N9pdJKX7BdSp\nUNsCwwTKBQVQG+CZTzzn92+tfd0f7PwqbU1iQSTMBdjy+/6Jo2zZwgfivpGEZBMb\nibgqEQ3P7GLI7yQtF4jEnXObeN56o5OXkculQ7CKQ3L5QnEUi5iV6/6mCOIKKjLf\nUaNYRmMygcfDdLowKvueUMNDtO5rpbVmMEm3hiaqLU0aDTm+OfhOj+ahY8pI5/g2\nemfMGRS2mK+H8Ja4+FoG4ibW6MF4Vy3GhSojucUd8N87PLW5Mgr7LKkk2C3a/BCn\nQeK0J8RXAgMBAAECggEAHAIDjJI1Kpn8V9Q8wa59E22slok5sgFPL6zEsWCyh19u\nHxjEKvRjWLg526EKLdMtN7T9qQpnwEgepiiupWxRKK943Jeff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pIe6cU+22qNGSMke8JGD8cpu6KLd22JIR6BOuQ0kZAl78j9hV7yl\nCL3xWiR/pXamXvApNXaghWk=\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-3pxyv@musix-canary.iam.gserviceaccount.com",
"client_id": "118395703537320139553",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-3pxyv%40musix-canary.iam.gserviceaccount.com"
}

19
struct/funcs/check.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = function (client, msg, command) {
const serverQueue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!serverQueue || !serverQueue.playing) return msg.channel.send('<:redx:674263474704220182> There is nothing playing!');
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== serverQueue.voiceChannel) return msg.channel.send(`<:redx:674263474704220182> I'm sorry but you need to be in the same voice channel as Musix to use this command!`);
if (client.global.db.guilds[msg.guild.id].permissions === true) {
if (client.global.db.guilds[msg.guild.id].dj) {
if (!msg.member.roles.has(client.global.db.guilds[msg.guild.id].djrole)) {
msg.channel.send('<:redx:674263474704220182> You need the `DJ` role to use this command!');
return false;
} else return true;
} else if (!permissions.has(command.permission)) {
msg.channel.send(`<:redx:674263474704220182> You need the \`${command.permission}\` permission to use this command!`);
return false;
} else return true;
} else return true;
} else return true;
};

22
struct/funcs/dbget.js Normal file
View File

@ -0,0 +1,22 @@
module.exports = async function (collection, doc, client) {
if (doc) {
let d = await client.db.collection(collection).doc(doc).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
return d.data();
} else {
let d = await client.db.collection(collection).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
let finalD = [];
d.forEach(doc => {
finalD.push({
id: doc.id,
d: doc.data(),
});
});
return finalD;
}
};

16
struct/funcs/exe.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = function (msg, args, client, Discord, prefix, command) {
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send('<:redx:674263474704220182> I cannot send embeds (Embed links), make sure I have the proper permissions!');
try {
command.uses++;
command.execute(msg, args, client, Discord, prefix, command);
} catch (error) {
msg.reply(`<:redx:674263474704220182> there was an error trying to execute that command! Please contact support with \`${prefix}bug\`!`);
const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **'))
.setColor('#b50002');
//client.fetchUser(client.config.devId).then(user => user.send(embed)).catch(console.error);
client.channels.get(client.config.debug_channel).send(embed);
}
};

7
struct/funcs/ffmpeg.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = async function (client) {
try {
await client.channels.get(client.configs.secondary_test_channel).join()
} catch (error) {
client.channels.get(client.config.debug_channel).send("Error detected: " + error);
}
};

View File

@ -0,0 +1,44 @@
module.exports = async function (video, msg, voiceChannel, client, playlist = false) {
const Discord = require('discord.js');
const song = {
id: video.id,
title: Discord.Util.escapeMarkdown(video.title),
url: `https://www.youtube.com/watch?v=${video.id}`,
author: msg.author
}
const serverQueue = client.queue.get(msg.guild.id);
if (serverQueue) {
serverQueue.songs.push(song);
if (playlist) return;
return msg.channel.send(`<:green_check_mark:674265384777416705> **${song.title}** has been added to the queue!`);
}
const construct = {
textChannel: msg.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: client.global.db.guilds[msg.guild.id].defaultVolume,
playing: false,
paused: false,
looping: false,
songLooping: false,
votes: 0,
voters: [],
votesNeeded: null,
time: 0,
};
construct.songs.push(song);
client.queue.set(msg.guild.id, construct);
try {
const connection = await voiceChannel.join();
construct.connection = connection;
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
} catch (error) {
client.queue.delete(msg.guild.id);
client.channels.get(client.config.debug_channel).send("Error with connecting to voice channel: " + error);
return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`);
}
return;
}

15
struct/funcs/msToTime.js Normal file
View File

@ -0,0 +1,15 @@
module.exports = function msToTime(duration, format) {
if (format = "hh:mm:ss") {
var seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return `${hours}:${minutes}:${seconds}`;
} else if (format = "dd:hh:mm") {
}
}

40
struct/funcs/play.js Normal file
View File

@ -0,0 +1,40 @@
module.exports = async function (guild, song, client, seek, play) {
const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const getThumb = require('video-thumbnail-url');
const serverQueue = client.queue.get(guild.id);
if (!song) {
console.log('No song')
serverQueue.voiceChannel.leave();
client.queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(await ytdl(song.url, { filter: "audio", highWaterMark: /*512*/1 << 25, volume: false }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 })
.on("finish", reason => {
client.dispatcher.finish(client, reason, guild);
});
dispatcher.on('start', () => {
dispatcher.player.streamingData.pausedTime = 0;
});
dispatcher.on('error', error => {
console.error(error);
serverQueue.voiceChannel.leave();
client.queue.delete(guild.id);
return serverQueue.textChannel.send('<:redx:674263474704220182> An error has occured while playing music! The queue has been deleted.');
});
dispatcher.setVolume(serverQueue.volume / 10);
if (client.global.db.guilds[guild.id].startPlaying || play) {
const data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
const songtime = (data.length_seconds * 1000).toFixed(0);
const thumbnail = getThumb(serverQueue.songs[0].url);
const embed = new Discord.MessageEmbed()
.setTitle(`<a:aNotes:674602408105476106> Start playing: **${song.title}**`)
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``)
.setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor)
serverQueue.textChannel.send(embed);
}
serverQueue.playing = true;
}

11
struct/funcs/shuffle.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = function (a) {
for (let i = a.length - 1; i > 1; i--) {
const j = Math.floor(Math.random() * (i + 1));
if (i === 0 || j === 0) {
console.log(`J or I is 0. I: ${i} J: ${j}`);
} else {
[a[i], a[j]] = [a[j], a[i]];
}
}
return a;
};

16
struct/funcs/urlMatch.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = async function (client, msg, youtube, voiceChannel, url) {
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const lmsg = await msg.channel.send('<a:loading:674284196700618783> Loading song(s)');
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);
}
lmsg.edit(`<:green_check_mark:674265384777416705> Playlist: **${playlist.title}** has been added to the queue!`);
return true;
} else {
console.log('return false')
return false;
}
};