From af29582c00d573a3a43c4e3e4fde32aa3d37cb86 Mon Sep 17 00:00:00 2001 From: MrUnknownDE Date: Mon, 9 May 2022 19:29:50 +0200 Subject: [PATCH] huch? --- .gitignore | 4 ++ CONTRIBUTING.md | 91 +++++++++++++++++++++++++++++++++ README.md | 2 +- commands/utility/hello.js | 15 ++++++ configs/config.json | 2 +- main.js | 27 ++++++++-- package-lock.json | 11 ++++ package.json | 1 + player/botDisconnect.js | 3 ++ player/channelEmpty.js | 3 ++ player/error.js | 21 ++++++++ player/noResults.js | 3 ++ player/playlistAdd.js | 3 ++ player/queueEnd.js | 3 ++ player/searchCancel.js | 3 ++ player/searchInvalidResponse.js | 6 +++ player/searchResults.js | 11 ++++ player/trackAdd.js | 3 ++ player/trackStart.js | 3 ++ 19 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 commands/utility/hello.js create mode 100644 player/botDisconnect.js create mode 100644 player/channelEmpty.js create mode 100644 player/error.js create mode 100644 player/noResults.js create mode 100644 player/playlistAdd.js create mode 100644 player/queueEnd.js create mode 100644 player/searchCancel.js create mode 100644 player/searchInvalidResponse.js create mode 100644 player/searchResults.js create mode 100644 player/trackAdd.js create mode 100644 player/trackStart.js diff --git a/.gitignore b/.gitignore index 6704566..d18d1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,7 @@ dist # TernJS port file .tern-port + + +# Discord-Bot Configs +./configs/config.json \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..cb64fd2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,91 @@ +# Contributing + +When contributing to this repository, please first discuss the change you wish to make via issue, +email, or any other method with the owners of this repository before making a change. + +Please note we have a code of conduct, please follow it in all your interactions with the project. + +## Pull Request Process + +1. Ensure any install or build dependencies are removed before the end of the layer when doing a + build. +2. Update the README.md with details of changes to the interface, this includes new environment + variables, exposed ports, useful file locations and container parameters. +3. Increase the version numbers in any examples files and the README.md to the new version that this + Pull Request would represent. +4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you + do not have permission to do that, you may request the second reviewer to merge it for you. + +## Code of Conduct + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +### Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting +### Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +### Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +### Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [INSERT EMAIL ADDRESS]. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +### Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [https://github.com/MrUnknownDE/UnknownAI/blob/main/version][version] + +[homepage]: https://github.com/MrUnknownDE/UnknownAI +[version]: https://github.com/MrUnknownDE/UnknownAI/blob/main/version diff --git a/README.md b/README.md index 37b6247..3853d95 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ### ✨ [Demo](https://mrunknown.de) -## Install +## Install (Node.JS 16.15.0v & NPM 8.5.5v) ```sh npm install diff --git a/commands/utility/hello.js b/commands/utility/hello.js new file mode 100644 index 0000000..4e1e4aa --- /dev/null +++ b/commands/utility/hello.js @@ -0,0 +1,15 @@ +const Discord = require('discord.js'); +const config = require('../../configs/config.json'); +module.exports = { + config: { + name: 'Hello', + description: '', + aliases: [""], + usage: '', + accessableby: "", + }, + run: async (client, message, args) => { + message.channel.send("Hello <3"); + + } +} \ No newline at end of file diff --git a/configs/config.json b/configs/config.json index 17a0d9a..3f57010 100644 --- a/configs/config.json +++ b/configs/config.json @@ -1,5 +1,5 @@ { "prefix": "ai.", "dev": "155076323612688384", - "token": "NDIzMjE1NTM1ODkxODA4MjY2.GivmSm.WGaa5Ivx9Mzm64RrHECHjiTwilNOzgq6Hw1i_Y" + "token": "NzQxNzMxNTc3NDY5NTk5NzQ0.Xy71XA.drqAYIjgARIGFfwqHe6GxS_hH40" } \ No newline at end of file diff --git a/main.js b/main.js index aa16ad6..0c0cfb6 100644 --- a/main.js +++ b/main.js @@ -1,19 +1,38 @@ +// PACKAGES + const Discord = require('discord.js'); const config = require('./configs/config.json'); const fs = require('fs'); const db = require('quick.db'); -const path = require('path'); -const client = new Discord.Client(); -client.commands = new Discord.Collection(); -client.aliases = new Discord.Collection(); +const path = require("path"); +const client = new Discord.Client; const { Player } = require('discord-player'); const player = new Player(client); + + +client.commands = new Discord.Collection(); +client.aliases = new Discord.Collection(); client.player = player; client.emotes = require('./configs/emotes.json') client.filters = require('./configs/filters.json'); + ["aliases", "commands"].forEach(cmd => client[cmd] = new Discord.Collection()); ["console", "command", "event"].forEach(events => require(`./handlers/${events}`)(client)); + client.categories = fs.readdirSync('./commands'); + + +fs.readdir('./player/', (err, files) => { + if (err) return console.error(err); + files.forEach(file => { + const event = require(`./player/${file}`); + let eventName = file.split(".")[0]; + console.log(`Loading player event ${eventName}`); + client.player.on(eventName, event.bind(null, client)); + }); +}); + + // EVENTS client.on('ready', async() => { console.log('UnknownAI Started!'); diff --git a/package-lock.json b/package-lock.json index 9a701d2..ecd974b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "chalk": "^5.0.1", "discord.js": "^13.6.0", "fs": "^0.0.1-security", + "loader": "^2.1.1", "moment": "^2.29.3", "npx": "^3.0.0", "path": "^0.12.7", @@ -490,6 +491,11 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "node_modules/loader": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/loader/-/loader-2.1.1.tgz", + "integrity": "sha1-iEixKj8AVy5aQkkzPM2seXc/tAI=" + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -2559,6 +2565,11 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "loader": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/loader/-/loader-2.1.1.tgz", + "integrity": "sha1-iEixKj8AVy5aQkkzPM2seXc/tAI=" + }, "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", diff --git a/package.json b/package.json index d402d49..b18e928 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "chalk": "^5.0.1", "discord.js": "^13.6.0", "fs": "^0.0.1-security", + "loader": "^2.1.1", "moment": "^2.29.3", "npx": "^3.0.0", "path": "^0.12.7", diff --git a/player/botDisconnect.js b/player/botDisconnect.js new file mode 100644 index 0000000..6e573f7 --- /dev/null +++ b/player/botDisconnect.js @@ -0,0 +1,3 @@ +module.exports = (client, message, queue) => { + message.channel.send(`${client.emotes.error} - Music stopped as i have been disconnected from the channel !`); +}; \ No newline at end of file diff --git a/player/channelEmpty.js b/player/channelEmpty.js new file mode 100644 index 0000000..823300f --- /dev/null +++ b/player/channelEmpty.js @@ -0,0 +1,3 @@ +module.exports = (client, message, queue) => { + message.channel.send(`${client.emotes.error} - Music stopped as there is no more member in the voice channel !`); +}; \ No newline at end of file diff --git a/player/error.js b/player/error.js new file mode 100644 index 0000000..2a2d096 --- /dev/null +++ b/player/error.js @@ -0,0 +1,21 @@ +module.exports = (client, error, message, ...args) => { + switch (error) { + case 'NotPlaying': + message.channel.send(`${client.emotes.error} - There is no music being played on this server !`); + break; + case 'NotConnected': + message.channel.send(`${client.emotes.error} - You are not connected in any voice channel !`); + break; + case 'UnableToJoin': + message.channel.send(`${client.emotes.error} - I am not able to join your voice channel, please check my permissions !`); + break; + case 'VideoUnavailable': + message.channel.send(`${client.emotes.error} - ${args[0].title} is not available in your country! Skipping...`); + break; + case 'MusicStarting': + message.channel.send(`The music is starting... please wait and retry!`); + break; + default: + message.channel.send(`${client.emotes.error} - Something went wrong ... Error : ${error}`); + }; +}; diff --git a/player/noResults.js b/player/noResults.js new file mode 100644 index 0000000..67855f2 --- /dev/null +++ b/player/noResults.js @@ -0,0 +1,3 @@ +module.exports = (client, message, query) => { + message.channel.send(`${client.emotes.error} - No results found on YouTube for ${query} !`); +}; \ No newline at end of file diff --git a/player/playlistAdd.js b/player/playlistAdd.js new file mode 100644 index 0000000..aac270f --- /dev/null +++ b/player/playlistAdd.js @@ -0,0 +1,3 @@ +module.exports = (client, message, queue, playlist) => { + message.channel.send(`${client.emotes.music} - ${playlist.title} has been added to the queue (**${playlist.tracks.length}** songs) !`); +}; \ No newline at end of file diff --git a/player/queueEnd.js b/player/queueEnd.js new file mode 100644 index 0000000..16e0e83 --- /dev/null +++ b/player/queueEnd.js @@ -0,0 +1,3 @@ +module.exports = (client, message, queue) => { + message.channel.send(`${client.emotes.error} - Music stopped as there is no more music in the queue !`); +}; \ No newline at end of file diff --git a/player/searchCancel.js b/player/searchCancel.js new file mode 100644 index 0000000..630e204 --- /dev/null +++ b/player/searchCancel.js @@ -0,0 +1,3 @@ +module.exports = (client, message, query, tracks) => { + message.channel.send(`${client.emotes.error} - You did not provide a valid response ... Please send the command again !`); +}; \ No newline at end of file diff --git a/player/searchInvalidResponse.js b/player/searchInvalidResponse.js new file mode 100644 index 0000000..5cd5f9a --- /dev/null +++ b/player/searchInvalidResponse.js @@ -0,0 +1,6 @@ +module.exports = (client, message, query, tracks, content, collector) => { + if (content === 'cancel') { + collector.stop(); + return message.channel.send(`${client.emotes.success} - The selection has been **cancelled** !`); + } else message.channel.send(`${client.emotes.error} - You must send a valid number between **1** and **${tracks.length}** !`); +}; \ No newline at end of file diff --git a/player/searchResults.js b/player/searchResults.js new file mode 100644 index 0000000..5c12855 --- /dev/null +++ b/player/searchResults.js @@ -0,0 +1,11 @@ +module.exports = (client, message, query, tracks) => { + message.channel.send({ + embed: { + color: 'BLUE', + author: { name: `Here are your search results for ${query}` }, + footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' }, + timestamp: new Date(), + description: `${tracks.map((t, i) => `**${i + 1}** - ${t.title}`).join('\n')}`, + }, + }); +}; \ No newline at end of file diff --git a/player/trackAdd.js b/player/trackAdd.js new file mode 100644 index 0000000..2a5fa74 --- /dev/null +++ b/player/trackAdd.js @@ -0,0 +1,3 @@ +module.exports = (client, message, queue, track) => { + message.channel.send(`${client.emotes.music} - ${track.title} has been added to the queue !`); +}; \ No newline at end of file diff --git a/player/trackStart.js b/player/trackStart.js new file mode 100644 index 0000000..d9e9b1b --- /dev/null +++ b/player/trackStart.js @@ -0,0 +1,3 @@ +module.exports = (client, message, track) => { + message.channel.send(`${client.emotes.music} - Now playing ${track.title} into ${message.member.voice.channel.name} ...`); +}; \ No newline at end of file