Compare commits
42 Commits
main
...
a9e4a58f1f
| Author | SHA1 | Date | |
|---|---|---|---|
| a9e4a58f1f | |||
| 5dae7744ef | |||
| fc1505314f | |||
| ed4ee91239 | |||
| 96830ee2c3 | |||
| 9b384f8757 | |||
| 1acef51a6f | |||
| b8e8615282 | |||
| 55f1c9ab2d | |||
| 32030caf64 | |||
| c874b3bf1c | |||
| 2cb6bbaf7b | |||
| 264379c958 | |||
| f4ad6b13ae | |||
| 57c94d44bf | |||
| 7b3fb8f184 | |||
| 932e378558 | |||
| ef4e1eddbf | |||
| a504d7baf1 | |||
| 1297805172 | |||
| d708fb8ea7 | |||
| 53e49e95e6 | |||
| 4824e5dfaf | |||
| 44103d410e | |||
| fc4e0ce274 | |||
| 353e135edb | |||
| 1cc2582e02 | |||
| 9ca04fbfd5 | |||
| 792cd83a66 | |||
| 185f5e7d35 | |||
| 0e1d0d4346 | |||
| 31391805f2 | |||
| b6d456ff43 | |||
| 1ddda1122d | |||
| c326d201f5 | |||
| fa8ba060be | |||
| f25484672b | |||
| 1ba07c0bbf | |||
| cf68d8fab3 | |||
| 6602ae27c5 | |||
| a39c61a951 | |||
|
|
85c4818e37 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,5 @@ Cargo.lock*
|
|||||||
node_modules
|
node_modules
|
||||||
/target
|
/target
|
||||||
result*
|
result*
|
||||||
/.tmp
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/.tmp
|
/.tmp
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
keys:
|
keys:
|
||||||
- &hydra age18c3v89md4yjc9exjgfmk42csn8yqr9fvumsqjm8rnku5ac3q6gqs6s5un9
|
- &hydra age12qq2fn4nxx9g99vp5knndtn0xa0p6g9ztn48gv9ap8054am39c3qsezz90
|
||||||
- &universedesk age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7
|
- &universedesk age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7
|
||||||
creation_rules:
|
creation_rules:
|
||||||
- path_regex: secrets/[^/]+\.yaml$
|
- path_regex: secrets/[^/]+\.yaml$
|
||||||
@@ -7,8 +7,3 @@ creation_rules:
|
|||||||
- age:
|
- age:
|
||||||
- *hydra
|
- *hydra
|
||||||
- *universedesk
|
- *universedesk
|
||||||
- path_regex: secrets/[^/]+\.(sh|nix)$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *hydra
|
|
||||||
- *universedesk
|
|
||||||
|
|||||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -819,7 +819,6 @@ dependencies = [
|
|||||||
name = "new_alan"
|
name = "new_alan"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand",
|
|
||||||
"serenity",
|
"serenity",
|
||||||
"songbird",
|
"songbird",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -12,5 +12,4 @@ tracing-futures = "0.2.5"
|
|||||||
serenity = { version = "0.11.5", features = ["voice", "client", "rustls_backend", "standard_framework"] }
|
serenity = { version = "0.11.5", features = ["voice", "client", "rustls_backend", "standard_framework"] }
|
||||||
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread", "signal"] }
|
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
songbird = "0.3.1"
|
songbird = "0.3.1"
|
||||||
rand = "0.8.5"
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,27 +10,17 @@
|
|||||||
nixosConfigurations."staging" = nixpkgs.lib.nixosSystem {
|
nixosConfigurations."staging" = nixpkgs.lib.nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [
|
modules = [
|
||||||
../secrets/config.nix
|
|
||||||
({ config, pkgs, ... }: {
|
({ config, pkgs, ... }: {
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
new_alan_overlay
|
new_alan_overlay
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
({lib, config, pkgs, ...}: {
|
({lib, config, pkgs, ...}: {
|
||||||
systemd.services.alan = {
|
system.stateVersion = "22.11";
|
||||||
wantedBy = ["networking-online.target"];
|
boot.isContainer = true;
|
||||||
enable = true;
|
environment.systemPackages = with pkgs; [
|
||||||
path = [
|
new_alan
|
||||||
pkgs.new_alan
|
];
|
||||||
pkgs.ffmpeg_5-headless
|
|
||||||
];
|
|
||||||
environment = {
|
|
||||||
DING_SOUND = "${pkgs.new_alan}/share/sounds/ding.mp3";
|
|
||||||
};
|
|
||||||
script = ''
|
|
||||||
${pkgs.new_alan}/bin/new_alan
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
164
flake.nix
164
flake.nix
@@ -40,8 +40,6 @@
|
|||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
# Add additional build inputs here
|
# Add additional build inputs here
|
||||||
libopus
|
libopus
|
||||||
stt
|
|
||||||
tts
|
|
||||||
] ++ lib.optionals pkgs.stdenv.isDarwin ([
|
] ++ lib.optionals pkgs.stdenv.isDarwin ([
|
||||||
# Additional darwin specific inputs can be set here
|
# Additional darwin specific inputs can be set here
|
||||||
pkgs.libiconv
|
pkgs.libiconv
|
||||||
@@ -68,108 +66,82 @@
|
|||||||
# artifacts from above.
|
# artifacts from above.
|
||||||
newalan = craneLib.buildPackage (commonArgs // {
|
newalan = craneLib.buildPackage (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
inherit cargoArtifacts;
|
||||||
postInstall = ''
|
|
||||||
mkdir -p $out/share/sounds
|
|
||||||
cp ${./ding.mp3} $out/share/sounds/ding.mp3
|
|
||||||
'';
|
|
||||||
});
|
});
|
||||||
in rec {
|
in
|
||||||
checks = pkgs.lib.optionalAttrs (system == "x86_64-linux") {
|
{
|
||||||
# Build the crate as part of `nix flake check` for convenience
|
checks = pkgs.lib.optionalAttrs (system == "x86_64-linux") {
|
||||||
inherit newalan;
|
# Build the crate as part of `nix flake check` for convenience
|
||||||
|
inherit newalan;
|
||||||
|
|
||||||
# Run clippy (and deny all warnings) on the crate source,
|
# Run clippy (and deny all warnings) on the crate source,
|
||||||
# again, resuing the dependency artifacts from above.
|
# again, resuing the dependency artifacts from above.
|
||||||
#
|
#
|
||||||
# Note that this is done as a separate derivation so that
|
# Note that this is done as a separate derivation so that
|
||||||
# we can block the CI if there are issues here, but not
|
# we can block the CI if there are issues here, but not
|
||||||
# prevent downstream consumers from building our crate by itself.
|
# prevent downstream consumers from building our crate by itself.
|
||||||
newalan-clippy = craneLib.cargoClippy (commonArgs // {
|
newalan-clippy = craneLib.cargoClippy (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
inherit cargoArtifacts;
|
||||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||||
});
|
});
|
||||||
|
|
||||||
newalan-doc = craneLib.cargoDoc (commonArgs // {
|
newalan-doc = craneLib.cargoDoc (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
inherit cargoArtifacts;
|
||||||
});
|
});
|
||||||
|
|
||||||
# Check formatting
|
# Check formatting
|
||||||
newalan-fmt = craneLib.cargoFmt {
|
newalan-fmt = craneLib.cargoFmt {
|
||||||
inherit src;
|
inherit src;
|
||||||
};
|
|
||||||
|
|
||||||
# Audit dependencies
|
|
||||||
newalan-audit = craneLib.cargoAudit {
|
|
||||||
inherit src advisory-db;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Run tests with cargo-nextest
|
|
||||||
# Consider setting `doCheck = false` on `newalan` if you do not want
|
|
||||||
# the tests to run twice
|
|
||||||
newalan-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)
|
|
||||||
newalan-coverage = craneLib.cargoTarpaulin (commonArgs // {
|
|
||||||
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
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Audit dependencies
|
||||||
|
newalan-audit = craneLib.cargoAudit {
|
||||||
|
inherit src advisory-db;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Run tests with cargo-nextest
|
||||||
|
# Consider setting `doCheck = false` on `newalan` if you do not want
|
||||||
|
# the tests to run twice
|
||||||
|
newalan-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)
|
||||||
|
newalan-coverage = craneLib.cargoTarpaulin (commonArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
packages.default = newalan;
|
runCommandHook = {
|
||||||
|
newalan = pkgs.writeScript "New Alan CD" ''
|
||||||
apps.default = flake-utils.lib.mkApp {
|
echo HIIIII $(date) >> ~/TEST_SCRIPT
|
||||||
drv = newalan;
|
echo Wheee
|
||||||
};
|
'';
|
||||||
|
};
|
||||||
|
packages.default = newalan;
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
apps.default = flake-utils.lib.mkApp {
|
||||||
inputsFrom = builtins.attrValues self.checks.${system};
|
drv = newalan;
|
||||||
|
};
|
||||||
|
|
||||||
nativeBuildInputs = with pkgs; [
|
devShells.default = pkgs.mkShell {
|
||||||
cargo
|
inputsFrom = builtins.attrValues self.checks.${system};
|
||||||
rustc
|
|
||||||
rust-analyzer
|
|
||||||
|
|
||||||
sops
|
# Additional dev-shell environment variables can be set directly
|
||||||
age
|
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
|
||||||
];
|
|
||||||
};
|
# Extra inputs can be added here
|
||||||
}
|
nativeBuildInputs = with pkgs; [
|
||||||
|
cargo
|
||||||
|
rustc
|
||||||
|
rust-analyzer
|
||||||
|
|
||||||
|
sops
|
||||||
|
age
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +1,30 @@
|
|||||||
hello: ENC[AES256_GCM,data:DzhDj76DB1tZGmIL7IoMwH5BHK/ry0B1IR11UXpmvlH06ChrkYtDyMtNXj5+Rg==,iv:oyd6395OkbXWJEvb4tc+YWrAPYatlGS547QMpJBRd4o=,tag:M/h7z6dBGpD9uKxYy29o8w==,type:str]
|
DISCORD_TOKEN: ENC[AES256_GCM,data:IA1ZKRjahzR/hyi9DeZPYJSmCwkWhJ1BQhD/RgADm7mAj4La5Svad7swNFltimMJSuSOX8bz1onPOBiPeqBF4ZfuFS8LKw==,iv:3DYPxVlyDahUCztVjSvBfkXbkLM3J0lp8oZPbOjXI/g=,tag:esTAmPTewAU9zlO1JNn25A==,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:
|
sops:
|
||||||
kms: []
|
kms: []
|
||||||
gcp_kms: []
|
gcp_kms: []
|
||||||
azure_kv: []
|
azure_kv: []
|
||||||
hc_vault: []
|
hc_vault: []
|
||||||
age:
|
age:
|
||||||
- recipient: age18c3v89md4yjc9exjgfmk42csn8yqr9fvumsqjm8rnku5ac3q6gqs6s5un9
|
- recipient: age12qq2fn4nxx9g99vp5knndtn0xa0p6g9ztn48gv9ap8054am39c3qsezz90
|
||||||
enc: |
|
enc: |
|
||||||
-----BEGIN AGE ENCRYPTED FILE-----
|
-----BEGIN AGE ENCRYPTED FILE-----
|
||||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB3azFLQWMybWk3dkVmTk9K
|
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMREpSMmI4K1J4LzlnNGdH
|
||||||
My9oWHpkM01YTjBZd0pBeWEvRnBKK0ZXN0hjCnBhMnhIblZiOGFGclphRnRxWHIx
|
S0k0dWdZUHo2YkNxeWR2eG5HYXpmQndxRmo0CmFZY2RrRUpIT0NsdkNKQTl3L3N3
|
||||||
QlJEWEl5TmFvTjF5NVFVSFdtMFNIV00KLS0tIEcrSXUwMDg3N2d0REdpcDF1SVk2
|
d2loNlZBajFyNmRPQzdIWUdMbUFzbEkKLS0tIGVGbEF1cDFneHl2ZUdpaTFjZGNq
|
||||||
MDN1K3NEalRVZXFFaitjblpFOXZDVXMKUFmHFa4zjkjdAt3+EIiFqis1Dtcnvwby
|
dVNwdUNxcnhhd0dxcXhvRlRuR2IwR2cKCDFj6ubhGwcy6EFx0EaCcB/bE3k2PDeA
|
||||||
nfXyjYKqHeulsa+iYoQd2F8RYdQc2owjoaXqwls0NjEoGBZhh2IeHg==
|
g8RhyS+k+XLpErkU2cd+Rz2Cwj2w4QORvJddwDhdnm/sqYCCLQlG3g==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
- recipient: age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7
|
- recipient: age1apajqje4zvah0n2dzds3kstlsakqr2ntk64xl7xc4erzedsuy9jqqk7cd7
|
||||||
enc: |
|
enc: |
|
||||||
-----BEGIN AGE ENCRYPTED FILE-----
|
-----BEGIN AGE ENCRYPTED FILE-----
|
||||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA0ZkUyWjRXcVhFcEpEVVVM
|
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA5RklkWE9VMFNQbkNIU0Z6
|
||||||
cFY4ZGJhVDBGdXdsQXZVOS9tandHKzZ3ZFJRCitOZmVRTkFlVWE2VS9nRU1UeXF0
|
WXBPTWthWG1oVzRsb3JWMUR1dE1zdEhMUkM4Clk0clA0d3A5SFdmem9lblhUVzRo
|
||||||
eVgvWVJDVGhHZlFCeWd6Q0UrTnBwMU0KLS0tIG4xb3F1RlUxOStxK3BlT0FHZkx0
|
djJ3SlFDS0p4NEpxSHhoMnlnN2h3OVEKLS0tIGx1eVdaYXVtZER1KzB2ZkZickFs
|
||||||
OE9IR2pyM3M5SmZuRW1saXdnYi9oQ1UKO9DWOVfAuNZdKySesHBWDhK0rvOEP4mV
|
TDd0dG1RYVFhWkkrWmlPVmt0aVJhclEK991J72XkQy2+1jQpY4rZSFkRFE8v/nqb
|
||||||
xLceQDXJxy53O+wvSH0E/noBLPgp0CSRSw4Xyn65d3Wfb/xg5H2+jQ==
|
Vt3dG7GfnCjpf/F0BZscLsQdo1fcZcwgumlG3omyBTylFXTGnWT4VA==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
lastmodified: "2023-03-10T04:14:40Z"
|
lastmodified: "2023-03-09T04:26:07Z"
|
||||||
mac: ENC[AES256_GCM,data:0LXnwmRhcMkn2MfTV8JZ60c0lC68G14MQtcQHTCy25suIL0BzWmVBkuypi//gPKRVRgHDHpIeKZm6KRP0Ipg4aSmyo7e/yDOIQq0rsWoeam00sY2kUiDTFnhF2oxP61+BwNf4yhbbiSzs0VfXhreZVZGj/0gJMJz+3BcFjmcnso=,iv:gNiaRqLYJz/CSfnV+lVLEgHNIfBIYlxgD0jpfGMyDUY=,tag:5zUaRsyN9DCIO36cC/Bmag==,type:str]
|
mac: ENC[AES256_GCM,data:Hj8QDZZj7NiLqjvA6cuTfvePdtkDt/noqO/g8sSsaUhkVceAbO8asKmRWezB9lhCzBk+EMzA/qZA1PeBqiw2FxU7DUQF2jC9RJTCrn242wUn2Ba9n70aj2QQQFSxjbBG0LwwAV2hqbxa/AhmLizvX2xd6lI/3E7Az7vsf9quFm8=,iv:oDZ7itiQ6lL9YHAlVk9izyjDVeUYtOJygaclSRl+SDg=,tag:hX2V7POGSjuFEqWw26b+IA==,type:str]
|
||||||
pgp: []
|
pgp: []
|
||||||
unencrypted_suffix: _unencrypted
|
unencrypted_suffix: _unencrypted
|
||||||
version: 3.7.3
|
version: 3.7.3
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
use serenity::framework::standard::macros::group;
|
use serenity::framework::standard::macros::group;
|
||||||
|
|
||||||
pub mod ping;
|
pub mod ping;
|
||||||
use ping::*;
|
use ping::*;
|
||||||
|
|
||||||
pub mod vc;
|
|
||||||
use vc::*;
|
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(ping, join)]
|
#[commands(ping)]
|
||||||
pub struct General;
|
pub struct General;
|
||||||
|
|||||||
@@ -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(())
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::gateway::Ready;
|
use serenity::model::gateway::Ready;
|
||||||
use serenity::model::prelude::Guild;
|
|
||||||
use serenity::prelude::Context;
|
use serenity::prelude::Context;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
use crate::utils::*;
|
|
||||||
|
|
||||||
pub struct Handler;
|
pub struct Handler;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -18,10 +15,9 @@ impl EventHandler for Handler {
|
|||||||
// In this case, just print what the current user's username is.
|
// In this case, just print what the current user's username is.
|
||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
println!("{} is connected!", ready.user.name);
|
println!("{} is connected!", ready.user.name);
|
||||||
}
|
for g_id in ctx.cache.guilds() {
|
||||||
|
let g = ctx.cache.guild(g_id).expect("Unable to fetch guild");
|
||||||
async fn guild_create(&self, ctx: Context, guild: Guild, _new: bool) {
|
println!("Initializing {}...", g.name);
|
||||||
println!("Guild joined: {}", guild.name);
|
}
|
||||||
guild_popin::add_guild(ctx, guild).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/main.rs
34
src/main.rs
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use serenity::framework::standard::{StandardFramework, WithWhiteSpace};
|
use serenity::framework::standard::StandardFramework;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
// This trait adds the `register_songbird` and `register_songbird_with` methods
|
// This trait adds the `register_songbird` and `register_songbird_with` methods
|
||||||
// to the client builder below, making it easy to install this voice client.
|
// 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`.
|
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
|
||||||
use songbird::{SerenityInit, Config, driver::DecodeMode};
|
use songbird::SerenityInit;
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
use commands::*;
|
use commands::*;
|
||||||
@@ -16,9 +16,6 @@ use commands::*;
|
|||||||
mod events;
|
mod events;
|
||||||
use events::*;
|
use events::*;
|
||||||
|
|
||||||
mod utils;
|
|
||||||
mod vc;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Trace async functions
|
// Trace async functions
|
||||||
@@ -26,39 +23,26 @@ async fn main() {
|
|||||||
// Configure the client with your Discord bot token in the environment.
|
// Configure the client with your Discord bot token in the environment.
|
||||||
let token = env::var("DISCORD_TOKEN").expect("Expected a 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
|
// Set gateway intents, which decides what events the bot will be notified about
|
||||||
let intents = GatewayIntents::non_privileged()
|
let intents = GatewayIntents::GUILD_MESSAGES
|
||||||
| GatewayIntents::privileged()
|
| GatewayIntents::GUILD_VOICE_STATES
|
||||||
|
| GatewayIntents::GUILD_MESSAGE_REACTIONS
|
||||||
|
| GatewayIntents::GUILD_MESSAGE_TYPING
|
||||||
| GatewayIntents::DIRECT_MESSAGES
|
| GatewayIntents::DIRECT_MESSAGES
|
||||||
| GatewayIntents::DIRECT_MESSAGE_REACTIONS
|
| GatewayIntents::DIRECT_MESSAGE_REACTIONS
|
||||||
| GatewayIntents::DIRECT_MESSAGE_TYPING
|
| GatewayIntents::DIRECT_MESSAGE_TYPING
|
||||||
| GatewayIntents::MESSAGE_CONTENT
|
| GatewayIntents::MESSAGE_CONTENT;
|
||||||
| GatewayIntents::GUILD_VOICE_STATES;
|
|
||||||
|
|
||||||
let framework = StandardFramework::new()
|
let framework = StandardFramework::new()
|
||||||
.configure(|c| {
|
.configure(|c| c.prefix("ALAN! "))
|
||||||
c.prefix("ALAN! ");
|
|
||||||
c.with_whitespace(WithWhiteSpace {
|
|
||||||
commands: true,
|
|
||||||
groups: true,
|
|
||||||
prefixes: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.group(&GENERAL_GROUP);
|
.group(&GENERAL_GROUP);
|
||||||
|
|
||||||
let songbird_config = Config::default()
|
|
||||||
.decode_mode(DecodeMode::Decode);
|
|
||||||
|
|
||||||
let mut client = Client::builder(&token, intents)
|
let mut client = Client::builder(&token, intents)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
.register_songbird_from_config(songbird_config)
|
.register_songbird()
|
||||||
.await
|
.await
|
||||||
.expect("Err creating client");
|
.expect("Err creating client");
|
||||||
|
|
||||||
utils::guild_popin::init(&client).await;
|
|
||||||
vc::init(&client).await;
|
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
println!("Client error: {:?}", why);
|
println!("Client error: {:?}", why);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod guild_popin;
|
|
||||||
249
src/vc/mod.rs
249
src/vc/mod.rs
@@ -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
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user