From a39c61a951093385f37ae621156862d9a7cdcbaf Mon Sep 17 00:00:00 2001 From: DavidCromp Date: Fri, 3 Mar 2023 09:32:00 -0500 Subject: [PATCH] Latest Things --- .gitignore | 4 ++ config.json | 3 ++ flake.lock | 43 ++++++++++++++++++ flake.nix | 23 ++++++++++ index.js | 121 +++++---------------------------------------------- package.json | 25 ++++++++++- 6 files changed, 109 insertions(+), 110 deletions(-) create mode 100644 .gitignore create mode 100644 config.json create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b13a881 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*lock* +.direnv +.envrc +node_modules diff --git a/config.json b/config.json new file mode 100644 index 0000000..b961d49 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "token": "NzA4NDYxNzc0ODYwNzEzOTg0.GIJcWn.AER_UTo9nUKk4-6Z_3HZDj4kMYQopAuA7Aa3JY" +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e7118c3 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1647be9 --- /dev/null +++ b/flake.nix @@ -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 + ]); + }; + }); +} diff --git a/index.js b/index.js index ff5826f..f2acc0f 100644 --- a/index.js +++ b/index.js @@ -1,114 +1,17 @@ -const Discord = require('discord.js'); -const bot = new Discord.Client(); -const ytdl = require('ytdl-core'); +// Note add tsserver support -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; -var channels = null; +// Create a new client instance +const client = new Client({ intents: [IntentsBitField.Flags.Guilds] }); -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(); +// When the client is ready, run this code (only once) +client.once('ready', () => { + console.log('Alan Bot is back BABY!'); + }); -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