commit 40f3e604d534292f90df134f77190860a919b2d5 Author: DavidCrompton1192@gmail.com Date: Tue Jul 19 19:19:49 2022 -0400 Original Alan Bot diff --git a/ding.mp3 b/ding.mp3 new file mode 100644 index 0000000..2df70c5 Binary files /dev/null and b/ding.mp3 differ diff --git a/index.js b/index.js new file mode 100644 index 0000000..ff5826f --- /dev/null +++ b/index.js @@ -0,0 +1,114 @@ +const Discord = require('discord.js'); +const bot = new Discord.Client(); +const ytdl = require('ytdl-core'); + +const status = require('minecraft-server-status'); + +var server = null; +var channels = null; + +var vid = null; +var con = null; + +var mcServer = 'bront.syzygial.cc' + +bot.on('ready', () => { + console.log(`Logged in as ${bot.user.tag}!`); + server = bot.guilds.cache.get("574723462803882018"); + channels = server.channels.cache.array(); + let t = Math.random()*300000+2000; + setTimeout(joinMostppl,t); + setTimeout(statLine,15000); + console.log("Joining in "+t/1000+"s"); + statLine(); +}); + +function statLine() { + console.log(mcServer) + status(mcServer, 25565, response => { + console.log(response) + if (response!=undefined) { + if (response.online) { + let mcmax = response.players.max; + let mccount = response.players.now; + bot.user.setActivity(mccount+"/"+mcmax+" Players Online"); + } + } + }) + setTimeout(statLine,15000); +} + +function joinMostppl() { + if (vid==null) { + let max=0; + let vids = channels.filter(c => c.type === 'voice'); + for (v in vids) { + if (vids[v].members.size>max) { + max = vids[v].members.size; + vid = vids[v]; + } + } + if (max>0) { + vid.join().then(c => { + con = c; + con.play("ding.mp3"); + let t = Math.random()*400000+6000; + setTimeout(leaveChannel,t); + console.log("Leaving in "+t/1000+"s"); + }); + } + } +} + +function leaveChannel() { + if (vid!=null) { + vid.leave(); + vid=null; + } + let t = Math.random()*1000000+2000; + setTimeout(joinMostppl,t); + console.log("Joining in "+t/1000+"s"); +} + +bot.on('message', msg => { + var str = msg.content; + if (str === "ALAN") { + vid = msg.member.voice.channel; + if (vid!=null) { + vid.join().then(c => { + // console.log(c); + con = c; + con.play("ding.mp3"); + }).catch(console.error); + } + }else if (str === "ALANO") { + if (vid!=null) { + vid.leave(); + vid=null; + } + }else if (str.startsWith("poll")) { + var poll = str.slice(5).split('\n'); + if (poll.length<3) { + msg.channel.send("You need at least two options for a poll"); + return; + } + var embed = new Discord.MessageEmbed().setTitle(`${msg.member.nickname} Poll:`) + .setColor('#348db2'); + embed.setDescription(poll[0]); + emos = bot.emojis.cache.random(poll.length-1); + for (let i=1; i { + for (let i=1; i