This commit is contained in:
nora 2021-05-14 20:08:37 +02:00
parent be64e7b51a
commit f66e2b9798
3 changed files with 18 additions and 16 deletions

22
Cargo.lock generated
View file

@ -177,9 +177,9 @@ dependencies = [
[[package]] [[package]]
name = "command_attr" name = "command_attr"
version = "0.3.5" version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fe1f0b69fde68f40ea2ee6ca8db23bc40d2e593db884659a65d8486032cc65b" checksum = "fd0432ed2b23b75b490f30cb28ec8261d49e419c39bb53e974bd1731e07cc9d0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1044,9 +1044,9 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.10.2" version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dac8367ecfd3380c00dcedf5eb9a47888ae74ae391419b5b1f7735895ed8df4" checksum = "e7775b6c4a554e495372cfa5d0e70349c84c62415666cf80c1ea79bc447c78d9"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",
@ -1064,7 +1064,6 @@ dependencies = [
"static_assertions", "static_assertions",
"tokio", "tokio",
"tracing", "tracing",
"tracing-futures",
"typemap_rev", "typemap_rev",
"url", "url",
"uwl", "uwl",
@ -1259,11 +1258,12 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.22" version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"log",
"pin-project-lite", "pin-project-lite",
"tracing-attributes", "tracing-attributes",
"tracing-core", "tracing-core",
@ -1271,9 +1271,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-attributes" name = "tracing-attributes"
version = "0.1.11" version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1282,9 +1282,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.17" version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
] ]

View file

@ -16,6 +16,6 @@ fancy-regex = "0.5.0"
rand = "0.8.3" rand = "0.8.3"
[dependencies.serenity] [dependencies.serenity]
version = "0.10.2" version = "0.10.7"
default-features = false default-features = false
features = ["client", "gateway", "rustls_backend", "model", "framework", "standard_framework", "cache", "http", "utils"] features = ["client", "gateway", "rustls_backend", "model", "framework", "standard_framework", "cache", "http", "utils"]

View file

@ -45,10 +45,8 @@ lazy_static! {
}; };
} }
#[hook] #[hook]
pub async fn normal_message(ctx: &Context, msg: &Message) { pub async fn normal_message(ctx: &Context, msg: &Message) {
let mut data = ctx.data.write().await; let mut data = ctx.data.write().await;
let map = data.get_mut::<LastMessageInChannel>().expect("LastMessageInChannel not found"); let map = data.get_mut::<LastMessageInChannel>().expect("LastMessageInChannel not found");
map.insert(msg.channel_id.clone(), msg.content.clone()); map.insert(msg.channel_id.clone(), msg.content.clone());
@ -57,10 +55,14 @@ pub async fn normal_message(ctx: &Context, msg: &Message) {
static ref TOM_REGEX: Regex = Regex::new(r"(?<=^|\D)(\d{6})(?=\D|$)").unwrap(); static ref TOM_REGEX: Regex = Regex::new(r"(?<=^|\D)(\d{6})(?=\D|$)").unwrap();
} }
let is_nsfw = msg.channel_id.to_channel(&ctx.http).await.expect("may be nsfw lol").is_nsfw();
if let Some(m) = TOM_REGEX.find(&msg.content).unwrap() { if let Some(m) = TOM_REGEX.find(&msg.content).unwrap() {
if is_nsfw {
let number = m.as_str().parse::<u32>().expect("matched regex, so it is valid"); let number = m.as_str().parse::<u32>().expect("matched regex, so it is valid");
reply(&*format!("<https://nhentai.net/g/{}/>", number), &msg, &ctx).await; reply(&*format!("<https://nhentai.net/g/{}/>", number), &msg, &ctx).await;
} }
}
for (trigger, answer) in RESPONSES.iter() { for (trigger, answer) in RESPONSES.iter() {
if msg.content.to_lowercase() == *trigger { if msg.content.to_lowercase() == *trigger {