From 450cb8539d384975e3ca43303b1a1e78646de880 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 19 Jul 2022 23:21:08 +0000 Subject: [PATCH] GPL License & Rust Time --- .gitignore | 6 +++ Cargo.lock | 7 +++ Cargo.toml | 8 ++++ ding.mp3 | Bin 3644 -> 0 bytes flake.lock | 43 ++++++++++++++++++ flake.nix | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 114 ----------------------------------------------- package.json | 1 - src/main.rs | 3 ++ 9 files changed, 189 insertions(+), 115 deletions(-) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 ding.mp3 create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 index.js delete mode 100644 package.json create mode 100644 src/main.rs 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 2df70c5ab1f348d634c2483f334090b3e0181fe1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3644 zcmezWd%_V0bP$o5m(IYzz|X+IAk4tPXTx9!0&XA>00L29kPZUHAkY8;U0^T`1Qvt9 zdJxzN28Tf490=S3fu~^b9t6IFz<&^6U|uyH|#s?sG zcxUOjz$8Wr{r~rdBMb~|8??bN@Bt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#tjSpb3e75@5sWw0OU4hcgGVt6BtkF@aQR2&v>}(U4Rq+qUiT3cGn(>-uxGCzKmh} zW-b*2_BD-BD}`?BXr_lx;^%p>TWytzW0`sI8KV?l*H!Qq@G3F@$ZdZZ+)u=6zxfGD zy-)tmHAc;iYMe7M}|(23w|&hFA3HJrI4Fl zsg(!BM946Qd@Z0f`nBQ64{g&YkDV4wVpHGIV-rihaX58??77B#fPwKJ0|SEs1A|Ee M0|N_A)#OV60QZ{tQvd(} 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