Compare commits

..

9 Commits

Author SHA1 Message Date
1ddda1122d Update Cargo Package Name 2023-03-03 13:36:52 -05:00
c326d201f5 Rename Crate Flake 2023-03-03 13:36:10 -05:00
fa8ba060be Test Hydra 2023-03-03 13:27:32 -05:00
f25484672b Add lock 2023-03-03 13:23:30 -05:00
1ba07c0bbf Delete lock 2023-03-03 13:21:52 -05:00
cf68d8fab3 Update Flake 2023-03-03 13:18:43 -05:00
6602ae27c5 Use Crane Flake 2023-03-03 10:09:45 -05:00
a39c61a951 Latest Things 2023-03-03 09:32:00 -05:00
Administrator
85c4818e37 Add LICENSE 2022-07-19 23:21:08 +00:00
20 changed files with 29 additions and 3032 deletions

3
.gitignore vendored
View File

@@ -4,6 +4,3 @@ Cargo.lock*
node_modules
/target
result*
/.tmp
.DS_Store
/.tmp

View File

@@ -1,14 +0,0 @@
keys:
- &hydra age18c3v89md4yjc9exjgfmk42csn8yqr9fvumsqjm8rnku5ac3q6gqs6s5un9
- &universedesk age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7
creation_rules:
- path_regex: secrets/[^/]+\.yaml$
key_groups:
- age:
- *hydra
- *universedesk
- path_regex: secrets/[^/]+\.(sh|nix)$
key_groups:
- age:
- *hydra
- *universedesk

2092
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,8 @@
[package]
name = "new_alan"
name = "New Alan"
version = "0.0.1"
edition = "2021"
edition = "2023"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
tracing-futures = "0.2.5"
serenity = { version = "0.11.5", features = ["voice", "client", "rustls_backend", "standard_framework"] }
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread", "signal"] }
songbird = "0.3.1"
rand = "0.8.5"

175
deploy/flake.lock generated
View File

@@ -1,175 +0,0 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1678190193,
"narHash": "sha256-nuiUyTTjzMVfeRZInX81mBrWk26/2AgjZs/cdjX1oIk=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "292b3a8437125f015adbd32efd6bcdbbd95303f3",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"newalan",
"nixpkgs"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1678152261,
"narHash": "sha256-cPRDxwygVMleiSEGELrvAiq9vYAN4c3KK/K4UEO13vU=",
"owner": "ipetkov",
"repo": "crane",
"rev": "5291dd0aa7a52d607fc952763ef60714e4c881d4",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"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"
}
},
"flake-utils_2": {
"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"
}
},
"newalan": {
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 0,
"narHash": "sha256-adKGCz1gVSev/Kf+Y38UCZJgcddTNeK5yGxn1ZwWhCE=",
"path": "/nix/store/8dvz739k19bsni4zdnyfz0sff6plqbr5-source",
"type": "path"
},
"original": {
"path": "/nix/store/8dvz739k19bsni4zdnyfz0sff6plqbr5-source",
"type": "path"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1678207308,
"narHash": "sha256-WrmS/Inla0koTZIiq094tmjQA0akXjKtvZMcbgqfEP0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0ef02c4792fbde4b78957a46a8cb107b6c7aa3cc",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1678111249,
"narHash": "sha256-ZTIbK7vthZwti5XeLZE+twkb4l44q01q2XoLMmmJe94=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a028e2873d7fcf44e66b784b4ba061824315537f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"newalan": "newalan",
"nixpkgs": "nixpkgs_2"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"newalan",
"crane",
"flake-utils"
],
"nixpkgs": [
"newalan",
"crane",
"nixpkgs"
]
},
"locked": {
"lastModified": 1677812689,
"narHash": "sha256-EakqhgRnjVeYJv5+BJx/NZ7/eFTMBxc4AhICUNquhUg=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e53e8853aa7b0688bc270e9e6a681d22e01cf299",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View File

@@ -1,38 +0,0 @@
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.newalan.url = "../";
outputs = { self, nixpkgs, newalan }: let
new_alan_overlay = (final: prev: {
new_alan = newalan.packages."x86_64-linux".default;
});
in {
nixosConfigurations."staging" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
../secrets/config.nix
({ config, pkgs, ... }: {
nixpkgs.overlays = [
new_alan_overlay
];
})
({lib, config, pkgs, ...}: {
systemd.services.alan = {
wantedBy = ["networking-online.target"];
enable = true;
path = [
pkgs.new_alan
pkgs.ffmpeg_5-headless
];
environment = {
DING_SOUND = "${pkgs.new_alan}/share/sounds/ding.mp3";
};
script = ''
${pkgs.new_alan}/bin/new_alan
'';
};
})
];
};
};
}

