Original Alan Bot
This commit is contained in:
114
index.js
Normal file
114
index.js
Normal file
@@ -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<poll.length; i++) {
|
||||
embed.addField(emos[i-1],poll[i]);
|
||||
}
|
||||
msg.channel.send(embed).then(m => {
|
||||
for (let i=1; i<poll.length; i++) {
|
||||
m.react(emos[i-1]);
|
||||
}
|
||||
});
|
||||
msg.delete();
|
||||
}else if (str.startsWith("ALAN STATUS")) {
|
||||
var words = str.slice(12).split(' ');
|
||||
mcServer = words[0];
|
||||
}
|
||||
});
|
||||
|
||||
bot.login('NzA4NDYxNzc0ODYwNzEzOTg0.XrX-dQ.fEo2gr8UHLV3JBr7CF47C-q8cOI');
|
||||
1
package.json
Normal file
1
package.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
Reference in New Issue
Block a user