diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11a7f74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*lock* +.direnv +.envrc +node_modules +/target +result* diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b3a9899 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "quick-start" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d83bbdf --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "quick-start" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/ding.mp3 b/ding.mp3 deleted file mode 100644 index 2df70c5..0000000 Binary files a/ding.mp3 and /dev/null differ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..92679b9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677655566, + "narHash": "sha256-I8G8Lmpp3YduYl4+pkiIJFGT1WKw+8ZMH2QwANkTu2U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ae8bdd2de4c23b239b5a771501641d2ef5e027d0", + "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..2c865fe --- /dev/null +++ b/flake.nix @@ -0,0 +1,122 @@ +{ + description = "Build a cargo project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + + inherit (pkgs) lib; + + craneLib = crane.lib.${system}; + src = craneLib.cleanCargoSource ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + + buildInputs = [ + # Add additional build inputs here + ] ++ lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + + # Additional environment variables can be set directly + # MY_CUSTOM_VAR = "some value"; + }; + + # Build *just* the cargo dependencies, so we can reuse + # all of that work (e.g. via cachix) when running in CI + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + my-crate = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + }); + in + { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit my-crate; + + # Run clippy (and deny all warnings) on the crate source, + # again, resuing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + my-crate-clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + my-crate-doc = craneLib.cargoDoc (commonArgs // { + inherit cargoArtifacts; + }); + + # Check formatting + my-crate-fmt = craneLib.cargoFmt { + inherit src; + }; + + # Audit dependencies + my-crate-audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # Run tests with cargo-nextest + # Consider setting `doCheck = false` on `my-crate` if you do not want + # the tests to run twice + my-crate-nextest = craneLib.cargoNextest (commonArgs // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + }); + } // lib.optionalAttrs (system == "x86_64-linux") { + # NB: cargo-tarpaulin only supports x86_64 systems + # Check code coverage (note: this will not upload coverage anywhere) + my-crate-coverage = craneLib.cargoTarpaulin (commonArgs // { + inherit cargoArtifacts; + }); + }; + + packages.default = my-crate; + + apps.default = flake-utils.lib.mkApp { + drv = my-crate; + }; + + devShells.default = pkgs.mkShell { + inputsFrom = builtins.attrValues self.checks.${system}; + + # Additional dev-shell environment variables can be set directly + # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; + + # Extra inputs can be added here + nativeBuildInputs = with pkgs; [ + cargo + rustc + ]; + }; + }); +} diff --git a/index.js b/index.js deleted file mode 100644 index ff5826f..0000000 --- a/index.js +++ /dev/null @@ -1,114 +0,0 @@ -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