BIN
ding.mp3

Binary file not shown.

24
flake.lock generated
View File

@@ -3,11 +3,11 @@
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1678190193,
"narHash": "sha256-nuiUyTTjzMVfeRZInX81mBrWk26/2AgjZs/cdjX1oIk=",
"lastModified": 1677345087,
"narHash": "sha256-PSkBGJ6KyGbTeLtEgdHSljm76NOeoww9hDgBD/QBffk=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "292b3a8437125f015adbd32efd6bcdbbd95303f3",
"rev": "9a5b1008028e4b37e91f5951e639ad7848232f8e",
"type": "github"
},
"original": {
@@ -26,11 +26,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1678152261,
"narHash": "sha256-cPRDxwygVMleiSEGELrvAiq9vYAN4c3KK/K4UEO13vU=",
"lastModified": 1677642623,
"narHash": "sha256-GlRa6/HWg8mIxPM29ZuTP2dP8y9sQ6BdbrjzCO8JgAo=",
"owner": "ipetkov",
"repo": "crane",
"rev": "5291dd0aa7a52d607fc952763ef60714e4c881d4",
"rev": "f3f763e4d9f156ec0c37f39b0f77e2d62213b296",
"type": "github"
},
"original": {
@@ -87,11 +87,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1678207308,
"narHash": "sha256-WrmS/Inla0koTZIiq094tmjQA0akXjKtvZMcbgqfEP0=",
"lastModified": 1677816901,
"narHash": "sha256-oqe8Q9LlWNGfVfUDkKfpWAk+I9RRDBvMSyYVIOZCfPM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0ef02c4792fbde4b78957a46a8cb107b6c7aa3cc",
"rev": "0749042bfaa2f4efa70ac829c5387133cfc0a337",
"type": "github"
},
"original": {
@@ -121,11 +121,11 @@
]
},
"locked": {
"lastModified": 1677812689,
"narHash": "sha256-EakqhgRnjVeYJv5+BJx/NZ7/eFTMBxc4AhICUNquhUg=",
"lastModified": 1676437770,
"narHash": "sha256-mhJye91Bn0jJIE7NnEywGty/U5qdELfsT8S+FBjTdG4=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e53e8853aa7b0688bc270e9e6a681d22e01cf299",
"rev": "a619538647bd03e3ee1d7b947f7c11ff289b376e",
"type": "github"
},
"original": {

View File

@@ -33,29 +33,13 @@
commonArgs = {
inherit src;
nativeBuildInputs = with pkgs; [
cmake
];
buildInputs = with pkgs; [
buildInputs = [
# Add additional build inputs here
libopus
stt
tts
] ++ lib.optionals pkgs.stdenv.isDarwin ([
] ++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
] ++ (with pkgs.darwin.apple_sdk.frameworks; [
Security
]));
propagatedBuildInputs = with pkgs; [
ffmpeg_5-headless
];
meta = {
hydraPlatforms = [ "x86_64-linux" ];
};
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
};
@@ -68,13 +52,10 @@
# artifacts from above.
newalan = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
postInstall = ''
mkdir -p $out/share/sounds
cp ${./ding.mp3} $out/share/sounds/ding.mp3
'';
});
in rec {
checks = pkgs.lib.optionalAttrs (system == "x86_64-linux") {
in
{
checks = {
# Build the crate as part of `nix flake check` for convenience
inherit newalan;
@@ -118,42 +99,9 @@
inherit cargoArtifacts;
});
};
hydraJobs = checks // lib.optionalAttrs
(system == "x86_64-linux" ) {
runCommandHook = {
newalan = pkgs.runCommand "New Alan Deployscript" {
nativeBuildInputs = [newalan];
} ''
cat << 'DOC' >> $out
#!${pkgs.runtimeShell}
export tmp=$(mktemp -d)
pushd $tmp
${pkgs.wget}/bin/wget \
https://git.syzygial.cc/Syzygial/New-Alan/archive/${self.rev}.bundle
git clone * src
${pkgs.tree}/bin/tree
cd src
${pkgs.sops}/bin/sops -i -d secrets/config.nix
${pkgs.sops}/bin/sops -i -d secrets/deploy.sh
export flake="$tmp/src/deploy"
${pkgs.runtimeShell} ./secrets/deploy.sh
succ=$?
popd
rm -rf $tmp
if [ $succ -eq 0 ]; then
true
else
false
fi
DOC
chmod +x $out
'';
};
};
packages.default = newalan;
apps.default = flake-utils.lib.mkApp {
drv = newalan;
};
@@ -161,15 +109,14 @@ DOC
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
rust-analyzer
sops
age
];
};
}
);
});
}

