Compare commits
No commits in common. "master" and "case-insensitive-objects" have entirely different histories.
master
...
case-insen
24 changed files with 832 additions and 4485 deletions
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
[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"
|
||||||
|
|
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
|
||||||
|
|
17
Cargo.lock
generated
17
Cargo.lock
generated
|
@ -41,17 +41,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-recursion"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.77"
|
version = "0.1.77"
|
||||||
|
@ -133,9 +122,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.35"
|
version = "0.4.34"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a"
|
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
@ -205,10 +194,8 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||||
name = "forcebot_rs"
|
name = "forcebot_rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-recursion",
|
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"casual_logger",
|
"casual_logger",
|
||||||
"chrono",
|
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"futures",
|
"futures",
|
||||||
"rand",
|
"rand",
|
||||||
|
|
|
@ -12,10 +12,7 @@ twitch-irc = "5.0.1"
|
||||||
rand = { version = "0.8.5", features = [] }
|
rand = { version = "0.8.5", features = [] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
async-trait = "0.1.77"
|
async-trait = "0.1.77"
|
||||||
async-recursion = "1.1.0"
|
|
||||||
casual_logger = "0.6.5"
|
casual_logger = "0.6.5"
|
||||||
chrono = "0.4.35"
|
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "bot_lib"
|
name = "bot_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,141 +1,27 @@
|
||||||
use twitch_irc::message::{PrivmsgMessage, TwitchUserBasics};
|
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::RwLock;
|
|
||||||
|
|
||||||
use crate::core::botinstance::BotInstance;
|
|
||||||
|
|
||||||
use super::{botmodules::{BotAction, BotModule}, identity::ChatBadge};
|
|
||||||
|
|
||||||
|
|
||||||
pub type BotAR = Arc<RwLock<BotInstance>>;
|
|
||||||
pub type ActAR = Arc<RwLock<BotAction>>;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ExecBodyParams {
|
|
||||||
pub bot : BotAR,
|
|
||||||
pub msg : PrivmsgMessage,
|
|
||||||
pub parent_act : ActAR ,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl ExecBodyParams {
|
|
||||||
|
|
||||||
pub async fn get_parent_module(&self) -> Option<BotModule> {
|
|
||||||
|
|
||||||
let parent_act = Arc::clone(&self.parent_act);
|
|
||||||
let parent_act_lock = parent_act.read().await;
|
|
||||||
let act = &(*parent_act_lock);
|
|
||||||
match act {
|
|
||||||
BotAction::C(c) => {
|
|
||||||
let temp = c.module.clone();
|
|
||||||
Some(temp)
|
|
||||||
},
|
|
||||||
BotAction::L(l) => {
|
|
||||||
let temp = l.module.clone();
|
|
||||||
Some(temp)
|
|
||||||
},
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_sender(&self) -> String {
|
|
||||||
self.msg.sender.name.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_sender_chatbadge(&self) -> Option<ChatBadge> {
|
|
||||||
|
|
||||||
let mut requestor_badge_mut: Option<ChatBadge> = None;
|
|
||||||
|
|
||||||
for b in &self.msg.badges {
|
|
||||||
if b.name == "moderator" {
|
|
||||||
requestor_badge_mut = Some(ChatBadge::Mod);
|
|
||||||
} else if b.name == "broadcaster" {
|
|
||||||
requestor_badge_mut = Some(ChatBadge::Broadcaster);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use tokio::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
|
use crate::core::botinstance::BotInstance;
|
||||||
|
|
||||||
|
pub type BotAM = Arc<Mutex<BotInstance>>;
|
||||||
|
pub type BotAR = Arc<RwLock<BotInstance>>;
|
||||||
|
|
||||||
pub type ExecBody = Box<
|
pub type ExecBody = Box<
|
||||||
dyn Fn(ExecBodyParams) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
|
dyn Fn(BotAR, PrivmsgMessage) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
pub fn asyncbox<T>(f: fn(ExecBodyParams) -> T) -> ExecBody
|
pub fn asyncbox<T>(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody
|
||||||
where
|
where
|
||||||
T: Future<Output = ()> + Send + 'static,
|
T: Future<Output = ()> + Send + 'static,
|
||||||
{
|
{
|
||||||
Box::new(move |a| Box::pin(f(a)))
|
Box::new(move |a, b| Box::pin(f(a, b)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,20 @@ use casual_logger::Log;
|
||||||
|
|
||||||
use crate::core::ratelimiter::RateLimiter;
|
use crate::core::ratelimiter::RateLimiter;
|
||||||
|
|
||||||
use crate::core::bot_actions::BotAR;
|
use crate::core::bot_actions::actions_util::BotAR;
|
||||||
use crate::core::botmodules::ModulesManager;
|
use crate::core::botmodules::ModulesManager;
|
||||||
use crate::core::identity::{IdentityManager, Permissible};
|
use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
|
||||||
|
|
||||||
use crate::core::botlog;
|
use crate::core::botlog;
|
||||||
use crate::core::chat::Chat;
|
use crate::core::chat::Chat;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||||
pub enum ChangeResult {
|
pub enum ChType {
|
||||||
Success(String),
|
Channel(String),
|
||||||
Failed(String),
|
|
||||||
NoChange(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use ChType::Channel;
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
|
||||||
|
|
||||||
pub struct Channel(pub String);
|
|
||||||
|
|
||||||
use super::bot_actions::ExecBodyParams;
|
|
||||||
use super::botmodules::StatusType;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BotManagers {
|
pub struct BotManagers {
|
||||||
|
@ -48,7 +40,7 @@ pub struct BotManagers {
|
||||||
|
|
||||||
impl BotManagers {
|
impl BotManagers {
|
||||||
pub fn init(
|
pub fn init(
|
||||||
ratelimiters: HashMap<Channel, RateLimiter>,
|
ratelimiters: HashMap<ChType, RateLimiter>,
|
||||||
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||||
) -> BotManagers {
|
) -> BotManagers {
|
||||||
BotManagers {
|
BotManagers {
|
||||||
|
@ -72,11 +64,11 @@ impl<T: Clone> ArcBox<T> {
|
||||||
|
|
||||||
pub struct BotInstance {
|
pub struct BotInstance {
|
||||||
pub prefix: char,
|
pub prefix: char,
|
||||||
pub bot_channel: Channel,
|
pub bot_channel: ChType,
|
||||||
pub incoming_messages: Arc<RwLock<UnboundedReceiver<ServerMessage>>>,
|
pub incoming_messages: Arc<RwLock<UnboundedReceiver<ServerMessage>>>,
|
||||||
pub botmodules: Arc<ModulesManager>,
|
pub botmodules: Arc<ModulesManager>,
|
||||||
pub twitch_oauth: String,
|
pub twitch_oauth: String,
|
||||||
pub bot_channels: Vec<Channel>,
|
pub bot_channels: Vec<ChType>,
|
||||||
pub botmgrs: BotManagers,
|
pub botmgrs: BotManagers,
|
||||||
//modesmgr : ModesManager, // [FUTURE] Silent/Quiet , uwu , frisky/horny
|
//modesmgr : ModesManager, // [FUTURE] Silent/Quiet , uwu , frisky/horny
|
||||||
}
|
}
|
||||||
|
@ -122,7 +114,7 @@ impl BotInstance {
|
||||||
|
|
||||||
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));
|
||||||
|
@ -154,18 +146,6 @@ impl BotInstance {
|
||||||
|
|
||||||
while let Some(message) = msglock.recv().await {
|
while let Some(message) = msglock.recv().await {
|
||||||
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
format!(
|
|
||||||
"[TRACE][ServerMessage] > {:?}",
|
|
||||||
message
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
Some("BotInstance > runner()".to_string()),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
match message {
|
match message {
|
||||||
ServerMessage::Notice(msg) => {
|
ServerMessage::Notice(msg) => {
|
||||||
botlog::notice(
|
botlog::notice(
|
||||||
|
@ -174,10 +154,8 @@ impl BotInstance {
|
||||||
Some("BotInstance > runner()".to_string()),
|
Some("BotInstance > runner()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
Log::flush();
|
|
||||||
}
|
}
|
||||||
ServerMessage::Privmsg(msg) => {
|
ServerMessage::Privmsg(msg) => {
|
||||||
|
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
format!(
|
format!(
|
||||||
"[Twitch Chat > {}] > {}: {}",
|
"[Twitch Chat > {}] > {}: {}",
|
||||||
|
@ -188,18 +166,6 @@ impl BotInstance {
|
||||||
Some(&msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
format!(
|
|
||||||
"[TRACE][Twitch Chat > {}] > {}: {:?}",
|
|
||||||
msg.channel_login, msg.sender.name, msg
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
Some("BotInstance > runner()".to_string()),
|
|
||||||
Some(&msg),
|
|
||||||
);
|
|
||||||
Log::flush();
|
|
||||||
|
|
||||||
BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
|
BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
|
||||||
}
|
}
|
||||||
ServerMessage::Whisper(msg) => {
|
ServerMessage::Whisper(msg) => {
|
||||||
|
@ -208,7 +174,6 @@ impl BotInstance {
|
||||||
Some("BotInstance > runner()".to_string()),
|
Some("BotInstance > runner()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
Log::flush();
|
|
||||||
}
|
}
|
||||||
ServerMessage::Join(msg) => {
|
ServerMessage::Join(msg) => {
|
||||||
botlog::notice(
|
botlog::notice(
|
||||||
|
@ -216,7 +181,6 @@ impl BotInstance {
|
||||||
Some("BotInstance > runner()".to_string()),
|
Some("BotInstance > runner()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
Log::flush();
|
|
||||||
}
|
}
|
||||||
ServerMessage::Part(msg) => {
|
ServerMessage::Part(msg) => {
|
||||||
botlog::notice(
|
botlog::notice(
|
||||||
|
@ -224,7 +188,6 @@ impl BotInstance {
|
||||||
Some("BotInstance > runner()".to_string()),
|
Some("BotInstance > runner()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
Log::flush();
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
@ -255,42 +218,6 @@ impl BotInstance {
|
||||||
|
|
||||||
// // [ ] #todo Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel)
|
// // [ ] #todo Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel)
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
[ ] What we should do instead is :
|
|
||||||
1. Check if the message is related to a Reply (so we know how many arguments we should skip)
|
|
||||||
2. If a reply, skip the first argument
|
|
||||||
*/
|
|
||||||
|
|
||||||
let mut msgiter= msg
|
|
||||||
.message_text
|
|
||||||
.split(' ');
|
|
||||||
|
|
||||||
let arg1 = msgiter.next();
|
|
||||||
let arg2 = msgiter.next();
|
|
||||||
|
|
||||||
let reply = if let Some(Some(replyid)) = msg.source.tags.0.get("reply-thread-parent-msg-id") {
|
|
||||||
Some(replyid)
|
|
||||||
} else { None }
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
let inpt = match reply {
|
|
||||||
None => { // Regular message, use the first arg as the command
|
|
||||||
match arg1 {
|
|
||||||
None => return, // return if no argument found
|
|
||||||
Some(a) => a,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Some(_) => {
|
|
||||||
match arg2 { // A reply message, use the 2nd arg as the command
|
|
||||||
None => return, // return if no argument found
|
|
||||||
Some(a) => a,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
let actsdb = Arc::clone(&botlock.botmodules.botactions);
|
let actsdb = Arc::clone(&botlock.botmodules.botactions);
|
||||||
let actsdblock = actsdb.read().await;
|
let actsdblock = actsdb.read().await;
|
||||||
|
@ -301,20 +228,14 @@ impl BotInstance {
|
||||||
Some(msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
for acts in (*actsdblock).values() {
|
for acts in (*actsdblock).values() {
|
||||||
|
|
||||||
|
|
||||||
for a in acts {
|
for a in acts {
|
||||||
|
match a {
|
||||||
let act_clone = Arc::clone(a);
|
|
||||||
|
|
||||||
match &(*act_clone.read().await) {
|
|
||||||
crate::core::botmodules::BotAction::C(c) => {
|
crate::core::botmodules::BotAction::C(c) => {
|
||||||
/*
|
/*
|
||||||
BotCommand handling -
|
BotCommand handling -
|
||||||
- [x] Checks if the input message is a prefix with command name or alias
|
- [x] Checks if the input message is a prefix with command name or alias
|
||||||
- [x] Validate User can run based on identityModule(From_Bot)::can_user_run(
|
- [ ] Validate User can run based on identityModule(From_Bot)::can_user_run(
|
||||||
_usr:String,
|
_usr:String,
|
||||||
_channelname:ChType,
|
_channelname:ChType,
|
||||||
_chat_badge:ChatBadge,
|
_chat_badge:ChatBadge,
|
||||||
|
@ -327,7 +248,11 @@ impl BotInstance {
|
||||||
Some(msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let inpt = msg
|
||||||
|
.message_text
|
||||||
|
.split(' ')
|
||||||
|
.next()
|
||||||
|
.expect("ERROR during BotCommand");
|
||||||
|
|
||||||
// [x] Check if a bot command based on ...
|
// [x] Check if a bot command based on ...
|
||||||
// [x] prefix + command
|
// [x] prefix + command
|
||||||
|
@ -359,72 +284,6 @@ impl BotInstance {
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
let id = botlock.get_identity();
|
let id = botlock.get_identity();
|
||||||
|
|
||||||
// [x] Check first if the Module for that Given Command is Enabled or Disabled on the given Channel
|
|
||||||
let modmgr = Arc::clone(&botlock.botmodules);
|
|
||||||
let modstatus = modmgr.modstatus(
|
|
||||||
c.module.clone(),
|
|
||||||
Channel(msg.channel_login.to_string())).await;
|
|
||||||
|
|
||||||
|
|
||||||
if let StatusType::Disabled(a) = modstatus {
|
|
||||||
|
|
||||||
// [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
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
&format!("Identified cmd is associated with Disabled Module : StatusLvl = {:?}", a),
|
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
|
||||||
Some(msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
let botclone = Arc::clone(&bot);
|
|
||||||
let botlock = botclone.read().await;
|
|
||||||
let id = botlock.get_identity();
|
|
||||||
let id = Arc::clone(&id);
|
|
||||||
let idlock = id.read().await; // <-- [ ] 03.24 - seems to work
|
|
||||||
let user_roles = idlock.getspecialuserroles(
|
|
||||||
msg.sender.name.clone(),
|
|
||||||
Some(Channel(msg.channel_login.clone()))
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
&format!("For Disabled Command Evaluating User Roles {:?}", user_roles),
|
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
|
||||||
Some(msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Only respond to those with th ebelow User Roles
|
|
||||||
|
|
||||||
let outstr =
|
|
||||||
format!("sadg Module is disabled : {:?}",a);
|
|
||||||
|
|
||||||
|
|
||||||
let params = ExecBodyParams {
|
|
||||||
bot : Arc::clone(&bot),
|
|
||||||
msg : (*msg).clone(),
|
|
||||||
parent_act : Arc::clone(&act_clone),
|
|
||||||
};
|
|
||||||
|
|
||||||
// When sending a BotMsgTypeNotif, send_botmsg does Roles related validation as required
|
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
outstr
|
|
||||||
),
|
|
||||||
params,
|
|
||||||
).await;
|
|
||||||
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
"ACQUIRING WRITE LOCK : ID",
|
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
|
||||||
Some(msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
let eval = {
|
let eval = {
|
||||||
let mut idlock = id.write().await;
|
let mut idlock = id.write().await;
|
||||||
let (permissability, chngrslt) = idlock
|
let (permissability, chngrslt) = idlock
|
||||||
|
@ -456,72 +315,25 @@ impl BotInstance {
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
let outstr =
|
let outstr =
|
||||||
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
|
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
|
||||||
|
botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await;
|
||||||
|
|
||||||
let params = ExecBodyParams {
|
|
||||||
bot : Arc::clone(&bot),
|
|
||||||
msg : (*msg).clone(),
|
|
||||||
parent_act : Arc::clone(&act_clone),
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
outstr.to_string()
|
|
||||||
),
|
|
||||||
params.clone(),
|
|
||||||
).await;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if innerstr
|
|
||||||
.to_lowercase()
|
|
||||||
.contains(&"Auto Promoted VIP".to_lowercase())
|
|
||||||
{
|
|
||||||
botlog::notice(
|
|
||||||
"Assigning VIP UserRole to VIP",
|
|
||||||
Some("botinstance > listener_main_prvmsg()".to_string()),
|
|
||||||
Some(msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
|
||||||
let outstr =
|
|
||||||
"❤️ a VIP - love ya!".to_string();
|
|
||||||
|
|
||||||
|
|
||||||
let params = ExecBodyParams {
|
|
||||||
bot : Arc::clone(&bot),
|
|
||||||
msg : (*msg).clone(),
|
|
||||||
parent_act : Arc::clone(&act_clone),
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
|
||||||
outstr.to_string()
|
|
||||||
),
|
|
||||||
params.clone(),
|
|
||||||
).await;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match eval {
|
match eval {
|
||||||
Permissible::Allow => {
|
Permissible::Allow => {
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"Executing as permissible",
|
"Executed as permissible",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let a = Arc::clone(&bot);
|
let a = Arc::clone(&bot);
|
||||||
c.execute(ExecBodyParams {
|
c.execute(a, msg.clone()).await;
|
||||||
bot : a,
|
|
||||||
msg : msg.clone() ,
|
|
||||||
parent_act : Arc::clone(&act_clone),
|
|
||||||
}).await;
|
|
||||||
|
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"exit out of execution",
|
"exit out of execution",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
|
// Some(&msg),
|
||||||
Some(msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -538,36 +350,8 @@ impl BotInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::core::botmodules::BotAction::L(l) => {
|
crate::core::botmodules::BotAction::L(l) => {
|
||||||
|
let a = Arc::clone(&bot);
|
||||||
let botlock = bot.read().await;
|
l.execute(a, msg.clone()).await;
|
||||||
|
|
||||||
// [x] Check first if the Module for that Given Command is Enabled or Disabled on the given Channel
|
|
||||||
let modmgr = Arc::clone(&botlock.botmodules);
|
|
||||||
let modstatus = modmgr.modstatus(
|
|
||||||
l.module.clone(),
|
|
||||||
Channel(msg.channel_login.to_string())).await;
|
|
||||||
|
|
||||||
|
|
||||||
if let StatusType::Disabled(a) = modstatus {
|
|
||||||
|
|
||||||
// [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
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
&format!("Identified listener is associated with Disabled Module : StatusLvl = {:?}", a),
|
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
|
||||||
Some(msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
let a = Arc::clone(&bot);
|
|
||||||
l.execute(ExecBodyParams {
|
|
||||||
bot : a,
|
|
||||||
msg : msg.clone() ,
|
|
||||||
parent_act : Arc::clone(&act_clone),
|
|
||||||
} ).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
371
src/core/chat.rs
371
src/core/chat.rs
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use twitch_irc::login::StaticLoginCredentials;
|
use twitch_irc::login::StaticLoginCredentials;
|
||||||
use twitch_irc::message::ReplyToMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
use twitch_irc::transport::tcp::{TCPTransport, TLS};
|
use twitch_irc::transport::tcp::{TCPTransport, TLS};
|
||||||
use twitch_irc::TwitchIRCClient;
|
use twitch_irc::TwitchIRCClient;
|
||||||
|
|
||||||
|
@ -15,36 +15,21 @@ use rand::Rng;
|
||||||
use crate::core::ratelimiter;
|
use crate::core::ratelimiter;
|
||||||
use crate::core::ratelimiter::RateLimiter;
|
use crate::core::ratelimiter::RateLimiter;
|
||||||
|
|
||||||
use crate::core::botinstance::Channel;
|
use crate::core::botinstance::ChType;
|
||||||
use crate::core::botlog;
|
use crate::core::botlog;
|
||||||
|
pub use ChType::Channel;
|
||||||
|
|
||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
|
|
||||||
use super::bot_actions::ExecBodyParams;
|
|
||||||
use super::identity;
|
|
||||||
|
|
||||||
|
|
||||||
use async_recursion::async_recursion;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
pub ratelimiters: Arc<Mutex<HashMap<Channel, RateLimiter>>>, // used to limit messages sent per channel
|
pub ratelimiters: Arc<Mutex<HashMap<ChType, RateLimiter>>>, // used to limit messages sent per channel
|
||||||
pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub enum BotMsgType {
|
|
||||||
SayInReplyTo(Channel,String,String), // ( Destination Channel , Message ID to reply to , OutMessage ) // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to
|
|
||||||
Say(String,String),
|
|
||||||
Notif(String), // For Bot Sent Notifications
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Chat {
|
impl Chat {
|
||||||
pub fn init(
|
pub fn init(
|
||||||
ratelimiters: HashMap<Channel, RateLimiter>,
|
ratelimiters: HashMap<ChType, RateLimiter>,
|
||||||
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||||
) -> Chat {
|
) -> Chat {
|
||||||
Chat {
|
Chat {
|
||||||
|
@ -53,16 +38,12 @@ impl Chat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init_channel(&mut self, chnl: Channel) {
|
pub async fn init_channel(&mut self, chnl: ChType) {
|
||||||
let n = RateLimiter::new();
|
let n = RateLimiter::new();
|
||||||
self.ratelimiters.lock().await.insert(chnl, n);
|
self.ratelimiters.lock().await.insert(chnl, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_recursion]
|
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) {
|
||||||
pub async fn send_botmsg(&self, msginput: BotMsgType, params : ExecBodyParams) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
formats message before sending to TwitchIRC
|
formats message before sending to TwitchIRC
|
||||||
|
|
||||||
|
@ -72,258 +53,12 @@ impl Chat {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
format!("send_bot_msg params : {:?}",msginput).as_str(),
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
Log::flush();
|
|
||||||
|
|
||||||
|
|
||||||
let (channel_login,mut outmsg) = match msginput.clone() {
|
|
||||||
BotMsgType::SayInReplyTo(chnl, _, outmsg) => {
|
|
||||||
(chnl.0.to_lowercase(), // Desintation Channel
|
|
||||||
outmsg)
|
|
||||||
},
|
|
||||||
BotMsgType::Say(a,b ) => {
|
|
||||||
(a.clone(),b.clone())
|
|
||||||
},
|
|
||||||
BotMsgType::Notif(outmsg) => {
|
|
||||||
(params.msg.channel_login.clone(),outmsg)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
"BEFORE parent_module call",
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
let parent_module = params.get_parent_module().await;
|
|
||||||
|
|
||||||
let params_clone = params.clone();
|
|
||||||
let botclone = Arc::clone(¶ms_clone.bot);
|
|
||||||
let botlock = botclone.read().await;
|
|
||||||
let modmgr = Arc::clone(&botlock.botmodules);
|
|
||||||
let modstatus = (*modmgr).modstatus(
|
|
||||||
parent_module.clone().expect("ERROR - Expected a module"),
|
|
||||||
Channel(channel_login.clone())
|
|
||||||
).await;
|
|
||||||
|
|
||||||
if !params.bot.read().await.bot_channels.contains(&Channel(channel_login.clone())) {
|
|
||||||
|
|
||||||
dbg!("ISSUE : NONJOINED CHANNEL",¶ms.bot.read().await.bot_channels,Channel(channel_login.clone()));
|
|
||||||
botlog::warn(
|
|
||||||
&format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()),
|
|
||||||
Some("Chat > send_botmsg".to_string()),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let BotMsgType::SayInReplyTo(_chnl,_msgid, _outmsg) = msginput {
|
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::Notif(
|
|
||||||
"uuh Bot can't send to a channel it isn't joined".to_string(),
|
|
||||||
),
|
|
||||||
params).await;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
[x] !! => 03.24 - Somewhere around here, we should be validating module for target channel
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
- Use ModulesManager.modstatus
|
|
||||||
|
|
||||||
modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
format!("BEFORE modstatus check : modstatus = {:?}",modstatus).as_str(),
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if let super::botmodules::StatusType::Disabled(lvl) = modstatus {
|
|
||||||
// Note : At this point, chat was called in a channel where the parent module IS enabled
|
|
||||||
// - this type of validation is done outside of Chat()
|
|
||||||
// This though takes into account scenarios where we are targetting a different channel
|
|
||||||
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
"BEFORE msginput check",
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
Log::flush();
|
|
||||||
|
|
||||||
match msginput {
|
|
||||||
BotMsgType::Notif(_) => (), // Do nothing with Notif > We'll validate the user later to handle
|
|
||||||
BotMsgType::SayInReplyTo(_, _, _) | BotMsgType::Say(_,_) => {
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
"BEFORE potential Async recursion",
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.clone().msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
Log::flush();
|
|
||||||
|
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::Notif(
|
|
||||||
format!("uuh {:?} is disabled on {} : {:?}",
|
|
||||||
parent_module.clone().unwrap(),
|
|
||||||
channel_login.clone(),
|
|
||||||
lvl
|
|
||||||
),
|
|
||||||
), params.clone()
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
"AFTER potential Async recursion",
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
Log::flush();
|
|
||||||
|
|
||||||
return
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
[x] !! => 03.24 - Would be nice if around here , validate the user has at least some special roles in target channel
|
|
||||||
- NOTE : If these need to be refined, they can be by the custom module developer at the parent calling function of say()
|
|
||||||
- This just prevents Chat from being triggered in a channel where the sending chatter does not have any special roles
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Use
|
|
||||||
pub async fn getspecialuserroles(
|
|
||||||
&self,
|
|
||||||
chattername: String,
|
|
||||||
channel: Option<Channel>,
|
|
||||||
) -> Vec<UserRole> {
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// let params_clone = params.clone();
|
|
||||||
|
|
||||||
let botclone = Arc::clone(¶ms.bot);
|
|
||||||
let botlock = botclone.read().await;
|
|
||||||
let id = botlock.get_identity();
|
|
||||||
let id = Arc::clone(&id);
|
|
||||||
let idlock = id.read().await;
|
|
||||||
let user_roles = idlock.getspecialuserroles(
|
|
||||||
params.get_sender(),
|
|
||||||
Some(Channel(channel_login.clone()))
|
|
||||||
).await;
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
format!("BEFORE user roles check check : userroles = {:?}",user_roles).as_str(),
|
|
||||||
Some("chat.rs > send_botmsg ".to_string()),
|
|
||||||
Some(¶ms.msg),
|
|
||||||
);
|
|
||||||
|
|
||||||
Log::flush();
|
|
||||||
|
|
||||||
// [x] If user has any of the following target roles, they will be allowed - otherwise, they will not be allowed to send
|
|
||||||
// - Otherwise if not (checked here) , this will not run
|
|
||||||
// - NOTE : For now, I've removed BotAdmin just for curiosity - BotAdmins can always elevate themselves if they want
|
|
||||||
// - Will be adding VIP to this as this should include Channel_Level Roles
|
|
||||||
|
|
||||||
if !(user_roles.contains(&identity::UserRole::Mod(Channel(channel_login.clone())))
|
|
||||||
|| user_roles.contains(&identity::UserRole::SupMod(Channel(channel_login.clone())))
|
|
||||||
|| user_roles.contains(&identity::UserRole::Broadcaster)
|
|
||||||
|| user_roles.contains(&identity::UserRole::VIP(Channel(channel_login.clone())))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
match msginput {
|
|
||||||
BotMsgType::Notif(_) => {
|
|
||||||
// If Sender is Not a BotAdmin, don't do anything about the notification and return
|
|
||||||
if !user_roles.contains(&identity::UserRole::BotAdmin) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
BotMsgType::SayInReplyTo(_,_,_ ) | BotMsgType::Say(_,_) => {
|
|
||||||
// If the BotMsg a Say/SayInReplyTo (from Developer or Chatter) , and the Sender does not have Specific Roles in the Source Channel Sent
|
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::Notif(
|
|
||||||
format!("uuh You do not have the right roles to send to {}",
|
|
||||||
channel_login.clone(),
|
|
||||||
),
|
|
||||||
), params.clone()
|
|
||||||
).await;
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
At this stage from the above Validations :
|
|
||||||
msginput would be :
|
|
||||||
a. BotMsgType::SayInReplyTo | BotMsgType::Say that is
|
|
||||||
- Towards a Destination Channel that the Sender has Elevated User Roles to Send to
|
|
||||||
b. BotMsgType::Notif that is
|
|
||||||
- Going to be sent to the Source Channel (rather than the original say/sayinreplyto was towards)
|
|
||||||
- A Sender that has Elevated User Roles in Source Channel will see a message ; otherwise, they will not
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Use the following
|
|
||||||
|
|
||||||
pub async fn can_user_run(
|
|
||||||
&mut self,
|
|
||||||
usr: String,
|
|
||||||
channelname: Channel,
|
|
||||||
chat_badge: Option<ChatBadge>,
|
|
||||||
cmdreqroles: Vec<UserRole>, // ) -> Result<Permissible,Box<dyn Error>> {
|
|
||||||
) -> (Permissible, ChangeResult) {
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
let rl = Arc::clone(&self.ratelimiters);
|
let rl = Arc::clone(&self.ratelimiters);
|
||||||
let mut rllock = rl.lock().await;
|
let mut rllock = rl.lock().await;
|
||||||
|
|
||||||
botlog::debug(
|
|
||||||
&format!("Ratelimiter being checked for channel : {}",channel_login.clone()),
|
|
||||||
Some("Chat > send_botmsg".to_string()),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
let contextratelimiter = rllock
|
let contextratelimiter = rllock
|
||||||
.get_mut(&Channel(channel_login.to_lowercase().clone()))
|
// .get_mut()
|
||||||
|
.get_mut(&Channel(String::from(&msg.channel_login)))
|
||||||
.expect("ERROR: Issue with Rate limiters");
|
.expect("ERROR: Issue with Rate limiters");
|
||||||
|
|
||||||
// Continue to check the limiter and sleep if required if the minimum is not reached
|
// Continue to check the limiter and sleep if required if the minimum is not reached
|
||||||
|
@ -340,49 +75,20 @@ impl Chat {
|
||||||
outmsg.push_str(blankspace);
|
outmsg.push_str(blankspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
match msginput.clone() {
|
self.client.say_in_reply_to(msg, outmsg).await.unwrap();
|
||||||
BotMsgType::SayInReplyTo(chnl,msgid, _) => {
|
|
||||||
|
|
||||||
dbg!(chnl.clone(),msgid.clone(),outmsg.clone());
|
|
||||||
|
|
||||||
self.client.say_in_reply_to(&(
|
|
||||||
chnl.0,
|
|
||||||
msgid),
|
|
||||||
outmsg).await.unwrap();
|
|
||||||
},
|
|
||||||
BotMsgType::Say(a, _) => {
|
|
||||||
self.client.say(a, outmsg).await.unwrap();
|
|
||||||
}
|
|
||||||
BotMsgType::Notif(outmsg) => {
|
|
||||||
|
|
||||||
dbg!(params.msg.channel_login(),params.msg.message_id());
|
|
||||||
self.client.say_in_reply_to(¶ms.msg, outmsg).await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
contextratelimiter.increment_counter();
|
contextratelimiter.increment_counter();
|
||||||
|
|
||||||
let logstr = format!(
|
let logstr = format!(
|
||||||
"(#{}) > {} ; contextratelimiter : {:?}",
|
"(#{}) > {} ; contextratelimiter : {:?}",
|
||||||
channel_login.clone(), "rate limit counter increase", contextratelimiter
|
msg.channel_login, "rate limit counter increase", contextratelimiter
|
||||||
);
|
);
|
||||||
|
|
||||||
if let BotMsgType::SayInReplyTo(_,_,_ ) = msginput {
|
botlog::trace(
|
||||||
botlog::trace(
|
logstr.as_str(),
|
||||||
logstr.as_str(),
|
Some("Chat > say_in_reply_to".to_string()),
|
||||||
Some("Chat > send_botmsg".to_string()),
|
Some(msg),
|
||||||
None,
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
botlog::trace(
|
|
||||||
logstr.as_str(),
|
|
||||||
Some("Chat > send_botmsg".to_string()),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ratelimiter::LimiterResp::Skip => {
|
ratelimiter::LimiterResp::Skip => {
|
||||||
// (); // do nothing otherwise
|
// (); // do nothing otherwise
|
||||||
|
@ -392,54 +98,15 @@ impl Chat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::flush();
|
||||||
Log::flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn _say(&self, _: String, _: String) {
|
||||||
pub async fn say_in_reply(
|
|
||||||
&self,
|
|
||||||
destination_channel : Channel ,
|
|
||||||
outmsg: String ,
|
|
||||||
params : ExecBodyParams)
|
|
||||||
{
|
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::SayInReplyTo(
|
|
||||||
destination_channel,
|
|
||||||
params.msg.message_id().to_string(),
|
|
||||||
outmsg) , params).await;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn say_in_reply_to(
|
|
||||||
&self,
|
|
||||||
destination_channel : Channel ,
|
|
||||||
reply_message_id : String ,
|
|
||||||
outmsg: String ,
|
|
||||||
params : ExecBodyParams)
|
|
||||||
{
|
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::SayInReplyTo(
|
|
||||||
destination_channel,
|
|
||||||
reply_message_id,
|
|
||||||
outmsg) , params).await;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn say(&self, channel_login: String, message: String , params : ExecBodyParams) {
|
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), params).await;
|
// self.client.say(msg,outmsg).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async fn _me(&self, _: String, _: String) {
|
async fn _me(&self, _: String, _: String) {
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
|
|
1734
src/core/identity.rs
1734
src/core/identity.rs
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
`custom` will :
|
`modules` will :
|
||||||
- be a starting refrence point for the bot instance to pull module definitions for
|
- be a starting refrence point for the bot instance to pull module definitions for
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -11,9 +11,7 @@ pub use crate::core::botmodules::ModulesManager;
|
||||||
|
|
||||||
// [ ] Load submodules
|
// [ ] Load submodules
|
||||||
|
|
||||||
// mod experiments;
|
mod experiments;
|
||||||
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
|
||||||
|
|
||||||
|
@ -21,7 +19,5 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// Modules initializer loads modules into the bot
|
// Modules initializer loads modules into the bot
|
||||||
// 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;
|
|
||||||
thisguy::init(&mgr).await;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
/*
|
|
||||||
`experimental` will :
|
|
||||||
- be for mostly experimental
|
|
||||||
*/
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
// pub use crate::core::botinstance::BotInstance;
|
|
||||||
pub use crate::core::botmodules::ModulesManager;
|
|
||||||
|
|
||||||
// [ ] Load submodules
|
|
||||||
|
|
||||||
mod experiment001;
|
|
||||||
mod experiment002;
|
|
||||||
|
|
||||||
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
|
||||||
|
|
||||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
|
||||||
// Modules initializer loads modules into the bot
|
|
||||||
// this is achieved by calling submodules that also have fn init() defined
|
|
||||||
|
|
||||||
experiment001::init(Arc::clone(&mgr)).await;
|
|
||||||
experiment002::init(Arc::clone(&mgr)).await;
|
|
||||||
}
|
|
|
@ -1,196 +0,0 @@
|
||||||
/*
|
|
||||||
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 std::sync::Arc;
|
|
||||||
|
|
||||||
use chrono::{TimeZone,Local};
|
|
||||||
use twitch_irc::message::ReplyToMessage;
|
|
||||||
|
|
||||||
|
|
||||||
use crate::core::bot_actions::ExecBodyParams;
|
|
||||||
use crate::core::botinstance::Channel;
|
|
||||||
use crate::core::botlog;
|
|
||||||
|
|
||||||
use casual_logger::Log;
|
|
||||||
|
|
||||||
use crate::core::bot_actions::actions_util;
|
|
||||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
|
||||||
|
|
||||||
use crate::core::identity::UserRole::*;
|
|
||||||
|
|
||||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
|
||||||
|
|
||||||
|
|
||||||
// 1. Define the BotAction
|
|
||||||
let botc1 = BotCommand {
|
|
||||||
module: BotModule(String::from("experiments002")),
|
|
||||||
command: String::from("say"), // command call name
|
|
||||||
alias: vec![
|
|
||||||
"s".to_string(),
|
|
||||||
], // String of alternative names
|
|
||||||
exec_body: actions_util::asyncbox(sayout),
|
|
||||||
help: String::from("Test Command tester"),
|
|
||||||
required_roles: vec![
|
|
||||||
BotAdmin,
|
|
||||||
// Mod(OF_CMD_CHANNEL),
|
|
||||||
VIP(OF_CMD_CHANNEL),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
// 2. Add the BotAction to ModulesManager
|
|
||||||
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
|
||||||
|
|
||||||
// If enabling by defauling at instance level , uncomment the following
|
|
||||||
// mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async fn sayout(params : ExecBodyParams) {
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
usage :
|
|
||||||
<target channel> <message>
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") {
|
|
||||||
Some(reply)
|
|
||||||
} else { None }
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
let reply_parent_ts = if let Some(Some(replyts)) = params.msg.source.tags.0.get("tmi-sent-ts") {
|
|
||||||
|
|
||||||
let a: i64 = replyts.parse().unwrap();
|
|
||||||
let b = Local.timestamp_millis_opt(a).unwrap();
|
|
||||||
Some(b.format("%m-%d %H:%M"))
|
|
||||||
} else { None }
|
|
||||||
;
|
|
||||||
|
|
||||||
// [x] Unwraps arguments from message
|
|
||||||
|
|
||||||
|
|
||||||
let argrslt =
|
|
||||||
if let Some((_,str1)) = params.msg.message_text.split_once(' ') {
|
|
||||||
if reply_parent.is_none() {
|
|
||||||
if let Some((channelstr,msgstr)) = str1.split_once(' ') {
|
|
||||||
Some((channelstr,msgstr))
|
|
||||||
}
|
|
||||||
else { None }
|
|
||||||
} else if let Some((_,str2)) = str1.split_once(' ') {
|
|
||||||
if let Some((channelstr,msgstr)) = str2.split_once(' ') {
|
|
||||||
Some((channelstr,msgstr))
|
|
||||||
}
|
|
||||||
else { None }
|
|
||||||
} else { None }
|
|
||||||
}
|
|
||||||
else { None };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
match argrslt {
|
|
||||||
Some((trgchnl,outmsg)) => {
|
|
||||||
|
|
||||||
let bot = Arc::clone(¶ms.bot);
|
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
|
||||||
|
|
||||||
// [x] Validate first if trgchnl exists
|
|
||||||
|
|
||||||
botlog::trace(
|
|
||||||
&format!("[TRACE] Evaluated status of {} : {:?}",
|
|
||||||
trgchnl.to_string().clone(),botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await),
|
|
||||||
Some("Chat > send_botmsg".to_string()),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
1. If a Reply ,
|
|
||||||
[ ] Get Parent Content message - reply_parent
|
|
||||||
[ ] Get Parent Chatter - reply_parent_usr
|
|
||||||
[ ] Get Parent Channel - msg.channel_login
|
|
||||||
-> Share this first then
|
|
||||||
[ ] Get Reply Message (that triggered bot command) - msgstr
|
|
||||||
[ ] Get Reply Sender - msg.sender.name
|
|
||||||
[ ] Get Target Channel - trgchnl
|
|
||||||
|
|
||||||
2. If not a reply
|
|
||||||
[ ] Get Reply Message (that triggered bot command) - msgstr
|
|
||||||
[ ] Get Reply Sender - msg.sender.name
|
|
||||||
[ ] Get Target Channel - trgchnl
|
|
||||||
*/
|
|
||||||
|
|
||||||
// reply_parent_ts
|
|
||||||
|
|
||||||
let newoutmsg = if let Some(srcmsg) = reply_parent {
|
|
||||||
|
|
||||||
format!("{} {} @ {} : {}",
|
|
||||||
reply_parent_ts.unwrap(),
|
|
||||||
params.msg.sender.name,
|
|
||||||
params.msg.channel_login,
|
|
||||||
srcmsg)
|
|
||||||
} else {
|
|
||||||
format!("in {} - {} : {}",
|
|
||||||
params.msg.channel_login,
|
|
||||||
params.msg.sender.name,
|
|
||||||
outmsg)
|
|
||||||
};
|
|
||||||
|
|
||||||
botlock
|
|
||||||
.botmgrs
|
|
||||||
.chat
|
|
||||||
.say(
|
|
||||||
trgchnl.to_string(),
|
|
||||||
newoutmsg.to_string(),
|
|
||||||
params.clone(),
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
botlog::debug(
|
|
||||||
"sayout had issues trying to parse arguments",
|
|
||||||
Some("experiment002 > sayout".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_to(
|
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
|
||||||
params.clone().msg.message_id().to_string(),
|
|
||||||
String::from("Invalid arguments"),
|
|
||||||
params.clone()
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::flush();
|
|
||||||
}
|
|
|
@ -10,19 +10,17 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
|
||||||
|
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use twitch_irc::message::ReplyToMessage;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::core::bot_actions::ExecBodyParams;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
use crate::core::botinstance::Channel;
|
|
||||||
|
// use crate::core::botinstance::ChType::Channel;
|
||||||
|
use crate::core::botinstance::ChType;
|
||||||
|
use ChType::Channel;
|
||||||
use crate::core::botlog;
|
use crate::core::botlog;
|
||||||
|
|
||||||
use crate::core::bot_actions::actions_util;
|
use crate::core::bot_actions::actions_util::{self, BotAR};
|
||||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
|
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
|
||||||
|
|
||||||
use crate::core::identity::UserRole::*;
|
use crate::core::identity::UserRole::*;
|
||||||
|
@ -31,6 +29,8 @@ use tokio::time::{sleep, Duration};
|
||||||
|
|
||||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
|
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||||
|
|
||||||
// 1. Define the BotAction
|
// 1. Define the BotAction
|
||||||
let botc1 = BotCommand {
|
let botc1 = BotCommand {
|
||||||
module: BotModule(String::from("experiments001")),
|
module: BotModule(String::from("experiments001")),
|
||||||
|
@ -60,6 +60,18 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// 2. Add the BotAction to ModulesManager
|
// 2. Add the BotAction to ModulesManager
|
||||||
list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
|
|
||||||
|
// // 1. Define the BotAction
|
||||||
|
// let list1 = Listener {
|
||||||
|
// module: BotModule(String::from("experiments001")),
|
||||||
|
// name: String::from("babygirl Listener"),
|
||||||
|
// exec_body: actions_util::asyncbox(babygirl),
|
||||||
|
// help: String::from(""),
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // 2. Add the BotAction to ModulesManager
|
||||||
|
// list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
// 1. Define the BotAction
|
// 1. Define the BotAction
|
||||||
let botc1 = BotCommand {
|
let botc1 = BotCommand {
|
||||||
module: BotModule(String::from("experiments001")),
|
module: BotModule(String::from("experiments001")),
|
||||||
|
@ -96,141 +108,75 @@ 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)
|
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
{
|
|
||||||
//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) {
|
|
||||||
|
|
||||||
// [ ] Uses gen_ratio() to output bool based on a ratio probability .
|
// [ ] 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)
|
// - 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
|
// - 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()
|
if msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|
||||||
|| params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
|| msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||||
|| params.msg.sender.name.to_lowercase() == "haruyuumei".to_lowercase()
|
// if msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||||
{
|
{
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"Good Girl Detected > Pausechamp",
|
"Good Girl Detected > Pausechamp",
|
||||||
Some("experiments > goodgirl()".to_string()),
|
Some("experiments > goodgirl()".to_string()),
|
||||||
Some(¶ms.msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let rollwin = rand::thread_rng().gen_ratio(1, 10);
|
let rollwin = rand::thread_rng().gen_ratio(1, 8);
|
||||||
|
|
||||||
if rollwin {
|
if rollwin {
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"Oh that's a good girl!",
|
"Oh that's a good girl!",
|
||||||
Some("experiments > goodgirl()".to_string()),
|
Some("experiments > goodgirl()".to_string()),
|
||||||
Some(¶ms.msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let bot = Arc::clone(¶ms.bot);
|
let bot = Arc::clone(&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
|
||||||
.say_in_reply_to(
|
.say_in_reply_to(&msg, String::from("GoodGirl xdd "))
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.await;
|
||||||
params.clone().msg.message_id().to_string(),
|
|
||||||
String::from("GoodGirl xdd "),
|
|
||||||
params.clone()
|
|
||||||
).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn testy(params : ExecBodyParams) {
|
async fn testy(mut _chat: BotAR, msg: PrivmsgMessage) {
|
||||||
println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"testy triggered!",
|
"testy triggered!",
|
||||||
Some("experiments > testy()".to_string()),
|
Some("experiments > testy()".to_string()),
|
||||||
Some(¶ms.msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn babygirl(params : ExecBodyParams) {
|
async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
|
|
||||||
|
|
||||||
println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"babygirl triggered!",
|
"babygirl triggered!",
|
||||||
Some("experiments > babygirl()".to_string()),
|
Some("experiments > babygirl()".to_string()),
|
||||||
Some(¶ms.msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
let bot = Arc::clone(¶ms.bot);
|
let bot = Arc::clone(&bot);
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
|
|
||||||
|
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply(
|
.say_in_reply_to(&msg, String::from("16:13 notohh: cafdk"))
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.await;
|
||||||
String::from("16:13 notohh: cafdk"),
|
|
||||||
params.clone()
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
sleep(Duration::from_secs_f64(0.5)).await;
|
sleep(Duration::from_secs_f64(0.5)).await;
|
||||||
|
@ -238,11 +184,8 @@ async fn babygirl(params : ExecBodyParams) {
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply(
|
.say_in_reply_to(&msg, String::from("16:13 notohh: have fun eating princess"))
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.await;
|
||||||
String::from("16:13 notohh: have fun eating princess"),
|
|
||||||
params.clone()
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
sleep(Duration::from_secs_f64(2.0)).await;
|
sleep(Duration::from_secs_f64(2.0)).await;
|
||||||
|
@ -250,23 +193,21 @@ async fn babygirl(params : ExecBodyParams) {
|
||||||
botlock
|
botlock
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply(
|
.say_in_reply_to(&msg, String::from("16:13 notohh: baby girl"))
|
||||||
Channel(params.clone().msg.channel_login().to_string()),
|
.await;
|
||||||
String::from("16:13 notohh: baby girl"),
|
|
||||||
params.clone()
|
|
||||||
).await;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn routinelike(params : ExecBodyParams) {
|
|
||||||
|
|
||||||
|
async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) {
|
||||||
println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"routinelike triggered!",
|
"routinelike triggered!",
|
||||||
Some("experiments > routinelike()".to_string()),
|
Some("experiments > routinelike()".to_string()),
|
||||||
Some(¶ms.msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// spawn an async block that runs independently from others
|
// spawn an async block that runs independently from others
|
|
@ -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;
|
||||||
|
|
|
@ -33,11 +33,7 @@ pub async fn main() {
|
||||||
|
|
||||||
for acts in (*actsdb_lock).values() {
|
for acts in (*actsdb_lock).values() {
|
||||||
for act in acts {
|
for act in acts {
|
||||||
|
let outstr = match act {
|
||||||
let act_prelock = act;
|
|
||||||
let act = act_prelock.read().await;
|
|
||||||
|
|
||||||
let outstr = match &(*act) {
|
|
||||||
botmodules::BotAction::C(b) => {
|
botmodules::BotAction::C(b) => {
|
||||||
format!("bot actions > Command : {}", b.command)
|
format!("bot actions > Command : {}", b.command)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
disabled = []
|
|
||||||
nix_version = '2.4'
|
|
||||||
ignore = ['.direnv']
|
|
Loading…
Reference in a new issue