Latest Things
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*lock*
|
||||||
|
.direnv
|
||||||
|
.envrc
|
||||||
|
node_modules
|
||||||
3
config.json
Normal file
3
config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"token": "NzA4NDYxNzc0ODYwNzEzOTg0.GIJcWn.AER_UTo9nUKk4-6Z_3HZDj4kMYQopAuA7Aa3JY"
|
||||||
|
}
|
||||||
43
flake.lock
generated
Normal file
43
flake.lock
generated
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1656928814,
|
||||||
|
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1658644204,
|
||||||
|
"narHash": "sha256-MWyfCH9K3eVTXJUxBi67OQSAh9jJAnvWklM6qm4j8w8=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "2f0c3be57c348f4cfd8820f2d189e29a685d9c41",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
23
flake.nix
Normal file
23
flake.nix
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
description = "AlanBot Nix Env";
|
||||||
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system: let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in {
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
|
nativeBuildInputs = [ pkgs.bashInteractive ];
|
||||||
|
buildInputs = (with pkgs; [
|
||||||
|
nodejs
|
||||||
|
python3
|
||||||
|
])
|
||||||
|
++
|
||||||
|
(with pkgs.nodePackages;[
|
||||||
|
npm
|
||||||
|
typescript
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
121
index.js
121
index.js
@@ -1,114 +1,17 @@
|
|||||||
const Discord = require('discord.js');
|
// Note add tsserver support
|
||||||
const bot = new Discord.Client();
|
|
||||||
const ytdl = require('ytdl-core');
|
|
||||||
|
|
||||||
const status = require('minecraft-server-status');
|
// Require the necessary discord.js classes
|
||||||
|
const { Client, IntentsBitField } = require('discord.js');
|
||||||
|
const { token } = require('./config.json');
|
||||||
|
|
||||||
var server = null;
|
// Create a new client instance
|
||||||
var channels = null;
|
const client = new Client({ intents: [IntentsBitField.Flags.Guilds] });
|
||||||
|
|
||||||
var vid = null;
|
// When the client is ready, run this code (only once)
|
||||||
var con = null;
|
client.once('ready', () => {
|
||||||
|
console.log('Alan Bot is back BABY!');
|
||||||
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() {
|
// Login to Discord with your client's token
|
||||||
console.log(mcServer)
|
client.login(token);
|
||||||
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');
|
|
||||||
|
|||||||
25
package.json
25
package.json
@@ -1 +1,24 @@
|
|||||||
{}
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"@discordjs/voice": "^0.11.0",
|
||||||
|
"bufferutil": "^4.0.6",
|
||||||
|
"discord.js": "^14.0.3",
|
||||||
|
"erlpack": "^0.1.4",
|
||||||
|
"utf-8-validate": "^5.0.9",
|
||||||
|
"zlib-sync": "^0.1.7"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"repl": "node",
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"name": "alanbot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Alan Bot",
|
||||||
|
"main": "index.js",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.syzygial.cc/syzygial/NewAlan"
|
||||||
|
},
|
||||||
|
"author": "Syzygial",
|
||||||
|
"license": "GPL-3.0"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user