View File

@@ -1,24 +0,0 @@
{
"data": "ENC[AES256_GCM,data:oe62garRP2YT7L5iB7sZmI+N7zFqMeIJLDY8vh+jOD2IHt8q6FniZGXHLgEuV6AAWK8Cr/nnW/hnIUopQ0vldcyXAdPx/9dV/o8e4zj4ip/mLaP4vOmk2aHvJvf9iHfROeL1Zv8ILwZGeKzTq9C0pK4YvR5NPXC8lJwsIKPgAOZ0P7jHO5gbrypuDG6N0u9hHNCzO+Vf1nRyPes3+jKPjywlM7lfDAdkSW4fxMHw4WJbg9tB3bnr4JGEXo8rkW+0emYZgVyw2rKIhq/99Fhh5PpY/1cg85VvwsOLxjqs8HlE5cPXsZS2pPuy7WK73V/Lmn6fZIrz6DPl6DLCURVSSvXF452RjSGSb8tUot6oZjQHnFv9w89IV8M3bQ++NeIGcgjcwj6DwS+q5Y+s028g2gRuWAywkEG4gCfssdknHbmz3lx+SZaD4OT0RIZ+qHg51+tfkDk9jfI4WiE6yDe8Kx8=,iv:itVF7y5k38elGWA2sYDEWdk1dYVwesgp4thrPv/b+d8=,tag:Pjv+GgOWku4pYxC+Ie8pFA==,type:str]",
"sops": {
"kms": null,
"gcp_kms": null,
"azure_kv": null,
"hc_vault": null,
"age": [
{
"recipient": "age18c3v89md4yjc9exjgfmk42csn8yqr9fvumsqjm8rnku5ac3q6gqs6s5un9",
"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBLU1hFOXpaN0wvWVk1N0t2\nQlBJZDFtOGdSOHZHZnJ3SGJsRnFtMHdQS2hnClcwdXFOWlliYjcrYVlxMHFrUU9O\nbTFsZ3BhRnFHbG05bXYzY2U3S3hKNmcKLS0tIGFRSm42Um04ZnZXTkpXYW1LVGVZ\nd21VREFGUGljbncyU04ra3JGek4wMWMKvpjyN1kijCpkcDPwpkrYkGZ9+DQrqKaC\nssh3OkuNoZ26FZv/2FWIC4+v9RJaHogDDbqqH1hFYqGZula3uPS1KQ==\n-----END AGE ENCRYPTED FILE-----\n"
},
{
"recipient": "age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7",
"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBsRDNqeW0rVU9LNGdVYWZB\nTVkxdDVIOGtiNlZ1UHI2SjZpZ2J0d1psM3owClhVbWNMTzZMWFpUMGpiMzJvOXVi\ndlQzZFZkOTJQd3J0ZVAzVmRnSExjSFEKLS0tIFFrYWNVMzlITC85a2E2QUR4d2s0\nY1JZazEzdVg1K2JaUW5BTGNSai9COU0KWNkWId02IHLp8Kih9lkkV4HOd69GVT2v\nq4PnDevZeofV9qOFIpvi3UkFNeU21pjORg8d6pJPBgzyCcCFbQN2cA==\n-----END AGE ENCRYPTED FILE-----\n"
}
],
"lastmodified": "2023-03-10T05:21:19Z",
"mac": "ENC[AES256_GCM,data:db1IOgyo3OpTODZ/uR2WzE05eMlM7XLhWZqIZMB1sAVnVJUiR510fsMagU+Z72PAx8UhnAgzk8/AirYlly9dreWhccM5ueaDi7mdBAneALX/F0ZF327MzndITW0L0X7nFmiZ5sbhdDO0OfuwGA7aldH9nIWQpUvTMbGS8uy6mLQ=,iv:chET/cFQcvVvH5F8nxNKSw9TnAsQckvSSU/a/UUkebU=,tag:5n73+26h1oSaO+uBdL7XhQ==,type:str]",
"pgp": null,
"unencrypted_suffix": "_unencrypted",
"version": "3.7.3"
}
}

View File

@@ -1,24 +0,0 @@
{
"data": "ENC[AES256_GCM,data:APVixjuK94PnVqEzfWkSPx0WdMr4+B1GjiUTRdOQgL/THoBydN1Ldu1vy1aKTZ92VfKcsvVEVgESelWy1F7clrn+vw+8S954qjZkRC+pbJnUVFpoCub/+WHRWz3KWFfwaSTtH40=,iv:F5mp8b++jKc2LlEzCm6ouLXq/9YRfcfhoUwS/MTACFY=,tag:5xiPOJfVKW6ExrLQc5846Q==,type:str]",
"sops": {
"kms": null,
"gcp_kms": null,
"azure_kv": null,
"hc_vault": null,
"age": [
{
"recipient": "age18c3v89md4yjc9exjgfmk42csn8yqr9fvumsqjm8rnku5ac3q6gqs6s5un9",
"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBKdU9yTms3clY3NTNqRmNa\nbTAzN09kWHQzYnIrdXplYzArckxQL3kxZ204ClFqR0VjY3VaMDRmOWRZRFd2bVBk\nUC9uKzBMaWhXS3NiNkpnbjJ2ZVNqd1kKLS0tIFVUZkFxMFl4S0t6Wi80c0VCUDFY\nOXQ1Z28vc0F6MWZuY0QyVTFtSkc3UFkK1r21ia+jaJqv9BN+O0dt3q5Xu/UfP7YR\npDowsKfP+zguP7ILYskmk57YIlIY46+8m7LOVoGrxDeEsryThjohQg==\n-----END AGE ENCRYPTED FILE-----\n"
},
{
"recipient": "age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7",
"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBKdUtHMERreXlZTGRGMWlM\nbldjMHFWWWRQZHRvZWx5QmhmVno0VmZQNmljCnFRUnZxT29iZkNxaExQbCtUNFFy\nMkttVkkrQkh0Ky91bnRxRmJ4VDk0N2MKLS0tIHhYREFwRUZ6a1BDM1FWZjlpcTJR\nVW5YSkwvZWQyMXNuaUdBTWpwa2Y1VWcKawzPRiMB/ruOBCylNssB/k+hITJDYX+6\nKpwHk9Avh6Pzhptm21yeY1zmVQkqEx6YU24aJiqs1RRmrQAvnWr3WQ==\n-----END AGE ENCRYPTED FILE-----\n"
}
],
"lastmodified": "2023-03-10T04:19:40Z",
"mac": "ENC[AES256_GCM,data:DTlHAsxV5bKgurcXdJfwEhZQ439ag8F+M7HYn5Ypqu02kRKjaYcq/rJyyW/KIOUSdMJyykYuPvEO4W/lfO7BNOpJ2fQ7d3kKrHnUNOcT2OWAWNaOuuoV0Tud/4qCUDq3Zv9oYJorG1tT1L0NLM9QRJG2BVJvHZCGTEEE7q/ear8=,iv:el1fjIahyKdCmBO6MRsjkZyfliXBXQjjS3NnYa737bQ=,tag:ZHocZJWqfG/JRgVxEtetHA==,type:str]",
"pgp": null,
"unencrypted_suffix": "_unencrypted",
"version": "3.7.3"
}
}

View File

