Update
This commit is contained in:
parent
c61502e6a7
commit
2ac85b4d89
4 changed files with 95 additions and 136 deletions
12
.build.yml
12
.build.yml
|
|
@ -1,12 +1,17 @@
|
||||||
image: alpine/latest
|
image: debian/bullseye
|
||||||
packages:
|
packages:
|
||||||
- curl
|
- curl
|
||||||
|
- lld
|
||||||
|
- gcc
|
||||||
|
- upx
|
||||||
sources:
|
sources:
|
||||||
- https://git.sr.ht/~cofob/matrix-dnsbot
|
- https://git.sr.ht/~cofob/matrix-dnsbot
|
||||||
triggers:
|
triggers:
|
||||||
- action: email
|
- action: email
|
||||||
condition: failure
|
condition: failure
|
||||||
to: failure@cofob.ru
|
to: failure@cofob.ru
|
||||||
|
artifacts:
|
||||||
|
- matrix-dnsbot/target/release/dnsbot
|
||||||
tasks:
|
tasks:
|
||||||
- install: |
|
- install: |
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y -q --default-toolchain nightly --profile minimal
|
curl https://sh.rustup.rs -sSf | sh -s -- -y -q --default-toolchain nightly --profile minimal
|
||||||
|
|
@ -18,3 +23,8 @@ tasks:
|
||||||
source $HOME/.cargo/env
|
source $HOME/.cargo/env
|
||||||
cd matrix-dnsbot
|
cd matrix-dnsbot
|
||||||
cargo test
|
cargo test
|
||||||
|
- build: |
|
||||||
|
source $HOME/.cargo/env
|
||||||
|
cd matrix-dnsbot
|
||||||
|
cargo build --release
|
||||||
|
upx -9 target/release/dnsbot
|
||||||
|
|
|
||||||
62
Cargo.lock
generated
62
Cargo.lock
generated
|
|
@ -272,17 +272,6 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
|
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atty"
|
|
||||||
version = "0.2.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"libc",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
@ -671,7 +660,6 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"matrix-sdk",
|
"matrix-sdk",
|
||||||
"matrix-sdk-sled",
|
"matrix-sdk-sled",
|
||||||
"pretty_env_logger",
|
|
||||||
"regex",
|
"regex",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
|
@ -735,19 +723,6 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "env_logger"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
|
||||||
dependencies = [
|
|
||||||
"atty",
|
|
||||||
"humantime",
|
|
||||||
"log",
|
|
||||||
"regex",
|
|
||||||
"termcolor",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "event-listener"
|
name = "event-listener"
|
||||||
version = "2.5.2"
|
version = "2.5.2"
|
||||||
|
|
@ -1077,15 +1052,6 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "humantime"
|
|
||||||
version = "1.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
|
||||||
dependencies = [
|
|
||||||
"quick-error",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.14.19"
|
version = "0.14.19"
|
||||||
|
|
@ -1763,16 +1729,6 @@ version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pretty_env_logger"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
|
|
||||||
dependencies = [
|
|
||||||
"env_logger",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
|
|
@ -2363,15 +2319,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termcolor"
|
|
||||||
version = "1.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.31"
|
version = "1.0.31"
|
||||||
|
|
@ -2882,15 +2829,6 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-util"
|
|
||||||
version = "0.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ anyhow = "^1"
|
||||||
regex = "^1"
|
regex = "^1"
|
||||||
lazy_static = "^1.4"
|
lazy_static = "^1.4"
|
||||||
tracing-subscriber = "^0.3"
|
tracing-subscriber = "^0.3"
|
||||||
pretty_env_logger = "^0.4"
|
|
||||||
async-std-resolver = "^0.21"
|
async-std-resolver = "^0.21"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|
|
||||||
26
src/main.rs
26
src/main.rs
|
|
@ -1,5 +1,7 @@
|
||||||
extern crate dotenv;
|
extern crate dotenv;
|
||||||
|
|
||||||
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
|
@ -13,7 +15,6 @@ use matrix_sdk::{
|
||||||
}, Client,
|
}, Client,
|
||||||
};
|
};
|
||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
use log::{info, debug};
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use async_std_resolver::resolver_from_system_conf;
|
use async_std_resolver::resolver_from_system_conf;
|
||||||
|
|
@ -30,17 +31,27 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
|
||||||
};
|
};
|
||||||
|
|
||||||
msg_body = msg_body.to_lowercase();
|
msg_body = msg_body.to_lowercase();
|
||||||
|
let mut i: u8 = 0;
|
||||||
|
|
||||||
if msg_body.contains("resolve help") {
|
for line in msg_body.rsplit('\n') {
|
||||||
|
if line.starts_with('>') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if line.contains("resolve help") {
|
||||||
let content = RoomMessageEventContent::text_html(
|
let content = RoomMessageEventContent::text_html(
|
||||||
"Just send 'resolve (domain)'. 'resolve source' to get the code.",
|
"Just send 'resolve (domain)'. 'resolve source' to get the code.",
|
||||||
"Just send <code>resolve (domain)</code>. <code>resolve source</code> to get the code.");
|
"Just send <code>resolve (domain)</code>. <code>resolve source</code> to get the code.");
|
||||||
room.send(content, None).await.unwrap();
|
room.send(content, None).await.unwrap();
|
||||||
} else if msg_body.contains("resolve source") {
|
} else if line.contains("resolve source") {
|
||||||
let content = RoomMessageEventContent::text_plain("https://git.sr.ht/~cofob/matrix-dnsbot");
|
let content = RoomMessageEventContent::text_plain("https://git.sr.ht/~cofob/matrix-dnsbot");
|
||||||
room.send(content, None).await.unwrap();
|
room.send(content, None).await.unwrap();
|
||||||
} else if msg_body.contains("resolve") {
|
} else if line.contains("resolve") {
|
||||||
let caps = RE.captures(&msg_body);
|
i += 1;
|
||||||
|
if i >= 6 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let caps = RE.captures(&line);
|
||||||
match caps {
|
match caps {
|
||||||
Some(cap) => {
|
Some(cap) => {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
@ -76,9 +87,9 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for ip in lookup {
|
for ip in lookup {
|
||||||
plain_answer.push_str(" '");
|
plain_answer.push_str(" `");
|
||||||
plain_answer.push_str(&ip.to_string());
|
plain_answer.push_str(&ip.to_string());
|
||||||
plain_answer.push_str("';");
|
plain_answer.push_str("`;");
|
||||||
answer.push_str(" <code>");
|
answer.push_str(" <code>");
|
||||||
answer.push_str(&ip.to_string());
|
answer.push_str(&ip.to_string());
|
||||||
answer.push_str("</code>;");
|
answer.push_str("</code>;");
|
||||||
|
|
@ -106,6 +117,7 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn on_stripped_state_member(
|
async fn on_stripped_state_member(
|
||||||
room_member: StrippedRoomMemberEvent,
|
room_member: StrippedRoomMemberEvent,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue