Compare commits
37 commits
master
...
issue-rout
Author | SHA1 | Date | |
---|---|---|---|
d8c6ce3ee8 | |||
b6a75f8d91 | |||
e3718688a7 | |||
e73bd75de9 | |||
8ed672fb3a | |||
e711c6454d | |||
fa5de03bae | |||
000094e9c4 | |||
4719b93ce5 | |||
745ac91522 | |||
0625e7f091 | |||
a38c84b8f4 | |||
fcf4f3f7cf | |||
9d94328cd6 | |||
b5e95668a5 | |||
66195138f8 | |||
5c35ad114a | |||
26f67787d7 | |||
1b534ebeb7 | |||
c27dd3b86f | |||
6d3b5eee41 | |||
2a1a7f8503 | |||
ca9361cc93 | |||
4637312da9 | |||
6c3a151668 | |||
e963ae250d | |||
60fae25419 | |||
537c3565a2 | |||
669b2da871 | |||
226da4362a | |||
8da8460e47 | |||
b08d91af5d | |||
3f8e798050 | |||
5249c3af25 | |||
4e9316ad49 | |||
2ba92388a2 | |||
6c7290883f |
26 changed files with 4320 additions and 785 deletions
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = ["--cfg", "tokio_unstable"]
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
# Based on https://doc.rust-lang.org/cargo/reference/config.html
|
# Based on https://doc.rust-lang.org/cargo/reference/config.html
|
||||||
OtherBots = "Supibot,buttsbot,PotatBotat,StreamElements,yuumeibot"
|
OtherBots = "Supibot,buttsbot,PotatBotat,StreamElements,yuumeibot"
|
||||||
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -22,10 +22,4 @@ target/
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# debug
|
# debug
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
# nix
|
|
||||||
result/
|
|
||||||
|
|
||||||
# pre-commit
|
|
||||||
/.pre-commit-config.yaml
|
|
|
@ -1,5 +1,5 @@
|
||||||
when:
|
when:
|
||||||
branch: master
|
branch: main
|
||||||
event: [push, pull_request]
|
event: [push, pull_request]
|
||||||
path:
|
path:
|
||||||
include:
|
include:
|
||||||
|
|
|
@ -37,7 +37,7 @@ steps:
|
||||||
owner: ${CI_REPO_OWNER}
|
owner: ${CI_REPO_OWNER}
|
||||||
repo: ${CI_REPO_NAME}
|
repo: ${CI_REPO_NAME}
|
||||||
branch: flake-lock-update
|
branch: flake-lock-update
|
||||||
base_branch: master
|
base_branch: main
|
||||||
pr_title: "flake.lock: update"
|
pr_title: "flake.lock: update"
|
||||||
pr_body: PR automatically created by Woodpecker CI
|
pr_body: PR automatically created by Woodpecker CI
|
||||||
close_pr_if_empty: true
|
close_pr_if_empty: true
|
||||||
|
|
1172
Cargo.lock
generated
1172
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
tokio = { version = "1.33.0", features = ["full"] }
|
tokio = { version = "1.33.0", features = ["full", "tracing"] }
|
||||||
twitch-irc = "5.0.1"
|
twitch-irc = "5.0.1"
|
||||||
rand = { version = "0.8.5", features = [] }
|
rand = { version = "0.8.5", features = [] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
@ -15,6 +15,9 @@ async-trait = "0.1.77"
|
||||||
async-recursion = "1.1.0"
|
async-recursion = "1.1.0"
|
||||||
casual_logger = "0.6.5"
|
casual_logger = "0.6.5"
|
||||||
chrono = "0.4.35"
|
chrono = "0.4.35"
|
||||||
|
tokio-console = "0.1.10"
|
||||||
|
console-subscriber = "0.2.0"
|
||||||
|
async-channel = "2.2.0"
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -9,10 +9,9 @@ test ModulatingForceBot
|
||||||
|
|
||||||
```
|
```
|
||||||
login_name = <botname>
|
login_name = <botname>
|
||||||
access_token = <oauth token>
|
access_token = <oath token>
|
||||||
bot_channels = <chnl1>,<chnl2>
|
bot_channels = <chnl1>,<chnl2>
|
||||||
prefix = <prefix>
|
prefix = <prefix>
|
||||||
bot_admins = <admins>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
173
flake.lock
173
flake.lock
|
@ -6,11 +6,11 @@
|
||||||
"rust-analyzer-src": "rust-analyzer-src"
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711952616,
|
"lastModified": 1706768574,
|
||||||
"narHash": "sha256-WJvDdOph001fA1Ap3AyaQtz/afJAe7meSG5uJAdSE+A=",
|
"narHash": "sha256-4o6TMpzBHO659EiJTzd/EGQGUDdbgwKwhqf3u6b23U8=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "fenix",
|
"repo": "fenix",
|
||||||
"rev": "209048d7c545905c470f6f8c05c5061f391031a8",
|
"rev": "668102037129923cd0fc239d864fce71eabdc6a3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -20,68 +20,13 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-compat": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1696426674,
|
|
||||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
|
||||||
"owner": "edolstra",
|
|
||||||
"repo": "flake-compat",
|
|
||||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "edolstra",
|
|
||||||
"repo": "flake-compat",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
|
||||||
"inputs": {
|
|
||||||
"systems": "systems"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1710146030,
|
|
||||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"gitignore": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"pre-commit-hooks",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1709087332,
|
|
||||||
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "gitignore.nix",
|
|
||||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "gitignore.nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711703276,
|
"lastModified": 1706550542,
|
||||||
"narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=",
|
"narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d8fe5e6c92d0d190646fb9f1056741a229980089",
|
"rev": "97b17f32362e475016f942bbdfda4a4a72a8a652",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -91,92 +36,36 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-stable": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1710695816,
|
|
||||||
"narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "614b4613980a522ba49f0d194531beddbb7220d3",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixos-23.11",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1712573573,
|
"lastModified": 1708296515,
|
||||||
"narHash": "sha256-xxon7WwNm4/EadMKg1eF40/5s0O78nXUy2ILZt6vT7E=",
|
"narHash": "sha256-FyF489fYNAUy7b6dkYV6rGPyzp+4tThhr80KNAaF/yY=",
|
||||||
"owner": "NixOS",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "0d28066770464d19d637f6e8e42e8688420b6ac6",
|
"rev": "b98a4e1746acceb92c509bc496ef3d0e5ad8d4aa",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "nixos",
|
||||||
"ref": "nixpkgs-unstable",
|
"ref": "nixos-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_3": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1710765496,
|
|
||||||
"narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pre-commit-hooks": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-compat": "flake-compat",
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"gitignore": "gitignore",
|
|
||||||
"nixpkgs": "nixpkgs_3",
|
|
||||||
"nixpkgs-stable": "nixpkgs-stable"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1712579741,
|
|
||||||
"narHash": "sha256-igpsH+pa6yFwYOdah3cFciCk8gw+ytniG9quf5f/q84=",
|
|
||||||
"owner": "cachix",
|
|
||||||
"repo": "pre-commit-hooks.nix",
|
|
||||||
"rev": "70f504012f0a132ac33e56988e1028d88a48855c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "cachix",
|
|
||||||
"repo": "pre-commit-hooks.nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"fenix": "fenix",
|
"fenix": "fenix",
|
||||||
"nixpkgs": "nixpkgs_2",
|
"nixpkgs": "nixpkgs_2"
|
||||||
"pre-commit-hooks": "pre-commit-hooks",
|
|
||||||
"systems": "systems_2"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-analyzer-src": {
|
"rust-analyzer-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711885694,
|
"lastModified": 1706735270,
|
||||||
"narHash": "sha256-dyezzeSbWMpflma+E9USmvSxuLgGcNGcGw3cOnX36ko=",
|
"narHash": "sha256-IJk+UitcJsxzMQWm9pa1ZbJBriQ4ginXOlPyVq+Cu40=",
|
||||||
"owner": "rust-lang",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"rev": "e4a405f877efd820bef9c0e77a02494e47c17512",
|
"rev": "42cb1a2bd79af321b0cc503d2960b73f34e2f92b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -185,36 +74,6 @@
|
||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"systems": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681028828,
|
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"systems_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1689347949,
|
|
||||||
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default-linux",
|
|
||||||
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default-linux",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
97
flake.nix
97
flake.nix
|
@ -1,80 +1,39 @@
|
||||||
{
|
{
|
||||||
description = "A basic flake";
|
description = "forcebot_rs flake";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
systems.url = "github:nix-systems/default-linux";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
||||||
fenix.url = "github:nix-community/fenix/monthly";
|
fenix.url = "github:nix-community/fenix/monthly";
|
||||||
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
|
||||||
systems,
|
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
fenix,
|
fenix,
|
||||||
pre-commit-hooks,
|
...
|
||||||
}: let
|
} @ inputs: let
|
||||||
eachSystem = nixpkgs.lib.genAttrs (import systems);
|
system = "x86_64-linux";
|
||||||
pkgsFor = eachSystem (system:
|
overlays = [fenix.overlays.default];
|
||||||
import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
localSystem.system = system;
|
inherit system overlays;
|
||||||
overlays = [fenix.overlays.default];
|
};
|
||||||
});
|
|
||||||
in {
|
in {
|
||||||
packages = eachSystem (system: let
|
devShells.${system}.default = pkgs.mkShell {
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
name = "forcebot_rs-devenv";
|
||||||
inherit ((builtins.fromTOML (builtins.readFile ./Cargo.toml)).package) version;
|
nativeBuildInputs = [pkgs.pkg-config];
|
||||||
in {
|
buildInputs = with pkgs; [openssl libiconv];
|
||||||
default = pkgsFor.${system}.rustPlatform.buildRustPackage {
|
packages = with pkgs; [
|
||||||
pname = "forcebot_rs";
|
nil
|
||||||
version = "${version}";
|
alejandra
|
||||||
|
rust-analyzer-nightly
|
||||||
src = self;
|
(fenix.packages.${system}.complete.withComponents [
|
||||||
|
"cargo"
|
||||||
cargoLock = {
|
"clippy"
|
||||||
lockFile = ./Cargo.lock;
|
"rust-src"
|
||||||
};
|
"rustc"
|
||||||
|
"rustfmt"
|
||||||
nativeBuildInputs = with pkgs; [pkg-config];
|
])
|
||||||
buildInputs = with pkgs; [openssl];
|
];
|
||||||
|
RUST_BACKTRACE = 1;
|
||||||
doCheck = false;
|
RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library";
|
||||||
};
|
};
|
||||||
});
|
|
||||||
checks = eachSystem (system: {
|
|
||||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
|
||||||
src = ./.;
|
|
||||||
hooks = {
|
|
||||||
# rust
|
|
||||||
rustfmt.enable = true;
|
|
||||||
clippy.enable = true;
|
|
||||||
# nix
|
|
||||||
statix.enable = true;
|
|
||||||
alejandra.enable = true;
|
|
||||||
deadnix.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
devShells = eachSystem (system: {
|
|
||||||
default = pkgsFor.${system}.mkShell {
|
|
||||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
|
||||||
packages = with pkgsFor.${system}; [
|
|
||||||
nil
|
|
||||||
alejandra
|
|
||||||
rust-analyzer-nightly
|
|
||||||
(fenix.packages.${system}.complete.withComponents [
|
|
||||||
"cargo"
|
|
||||||
"clippy"
|
|
||||||
"rust-src"
|
|
||||||
"rustc"
|
|
||||||
"rustfmt"
|
|
||||||
])
|
|
||||||
];
|
|
||||||
RUST_BACKTRACE = 1;
|
|
||||||
RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library";
|
|
||||||
};
|
|
||||||
});
|
|
||||||
nixosModules.default = import ./nix/module.nix {inherit self;};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
{self}: {
|
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
inherit (lib) types;
|
|
||||||
inherit (lib.modules) mkIf;
|
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
|
||||||
inherit (pkgs.stdenv.hostPlatform) system;
|
|
||||||
cfg = config.services.forcebot_rs;
|
|
||||||
in {
|
|
||||||
options.services.forcebot_rs = {
|
|
||||||
enable = mkEnableOption ''
|
|
||||||
Enable forcebot
|
|
||||||
'';
|
|
||||||
|
|
||||||
package = mkOption {
|
|
||||||
type = types.package;
|
|
||||||
inherit (self.packages.${system}) default;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
systemd.services.forcebot_rs = {
|
|
||||||
wantedBy = ["multi-user.target"];
|
|
||||||
serviceConfig.ExecStart = "${cfg.package}/bin/forcebot_rs";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,43 +1,147 @@
|
||||||
use twitch_irc::message::{PrivmsgMessage, TwitchUserBasics};
|
|
||||||
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::core::botinstance::BotInstance;
|
use crate::core::botinstance::BotInstance;
|
||||||
|
|
||||||
use super::{botmodules::{BotAction, BotModule}, identity::ChatBadge};
|
use super::{botinstance::Channel, botmodules::{BotAction, BotModule, Routine}, identity::ChatBadge};
|
||||||
|
|
||||||
|
|
||||||
pub type BotAR = Arc<RwLock<BotInstance>>;
|
pub type BotAR = Arc<RwLock<BotInstance>>;
|
||||||
pub type ActAR = Arc<RwLock<BotAction>>;
|
pub type ActAR = Arc<RwLock<BotAction>>;
|
||||||
|
pub type RoutineAR = Arc<RwLock<Routine>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ExecBodyParams {
|
pub struct ExecBodyParams {
|
||||||
pub bot : BotAR,
|
pub bot : BotAR,
|
||||||
pub msg : PrivmsgMessage,
|
pub msg : PrivmsgMessage,
|
||||||
pub parent_act : ActAR ,
|
pub parent_act : Option<ActAR> ,
|
||||||
|
pub curr_act : Option<ActAR> ,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Eq,PartialEq,Hash)]
|
||||||
|
pub enum ParamLevel {
|
||||||
|
Parent,
|
||||||
|
Current,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl ExecBodyParams {
|
impl ExecBodyParams {
|
||||||
|
|
||||||
pub async fn get_parent_module(&self) -> Option<BotModule> {
|
// pub async fn get_parent_module(&self) -> Option<BotModule> {
|
||||||
|
// pub async fn get_parent_module(&self) -> BotModule {
|
||||||
|
pub async fn get_module(&self) -> BotModule {
|
||||||
|
|
||||||
let parent_act = Arc::clone(&self.parent_act);
|
let curr_acta = Arc::clone(&(self.curr_act.clone().unwrap()));
|
||||||
let parent_act_lock = parent_act.read().await;
|
let parent_act_lock = curr_acta.read().await;
|
||||||
let act = &(*parent_act_lock);
|
let act = &(*parent_act_lock);
|
||||||
match act {
|
match act {
|
||||||
BotAction::C(c) => {
|
BotAction::C(c) => {
|
||||||
let temp = c.module.clone();
|
// let temp = c.module.clone();
|
||||||
Some(temp)
|
// Some(temp)
|
||||||
|
c.module.clone()
|
||||||
},
|
},
|
||||||
BotAction::L(l) => {
|
BotAction::L(l) => {
|
||||||
let temp = l.module.clone();
|
// let temp = l.module.clone();
|
||||||
Some(temp)
|
// Some(temp)
|
||||||
|
l.module.clone()
|
||||||
},
|
},
|
||||||
_ => None
|
BotAction::R(r) => {
|
||||||
|
// let temp = r.module.clone();
|
||||||
|
// Some(temp)
|
||||||
|
r.read().await.module.clone()
|
||||||
|
}
|
||||||
|
// _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub async fn get_channel(&self) -> Option<Channel> {
|
||||||
|
pub fn get_channel(&self) -> Option<Channel> {
|
||||||
|
|
||||||
|
dbg!("Core > ExecBodyParams > GetChannels START");
|
||||||
|
dbg!("!! [x] Document - After SUCCESS message was sent to chat");
|
||||||
|
dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 ");
|
||||||
|
dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1 ");
|
||||||
|
dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0 ");
|
||||||
|
dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2");
|
||||||
|
|
||||||
|
|
||||||
|
let curr_act = Arc::clone(&self.curr_act.clone().unwrap());
|
||||||
|
// let curr_act_lock = curr_act.read().await;
|
||||||
|
|
||||||
|
// Note : The below `curr_act.blocking_read()` is not possible. I get the following
|
||||||
|
// during runtime in this areas
|
||||||
|
/*
|
||||||
|
thread 'tokio-runtime-worker' panicked at src\core\bot_actions.rs:66:38:
|
||||||
|
Cannot block the current thread from within a runtime. This happens because a function attempted to block the current thread while the thread is being used to drive asynchronous tasks.
|
||||||
|
*/
|
||||||
|
let curr_act_lock = curr_act.blocking_read();
|
||||||
|
|
||||||
|
dbg!("Core > ExecBodyParams > After Creating ExecBodyParams.current_act.read() Guard ");
|
||||||
|
dbg!("!! [x] Document - After SUCCESS message was sent to chat");
|
||||||
|
dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 ");
|
||||||
|
dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1 ");
|
||||||
|
dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0 ");
|
||||||
|
dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2");
|
||||||
|
|
||||||
|
let act = &(*curr_act_lock);
|
||||||
|
|
||||||
|
dbg!("Core > ExecBodyParams > Using the Read Guard ");
|
||||||
|
dbg!("!! [x] Document - After SUCCESS message was sent to chat");
|
||||||
|
dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 ");
|
||||||
|
dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1");
|
||||||
|
dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = Not Listed ");
|
||||||
|
dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2");
|
||||||
|
|
||||||
|
let out = match act {
|
||||||
|
BotAction::C(_) => {
|
||||||
|
// let temp = c.module.clone();
|
||||||
|
// Some(temp)
|
||||||
|
Some(Channel(self.msg.channel_login.clone()))
|
||||||
|
},
|
||||||
|
BotAction::L(_) => {
|
||||||
|
// let temp = l.module.clone();
|
||||||
|
// Some(temp)
|
||||||
|
// l.module.clone()
|
||||||
|
Some(Channel(self.msg.channel_login.clone()))
|
||||||
|
},
|
||||||
|
BotAction::R(r) => {
|
||||||
|
// let temp = r.module.clone();
|
||||||
|
// Some(temp)
|
||||||
|
dbg!("Core > ExecBodyParams > GetChannels - routine identified");
|
||||||
|
dbg!("!! [x] Document");
|
||||||
|
dbg!(">> BotActionAR - RwLock from botmodules.rs::930:46 - current_readers = 2");
|
||||||
|
dbg!(">> RoutineAR - RwLock from botmodules.rs::1262:32 - current_readers = 1");
|
||||||
|
dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0");
|
||||||
|
dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 1");
|
||||||
|
// => 03.30 - Just before deadlock
|
||||||
|
// dbg!("ISSUE : RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1");
|
||||||
|
// let out = Some(r.read().await.channel.clone());
|
||||||
|
|
||||||
|
|
||||||
|
dbg!("ISSUE > Never makes it after the following read guard");
|
||||||
|
|
||||||
|
// let guard = r.read().await;
|
||||||
|
let guard = r.blocking_read();
|
||||||
|
|
||||||
|
dbg!("ISSUE RESOLVED > If passed htis point");
|
||||||
|
|
||||||
|
let channel = guard.channel.clone();
|
||||||
|
drop(guard);
|
||||||
|
let out = Some(channel);
|
||||||
|
|
||||||
|
// => 03.30 - This isn't reached because of the Deadlock
|
||||||
|
dbg!(">> Just after Potential Deadlock Lock");
|
||||||
|
out
|
||||||
|
}
|
||||||
|
// _ => None
|
||||||
|
};
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn get_sender(&self) -> String {
|
pub fn get_sender(&self) -> String {
|
||||||
self.msg.sender.name.clone()
|
self.msg.sender.name.clone()
|
||||||
}
|
}
|
||||||
|
@ -56,68 +160,9 @@ impl ExecBodyParams {
|
||||||
requestor_badge_mut
|
requestor_badge_mut
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns some information about the message that was replied to by the `PrivmsgMessage` contained
|
|
||||||
/// in the `msg` field of this struct.
|
|
||||||
///
|
|
||||||
/// If that message replied to message return that information in form of `Some<ReplyParent>`.
|
|
||||||
/// Otherwise, return `None`.
|
|
||||||
pub fn get_parent_reply(&self) -> Option<ReplyParent> {
|
|
||||||
let map = &self.msg.source.tags.0;
|
|
||||||
let tags = [
|
|
||||||
"reply-parent-user-id",
|
|
||||||
"reply-parent-user-login",
|
|
||||||
"reply-parent-display-name",
|
|
||||||
"reply-parent-msg-id",
|
|
||||||
"reply-parent-msg-body"
|
|
||||||
];
|
|
||||||
|
|
||||||
// filter out all tags that do not have content.
|
|
||||||
let tag_contents: Vec<String> = tags.iter().filter_map(|tag| {
|
|
||||||
// if let Some(&Some(ref t)) = map.get(*tag) {
|
|
||||||
if let Some(Some(t)) = map.get(*tag) {
|
|
||||||
Some(t.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
// if no tags got filtered out return the struct.
|
|
||||||
// else return `None`.
|
|
||||||
if tag_contents.len() == 5 {
|
|
||||||
Some(ReplyParent {
|
|
||||||
sender: TwitchUserBasics {
|
|
||||||
id: tag_contents[0].clone(),
|
|
||||||
login: tag_contents[1].clone(),
|
|
||||||
name: tag_contents[2].clone(),
|
|
||||||
},
|
|
||||||
message_id: tag_contents[3].clone(),
|
|
||||||
message_text: tag_contents[4].clone(),
|
|
||||||
channel_login: self.msg.channel_login.clone(),
|
|
||||||
channel_id: self.msg.channel_id.clone(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the message a `PrivmsgMessage` replies to.
|
|
||||||
/// Similar to a less detailed `PrivmsgMessage`.
|
|
||||||
///
|
|
||||||
/// This should not be constructed manually but only from calling `get_parent_reply()` on
|
|
||||||
/// `ExecBodyParams`.
|
|
||||||
///
|
|
||||||
/// Fields that will be the same as the `PrivmsgMessage` this was generated from:
|
|
||||||
/// - `channel_login`
|
|
||||||
/// - `channel_id`
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub struct ReplyParent {
|
|
||||||
pub sender: TwitchUserBasics,
|
|
||||||
pub message_id: String,
|
|
||||||
pub message_text: String,
|
|
||||||
pub channel_login: String,
|
|
||||||
pub channel_id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub mod actions_util {
|
pub mod actions_util {
|
||||||
|
|
|
@ -40,15 +40,15 @@ pub struct Channel(pub String);
|
||||||
use super::bot_actions::ExecBodyParams;
|
use super::bot_actions::ExecBodyParams;
|
||||||
use super::botmodules::StatusType;
|
use super::botmodules::StatusType;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct BotManagers {
|
pub struct BotManagers {
|
||||||
pub identity: Arc<RwLock<IdentityManager>>,
|
pub identity: Arc<RwLock<IdentityManager>>,
|
||||||
pub chat: Chat,
|
pub chat: Arc<RwLock<Chat>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotManagers {
|
impl BotManagers {
|
||||||
pub fn init(
|
pub fn init(
|
||||||
ratelimiters: HashMap<Channel, RateLimiter>,
|
ratelimiters: HashMap<Channel, Arc<RwLock<RateLimiter>>>,
|
||||||
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||||
) -> BotManagers {
|
) -> BotManagers {
|
||||||
BotManagers {
|
BotManagers {
|
||||||
|
@ -70,6 +70,7 @@ impl<T: Clone> ArcBox<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct BotInstance {
|
pub struct BotInstance {
|
||||||
pub prefix: char,
|
pub prefix: char,
|
||||||
pub bot_channel: Channel,
|
pub bot_channel: Channel,
|
||||||
|
@ -115,14 +116,14 @@ impl BotInstance {
|
||||||
|
|
||||||
client.join(chnl.to_owned()).unwrap();
|
client.join(chnl.to_owned()).unwrap();
|
||||||
|
|
||||||
let n = RateLimiter::new();
|
let n = Arc::new(RwLock::new(RateLimiter::new()));
|
||||||
ratelimiters.insert(Channel(String::from(chnl)), n);
|
ratelimiters.insert(Channel(String::from(chnl)), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tokio::spawn(async {
|
tokio::spawn(async {
|
||||||
loop {
|
loop {
|
||||||
let routine_mins = 60 * 24 ; // Every 1 Day
|
let routine_mins = 60 * 60 * 24 ; // Every 1 Day
|
||||||
// let routine_mins = 1; // Every 1 Minute
|
// let routine_mins = 1; // Every 1 Minute
|
||||||
Log::remove_old_logs();
|
Log::remove_old_logs();
|
||||||
Log::info(&format!("Internal Purge Routine Triggered - running every {} mins",routine_mins));
|
Log::info(&format!("Internal Purge Routine Triggered - running every {} mins",routine_mins));
|
||||||
|
@ -168,6 +169,7 @@ impl BotInstance {
|
||||||
|
|
||||||
match message {
|
match message {
|
||||||
ServerMessage::Notice(msg) => {
|
ServerMessage::Notice(msg) => {
|
||||||
|
dbg!("NOTICE TRIGGERED",msg.clone());
|
||||||
botlog::notice(
|
botlog::notice(
|
||||||
format!("NOTICE : (#{:?}) {}", msg.channel_login, msg.message_text)
|
format!("NOTICE : (#{:?}) {}", msg.channel_login, msg.message_text)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
|
@ -200,7 +202,18 @@ impl BotInstance {
|
||||||
);
|
);
|
||||||
Log::flush();
|
Log::flush();
|
||||||
|
|
||||||
BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
|
let botarc = Arc::clone(&bot);
|
||||||
|
// let msgarc = Arc::new(RwLock::new(msg.clone()));
|
||||||
|
|
||||||
|
let msgtext = msg.message_text.clone();
|
||||||
|
|
||||||
|
dbg!("will spawn listener_main_prvmsg from runner",chrono::offset::Local::now(),msgtext.clone());
|
||||||
|
tokio::spawn( async move {
|
||||||
|
// let msgarc_c = msgarc.clone();
|
||||||
|
BotInstance::listener_main_prvmsg(botarc, &msg.clone()).await;
|
||||||
|
});
|
||||||
|
// BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
|
||||||
|
dbg!("completed spawn listener_main_prvmsg from runner",chrono::offset::Local::now(), msgtext);
|
||||||
}
|
}
|
||||||
ServerMessage::Whisper(msg) => {
|
ServerMessage::Whisper(msg) => {
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
|
@ -366,13 +379,13 @@ impl BotInstance {
|
||||||
Channel(msg.channel_login.to_string())).await;
|
Channel(msg.channel_login.to_string())).await;
|
||||||
|
|
||||||
|
|
||||||
if let StatusType::Disabled(a) = modstatus {
|
if let StatusType::Disabled(statuslvl) = modstatus {
|
||||||
|
|
||||||
// [x] Should only respond if a BotAdmin , Mod , SupMod , BroadCaster
|
// [x] Should only respond if a BotAdmin , Mod , SupMod , BroadCaster
|
||||||
// - Specifically it should respond only to those who may be able to enable the module
|
// - Specifically it should respond only to those who may be able to enable the module
|
||||||
|
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
&format!("Identified cmd is associated with Disabled Module : StatusLvl = {:?}", a),
|
&format!("Identified cmd is associated with Disabled Module : StatusLvl = {:?}", statuslvl),
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
@ -396,20 +409,24 @@ impl BotInstance {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only respond to those with th ebelow User Roles
|
// Only respond to those with th ebelow User Roles
|
||||||
|
// [x] Need to add in Module as well
|
||||||
|
|
||||||
let outstr =
|
let outstr =
|
||||||
format!("sadg Module is disabled : {:?}",a);
|
format!("sadg Module is disabled : {:?} {:?}",c.module.clone(),statuslvl);
|
||||||
|
|
||||||
|
|
||||||
let params = ExecBodyParams {
|
let params = ExecBodyParams {
|
||||||
bot : Arc::clone(&bot),
|
bot : Arc::clone(&bot),
|
||||||
msg : (*msg).clone(),
|
msg : (*msg).clone(),
|
||||||
parent_act : Arc::clone(&act_clone),
|
parent_act : None,
|
||||||
|
curr_act : Some(Arc::clone(&act_clone)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let params = Arc::new(RwLock::new(params));
|
||||||
|
|
||||||
// When sending a BotMsgTypeNotif, send_botmsg does Roles related validation as required
|
// When sending a BotMsgTypeNotif, send_botmsg does Roles related validation as required
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
outstr
|
outstr
|
||||||
),
|
),
|
||||||
params,
|
params,
|
||||||
|
@ -461,11 +478,15 @@ impl BotInstance {
|
||||||
let params = ExecBodyParams {
|
let params = ExecBodyParams {
|
||||||
bot : Arc::clone(&bot),
|
bot : Arc::clone(&bot),
|
||||||
msg : (*msg).clone(),
|
msg : (*msg).clone(),
|
||||||
parent_act : Arc::clone(&act_clone),
|
parent_act : None,
|
||||||
|
curr_act : Some(Arc::clone(&act_clone)),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
|
let params = Arc::new(RwLock::new(params));
|
||||||
|
|
||||||
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
outstr.to_string()
|
outstr.to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
params.clone(),
|
||||||
|
@ -491,11 +512,15 @@ impl BotInstance {
|
||||||
let params = ExecBodyParams {
|
let params = ExecBodyParams {
|
||||||
bot : Arc::clone(&bot),
|
bot : Arc::clone(&bot),
|
||||||
msg : (*msg).clone(),
|
msg : (*msg).clone(),
|
||||||
parent_act : Arc::clone(&act_clone),
|
parent_act : None,
|
||||||
|
curr_act : Some(Arc::clone(&act_clone)),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
|
let params = Arc::new(RwLock::new(params));
|
||||||
|
|
||||||
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
outstr.to_string()
|
outstr.to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
params.clone(),
|
||||||
|
@ -512,11 +537,14 @@ impl BotInstance {
|
||||||
Some(msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dbg!("Running botcommand");
|
||||||
|
|
||||||
let a = Arc::clone(&bot);
|
let a = Arc::clone(&bot);
|
||||||
c.execute(ExecBodyParams {
|
c.execute(ExecBodyParams {
|
||||||
bot : a,
|
bot : a,
|
||||||
msg : msg.clone() ,
|
msg : msg.clone() ,
|
||||||
parent_act : Arc::clone(&act_clone),
|
parent_act : None,
|
||||||
|
curr_act : Some(Arc::clone(&act_clone)),
|
||||||
}).await;
|
}).await;
|
||||||
|
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
|
@ -564,7 +592,8 @@ impl BotInstance {
|
||||||
l.execute(ExecBodyParams {
|
l.execute(ExecBodyParams {
|
||||||
bot : a,
|
bot : a,
|
||||||
msg : msg.clone() ,
|
msg : msg.clone() ,
|
||||||
parent_act : Arc::clone(&act_clone),
|
parent_act : None,
|
||||||
|
curr_act : Some(Arc::clone(&act_clone)),
|
||||||
} ).await;
|
} ).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,11 @@ debug = "Checking bot actions",
|
||||||
pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
@ -44,10 +45,11 @@ pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&Privmsg
|
||||||
pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
@ -64,10 +66,11 @@ pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&Privmsg
|
||||||
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
@ -84,10 +87,11 @@ pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgM
|
||||||
pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
@ -104,10 +108,11 @@ pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&Privms
|
||||||
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
@ -124,10 +129,11 @@ pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgM
|
||||||
pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
@ -148,10 +154,11 @@ pub fn fatal<'a>(
|
||||||
) -> &'a str {
|
) -> &'a str {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
(
|
(
|
||||||
Some(prvmsg.channel_login.clone()),
|
Some(prvmsg.channel_login.clone()),
|
||||||
Some(prvmsg.sender.name.clone()),
|
Some(prvmsg.sender.name.clone()),
|
||||||
)
|
) // <-- Clone fine atm while we're just working with Strings
|
||||||
}
|
}
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
890
src/core/chat.rs
890
src/core/chat.rs
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,6 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use tokio::time::{sleep,Duration};
|
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
use casual_logger::Log;
|
use casual_logger::Log;
|
||||||
|
@ -18,24 +17,19 @@ use crate::core::bot_actions::ExecBodyParams;
|
||||||
use crate::core::botinstance::{Channel,ChangeResult};
|
use crate::core::botinstance::{Channel,ChangeResult};
|
||||||
use crate::core::botlog;
|
use crate::core::botlog;
|
||||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
||||||
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
fn adminvector() -> Vec<String> {
|
fn adminvector() -> Vec<String> {
|
||||||
dotenv().ok();
|
vec![String::from("ModulatingForce")]
|
||||||
let mut admins = Vec::new();
|
//vec![]
|
||||||
|
|
||||||
if let Ok(value) = env::var("bot_admins") {
|
|
||||||
for admin in value.split(',') {
|
|
||||||
admins.push(String::from(admin))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
admins
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn otherbots_vector() -> Vec<String> {
|
pub fn otherbots_vector() -> Vec<String> {
|
||||||
|
// vec![String::from("ModulatingForce")]
|
||||||
|
// //vec![]
|
||||||
|
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let mut other_bots = Vec::new();
|
let mut other_bots = Vec::new();
|
||||||
|
@ -68,10 +62,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
let tempb = BotCommand {
|
let tempb = BotCommand {
|
||||||
module: BotModule(String::from("identity")),
|
module: BotModule(String::from("identity")),
|
||||||
command: String::from("promote"), // command call name
|
command: String::from("promote"), // command call name
|
||||||
alias: vec![
|
alias: vec![], // String of alternative names
|
||||||
"cucked".to_string(),
|
|
||||||
"cuck".to_string(),
|
|
||||||
], // String of alternative names
|
|
||||||
exec_body: actions_util::asyncbox(cmd_promote),
|
exec_body: actions_util::asyncbox(cmd_promote),
|
||||||
help: String::from("promote"),
|
help: String::from("promote"),
|
||||||
required_roles: vec![
|
required_roles: vec![
|
||||||
|
@ -176,7 +167,7 @@ async fn cmd_promote(params : ExecBodyParams) {
|
||||||
|
|
||||||
let mut argv = params.msg.message_text.split(' ');
|
let mut argv = params.msg.message_text.split(' ');
|
||||||
|
|
||||||
let cmdname = argv.next(); // Skip the command name
|
argv.next(); // Skip the command name
|
||||||
|
|
||||||
let arg1 = argv.next();
|
let arg1 = argv.next();
|
||||||
|
|
||||||
|
@ -214,7 +205,7 @@ async fn cmd_promote(params : ExecBodyParams) {
|
||||||
// [x] 1. Get trgusr (regardless of -admin flag)
|
// [x] 1. Get trgusr (regardless of -admin flag)
|
||||||
|
|
||||||
// let targetusr = if arg1 == Some("-admin") { arg2 } else { arg1 };
|
// let targetusr = if arg1 == Some("-admin") { arg2 } else { arg1 };
|
||||||
let mut targetusr = if
|
let targetusr = if
|
||||||
arg1 == Some("-admin")
|
arg1 == Some("-admin")
|
||||||
|| arg1 == Some("-v")
|
|| arg1 == Some("-v")
|
||||||
|| arg1 == Some("-vip")
|
|| arg1 == Some("-vip")
|
||||||
|
@ -223,61 +214,17 @@ async fn cmd_promote(params : ExecBodyParams) {
|
||||||
{ arg2 }
|
{ arg2 }
|
||||||
else if let Some(a) = arg1 {
|
else if let Some(a) = arg1 {
|
||||||
if a.starts_with('-') {
|
if a.starts_with('-') {
|
||||||
botlock.botmgrs.chat.send_botmsg(
|
botlock.botmgrs.chat.read().await.send_botmsg(
|
||||||
super::chat::BotMsgType::Notif(
|
super::chat::BotMsgType::Notif(
|
||||||
"Invalid Argument Flag".to_string()
|
"Invalid Argument Flag".to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
Arc::new(RwLock::new(params.clone())),
|
||||||
).await;
|
).await;
|
||||||
return
|
return
|
||||||
} else { arg1 }
|
} else { arg1 }
|
||||||
}
|
}
|
||||||
else { arg1 };
|
else { arg1 };
|
||||||
|
|
||||||
|
|
||||||
// [x] Check if target is an existing user
|
|
||||||
targetusr = if let Some(chkusr) = targetusr {
|
|
||||||
match twitch_irc::validate::validate_login(chkusr.to_lowercase().as_str()) {
|
|
||||||
Ok(_) => Some(chkusr),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
} else { None } ;
|
|
||||||
|
|
||||||
|
|
||||||
// [x] Check if cmd passed is cucked, then go through special cucked handling
|
|
||||||
if let Some(cmd_to_check) = cmdname {
|
|
||||||
if cmd_to_check.to_lowercase() == String::from(botlock.get_prefix()) + "cucked"
|
|
||||||
|| cmd_to_check.to_lowercase() == String::from(botlock.get_prefix()) + "cuck"
|
|
||||||
{
|
|
||||||
|
|
||||||
let idlock = botlock.botmgrs.identity.read().await;
|
|
||||||
let senderroles = idlock.getspecialuserroles(sendername.clone(), Some(Channel(targetchnl.to_lowercase()))).await;
|
|
||||||
|
|
||||||
if senderroles.contains(&UserRole::BotAdmin) && targetusr.is_none() {
|
|
||||||
targetusr = Some(sendername.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
"uuh ".to_string()
|
|
||||||
),
|
|
||||||
params.clone(),
|
|
||||||
).await;
|
|
||||||
|
|
||||||
sleep(Duration::from_secs_f64(2.0)).await;
|
|
||||||
|
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
"... chatter getting cucked ...".to_string()
|
|
||||||
),
|
|
||||||
params.clone(),
|
|
||||||
).await;
|
|
||||||
|
|
||||||
sleep(Duration::from_secs_f64(1.0)).await;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// [x] 2. promote trguser
|
// [x] 2. promote trguser
|
||||||
|
|
||||||
// [x] Get a required lock first
|
// [x] Get a required lock first
|
||||||
|
@ -328,23 +275,14 @@ async fn cmd_promote(params : ExecBodyParams) {
|
||||||
// [x] 3. Output resulting change
|
// [x] 3. Output resulting change
|
||||||
|
|
||||||
let outmsg = match rslt {
|
let outmsg = match rslt {
|
||||||
ChangeResult::Success(rsltstr) => {
|
ChangeResult::Success(a) => {
|
||||||
format!("o7 Successfully promoted {} : {}",
|
format!("o7 Successfully promoted : {a}")
|
||||||
targetusr.unwrap(),
|
|
||||||
rsltstr
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ChangeResult::Failed(rsltstr) => {
|
ChangeResult::Failed(a) => {
|
||||||
format!("PoroSad failed to promote {} : {}",
|
format!("PoroSad failed to promote : {a}")
|
||||||
targetusr.unwrap(),
|
|
||||||
rsltstr
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ChangeResult::NoChange(rsltstr) => {
|
ChangeResult::NoChange(a) => {
|
||||||
format!("uuh No Promotion Change {} : {}",
|
format!("uuh No Promotion Change : {a}")
|
||||||
targetusr.unwrap(),
|
|
||||||
rsltstr
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -356,10 +294,10 @@ async fn cmd_promote(params : ExecBodyParams) {
|
||||||
|
|
||||||
// We should call a notification around here
|
// We should call a notification around here
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
outmsg.to_string()
|
outmsg.to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
Arc::new(RwLock::new(params.clone())),
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
@ -494,11 +432,11 @@ async fn cmd_demote(params : ExecBodyParams) {
|
||||||
{ arg2 }
|
{ arg2 }
|
||||||
else if let Some(a) = arg1 {
|
else if let Some(a) = arg1 {
|
||||||
if a.starts_with('-') {
|
if a.starts_with('-') {
|
||||||
botlock.botmgrs.chat.send_botmsg(
|
botlock.botmgrs.chat.read().await.send_botmsg(
|
||||||
super::chat::BotMsgType::Notif(
|
super::chat::BotMsgType::Notif(
|
||||||
"Invalid Argument Flag".to_string()
|
"Invalid Argument Flag".to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
Arc::new(RwLock::new(params.clone())),
|
||||||
).await;
|
).await;
|
||||||
return
|
return
|
||||||
} else { arg1 }
|
} else { arg1 }
|
||||||
|
@ -564,23 +502,14 @@ async fn cmd_demote(params : ExecBodyParams) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let outmsg = match rslt {
|
let outmsg = match rslt {
|
||||||
ChangeResult::Success(rsltstr) => {
|
ChangeResult::Success(a) => {
|
||||||
format!("o7 Successfully demoted {} : {}",
|
format!("o7 Successfully demoted : {a}")
|
||||||
targetusr.unwrap(),
|
|
||||||
rsltstr
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ChangeResult::Failed(rsltstr) => {
|
ChangeResult::Failed(a) => {
|
||||||
format!("PoroSad failed to demote {} : {}",
|
format!("PoroSad failed to demote : {a}")
|
||||||
targetusr.unwrap(),
|
|
||||||
rsltstr
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ChangeResult::NoChange(rsltstr) => {
|
ChangeResult::NoChange(a) => {
|
||||||
format!("uuh No Demotion Change {} : {}",
|
format!("uuh No Demotion Change : {a}")
|
||||||
targetusr.unwrap(),
|
|
||||||
rsltstr
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -590,10 +519,10 @@ async fn cmd_demote(params : ExecBodyParams) {
|
||||||
Some(¶ms.msg),
|
Some(¶ms.msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
outmsg.to_string()
|
outmsg.to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
Arc::new(RwLock::new(params.clone())),
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
@ -616,7 +545,7 @@ async fn getroles(params : ExecBodyParams) {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let sendername = params.msg.clone().sender.name;
|
dbg!("In getroles command");
|
||||||
|
|
||||||
|
|
||||||
let mut argv = params.msg.message_text.split(' ');
|
let mut argv = params.msg.message_text.split(' ');
|
||||||
|
@ -625,27 +554,45 @@ async fn getroles(params : ExecBodyParams) {
|
||||||
|
|
||||||
let arg1 = argv.next();
|
let arg1 = argv.next();
|
||||||
|
|
||||||
let mut targetuser = match arg1 {
|
let targetuser = match arg1 {
|
||||||
// None => return, // exit if no arguments
|
None => {
|
||||||
None => sendername.as_str(), // self-invoke in this case
|
dbg!("Expected Exit");
|
||||||
Some(arg) => arg,
|
botlog::debug(
|
||||||
};
|
"Exitting cmd getroles - Invalid arguments ",
|
||||||
|
Some("identity.rs > init > getroles()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
targetuser = match twitch_irc::validate::validate_login(targetuser.to_lowercase().as_str()) {
|
|
||||||
Ok(_) => targetuser,
|
let botlock = params.bot.read().await;
|
||||||
Err(_) => sendername.as_str(), // self-invoke in this case
|
|
||||||
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
|
"Invalid Arguments".to_string()
|
||||||
|
),
|
||||||
|
Arc::new(RwLock::new(params.clone())),
|
||||||
|
).await;
|
||||||
|
|
||||||
|
drop(botlock);
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}, // exit if no arguments
|
||||||
|
Some(arg) => arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
let arg2 = argv.next();
|
let arg2 = argv.next();
|
||||||
|
|
||||||
let targetchnl = arg2;
|
let targetchnl = arg2;
|
||||||
|
|
||||||
|
dbg!("In prior to bot read guard command");
|
||||||
|
|
||||||
let botlock = params.bot.read().await;
|
let botlock = params.bot.read().await;
|
||||||
|
|
||||||
let id = botlock.get_identity();
|
let id = botlock.get_identity();
|
||||||
|
|
||||||
let idlock = id.read().await;
|
let idlock = id.read().await;
|
||||||
|
|
||||||
|
dbg!("Pror to getspecialuserroles()");
|
||||||
let sproles = match targetchnl {
|
let sproles = match targetchnl {
|
||||||
None => {
|
None => {
|
||||||
// [ ] If targetchnl is not provided, default to pulling the current channel
|
// [ ] If targetchnl is not provided, default to pulling the current channel
|
||||||
|
@ -719,9 +666,7 @@ async fn getroles(params : ExecBodyParams) {
|
||||||
params.msg.channel_login.to_lowercase(),
|
params.msg.channel_login.to_lowercase(),
|
||||||
))) || sproles.contains(&UserRole::BotAdmin)
|
))) || sproles.contains(&UserRole::BotAdmin)
|
||||||
{
|
{
|
||||||
// targetuser
|
outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str();
|
||||||
// outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str();
|
|
||||||
outmsg += format!("{}'s user roles are : {:?}", targetuser, sproles).as_str();
|
|
||||||
}
|
}
|
||||||
outmsg
|
outmsg
|
||||||
} else if sproles.contains(&UserRole::Mod(Channel(
|
} else if sproles.contains(&UserRole::Mod(Channel(
|
||||||
|
@ -730,10 +675,9 @@ async fn getroles(params : ExecBodyParams) {
|
||||||
params.msg.channel_login.to_lowercase(),
|
params.msg.channel_login.to_lowercase(),
|
||||||
))) || sproles.contains(&UserRole::BotAdmin)
|
))) || sproles.contains(&UserRole::BotAdmin)
|
||||||
{
|
{
|
||||||
// format!("Target chatter's user roles are : {:?}", sproles)
|
format!("Target chatter's user roles are : {:?}", sproles)
|
||||||
format!("{}'s user roles are : {:?}", targetuser, sproles)
|
|
||||||
} else {
|
} else {
|
||||||
format!("{} has no special roles LULE ",targetuser)
|
"Target chatter has no special roles LULE ".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
|
@ -742,14 +686,19 @@ async fn getroles(params : ExecBodyParams) {
|
||||||
Some(¶ms.msg),
|
Some(¶ms.msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
dbg!("Pror to getroles send_botmsg");
|
||||||
|
|
||||||
|
botlock.botmgrs.chat.read().await.send_botmsg(super::chat::BotMsgType::Notif(
|
||||||
outmsg.to_string()
|
outmsg.to_string()
|
||||||
),
|
),
|
||||||
params.clone(),
|
Arc::new(RwLock::new(params.clone())),
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
// [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside
|
// [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside
|
||||||
|
|
||||||
|
|
||||||
|
dbg!("End of getroles command");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -771,7 +720,7 @@ pub enum Permissible {
|
||||||
|
|
||||||
type UserRolesDB = HashMap<String, Arc<RwLock<Vec<UserRole>>>>;
|
type UserRolesDB = HashMap<String, Arc<RwLock<Vec<UserRole>>>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct IdentityManager {
|
pub struct IdentityManager {
|
||||||
special_roles_users: Arc<RwLock<UserRolesDB>>,
|
special_roles_users: Arc<RwLock<UserRolesDB>>,
|
||||||
}
|
}
|
||||||
|
@ -1549,6 +1498,7 @@ impl IdentityManager {
|
||||||
return ChangeResult::NoChange("Already does not have VIP role".to_string());
|
return ChangeResult::NoChange("Already does not have VIP role".to_string());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// self.affirm_chatter_in_db(trgchatter.clone()).await;
|
||||||
|
|
||||||
self.remove_role(trgchatter.clone(), UserRole::VIP(channel.clone())).await;
|
self.remove_role(trgchatter.clone(), UserRole::VIP(channel.clone())).await;
|
||||||
|
|
||||||
|
@ -1616,6 +1566,8 @@ impl IdentityManager {
|
||||||
Note : Ideally this be called for a given chatter name ?
|
Note : Ideally this be called for a given chatter name ?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
dbg!("In getspecialuserroles()");
|
||||||
|
|
||||||
// [ ] !!! TODO: I don't think below is evaluating by given channel
|
// [ ] !!! TODO: I don't think below is evaluating by given channel
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
&format!(
|
&format!(
|
||||||
|
@ -1647,6 +1599,9 @@ impl IdentityManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dbg!("Before reading Vector Roles");
|
||||||
|
|
||||||
let rolesdb = Arc::clone(&self.special_roles_users);
|
let rolesdb = Arc::clone(&self.special_roles_users);
|
||||||
|
|
||||||
let rolesdb_lock = rolesdb.read().await;
|
let rolesdb_lock = rolesdb.read().await;
|
||||||
|
@ -1702,6 +1657,8 @@ impl IdentityManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbg!("exit getspecialusreroles with",&evalsproles);
|
||||||
|
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
&format!("OUT > evalsproles {:?}", &evalsproles),
|
&format!("OUT > evalsproles {:?}", &evalsproles),
|
||||||
Some("IdentityManager > getspecialuserroles()".to_string()),
|
Some("IdentityManager > getspecialuserroles()".to_string()),
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
// Related : https://dev.twitch.tv/docs/irc/#rate-limits
|
||||||
|
|
||||||
|
|
||||||
const TIME_THRESHOLD_S: u64 = 30;
|
const TIME_THRESHOLD_S: u64 = 30;
|
||||||
const TIME_MIN_S_F64: f64 = 1.0;
|
const TIME_MIN_S_F64: f64 = 1.0;
|
||||||
const MSG_THRESHOLD: u32 = 20;
|
const MSG_THRESHOLD: u32 = 20;
|
||||||
|
const DUPMSG_MIN_SEND_S: f64 = 30.0;
|
||||||
|
|
||||||
|
use std::{sync::Arc, time::Instant};
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use std::time::Instant;
|
|
||||||
use crate::core::botlog;
|
use crate::core::botlog;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -10,9 +16,10 @@ pub struct RateLimiter {
|
||||||
timer: Instant,
|
timer: Instant,
|
||||||
msgcounter: u32,
|
msgcounter: u32,
|
||||||
lastmsgtimer : Instant,
|
lastmsgtimer : Instant,
|
||||||
|
lastmsgdup : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug,Clone)]
|
||||||
pub enum LimiterResp {
|
pub enum LimiterResp {
|
||||||
Allow, // when it's evaluated to be within limits
|
Allow, // when it's evaluated to be within limits
|
||||||
Skip, // as outside of rate limits
|
Skip, // as outside of rate limits
|
||||||
|
@ -32,10 +39,20 @@ impl RateLimiter {
|
||||||
timer: Instant::now(),
|
timer: Instant::now(),
|
||||||
msgcounter: 0,
|
msgcounter: 0,
|
||||||
lastmsgtimer: Instant::now(),
|
lastmsgtimer: Instant::now(),
|
||||||
|
lastmsgdup : String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_limiter(&mut self) -> LimiterResp {
|
fn dupmsg(&self,inmsg : String) -> bool {
|
||||||
|
dbg!("dubmsg()",&inmsg,&self.lastmsgdup);
|
||||||
|
if self.lastmsgdup == inmsg && self.lastmsgtimer.elapsed().as_secs_f64() < DUPMSG_MIN_SEND_S {
|
||||||
|
// duplicate detected
|
||||||
|
// self.lastmsgdup = String::new(); // update it as no longer duplicate
|
||||||
|
return true;
|
||||||
|
} else { return false; };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_limiter(&mut self,inmsg : String) -> LimiterResp {
|
||||||
|
|
||||||
|
|
||||||
let logstr = format!(
|
let logstr = format!(
|
||||||
|
@ -49,32 +66,104 @@ impl RateLimiter {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
let rsp = if self.timer.elapsed().as_secs() >= TIME_THRESHOLD_S {
|
/*
|
||||||
self.timer = Instant::now();
|
Documented Thesholds from https://dev.twitch.tv/docs/irc/#rate-limits
|
||||||
self.msgcounter = 0;
|
- [x] self.timer.elapsed().as_secs() >= TIME_THRESHOLD_S
|
||||||
|
>> initialize with LimiterResp::Allow
|
||||||
|
- [x] self.msgcounter < MSG_THRESHOLD &&
|
||||||
|
self.lastmsgtimer.elapsed().as_secs_f64() >= TIME_MIN_S_F64
|
||||||
|
>> LimiterResp::Allow
|
||||||
|
- [x] else
|
||||||
|
>> LimiterResp::Sleep(TIME_MIN_S_F64 - self.lastmsgtimer.elapsed().as_secs_f64() + 0.1)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// let ratelimiter_ar = Arc::new(RwLock::new((*self).clone()));
|
||||||
|
let ratelimiter_ar = Arc::new(RwLock::new(self));
|
||||||
|
let mut rl_guard = ratelimiter_ar.write().await;
|
||||||
|
|
||||||
|
let rsp = if rl_guard.timer.elapsed().as_secs() >= TIME_THRESHOLD_S {
|
||||||
|
rl_guard.timer = Instant::now();
|
||||||
|
rl_guard.msgcounter = 0;
|
||||||
LimiterResp::Allow
|
LimiterResp::Allow
|
||||||
} else if self.msgcounter < MSG_THRESHOLD &&
|
} else if rl_guard.msgcounter < MSG_THRESHOLD &&
|
||||||
self.lastmsgtimer.elapsed().as_secs_f64() >= TIME_MIN_S_F64 {
|
rl_guard.lastmsgtimer.elapsed().as_secs_f64() >= TIME_MIN_S_F64 {
|
||||||
LimiterResp::Allow
|
LimiterResp::Allow
|
||||||
} else {
|
} else {
|
||||||
// when elapsed() < TIME_THRESHOLD_S && msgcounter >= MSG_THRESHOLD
|
// when elapsed() < TIME_THRESHOLD_S && msgcounter >= MSG_THRESHOLD
|
||||||
// LimiterResp::Skip
|
// LimiterResp::Skip
|
||||||
LimiterResp::Sleep(TIME_MIN_S_F64 - self.lastmsgtimer.elapsed().as_secs_f64() + 0.1)
|
LimiterResp::Sleep(TIME_MIN_S_F64 - rl_guard.lastmsgtimer.elapsed().as_secs_f64() + 0.1)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// [ ] If rsp is still allow at this point, also do a dupcheck to adjust rsp to a sleep
|
||||||
|
|
||||||
|
dbg!(inmsg.clone());
|
||||||
|
dbg!(rl_guard.dupmsg(inmsg.clone()));
|
||||||
|
dbg!("Before Dup test",rsp.clone());
|
||||||
|
dbg!(matches!(rsp.clone(),LimiterResp::Allow));
|
||||||
|
|
||||||
|
|
||||||
|
// [-] Comment this area if removing Duplicate checking functionality
|
||||||
|
/* */
|
||||||
|
let rsp = if rl_guard.dupmsg(inmsg.clone()) && matches!(rsp,LimiterResp::Allow) {
|
||||||
|
//self.lastmsgdup = String::new();
|
||||||
|
// LimiterResp::Sleep(DUPMSG_MIN_SEND_S)
|
||||||
|
dbg!("Duplicate detected");
|
||||||
|
LimiterResp::Sleep(DUPMSG_MIN_SEND_S - rl_guard.lastmsgtimer.elapsed().as_secs_f64() + 0.1)
|
||||||
|
} else { rsp.clone() };
|
||||||
|
/* */
|
||||||
|
|
||||||
|
// => 04.02 - Don't update here
|
||||||
|
// // After Dup is checked, Set the lastmsgdup to latest message
|
||||||
|
// dbg!("Before Assigning Lastmsgdup",rl_guard.lastmsgdup.clone(),inmsg.clone(),rsp.clone());
|
||||||
|
// rl_guard.lastmsgdup = inmsg.clone();
|
||||||
|
// dbg!("After Assigning Lastmsgdup",rl_guard.lastmsgdup.clone(),inmsg.clone());
|
||||||
|
|
||||||
|
|
||||||
|
// [ ] Allows if sleep came up as negative
|
||||||
|
let rsp = match rsp {
|
||||||
|
LimiterResp::Sleep(sleeptime) if sleeptime < 0.0 => LimiterResp::Allow , // allow is sleeptime evaluated is negative
|
||||||
|
_ => rsp.clone(),
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
dbg!(rsp.clone());
|
||||||
|
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
&format!("Limiter Response : {:?} ; Elapsed (as_sec_f64) : {}",
|
&format!("Limiter Response : {:?} ; Elapsed (as_sec_f64) : {}",
|
||||||
rsp, self.lastmsgtimer.elapsed().as_secs_f64()),
|
rsp, rl_guard.lastmsgtimer.elapsed().as_secs_f64()),
|
||||||
Some("Rate Limiter Inner".to_string()),
|
Some("Rate Limiter Inner".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dbg!("check_limiter() > ratelimiter guard",rl_guard.clone());
|
||||||
|
|
||||||
|
drop(rl_guard);
|
||||||
|
|
||||||
|
|
||||||
rsp
|
rsp
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn increment_counter(&mut self) {
|
// pub fn increment_counter(&mut self) {
|
||||||
|
// self.msgcounter += 1;
|
||||||
|
// self.lastmsgtimer = Instant::now();
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub async fn sent_msg(&mut self,msgstr : String) {
|
||||||
|
|
||||||
|
dbg!("sent_msg triggered",&msgstr);
|
||||||
|
|
||||||
|
// let ratelimiter_ar = Arc::new(RwLock::new((*self).clone()));
|
||||||
|
// let mut rl_guard = ratelimiter_ar.write().await;
|
||||||
|
|
||||||
|
dbg!("sent_msg > lastmsg before update",&self.lastmsgdup);
|
||||||
|
|
||||||
|
self.lastmsgdup = msgstr;
|
||||||
self.msgcounter += 1;
|
self.msgcounter += 1;
|
||||||
self.lastmsgtimer = Instant::now();
|
self.lastmsgtimer = Instant::now();
|
||||||
|
|
||||||
|
dbg!("sent_msg > lastmsg after update",&self.lastmsgdup);
|
||||||
|
|
||||||
|
// drop(rl_guard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ pub use crate::core::botmodules::ModulesManager;
|
||||||
|
|
||||||
// mod experiments;
|
// mod experiments;
|
||||||
mod experimental;
|
mod experimental;
|
||||||
mod thisguy;
|
|
||||||
|
|
||||||
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
||||||
|
|
||||||
|
@ -22,6 +21,5 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// this is achieved by calling submodules that also have fn init() defined
|
// this is achieved by calling submodules that also have fn init() defined
|
||||||
|
|
||||||
// experiments::init(mgr).await
|
// experiments::init(mgr).await
|
||||||
experimental::init(mgr.clone()).await;
|
experimental::init(mgr).await;
|
||||||
thisguy::init(&mgr).await;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub use crate::core::botmodules::ModulesManager;
|
||||||
|
|
||||||
mod experiment001;
|
mod experiment001;
|
||||||
mod experiment002;
|
mod experiment002;
|
||||||
|
mod experiment003;
|
||||||
|
|
||||||
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
||||||
|
|
||||||
|
@ -21,4 +22,5 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
experiment001::init(Arc::clone(&mgr)).await;
|
experiment001::init(Arc::clone(&mgr)).await;
|
||||||
experiment002::init(Arc::clone(&mgr)).await;
|
experiment002::init(Arc::clone(&mgr)).await;
|
||||||
|
experiment003::init(Arc::clone(&mgr)).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||||
|
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use twitch_irc::message::ReplyToMessage;
|
use tokio::sync::RwLock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::core::bot_actions::ExecBodyParams;
|
use crate::core::bot_actions::ExecBodyParams;
|
||||||
|
@ -96,65 +96,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// 2. Add the BotAction to ModulesManager
|
// 2. Add the BotAction to ModulesManager
|
||||||
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
let bc1 = BotCommand {
|
|
||||||
module: BotModule(String::from("experiments001")),
|
|
||||||
command: String::from("rp1"), // command call name
|
|
||||||
alias: vec![
|
|
||||||
String::from("rp2"),
|
|
||||||
String::from("rp3")], // String of alternative names
|
|
||||||
exec_body: actions_util::asyncbox(rp),
|
|
||||||
help: String::from("Test Command tester"),
|
|
||||||
required_roles: vec![
|
|
||||||
BotAdmin,
|
|
||||||
Mod(OF_CMD_CHANNEL),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
bc1.add_core_to_modmgr(Arc::clone(&mgr)).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn rp(params : ExecBodyParams)
|
|
||||||
{
|
|
||||||
//triggers if the message is a reply
|
|
||||||
if params.get_parent_reply().is_some(){
|
|
||||||
|
|
||||||
//getting the channel id where the message was sent
|
|
||||||
let channel_id = params.get_parent_reply().unwrap().channel_login;
|
|
||||||
|
|
||||||
//getting the first message id that was sent
|
|
||||||
let message_id = params.get_parent_reply().unwrap().message_id;
|
|
||||||
|
|
||||||
//just for testing purposes
|
|
||||||
//print!("{} , {}",channel_id, message_id);
|
|
||||||
|
|
||||||
//creating a tuple with the channel id and message id
|
|
||||||
let answear =
|
|
||||||
(
|
|
||||||
channel_id.clone(),
|
|
||||||
message_id.clone()
|
|
||||||
);
|
|
||||||
|
|
||||||
let bot = Arc::clone(¶ms.bot);
|
|
||||||
let botlock = bot.read().await;
|
|
||||||
// uses chat.say_in_reply_to() for the bot controls for messages
|
|
||||||
botlock
|
|
||||||
.botmgrs
|
|
||||||
.chat
|
|
||||||
.say_in_reply_to(
|
|
||||||
//using the tuple as param to the message being replied
|
|
||||||
Channel(answear.0),
|
|
||||||
answear.1,
|
|
||||||
String::from("hey there"),
|
|
||||||
params.clone()
|
|
||||||
).await;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
println!("no reply")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async fn good_girl(params : ExecBodyParams) {
|
async fn good_girl(params : ExecBodyParams) {
|
||||||
|
|
||||||
// [ ] Uses gen_ratio() to output bool based on a ratio probability .
|
// [ ] Uses gen_ratio() to output bool based on a ratio probability .
|
||||||
|
@ -163,7 +106,6 @@ async fn good_girl(params : ExecBodyParams) {
|
||||||
|
|
||||||
if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|
if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|
||||||
|| params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
|| params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||||
|| params.msg.sender.name.to_lowercase() == "haruyuumei".to_lowercase()
|
|
||||||
{
|
{
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"Good Girl Detected > Pausechamp",
|
"Good Girl Detected > Pausechamp",
|
||||||
|
@ -181,18 +123,22 @@ async fn good_girl(params : ExecBodyParams) {
|
||||||
);
|
);
|
||||||
|
|
||||||
let bot = Arc::clone(¶ms.bot);
|
let bot = Arc::clone(¶ms.bot);
|
||||||
|
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
|
|
||||||
// uses chat.say_in_reply_to() for the bot controls for messages
|
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
|
.read().await
|
||||||
.say_in_reply_to(
|
.say_in_reply_to(
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
¶ms.msg,
|
||||||
params.clone().msg.message_id().to_string(),
|
|
||||||
String::from("GoodGirl xdd "),
|
String::from("GoodGirl xdd "),
|
||||||
params.clone()
|
Arc::new(RwLock::new(params.clone()))
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,22 +172,25 @@ async fn babygirl(params : ExecBodyParams) {
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply(
|
.read().await
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
String::from("16:13 notohh: cafdk"),
|
String::from("16:13 notohh: cafdk"),
|
||||||
params.clone()
|
Arc::new(RwLock::new(params.clone()))
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sleep(Duration::from_secs_f64(0.5)).await;
|
sleep(Duration::from_secs_f64(0.5)).await;
|
||||||
|
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply(
|
.read().await
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
String::from("16:13 notohh: have fun eating princess"),
|
String::from("16:13 notohh: have fun eating princess"),
|
||||||
params.clone()
|
Arc::new(RwLock::new(params.clone()))
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,10 +199,11 @@ async fn babygirl(params : ExecBodyParams) {
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply(
|
.read().await
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
String::from("16:13 notohh: baby girl"),
|
String::from("16:13 notohh: baby girl"),
|
||||||
params.clone()
|
Arc::new(RwLock::new(params.clone()))
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,5 +231,39 @@ async fn routinelike(params : ExecBodyParams) {
|
||||||
|
|
||||||
// lines are executed after in conjunction to the spawn
|
// lines are executed after in conjunction to the spawn
|
||||||
|
|
||||||
|
// spawn 5 independent spawns
|
||||||
|
|
||||||
|
let bot = Arc::clone(¶ms.bot);
|
||||||
|
let params_ar = Arc::new(RwLock::new(params.clone()));
|
||||||
|
let params_c = params_ar.clone();
|
||||||
|
|
||||||
|
for _ in 0..5 {
|
||||||
|
let bot_clone = bot.clone();
|
||||||
|
let params_cc = params_c.clone();
|
||||||
|
tokio::spawn( async move {
|
||||||
|
println!(">> SPAWNED Innterroutine triggered!");
|
||||||
|
sleep(Duration::from_secs_f64(5.0)).await;
|
||||||
|
|
||||||
|
let botlock = bot_clone.read().await;
|
||||||
|
let params_ccc = params_cc.clone();
|
||||||
|
let paramsguard = params_ccc.read().await;
|
||||||
|
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
¶msguard.msg,
|
||||||
|
String::from("SPAWNED GoodGirl xdd "),
|
||||||
|
params_cc,
|
||||||
|
).await;
|
||||||
|
|
||||||
|
drop(botlock);
|
||||||
|
drop(paramsguard);
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use chrono::{TimeZone,Local};
|
use chrono::{TimeZone,Local};
|
||||||
use twitch_irc::message::ReplyToMessage;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
|
|
||||||
use crate::core::bot_actions::ExecBodyParams;
|
use crate::core::bot_actions::ExecBodyParams;
|
||||||
|
@ -117,7 +117,7 @@ async fn sayout(params : ExecBodyParams) {
|
||||||
|
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
&format!("[TRACE] Evaluated status of {} : {:?}",
|
&format!("[TRACE] Evaluated status of {} : {:?}",
|
||||||
trgchnl.to_string().clone(),botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await),
|
trgchnl.to_string().clone(),botlock.botmgrs.chat.read().await.client.get_channel_status(trgchnl.to_string().clone()).await),
|
||||||
Some("Chat > send_botmsg".to_string()),
|
Some("Chat > send_botmsg".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -157,10 +157,11 @@ async fn sayout(params : ExecBodyParams) {
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
|
.read().await
|
||||||
.say(
|
.say(
|
||||||
trgchnl.to_string(),
|
trgchnl.to_string(),
|
||||||
newoutmsg.to_string(),
|
newoutmsg.to_string(),
|
||||||
params.clone(),
|
Arc::new(RwLock::new(params.clone())),
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,11 +181,11 @@ async fn sayout(params : ExecBodyParams) {
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
|
.read().await
|
||||||
.say_in_reply_to(
|
.say_in_reply_to(
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
¶ms.msg,
|
||||||
params.clone().msg.message_id().to_string(),
|
|
||||||
String::from("Invalid arguments"),
|
String::from("Invalid arguments"),
|
||||||
params.clone()
|
Arc::new(RwLock::new(params.clone()))
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
830
src/custom/experimental/experiment003.rs
Normal file
830
src/custom/experimental/experiment003.rs
Normal file
|
@ -0,0 +1,830 @@
|
||||||
|
/*
|
||||||
|
Custom Modules -
|
||||||
|
|
||||||
|
Usage :
|
||||||
|
[ ] within the file's init(), define BotActions & Load them into the ModulesManager
|
||||||
|
[ ] Define Execution Bodies for these BotActions
|
||||||
|
[ ] Afterwards, add the following to parent modules.rs file
|
||||||
|
- mod <modulename>;
|
||||||
|
- within init(), <modulename>::init(mgr).await
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||||
|
|
||||||
|
|
||||||
|
use casual_logger::Log;
|
||||||
|
use rand::Rng;
|
||||||
|
use rand::thread_rng;
|
||||||
|
use rand::rngs::StdRng;
|
||||||
|
use rand::seq::SliceRandom;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::borrow::BorrowMut;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::core::bot_actions::ExecBodyParams;
|
||||||
|
use crate::core::botinstance::Channel;
|
||||||
|
use crate::core::botlog;
|
||||||
|
|
||||||
|
use crate::core::bot_actions::actions_util;
|
||||||
|
use crate::core::botmodules::{BotAction, BotActionTrait, BotCommand, BotModule, Listener, ModulesManager, Routine, RoutineAttr};
|
||||||
|
|
||||||
|
use crate::core::identity::UserRole::*;
|
||||||
|
|
||||||
|
use tokio::time::{sleep, Duration};
|
||||||
|
|
||||||
|
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
|
// 1. Define the BotAction
|
||||||
|
let botc1 = BotCommand {
|
||||||
|
module: BotModule(String::from("experiments003")),
|
||||||
|
command: String::from("test3"), // command call name
|
||||||
|
alias: vec![], // String of alternative names
|
||||||
|
exec_body: actions_util::asyncbox(test3_body),
|
||||||
|
help: String::from("Test Command tester"),
|
||||||
|
required_roles: vec![
|
||||||
|
BotAdmin,
|
||||||
|
Mod(OF_CMD_CHANNEL),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. Add the BotAction to ModulesManager
|
||||||
|
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
|
|
||||||
|
// 1. Define the BotAction
|
||||||
|
let botc1 = BotCommand {
|
||||||
|
module: BotModule(String::from("experiments003")),
|
||||||
|
command: String::from("countdown"), // command call name
|
||||||
|
alias: vec![], // String of alternative names
|
||||||
|
exec_body: actions_util::asyncbox(countdown_chnl_v1),
|
||||||
|
help: String::from("Test Command tester"),
|
||||||
|
required_roles: vec![
|
||||||
|
BotAdmin,
|
||||||
|
Mod(OF_CMD_CHANNEL),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. Add the BotAction to ModulesManager
|
||||||
|
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn countdown_chnl_v1(params : ExecBodyParams) {
|
||||||
|
|
||||||
|
botlog::debug(
|
||||||
|
"[CHILDFN] countdown_chnl() triggered!",
|
||||||
|
Some("Experiments003 > countdown_chnl()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
create a fun countdown BotCommand that allows an Elevated Chatter to
|
||||||
|
-a add channels to target a routine message
|
||||||
|
-start to start the routine with an input String, that sends a number
|
||||||
|
of messages to the targeted channels with a countdown, until it
|
||||||
|
reaches 0 when it sends a cute or funny message
|
||||||
|
|
||||||
|
NOTE : At the moment, I don't have customizable persistence, so I would just use
|
||||||
|
counters from the Routine itself
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Because of some bot core features are not available, v1.0 of this could be :
|
||||||
|
[x] 1. Create a Routine & start a routine
|
||||||
|
[x] 2. Have the routine go through each joined channel randomly and countdown
|
||||||
|
[x] 3. At the end, say "0, I love you uwu~" in the last chosen channel
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Usage => 03.28 - skipping arguments as functinoality isn't enhanced
|
||||||
|
|
||||||
|
-a <channel> => 03.28 - Not sure if this is possible at the moment?
|
||||||
|
|
||||||
|
-start
|
||||||
|
|
||||||
|
-stop => 03.28 - Not sure if this is possible at the moment?
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
[ ] Functional Use Case
|
||||||
|
|
||||||
|
1. -a <channel> adds targetted channels
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// [-] Unwraps arguments from message
|
||||||
|
|
||||||
|
// let (arg1, arg2) = {
|
||||||
|
|
||||||
|
// let mut argv = params.msg.message_text.split(' ');
|
||||||
|
|
||||||
|
// argv.next(); // Skip the command name
|
||||||
|
|
||||||
|
// let arg1 = argv.next();
|
||||||
|
|
||||||
|
// let arg2 = argv.next();
|
||||||
|
|
||||||
|
// (arg1, arg2)
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// [ ] 1. Create a Routine & start a routine
|
||||||
|
|
||||||
|
let params_ar = Arc::new(RwLock::new(params));
|
||||||
|
|
||||||
|
// let parentmodule = params.get_parent_module().await;
|
||||||
|
let module = params_ar.read().await.get_module().await;
|
||||||
|
// let channel = params.get_channel().await;
|
||||||
|
// let channel = params.get_channel().await;
|
||||||
|
// let channel = params.get_channel();
|
||||||
|
|
||||||
|
let channel_task_grabber = tokio::task::spawn_blocking( move || {
|
||||||
|
let params_clone = params_ar.clone();
|
||||||
|
let channel = params_clone.blocking_read().get_channel();
|
||||||
|
drop(params_clone);
|
||||||
|
(channel,params_ar)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (channel,params_ar) = channel_task_grabber.await.unwrap();
|
||||||
|
|
||||||
|
let routine_attr = vec![
|
||||||
|
// RoutineAttr::RunOnce
|
||||||
|
RoutineAttr::MaxIterations(5),
|
||||||
|
RoutineAttr::LoopDuration(Duration::from_secs(1))
|
||||||
|
];
|
||||||
|
// let exec_body = actions_util::asyncbox(rtestbody);
|
||||||
|
// let exec_body = actions_util::asyncbox(innertester); // <-- 03.27 - when below is uncommented, this is throwing an issue
|
||||||
|
let exec_body = innertester;
|
||||||
|
|
||||||
|
// async fn innertester(params : ExecBodyParams) {
|
||||||
|
fn innertester(params : Arc<RwLock<ExecBodyParams>>) {
|
||||||
|
|
||||||
|
{
|
||||||
|
// let curract_guard = params.curr_act.read().await;
|
||||||
|
let paramguard1 = params.blocking_read();
|
||||||
|
let curract = paramguard1.curr_act.clone().unwrap();
|
||||||
|
let curract_guard = curract.blocking_read();
|
||||||
|
|
||||||
|
|
||||||
|
// let logmsg_botact = match *params.curr_act.read().await {
|
||||||
|
|
||||||
|
let logmsg_botact = match *curract_guard {
|
||||||
|
BotAction::C(_) => "command",
|
||||||
|
BotAction::R(_) => "routine",
|
||||||
|
BotAction::L(_) => "listener",
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
|
||||||
|
Some("Experiments003 > countdown_chnl()".to_string()),
|
||||||
|
Some(¶ms.blocking_read().msg),
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let bot = Arc::clone(¶ms.blocking_read().bot);
|
||||||
|
// let botlock = bot.read().await;
|
||||||
|
let botlock = bot.blocking_read();
|
||||||
|
|
||||||
|
// let curract_guard = params.curr_act.write().await;
|
||||||
|
let paramguard1 = params.blocking_read();
|
||||||
|
let curract = paramguard1.curr_act.clone().unwrap();
|
||||||
|
let curract_guard = curract.blocking_write();
|
||||||
|
|
||||||
|
// let routine_lock = arr.write().await;
|
||||||
|
|
||||||
|
if let BotAction::R(arr) = &*curract_guard {
|
||||||
|
// if let BotAction::R(arr) = &*params.curr_act.read().await {
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
"Before loading remaining iterations",
|
||||||
|
Some("Experiments003 > countdown_chnl()".to_string()),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
|
||||||
|
// let iterleft = arr.read().await.remaining_iterations.unwrap_or(0);
|
||||||
|
|
||||||
|
// // let iterleft = if arr.read().await.remaining_iterations.is_none() { 0i64 }
|
||||||
|
// // else { arr.read().await.remaining_iterations.unwrap() };
|
||||||
|
// let iterleft = match arr.read().await.remaining_iterations {
|
||||||
|
// None => 0,
|
||||||
|
// Some(a) => a,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// let routine_lock = arr.read().await;
|
||||||
|
// if let Some(a) = routine_lock.remaining_iterations.clone() {
|
||||||
|
// println!("Remaining iterations > {}",a)
|
||||||
|
// }
|
||||||
|
|
||||||
|
let iterleft;
|
||||||
|
{
|
||||||
|
// let routine_lock = arr.write().await;
|
||||||
|
// let routine_lock = arr.blocking_write();
|
||||||
|
let routine_lock = arr.blocking_read();
|
||||||
|
iterleft = routine_lock.remaining_iterations.unwrap_or(0);
|
||||||
|
println!("remaining iterations : {:?}", iterleft);
|
||||||
|
}
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
"after loading remaining iterations",
|
||||||
|
Some("Experiments003 > countdown_chnl()".to_string()),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
// [ ] get joined channels
|
||||||
|
let joinedchannels = botlock.bot_channels.clone();
|
||||||
|
|
||||||
|
|
||||||
|
fn pick_a_channel(chnlvec : Vec<Channel>) -> Channel {
|
||||||
|
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
"In Pick_a_Channel()",
|
||||||
|
Some("Experiments003 > countdown_chnl()".to_string()),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
// More Information : https://docs.rs/rand/0.7.2/rand/seq/trait.SliceRandom.html#tymethod.choose
|
||||||
|
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
|
||||||
|
// let joinedchannels = botlock.bot_channels.clone();
|
||||||
|
(*chnlvec.choose(&mut rng).unwrap()).clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let chosen_channel = pick_a_channel(joinedchannels);
|
||||||
|
|
||||||
|
dbg!("SUCCESS", chosen_channel.clone());
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
format!("Picked a channel: {:?}", chosen_channel).as_str(),
|
||||||
|
Some("Experiments003 > countdown_chnl()".to_string()),
|
||||||
|
Some(¶ms.blocking_read().msg),
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
// [ ] !! ISSUE : With this fix though, the custom fn is no longer
|
||||||
|
// async. This is an issue because chat module is async
|
||||||
|
// - There should be no need to change chat , as async allows
|
||||||
|
// us to multitask with messages
|
||||||
|
|
||||||
|
// let a = || {
|
||||||
|
|
||||||
|
// let chosen_channel_ar = Arc::new(RwLock::new(chosen_channel));
|
||||||
|
|
||||||
|
// let params_clone = params.clone();
|
||||||
|
// // let bot = Arc::clone(¶ms.blocking_read().bot);
|
||||||
|
|
||||||
|
|
||||||
|
// // dbg!("in chat async function");
|
||||||
|
|
||||||
|
// // let botlock = bot.blocking_read();
|
||||||
|
// let channel_ar_clone = chosen_channel_ar.clone();
|
||||||
|
|
||||||
|
// let outmsg = if iterleft <= 1 {
|
||||||
|
// format!("{} I love you uwu~",iterleft)
|
||||||
|
// } else { format!("{}",iterleft) };
|
||||||
|
|
||||||
|
// botlock.botmgrs.chat
|
||||||
|
// .say(
|
||||||
|
// channel_ar_clone.blocking_read().0.clone(),
|
||||||
|
// outmsg,
|
||||||
|
// params_clone,
|
||||||
|
// );
|
||||||
|
|
||||||
|
let outmsg = if iterleft <= 1 {
|
||||||
|
// format!("{} I love you uwu~",iterleft)
|
||||||
|
let msgtxt = params.blocking_read().msg.message_text.clone();
|
||||||
|
// format!("{} {} I love you uwu~",iterleft,msgtxt)
|
||||||
|
format!("{} {}",iterleft,msgtxt)
|
||||||
|
} else { format!("{} Tomfoolery Clap",iterleft) };
|
||||||
|
|
||||||
|
botlock.botmgrs.chat.blocking_read()
|
||||||
|
.blocking_say(
|
||||||
|
chosen_channel.0.clone(),
|
||||||
|
outmsg,
|
||||||
|
Arc::new(RwLock::new(params.blocking_read().clone())),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// [ ] setup the routine
|
||||||
|
if let Ok(newr) = Routine::from(
|
||||||
|
"Routine Test".to_string(),
|
||||||
|
module,
|
||||||
|
channel.unwrap(),
|
||||||
|
routine_attr,
|
||||||
|
// Arc::new(RwLock::new(exec_body)),
|
||||||
|
exec_body,
|
||||||
|
Arc::new(RwLock::new(params_ar.clone().read().await.clone())),
|
||||||
|
).await {
|
||||||
|
let newr_ar = newr.clone();
|
||||||
|
// [ ] start the routine
|
||||||
|
if let Ok(_) = Routine::start(newr_ar.clone()).await {
|
||||||
|
|
||||||
|
|
||||||
|
botlog::debug(
|
||||||
|
"Successfully started",
|
||||||
|
Some("experiment003 > countdown_chnl()".to_string()),
|
||||||
|
Some(¶ms_ar.read().await.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
let bot = Arc::clone(¶ms_ar.read().await.bot);
|
||||||
|
|
||||||
|
// let botlock = bot.read().await;
|
||||||
|
|
||||||
|
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||||
|
|
||||||
|
// [ ] 04.01 - in an ASYNC context, ensure to raise a Blocking Spawn
|
||||||
|
// botlock
|
||||||
|
// .botmgrs
|
||||||
|
// .chat
|
||||||
|
// .say_in_reply_to(
|
||||||
|
// ¶ms_ar.read().await.msg,
|
||||||
|
// "Started Routine!".to_string(),
|
||||||
|
// Arc::new(RwLock::new(params_ar.read().await.clone()))
|
||||||
|
// );
|
||||||
|
|
||||||
|
// let jhandle = newr.clone().read().await.join_handle.clone().unwrap();
|
||||||
|
// let a = jhandle.write().await;
|
||||||
|
// a.
|
||||||
|
// sleep(Duration::from_secs(300)).await;
|
||||||
|
|
||||||
|
|
||||||
|
// let loopbodyspawn = tokio::task::spawn_blocking( move || {
|
||||||
|
// let botlock = bot.blocking_read();
|
||||||
|
// botlock
|
||||||
|
// .botmgrs
|
||||||
|
// .chat
|
||||||
|
// .say_in_reply_to(
|
||||||
|
// ¶ms_ar.blocking_read().msg,
|
||||||
|
// "Started Routine!".to_string(),
|
||||||
|
// Arc::new(RwLock::new(params_ar.blocking_read().clone()))
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
|
||||||
|
// loopbodyspawn.await.unwrap();
|
||||||
|
|
||||||
|
// let botlock = bot.read().await;
|
||||||
|
// botlock
|
||||||
|
// .botmgrs
|
||||||
|
// .chat
|
||||||
|
// .say_in_reply_to(
|
||||||
|
// ¶ms_ar.blocking_read().msg,
|
||||||
|
// "Started Routine!".to_string(),
|
||||||
|
// Arc::new(RwLock::new(params_ar.blocking_read().clone()))
|
||||||
|
// ).await;
|
||||||
|
// drop(botlock);
|
||||||
|
|
||||||
|
|
||||||
|
let botlock = bot.read().await;
|
||||||
|
let params_guard = params_ar.read().await;
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
// ¶ms_ar.blocking_read().msg,
|
||||||
|
¶ms_guard.msg,
|
||||||
|
"Started Routine!".to_string(),
|
||||||
|
Arc::new(RwLock::new(params_guard.clone()))
|
||||||
|
).await;
|
||||||
|
drop(botlock);
|
||||||
|
drop(params_guard);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// botlock
|
||||||
|
// .botmgrs
|
||||||
|
// .chat
|
||||||
|
// .say_in_reply_to(
|
||||||
|
// ¶ms.msg,
|
||||||
|
// format!("{:?}",),
|
||||||
|
// params.clone()
|
||||||
|
// ).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async fn test3_body(params : ExecBodyParams) {
|
||||||
|
// println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
|
botlog::debug(
|
||||||
|
"testy triggered!",
|
||||||
|
Some("Experiments003 > test3 command body".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test Routine Start() by :
|
||||||
|
1. In this single exec body , create a Routine
|
||||||
|
2. Create a Routine Execution Body
|
||||||
|
3. Pass the Execution Body & Routine Attributes to create the Routine
|
||||||
|
4. Start the Routine
|
||||||
|
5. For RunOnce , we should see it only trigger once, and then complete in the logs
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// [x] Get the module from params
|
||||||
|
|
||||||
|
|
||||||
|
let params_ar = Arc::new(RwLock::new(params));
|
||||||
|
|
||||||
|
// let parentmodule = params.get_parent_module().await;
|
||||||
|
let module = params_ar.read().await.get_module().await;
|
||||||
|
// let channel = params.get_channel().await;
|
||||||
|
// let channel = params.get_channel().await;
|
||||||
|
// let channel = params.get_channel();
|
||||||
|
let routine_attr = vec![
|
||||||
|
RoutineAttr::RunOnce
|
||||||
|
];
|
||||||
|
// let exec_body = actions_util::asyncbox(rtestbody);
|
||||||
|
// let exec_body = actions_util::asyncbox(rtestbody); // <-- 03.27 - when below is uncommented, this is throwing an issue
|
||||||
|
|
||||||
|
// let channel = params.get_channel();
|
||||||
|
let channel_task_grabber = tokio::task::spawn_blocking( move || {
|
||||||
|
let params_clone = params_ar.clone();
|
||||||
|
let channel = params_clone.blocking_read().get_channel();
|
||||||
|
drop(params_clone);
|
||||||
|
(channel,params_ar)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (channel,params_ar) = channel_task_grabber.await.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let exec_body = rtestbody;
|
||||||
|
|
||||||
|
// let parent_params = params.clone();
|
||||||
|
// let params_clone = params.clone();
|
||||||
|
|
||||||
|
|
||||||
|
// async fn rtestbody(params : ExecBodyParams) {
|
||||||
|
fn rtestbody(params : Arc<RwLock<ExecBodyParams>>) {
|
||||||
|
|
||||||
|
|
||||||
|
// let guard1 = params.curr_act.read().await;
|
||||||
|
let paramguard1 = params.blocking_read();
|
||||||
|
let curract = paramguard1.curr_act.clone().unwrap();
|
||||||
|
let guard1 = curract.blocking_read();
|
||||||
|
{
|
||||||
|
let logmsg_botact = match *guard1 {
|
||||||
|
BotAction::C(_) => "command",
|
||||||
|
BotAction::R(_) => "routine",
|
||||||
|
BotAction::L(_) => "listener",
|
||||||
|
} ;
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
|
||||||
|
Some("Experiments003 > test3 command body".to_string()),
|
||||||
|
Some(¶ms.blocking_read().msg),
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
let logmsg_botact = match &*guard1 {
|
||||||
|
BotAction::C(_) => "command 2",
|
||||||
|
BotAction::R(_) => "routine 2",
|
||||||
|
BotAction::L(_) => "listener 2",
|
||||||
|
} ;
|
||||||
|
|
||||||
|
botlog::trace(
|
||||||
|
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
|
||||||
|
Some("Experiments003 > test3 command body".to_string()),
|
||||||
|
Some(¶ms.blocking_read().msg),
|
||||||
|
);
|
||||||
|
Log::flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop(guard1);
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
dbg!("Custom > within Child Custom fn - Before Critical area");
|
||||||
|
println!("Critical code area start"); // <= 03.29 - This is printed
|
||||||
|
|
||||||
|
// if let BotAction::R(c) = &*guard {
|
||||||
|
// println!("{:?}",c.read().await.channel);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let routine_channel = if let BotAction::R(c) = &*guard1 {
|
||||||
|
// dbg!("Custom > within Child Custom fn - During Critical area > Routine Guard ");
|
||||||
|
// let routineguard = c.read().await;
|
||||||
|
// Some(routineguard.channel.clone());
|
||||||
|
// } else {
|
||||||
|
// None
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
// let chnl = match &*guard1 {
|
||||||
|
// BotAction::R(arr) => {
|
||||||
|
// dbg!("Custom > within Child Custom fn - During Critical area > Before Routine Guard ");
|
||||||
|
// let routineguard = arr.read().await;
|
||||||
|
// dbg!("Custom > within Child Custom fn - During Critical area > After Routine Guard ");
|
||||||
|
// Some(routineguard.channel.clone())
|
||||||
|
// },
|
||||||
|
// BotAction::C(_) | BotAction::L(_) => None ,
|
||||||
|
// } ;
|
||||||
|
|
||||||
|
// let chnl = params.get_channel().await;
|
||||||
|
// let chnl = params.get_channel().await;
|
||||||
|
let chnl = params.blocking_read().get_channel();
|
||||||
|
dbg!("Custom > within Child Custom fn - after GetChannel");
|
||||||
|
println!("{:?}",chnl);
|
||||||
|
|
||||||
|
|
||||||
|
println!("Critical code area end"); // <= 03.29 - ISSUE This is NOT printed
|
||||||
|
dbg!("Custom > within Child Custom fn - Before Critical area");
|
||||||
|
|
||||||
|
// if let BotAction::R(arr) = &*params.curr_act.read().await {
|
||||||
|
// for curriter in 0..5 {
|
||||||
|
// println!("tester - Routine - Completed Iterations : {}",
|
||||||
|
// arr.read().await.complete_iterations);
|
||||||
|
// println!("tester - Custom Loop - Completed Iterations : {}",
|
||||||
|
// curriter);
|
||||||
|
// sleep(Duration::from_secs_f64(0.5)).await;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let params_clone = params_ar.clone();
|
||||||
|
|
||||||
|
botlog::debug(
|
||||||
|
format!("RTESTBODY : module - {:?} ; channel - {:?}",
|
||||||
|
module,channel
|
||||||
|
).as_str(),
|
||||||
|
Some("experiment003 > test3_body".to_string()),
|
||||||
|
Some(¶ms_clone.read().await.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let a = Routine::from(
|
||||||
|
"Routine Test".to_string(),
|
||||||
|
module,
|
||||||
|
channel.unwrap(),
|
||||||
|
routine_attr,
|
||||||
|
// Arc::new(RwLock::new(exec_body)),
|
||||||
|
exec_body,
|
||||||
|
Arc::new(RwLock::new(params_clone.read().await.clone()))
|
||||||
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if let Ok(newr) = a {
|
||||||
|
|
||||||
|
// NOTE : The below is a "Playing aound" feature
|
||||||
|
// In the below, we're unnecessarily adjusting the ExecBodyParams of the parent
|
||||||
|
|
||||||
|
// To get the reference to the Routine or the BotAction there are now refernces to itself
|
||||||
|
|
||||||
|
// [ ] before execute , be sure to adjust curr_act
|
||||||
|
|
||||||
|
// let mut params_mut = params;
|
||||||
|
let newr_ar = newr.clone();
|
||||||
|
|
||||||
|
// params_mut.curr_act = Arc::new(RwLock::new(
|
||||||
|
// BotAction::R(newr_ar.clone())
|
||||||
|
// ));
|
||||||
|
|
||||||
|
|
||||||
|
// {
|
||||||
|
// newr_ar.write().await.parent_params = params_mut.clone();
|
||||||
|
// }
|
||||||
|
|
||||||
|
let rslt = Routine::start(newr_ar.clone()).await;
|
||||||
|
|
||||||
|
// let rslt = newr_ar.read().await.start().await;
|
||||||
|
|
||||||
|
let rsltstr = match rslt {
|
||||||
|
Ok(_) => "successful".to_string(),
|
||||||
|
Err(a) => a,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
botlog::debug(
|
||||||
|
format!("TEST3_BODY RESULT : {:?}",
|
||||||
|
rsltstr
|
||||||
|
).as_str(),
|
||||||
|
Some("experiment003 > test3_body".to_string()),
|
||||||
|
Some(&(params_ar.clone()).read().await.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
let bot = Arc::clone(¶ms_ar.read().await.bot);
|
||||||
|
|
||||||
|
let botlock = bot.read().await;
|
||||||
|
|
||||||
|
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
¶ms_ar.read().await.msg,
|
||||||
|
format!("Routine Result : {:?}",rsltstr),
|
||||||
|
Arc::new(RwLock::new(params_clone.read().await.clone()))
|
||||||
|
).await;
|
||||||
|
|
||||||
|
// [x] Will not be handling JoinHandles here . If immediate abort() handling is required, below is an example that works
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
let a = newr.clone().read().await.join_handle.clone();
|
||||||
|
match a {
|
||||||
|
Some(b) => {
|
||||||
|
b.read().await.borrow().abort(); // [x] <-- This aborts if wanting to abort immediately
|
||||||
|
//()
|
||||||
|
},
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log::flush();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async fn good_girl(params : ExecBodyParams) {
|
||||||
|
|
||||||
|
// [ ] Uses gen_ratio() to output bool based on a ratio probability .
|
||||||
|
// - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator)
|
||||||
|
// - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio
|
||||||
|
|
||||||
|
if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|
||||||
|
|| params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||||
|
{
|
||||||
|
botlog::debug(
|
||||||
|
"Good Girl Detected > Pausechamp",
|
||||||
|
Some("experiments > goodgirl()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rollwin = rand::thread_rng().gen_ratio(1, 10);
|
||||||
|
|
||||||
|
if rollwin {
|
||||||
|
botlog::debug(
|
||||||
|
"Oh that's a good girl!",
|
||||||
|
Some("experiments > goodgirl()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
let bot = Arc::clone(¶ms.bot);
|
||||||
|
|
||||||
|
|
||||||
|
let botlock = bot.read().await;
|
||||||
|
|
||||||
|
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
|
String::from("GoodGirl xdd "),
|
||||||
|
Arc::new(RwLock::new(params.clone()))
|
||||||
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn testy(params : ExecBodyParams) {
|
||||||
|
println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
|
botlog::debug(
|
||||||
|
"testy triggered!",
|
||||||
|
Some("experiments > testy()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn babygirl(params : ExecBodyParams) {
|
||||||
|
|
||||||
|
|
||||||
|
println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
|
botlog::debug(
|
||||||
|
"babygirl triggered!",
|
||||||
|
Some("experiments > babygirl()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
let bot = Arc::clone(¶ms.bot);
|
||||||
|
|
||||||
|
let botlock = bot.read().await;
|
||||||
|
|
||||||
|
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
|
String::from("16:13 notohh: cafdk"),
|
||||||
|
Arc::new(RwLock::new(params.clone()))
|
||||||
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
sleep(Duration::from_secs_f64(0.5)).await;
|
||||||
|
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
|
String::from("16:13 notohh: have fun eating princess"),
|
||||||
|
Arc::new(RwLock::new(params.clone()))
|
||||||
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
sleep(Duration::from_secs_f64(2.0)).await;
|
||||||
|
|
||||||
|
botlock
|
||||||
|
.botmgrs
|
||||||
|
.chat
|
||||||
|
.read().await
|
||||||
|
.say_in_reply_to(
|
||||||
|
¶ms.msg,
|
||||||
|
String::from("16:13 notohh: baby girl"),
|
||||||
|
Arc::new(RwLock::new(params.clone()))
|
||||||
|
).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn routinelike(params : ExecBodyParams) {
|
||||||
|
println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
|
botlog::debug(
|
||||||
|
"routinelike triggered!",
|
||||||
|
Some("experiments > routinelike()".to_string()),
|
||||||
|
Some(¶ms.msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
// spawn an async block that runs independently from others
|
||||||
|
|
||||||
|
tokio::spawn( async {
|
||||||
|
for _ in 0..5 {
|
||||||
|
println!(">> Innterroutine triggered!");
|
||||||
|
sleep(Duration::from_secs_f64(5.0)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// lines are executed after in conjunction to the spawn
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
use crate::core::bot_actions::*;
|
|
||||||
use crate::core::botinstance::Channel;
|
|
||||||
use crate::core::botlog;
|
|
||||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
|
||||||
use crate::core::identity::UserRole::*;
|
|
||||||
use rand::Rng;
|
|
||||||
use twitch_irc::message::ReplyToMessage;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::time::{sleep, Duration};
|
|
||||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
|
||||||
|
|
||||||
async fn tsg(params: ExecBodyParams) {
|
|
||||||
|
|
||||||
let phrases: [String; 6] = [
|
|
||||||
"Clueless ".to_string(),
|
|
||||||
"ICANT This guy....".to_string(),
|
|
||||||
"He is right tho".to_string(),
|
|
||||||
"KEKW true!".to_string(),
|
|
||||||
"OMEGALUL wth man...".to_string(),
|
|
||||||
"PepeLaugh El no sabe".to_string(),
|
|
||||||
];
|
|
||||||
|
|
||||||
let r = rand::thread_rng().gen_range(0..=4);
|
|
||||||
let a = phrases[r].clone();
|
|
||||||
|
|
||||||
botlog::debug(
|
|
||||||
"This guy works!",
|
|
||||||
Some("modules > thisguy()".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
let bot = Arc::clone(¶ms.bot);
|
|
||||||
let botlock = bot.read().await;
|
|
||||||
|
|
||||||
// uses chat.say_in_reply_to() for the bot controls for messages
|
|
||||||
botlock
|
|
||||||
.botmgrs
|
|
||||||
.chat
|
|
||||||
.say_in_reply(
|
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
|
||||||
a,
|
|
||||||
params.clone()
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
sleep(Duration::from_secs_f64(0.5)).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn init(mgr: &Arc<ModulesManager>) {
|
|
||||||
BotCommand {
|
|
||||||
module: BotModule(String::from("thisguy")),
|
|
||||||
command: String::from("thisguy"),
|
|
||||||
alias: vec![String::from("Thisguy")],
|
|
||||||
exec_body: actions_util::asyncbox(tsg),
|
|
||||||
help: String::from("test"),
|
|
||||||
required_roles: vec![
|
|
||||||
BotAdmin,
|
|
||||||
Mod(OF_CMD_CHANNEL),
|
|
||||||
Broadcaster
|
|
||||||
],
|
|
||||||
}
|
|
||||||
.add_to_modmgr(Arc::clone(mgr))
|
|
||||||
.await;
|
|
||||||
}
|
|
|
@ -1,2 +1,2 @@
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod custom;
|
pub mod custom;
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -14,12 +14,22 @@ pub type BotAR = Arc<RwLock<BotInstance>>;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
|
console_subscriber::init();
|
||||||
|
|
||||||
|
|
||||||
Log::set_file_ext(Extension::Log);
|
Log::set_file_ext(Extension::Log);
|
||||||
Log::set_level(Level::Trace);
|
Log::set_level(Level::Trace);
|
||||||
Log::set_retention_days(2);
|
Log::set_retention_days(2);
|
||||||
// Log::set_level(Level::Notice);
|
// Log::set_level(Level::Notice);
|
||||||
|
|
||||||
|
// fn innerbody() -> i64 {
|
||||||
|
// println!("hello");
|
||||||
|
// 64
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let exec_body:fn() -> i64 = innerbody;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
disabled = []
|
|
||||||
nix_version = '2.4'
|
|
||||||
ignore = ['.direnv']
|
|
Loading…
Reference in a new issue