@@ -1,39 +0,0 @@
hello: ENC[AES256_GCM,data:DzhDj76DB1tZGmIL7IoMwH5BHK/ry0B1IR11UXpmvlH06ChrkYtDyMtNXj5+Rg==,iv:oyd6395OkbXWJEvb4tc+YWrAPYatlGS547QMpJBRd4o=,tag:M/h7z6dBGpD9uKxYy29o8w==,type:str]
example_key: ENC[AES256_GCM,data:SSr8mQx4OR0GYkYZDQ==,iv:RhDK/LjUg4X35t/P80DcHsfTezjEO960Z14eJnDDwNo=,tag:HUjYwT8jyUIri8hdwwTaRA==,type:str]
#ENC[AES256_GCM,data:/eE2HOG2x/3H2tfK48Gvhg==,iv:6iWXJSkysBIFN2XetflpXVHieR85ibPL8aCcz4Xw3do=,tag:YJxpl/9pBA/XGI7eVVQH3g==,type:comment]
example_array:
- ENC[AES256_GCM,data:EVklKJgxr8N4lftGKO8=,iv:Mbe2FdHkKOAf15nQGFl0db3+f6/ZLN6OXPpEzUgZkT4=,tag:Jw8U8pEsvtZYcABbKpNJXw==,type:str]
- ENC[AES256_GCM,data:82H3Nf1olURg3/ZFCbY=,iv:wfIeLd1qaa2QmGIrjcaDmMTI8DcpGjme47Ja7GeIWc0=,tag:k5AHfnS6VylNUFLWQ9cWKA==,type:str]
example_number: ENC[AES256_GCM,data:0jlA2A4QsBSLbw==,iv:1pcunZ8qP/REWGM+o73m3wiIV613x6ZYmDc9P9HT718=,tag:u2YRJIRuWsflrDc/Q4VgxA==,type:float]
example_booleans:
- ENC[AES256_GCM,data:p1DhKw==,iv:nNktbyA1bIHesqI5YjBRegn3g+hB+fI2xgH6yiAub78=,tag:WlLh22H/11vwWOnVPboAgQ==,type:bool]
- ENC[AES256_GCM,data:ptkWwvQ=,iv:LHNgxVJwiBneXR0KdxqKX387UmfnFmqwworuM+4lJko=,tag:S6wLEsWEH4F0yi+mDmHFWg==,type:bool]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age18c3v89md4yjc9exjgfmk42csn8yqr9fvumsqjm8rnku5ac3q6gqs6s5un9
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB3azFLQWMybWk3dkVmTk9K
My9oWHpkM01YTjBZd0pBeWEvRnBKK0ZXN0hjCnBhMnhIblZiOGFGclphRnRxWHIx
QlJEWEl5TmFvTjF5NVFVSFdtMFNIV00KLS0tIEcrSXUwMDg3N2d0REdpcDF1SVk2
MDN1K3NEalRVZXFFaitjblpFOXZDVXMKUFmHFa4zjkjdAt3+EIiFqis1Dtcnvwby
nfXyjYKqHeulsa+iYoQd2F8RYdQc2owjoaXqwls0NjEoGBZhh2IeHg==
-----END AGE ENCRYPTED FILE-----
- recipient: age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA0ZkUyWjRXcVhFcEpEVVVM
cFY4ZGJhVDBGdXdsQXZVOS9tandHKzZ3ZFJRCitOZmVRTkFlVWE2VS9nRU1UeXF0
eVgvWVJDVGhHZlFCeWd6Q0UrTnBwMU0KLS0tIG4xb3F1RlUxOStxK3BlT0FHZkx0
OE9IR2pyM3M5SmZuRW1saXdnYi9oQ1UKO9DWOVfAuNZdKySesHBWDhK0rvOEP4mV
xLceQDXJxy53O+wvSH0E/noBLPgp0CSRSw4Xyn65d3Wfb/xg5H2+jQ==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2023-03-10T04:14:40Z"
mac: ENC[AES256_GCM,data:0LXnwmRhcMkn2MfTV8JZ60c0lC68G14MQtcQHTCy25suIL0BzWmVBkuypi//gPKRVRgHDHpIeKZm6KRP0Ipg4aSmyo7e/yDOIQq0rsWoeam00sY2kUiDTFnhF2oxP61+BwNf4yhbbiSzs0VfXhreZVZGj/0gJMJz+3BcFjmcnso=,iv:gNiaRqLYJz/CSfnV+lVLEgHNIfBIYlxgD0jpfGMyDUY=,tag:5zUaRsyN9DCIO36cC/Bmag==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.7.3

View File

@@ -1,11 +0,0 @@
use serenity::framework::standard::macros::group;
pub mod ping;
use ping::*;
pub mod vc;
use vc::*;
#[group]
#[commands(ping, join)]
pub struct General;

View File

@@ -1,11 +0,0 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::channel::Message;
use serenity::prelude::Context;
#[command]
pub async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
msg.channel_id.say(&ctx.http, "pong!").await?;
Ok(())
}

View File

@@ -1,30 +0,0 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::channel::Message;
use serenity::prelude::Context;
use crate::vc;
#[command]
#[only_in(guilds)]
pub async fn join(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).unwrap();
let channel_id = guild
.voice_states
.get(&msg.author.id)
.and_then(|voice_state| voice_state.channel_id);
let connect_to = match channel_id {
Some(channel) => channel,
None => {
msg.reply(ctx, "Not in a voice channel").await;
return Ok(());
},
};
vc::join(ctx.clone(), guild.clone(), connect_to).await;
Ok(())
}

