Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const redis = require('redis')
- const redisClient = redis.createClient()
- const prism = require('prism-media');
- const { inspect } = require('util');
- const Discord = require("discord.js");
- const { prefix, token } = require("./config.json");
- const ytdl = require("ytdl-core");
- const { Worker, isMainThread, parentPort } = require('worker_threads');
- const client = new Discord.Client();
- var volume = new Map();
- redisClient.get("Volume",(err,data)=>{
- if (!err && data){
- volume = new Map(Object.entries(data));
- } else {
- volume = new Map();
- }
- })
- const dispatcher = new Map();
- const queue = new Map();
- const eventschid = "797505130210656316"
- var waitingownerid = true
- var ownerid
- redisClient.get('ownerid',(error,data)=>{
- if (error){
- console.error(error)
- } else {
- ownerid = data
- console.log(data,ownerid)
- }
- waitingownerid = false
- })
- function wait(ms) {
- const end = Date.now() + ms;
- while (Date.now() < end) { }
- }
- wait(2000)
- client.once("ready", () => {
- console.log("Ready!");
- });
- client.once("reconnecting", () => {
- console.log("Reconnecting!");
- });
- client.once("disconnect", () => {
- console.log("Disconnect!");
- });
- const lucene_live = new Worker("./loopevent_check_live_lucene.js");
- lucene_live.on('message', (msg) => {
- console.log(`lucene_live: ${msg}`);
- if(msg=="LIVE Lucene"){
- client.emit("Check_PolygonProject_Live",msg)
- }
- });
- client.on("Check_PolygonProject_Live",(msg)=>{
- if (client.channels.cache.get(eventschid)){
- client.channels.cache.get(eventschid).send(`${msg}`)
- } else {
- console.warn("client.channels.cache.get(eventschid) == NULL")
- }
- })
- client.on("message", async message => {
- if (message.author.bot) return;
- if (!message.content.startsWith(prefix)) return;
- const serverQueue = queue.get(message.guild.id);
- if (message.content.startsWith(`${prefix}play`)) {
- execute(message, serverQueue);
- return;
- } else if (message.content.startsWith(`${prefix}skip`)) {
- skip(message, serverQueue);
- return;
- } else if (message.content.startsWith(`${prefix}stop`)) {
- stop(message, serverQueue);
- return;
- } else if (message.content.startsWith(`${prefix}loop`)) {
- loop(message, serverQueue);
- return;
- } else if (message.content.startsWith(`${prefix}eval`)) {
- if (message.author.id == ownerid){
- execution_eval(message)
- } else {
- console.log(message.author.id == ownerid, message.author.id, ownerid)
- }
- return
- } else if (message.content.startsWith(`${prefix}volume`)) {
- volumefunc(message, serverQueue, volume.get(message.guild.id));
- return;
- }
- });
- async function execution_eval(message){
- const args = message.content.split(' ');
- const command = args.shift().toLowerCase();
- let evaled;
- try {
- evaled = await eval(args.join(' '));
- if (new String(evaled).length <= 1994){
- message.channel.send("```"+inspect(evaled)+"```");
- } else {
- message.channel.send("message.length > 2000\nlength:"+new String(evaled).length);
- console.log(new String(evaled).length)
- }
- console.log(inspect(evaled));
- }
- catch (error) {
- console.error(error);
- message.reply('there was an error during evaluation.');
- }
- }
- async function execute(message, serverQueue) {
- const args = message.content.split(" ");
- const voiceChannel = message.member.voice.channel;
- if (!voiceChannel)
- return message.channel.send(
- "You need to be in a voice channel to play music!"
- );
- const permissions = voiceChannel.permissionsFor(message.client.user);
- if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
- return message.channel.send(
- "I need the permissions to join and speak in your voice channel!"
- );
- }
- const songInfo = await ytdl.getInfo(args[1]);
- const song = {
- title: songInfo.videoDetails.title,
- url: songInfo.videoDetails.video_url,
- };
- if (!volume.get(message.guild.id)){
- volume.set(message.guild.id,100)
- }
- if (!dispatcher.get(message.guild.id)){
- dispatcher.set(message.guild.id,null)
- }
- if (!serverQueue) {
- const queueContruct = {
- textChannel: message.channel,
- voiceChannel: voiceChannel,
- //connection: null,
- songs: [],
- playing: true,
- looped: false,
- skipping:false
- };
- queue.set(message.guild.id, queueContruct);
- queueContruct.songs.push(song);
- try {
- var connection = await voiceChannel.join();
- dispatcher.set(message.guild.id,connection);
- play(message.guild, queueContruct.songs[0]);
- } catch (err) {
- console.log(err);
- queue.delete(message.guild.id);
- return message.channel.send(err);
- }
- } else {
- serverQueue.songs.push(song);
- return message.channel.send(`${song.title} has been added to the queue!`);
- }
- }
- function volumefunc(message, serverQueue, Volume) {
- if (!message.member.voice.channel)
- return message.channel.send(
- "You have to be in a voice channel to Change Volume!"
- );
- if(!serverQueue)
- return message.channel.send("There is no song that I could adjust volume!");
- const args = message.content.split(" ");
- Volume = args[1]
- dispatcher.get(message.guild.id).dispatcher.setVolume(Volume / 100);
- // console.log(serverQueue.connection.dispatcher.constructor)
- redisClient.set("Volume", JSON.stringify(Object.fromEntries(volume)))
- message.channel.send(`volume:${Volume}`);
- //redisClient.set("Volume", JSON.stringify(Object.fromEntries(volume)))
- }
- function skip(message, serverQueue) {
- if (!message.member.voice.channel)
- return message.channel.send(
- "You have to be in a voice channel to stop the music!"
- );
- if (!serverQueue)
- return message.channel.send("There is no song that I could skip!");
- if (serverQueue.looped){
- serverQueue.looped = false;
- wait(100)
- dispatcher.get(message.guild.id).dispatcher.end();
- serverQueue.looped = true;
- } else {
- dispatcher.get(message.guild.id).dispatcher.end();
- }
- }
- function loop(message, serverQueue) {
- if (!message.member.voice.channel)
- return message.channel.send(
- "You have to be in a voice channel to stop the music!"
- );
- if(!serverQueue)
- return message.channel.send("There is no song that I could Loop!");
- serverQueue.looped = !serverQueue.looped
- message.channel.send(`Loop:${serverQueue.looped}`);
- }
- function stop(message, serverQueue) {
- if (!message.member.voice.channel)
- return message.channel.send(
- "You have to be in a voice channel to stop the music!"
- );
- if (!serverQueue)
- return message.channel.send("There is no song that I could stop!");
- serverQueue.songs = [];
- dispatcher.get(message.guild.id).dispatcher.end();
- }
- function play(guild, song) {
- const serverQueue = queue.get(guild.id);
- //console.log(`Guild:${guild.id}\nloop:${serverQueue.looped}\ncurrent song:${song.title}\nnext song:${serverQueue.songs[1]}`)
- if (!song) {
- console.log(`Guild:${guild.name}\nloop:${serverQueue.looped}\ncurrent song:NULL\nnext song:NULL`)
- serverQueue.voiceChannel.leave();
- //queue.delete(guild.id);
- return;
- }
- console.log(`Guild:${guild.name}\nloop:${serverQueue.looped}\ncurrent song:${song.title}\nnext song:${serverQueue.songs[1]}`)
- dispatcher.get(guild.id).play(ytdl(song.url, { quality: 'highestaudio' }))
- dispatcher.get(guild.id).dispatcher.on("finish", () => {
- if (!serverQueue.looped){
- serverQueue.songs.shift();
- }
- play(guild, serverQueue.songs[0]);
- })
- dispatcher.get(guild.id).dispatcher.on("error", error => console.error(error));
- dispatcher.get(guild.id).dispatcher.setVolume(volume.get(guild.id) / 100);
- //serverQueue.textChannel.send(`Start playing: **${song.title}**`);
- }
- console.log(`prefix:${prefix}\ntoken:${token}`)
- client.login(token);
- redisClient.set("Volume", JSON.stringify(Object.fromEntries(volume)))
- console.log(JSON.stringify(Object.fromEntries(volume)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement