awsredtyguil
This commit is contained in:
parent
d722add09b
commit
36d363271b
8 changed files with 221 additions and 1837 deletions
28
config.js
28
config.js
|
@ -0,0 +1,28 @@
|
||||||
|
const config = {
|
||||||
|
// Users added to this embed get access to developer-level commands
|
||||||
|
devs: ['433790467830972417', '324937993972350976', '343081377249493044'],
|
||||||
|
|
||||||
|
// Default settings for individual users
|
||||||
|
defaultUserSettings: {
|
||||||
|
prefixes: ['~'],
|
||||||
|
systemNotice: true
|
||||||
|
},
|
||||||
|
|
||||||
|
// Default per-guild settings
|
||||||
|
defaultGuildSettings: {
|
||||||
|
prefixes: ['~'],
|
||||||
|
systemNotice: true
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
permLevels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
name: 'User',
|
||||||
|
|
||||||
|
check: () => true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = config
|
0
dash/dashboard maybe?.txt
Normal file
0
dash/dashboard maybe?.txt
Normal file
|
@ -1,3 +1,3 @@
|
||||||
module.exports = (client) => {
|
module.exports = (client) => {
|
||||||
console.log('Discord client ready!');
|
console.log('Discord client ready!')
|
||||||
};
|
}
|
||||||
|
|
33
index.js
33
index.js
|
@ -2,13 +2,15 @@
|
||||||
// Copyright 2020 mudkipscience
|
// Copyright 2020 mudkipscience
|
||||||
|
|
||||||
// Check node.js version
|
// Check node.js version
|
||||||
if (Number(process.version.slice(1).split('.')[0]) < 13) {
|
if (Number(process.version.slice(1).split('.')[0]) < 12) {
|
||||||
console.log('NodeJS 12.0.0 or higher is required. Please update NodeJS on your system.')
|
console.log('NodeJS 12.0.0 or higher is required. Please update NodeJS on your system.')
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load environment variables / config
|
// Load environment variables / config
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const Discord = require('discord.js')
|
||||||
|
const client = new Discord.Client({ disabledEvents: ['TYPING_START'] })
|
||||||
|
|
||||||
if (fs.existsSync('./.env') === false) {
|
if (fs.existsSync('./.env') === false) {
|
||||||
console.log('.env file not found!')
|
console.log('.env file not found!')
|
||||||
|
@ -21,32 +23,33 @@ if (fs.existsSync('./config.js') === false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
client.config = require('config')
|
||||||
|
|
||||||
// Prepare variables
|
// Command/alias cache
|
||||||
const Discord = require('discord.js')
|
client.commands = new Discord.Collection()
|
||||||
const client = new Discord.Client({ disabledEvents: ['TYPING_START'] })
|
client.aliases = new Discord.Collection()
|
||||||
|
|
||||||
//client.commands = new Discord.Collection()
|
|
||||||
//client.aliases = new Discord.Collection()
|
|
||||||
|
|
||||||
// Command cache containing every prefix + command combination without arguments ( ~ping )
|
|
||||||
client.commandCache = {};
|
|
||||||
|
|
||||||
// Initialization function
|
// Initialization function
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
// Load modules
|
// Load modules
|
||||||
|
|
||||||
// Register events
|
// Load events
|
||||||
fs.readdir('./events', (err, files) => {
|
fs.readdir('./events', (err, files) => {
|
||||||
|
if (err) {}// Prepare variableseturn err
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
client.on(file.substr(0, file.length - 3), require('./events/' + file))
|
client.on(file.substr(0, file.length - 3), require('./events/' + file))
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
// Load commands
|
// Load commands
|
||||||
|
|
||||||
|
// Level cache
|
||||||
|
for (let i = 0; i < client.config.permLevels.length; i++) {
|
||||||
|
const currentlevel = client.config.permLevels[i]
|
||||||
|
client.levelCache[currentlevel.name] = currentlevel.level
|
||||||
|
}
|
||||||
// Login into Discord
|
// Login into Discord
|
||||||
client.login(process.env.TOKEN);
|
client.login(process.env.TOKEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init()
|
||||||
|
|
3
modules/botlists.js
Normal file
3
modules/botlists.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = client => {
|
||||||
|
|
||||||
|
}
|
170
modules/music.js
Normal file
170
modules/music.js
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
module.exports = client => {
|
||||||
|
client.music = {guilds: {}}
|
||||||
|
|
||||||
|
client.music.isYoutubeLink = function(input) {
|
||||||
|
return input.startsWith('https://www.youtube.com/') || input.startsWith('http://www.youtube.com/') || input.startsWith('https://youtube.com/') || input.startsWith('http://youtube.com/') || input.startsWith('https://youtu.be/') || input.startsWith('http://youtu.be/') || input.startsWith('http://m.youtube.com/') || input.startsWith('https://m.youtube.com/')
|
||||||
|
}
|
||||||
|
|
||||||
|
client.music.search = async function(query)
|
||||||
|
{
|
||||||
|
return new Promise(function(resolve, reject)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
fetch("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + process.env.YTKEY)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(json => {
|
||||||
|
if(!json.items) { reject() return }
|
||||||
|
resolve(json.items[0])
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
client.logger.error("Music search err: ", err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
client.music.getGuild = function(id)
|
||||||
|
{
|
||||||
|
if(client.music.guilds[id]) return client.music.guilds[id]
|
||||||
|
|
||||||
|
return client.music.guilds[id] =
|
||||||
|
{
|
||||||
|
queue: [],
|
||||||
|
playing: false,
|
||||||
|
paused: false,
|
||||||
|
dispatcher: null,
|
||||||
|
skippers: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.music.getMeta = async function(id)
|
||||||
|
{
|
||||||
|
return new Promise(function(resolve, reject)
|
||||||
|
{
|
||||||
|
youtubeInfo(id, function(err, videoInfo)
|
||||||
|
{
|
||||||
|
if(err) throw err
|
||||||
|
|
||||||
|
resolve(videoInfo)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
client.music.play = async function(message, input, bypassQueue)
|
||||||
|
{
|
||||||
|
let voiceChannel = message.member.voice.channel
|
||||||
|
if(!voiceChannel) return message.channel.send('<:error:466995152976871434> You need to be in a voice channel to use this command!')
|
||||||
|
|
||||||
|
let permissions = voiceChannel.permissionsFor(client.user)
|
||||||
|
if (!permissions.has('CONNECT')) {
|
||||||
|
return message.channel.send('<:error:466995152976871434> I do not have permission to join your voice channel.')
|
||||||
|
}
|
||||||
|
if (!permissions.has('SPEAK')) {
|
||||||
|
return message.channel.send('<:error:466995152976871434> I do not have permission to join your voice channel.')
|
||||||
|
}
|
||||||
|
if (voiceChannel.joinable != true) {
|
||||||
|
return message.channel.send("<:error:466995152976871434> I do not have permission to join your voice channel.")
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = undefined
|
||||||
|
|
||||||
|
if(client.music.isYoutubeLink(input))
|
||||||
|
{
|
||||||
|
id = await getYoutubeId(input)
|
||||||
|
} else {
|
||||||
|
let item = await client.music.search(input)
|
||||||
|
if(!item) {
|
||||||
|
return message.channel.send(`<:error:466995152976871434> No results found.`)
|
||||||
|
}
|
||||||
|
id = item.id.videoId
|
||||||
|
}
|
||||||
|
|
||||||
|
if(client.music.getGuild(message.guild.id).queue.length == 0 || bypassQueue)
|
||||||
|
{
|
||||||
|
let meta = await client.music.getMeta(id)
|
||||||
|
|
||||||
|
if(!bypassQueue) client.music.getGuild(message.guild.id).queue.push({input: input, id: id, requestedBy: message.author, title: meta.title, author: meta.owner, thumbnail: meta.thumbnailUrl, duration: meta.duration})
|
||||||
|
|
||||||
|
let connection = await new Promise((resolve, reject) =>
|
||||||
|
{
|
||||||
|
voiceChannel.join().then((connection) =>
|
||||||
|
{
|
||||||
|
resolve(connection)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function end(silent)
|
||||||
|
{
|
||||||
|
client.music.getGuild(message.guild.id).queue.shift()
|
||||||
|
client.music.getGuild(message.guild.id).dispatcher = null
|
||||||
|
|
||||||
|
if(client.music.getGuild(message.guild.id).queue.length > 0)
|
||||||
|
{
|
||||||
|
client.music.play(message, client.music.getGuild(message.guild.id).queue[0].input, true)
|
||||||
|
} else {
|
||||||
|
client.music.getGuild(message.guild.id).playing = false
|
||||||
|
|
||||||
|
if(!silent) {
|
||||||
|
message.channel.send("<:play:467216788187512832> Queue is empty! Disconnecting from the voice channel.")
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.music.getGuild(message.guild.id).playing = true
|
||||||
|
|
||||||
|
let song = client.music.getGuild(message.guild.id).queue[0]
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
let dispatcher = client.music.getGuild(message.guild.id).dispatcher = connection.play(await ytdl("https://www.youtube.com/watch?v=" + id, {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'})
|
||||||
|
|
||||||
|
dispatcher.on('finish', (a, b) =>
|
||||||
|
{
|
||||||
|
end(a == "silent")
|
||||||
|
})
|
||||||
|
} catch(err) {
|
||||||
|
message.channel.send('<:error:466995152976871434> Failed to play **' + song.title + '** ' + err)
|
||||||
|
|
||||||
|
end()
|
||||||
|
}
|
||||||
|
|
||||||
|
client.music.getGuild(message.guild.id).skippers = []
|
||||||
|
message.channel.send(`<:play:467216788187512832> Now playing: **${song.title}**`)
|
||||||
|
} else {
|
||||||
|
let meta = await client.music.getMeta(id)
|
||||||
|
let song = {input: input, id: id, requestedBy: message.author, title: meta.title, author: meta.owner, thumbnail: meta.thumbnailUrl, duration: meta.duration}
|
||||||
|
|
||||||
|
client.music.getGuild(message.guild.id).queue.push(song)
|
||||||
|
|
||||||
|
message.channel.send(`<:success:466995111885144095> Added to queue: **${song.title}**`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MUSIC - TIMESTAMP
|
||||||
|
client.createTimestamp = function(duration){
|
||||||
|
hrs = ~~(duration / 60 / 60),
|
||||||
|
min = ~~(duration / 60) % 60,
|
||||||
|
sec = ~~(duration - min * 60)
|
||||||
|
|
||||||
|
if(String(hrs).length < 2) {
|
||||||
|
hrs = "0" + String(hrs) + ":"
|
||||||
|
}
|
||||||
|
|
||||||
|
if(String(min).length < 2) {
|
||||||
|
min = "0" + String(min)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(String(sec).length < 2) {
|
||||||
|
sec = "0" + String(sec)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hrs == "00:") {
|
||||||
|
hrs = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var time = hrs + min + ":" + sec
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
}
|
1820
package-lock.json
generated
1820
package-lock.json
generated
File diff suppressed because it is too large
Load diff
0
resources/placeholder
Normal file
0
resources/placeholder
Normal file
Loading…
Add table
Add a link
Reference in a new issue