View File

@@ -1,27 +0,0 @@
use serenity::async_trait;
use serenity::model::gateway::Ready;
use serenity::model::prelude::Guild;
use serenity::prelude::Context;
use serenity::prelude::*;
use crate::utils::*;
pub struct Handler;
#[async_trait]
impl EventHandler for Handler {
// Set a handler to be called on the `ready` event. This is called when a
// shard is booted, and a READY payload is sent by Discord. This payload
// contains data like the current user's guild Ids, current user data,
// private channels, and more.
//
// In this case, just print what the current user's username is.
async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
}
async fn guild_create(&self, ctx: Context, guild: Guild, _new: bool) {
println!("Guild joined: {}", guild.name);
guild_popin::add_guild(ctx, guild).await;
}
}

View File

@@ -1,65 +1,3 @@
/* TODO: Use tracing for better debugging following events */
use std::env;
use serenity::framework::standard::{StandardFramework, WithWhiteSpace};
use serenity::prelude::*;
// This trait adds the `register_songbird` and `register_songbird_with` methods
// to the client builder below, making it easy to install this voice client.
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
use songbird::{SerenityInit, Config, driver::DecodeMode};
mod commands;
use commands::*;
mod events;
use events::*;
mod utils;
mod vc;
#[tokio::main]
async fn main() {
// Trace async functions
tracing_subscriber::fmt::init();
// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
// Set gateway intents, which decides what events the bot will be notified about
let intents = GatewayIntents::non_privileged()
| GatewayIntents::privileged()
| GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::DIRECT_MESSAGE_REACTIONS
| GatewayIntents::DIRECT_MESSAGE_TYPING
| GatewayIntents::MESSAGE_CONTENT
| GatewayIntents::GUILD_VOICE_STATES;
let framework = StandardFramework::new()
.configure(|c| {
c.prefix("ALAN! ");
c.with_whitespace(WithWhiteSpace {
commands: true,
groups: true,
prefixes: true
})
}
)
.group(&GENERAL_GROUP);
let songbird_config = Config::default()
.decode_mode(DecodeMode::Decode);
let mut client = Client::builder(&token, intents)
.event_handler(Handler)
.framework(framework)
.register_songbird_from_config(songbird_config)
.await
.expect("Err creating client");
utils::guild_popin::init(&client).await;
vc::init(&client).await;
if let Err(why) = client.start().await {
println!("Client error: {:?}", why);
}
fn main() {
println!("Hello, hydra!");
}

View File

@@ -1,144 +0,0 @@
use rand::prelude::*;
use serenity::model::id::GuildId;
use serenity::Client;
use songbird::Call;
use std::collections::HashMap;
use std::ops::Range;
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
use serenity::model::prelude::{ChannelType, Guild};
use serenity::prelude::{Context, RwLock, TypeMapKey, Mutex};
use crate::vc;
#[derive(Debug)]
struct GuildPopIn {
min: u64, // milliseconds
max: u64, // milliseconds
}
impl TypeMapKey for GuildPopIn {
type Value = Arc<RwLock<HashMap<GuildId, GuildPopIn>>>;
}
fn init_pop_state() -> GuildPopIn {
GuildPopIn {
min: 30*60*1000,
max: 180*60*1000,
}
}
async fn popin(ctx: Context, guild: Guild) {
println!("Gonna join, I'll do it");
let mut most = None;
let mut n = 0;
for (id, chan) in guild.clone().channels {
match chan.guild() {
Some(g_chan) => {
if g_chan.kind == ChannelType::Voice {
match g_chan.members(&ctx.cache).await {
Ok(members) => {
if members.len() > n {
n = members.len();
most = Some(id);
}
}
Err(_error) => {}
};
}
}
None => {}
}
}
let mut call = None;
match most {
Some(chan) => {
call = vc::join(ctx.clone(), guild.clone(), chan).await;
}
None => {
println!("No good channel to join");
}
}
tokio::spawn(popout_soon(ctx.clone(), guild, call));
}
async fn popin_soon(ctx: Context, guild: Guild) {
let data = ctx.data.read().await;
let pops = data
.get::<GuildPopIn>()
.expect("Guild Popin states not initialized");
let pops = pops.read().await;
let popwhen = pops
.get(&guild.id)
.expect(format!("PopIn: guild {} not found", guild.name.as_str()).as_str());
let mut rng = thread_rng();
let join_in = rng.gen_range(Range {
start: popwhen.min,
end: popwhen.max,
});
println!("Joining in: {}", join_in);
sleep(Duration::from_millis(join_in));
tokio::spawn(popin(ctx.clone(), guild));
}
async fn popout(ctx: Context, guild: Guild, call: Option<Arc<Mutex<Call>>>) {
match call {
Some(call) => {
let mut call = call.lock().await;
let status = call.leave().await;
match status {
Ok(_) => {},
Err(_err) => {
println!("Failed to leave call");
}
}
},
None => {}
}
start_dingdong(ctx.clone(), guild);
}
async fn popout_soon(ctx: Context, guild: Guild, call: Option<Arc<Mutex<Call>>>) {
let data = ctx.data.read().await;
let pops = data
.get::<GuildPopIn>()
.expect("Guild Popin states not initialized");
let pops = pops.read().await;
let popwhen = pops
.get(&guild.id)
.expect(format!("PopIn: guild {} not found", guild.name.as_str()).as_str());
let mut rng = thread_rng();
let join_in = rng.gen_range(Range {
start: popwhen.min,
end: popwhen.max,
});
println!("Leaving in: {}", join_in);
sleep(Duration::from_millis(join_in));
tokio::spawn(popout(ctx.clone(), guild, call.clone()));
}
fn start_dingdong(ctx: Context, guild: Guild) {
tokio::spawn(async {
popin_soon(ctx, guild).await;
});
}
pub async fn init(client: &Client) {
let mut data = client.data.write().await;
data.insert::<GuildPopIn>(Arc::new(RwLock::new(HashMap::default())))
}
pub async fn add_guild(ctx: Context, guild: Guild) {
let data = ctx.data.write().await;
let pops = data
.get::<GuildPopIn>()
.expect("Guild Popin States Not Initialized");
{
let mut pops = pops.write().await;
pops.insert(guild.id, init_pop_state());
println!("GuildsPopIns: {:?}", pops);
start_dingdong(ctx.clone(), guild);
}
}

View File

@@ -1 +0,0 @@
pub mod guild_popin;

View File

@@ -1,249 +0,0 @@
use std::{collections::HashMap, sync::Arc};
use serenity::{
async_trait,
model::prelude::{ChannelId, Guild, GuildId},
prelude::{Context, Mutex, RwLock, TypeMapKey}, Client,
};
use songbird::{
create_player,
events::context_data::{ConnectData, DisconnectData},
ffmpeg,
model::{
id::UserId,
payload::{ClientDisconnect, Speaking},
},
Call, CoreEvent, Event, EventContext, EventHandler,
};
#[derive(Eq, Hash)]
struct CallLocation {
guild: GuildId,
channel: ChannelId
}
impl PartialEq for CallLocation {
fn eq(&self, other: &Self) -> bool {
self.guild == other.guild && self.channel == other.channel
}
}
struct VoiceData {
call: Arc<Mutex<Call>>,
users: Arc<RwLock<HashMap<u32, Option<UserId>>>>,
}
impl VoiceData {
pub fn new(call: Arc<Mutex<Call>>) -> Self {
Self {
call,
users: Arc::new(RwLock::new(HashMap::default()))
}
}
}
struct VCData {
loc: Arc<CallLocation>,
data: Arc<RwLock<VoiceData>>
}
impl TypeMapKey for VCData {
type Value = Arc<RwLock<HashMap<CallLocation, VCData>>>;
}
impl VCData {
pub fn new(loc: CallLocation, data: VoiceData) -> Self {
// You can manage state here, such as a buffer of audio packet bytes so
// you can later store them in intervals.
VCData {
loc: Arc::new(loc),
data: Arc::new(RwLock::new(data))
}
}
pub fn clone(&self) -> Self {
VCData {
loc: self.loc.clone(),
data: self.data.clone()
}
}
}
pub async fn init(client: &Client) {
let mut data = client.data.write().await;
data.insert::<VCData>(Arc::new(RwLock::new(HashMap::default())))
}
#[async_trait]
impl EventHandler for VCData {
#[allow(unused_variables)]
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
use EventContext as Ctx;
match ctx {
Ctx::SpeakingStateUpdate(Speaking {
speaking,
ssrc,
user_id,
..
}) => {
// Discord voice calls use RTP, where every sender uses a randomly allocated
// *Synchronisation Source* (SSRC) to allow receivers to tell which audio
// stream a received packet belongs to. As this number is not derived from
// the sender's user_id, only Discord Voice Gateway messages like this one
// inform us about which random SSRC a user has been allocated. Future voice
// packets will contain *only* the SSRC.
//
// You can implement logic here so that you can differentiate users'
// SSRCs and map the SSRC to the User ID and maintain this state.
// Using this map, you can map the `ssrc` in `voice_packet`
// to the user ID and handle their audio packets separately.
{
let data = self.data.write().await;
let mut users = data.users.write().await;
users.insert(ssrc.clone(), user_id.clone());
}
println!(
"\n\n\nSpeaking state update: user {:?} has SSRC {:?}, using {:?}\n\n\n",
user_id, ssrc, speaking,
);
}
Ctx::SpeakingUpdate(data) => {
// You can implement logic here which reacts to a user starting
// or stopping speaking, and to map their SSRC to User ID.
let vcdata = self.data.read().await;
let users = vcdata.users.read().await;
println!(
"Source {}/{:?} has {} speaking.",
data.ssrc,
users.get(&data.ssrc),
if data.speaking { "started" } else { "stopped" },
);
}
Ctx::VoicePacket(data) => {
// An event which fires for every received audio packet,
// containing the decoded data.
if let Some(audio) = data.audio {
// println!("Audio packet's first 5 samples: {:?}", audio.get(..5.min(audio.len())));
// println!(
// "Audio packet sequence {:05} has {:04} bytes (decompressed from {}), SSRC {}",
// data.packet.sequence.0,
// audio.len() * std::mem::size_of::<i16>(),
// data.packet.payload.len(),
// data.packet.ssrc,
// );
} else {
// println!("RTP packet, but no audio. Driver may not be configured to decode.");
}
}
Ctx::RtcpPacket(data) => {
// An event which fires for every received rtcp packet,
// containing the call statistics and reporting information.
// println!("RTCP packet received: {:?}", data.packet);
}
Ctx::ClientDisconnect(ClientDisconnect { user_id, .. }) => {
// You can implement your own logic here to handle a user who has left the
// voice channel e.g., finalise processing of statistics etc.
// You will typically need to map the User ID to their SSRC; observed when
// first speaking.
println!("Client disconnected: user {:?}", user_id);
}
Ctx::DriverConnect(ConnectData { channel_id, .. }) => {
println!("VoiceDriver is connected.");
}
Ctx::DriverDisconnect(DisconnectData {
channel_id,
guild_id,
..
}) => {
// TODO: Remove data from GuildVoiceData
}
_ => {
// We won't be registering this struct for any more event classes.
unimplemented!()
}
}
None
}
}
pub async fn play_file(call: Arc<Mutex<Call>>, file: String) {
let mut call = call.lock().await;
let ff_src = ffmpeg(file).await.expect("Unable to find file.");
let (audio, handle) = create_player(ff_src);
call.play(audio);
}
pub async fn join(ctx: Context, guild: Guild, cid: ChannelId) -> Option<Arc<Mutex<Call>>> {
let manager = songbird::get(&ctx).await.expect("Songbird: intialization");
let (call, status) = manager.join(guild.id, cid).await;
match status {
Ok(_) => {
let vc_data: VCData = VCData::new(
CallLocation {
guild: guild.id,
channel: cid
}, VoiceData::new(
call.clone()
)
);
{
let data = ctx.data.read().await;
match data.get::<VCData>() {
Some(vc_guild) => {
let mut vc_guild = vc_guild.write().await;
vc_guild.insert(CallLocation {
guild: guild.id,
channel: cid
}, vc_data.clone());
}
None => {
println!("VoiceData for client hasn't been initialized");
}
}
}
let call_handle = call.clone();
{
let mut call = call.lock().await;
call.add_global_event(
CoreEvent::SpeakingStateUpdate.into(),
vc_data.clone()
);
call.add_global_event(
CoreEvent::SpeakingUpdate.into(),
vc_data.clone()
);
call.add_global_event(
CoreEvent::VoicePacket.into(),
vc_data.clone()
);
call.add_global_event(
CoreEvent::RtcpPacket.into(),
vc_data.clone()
);
call.add_global_event(
CoreEvent::ClientDisconnect.into(),
vc_data.clone()
);
call.add_global_event(
CoreEvent::DriverConnect.into(),
vc_data.clone()
);
}
let ding_src = std::env::var("DING_SOUND").expect("DING not found in DING_SOUND");
play_file(call_handle, ding_src).await;
return Some(call);
}
Err(_err) => {
println!("Error joining channel");
}
}
None
}