Initial commit

This commit is contained in:
hr567 2022-07-02 23:24:53 +08:00
parent 960dc08ecd
commit 31c1bcdce1
No known key found for this signature in database
GPG Key ID: 44CA67290D5250EA
5 changed files with 1092 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/target
.vscode/

1043
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

14
Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "capbot"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
axum = { version = "0.5.10", features = ["http2", "ws"] }
env_logger = "0.9.0"
log = "0.4.17"
regex = "1.5.6"
thiserror = "1.0.31"
tokio = { version = "1.19.2", features = ["full"] }

1
docker-compose.yml Normal file
View File

@ -0,0 +1 @@
version: 3

31
src/main.rs Normal file
View File

@ -0,0 +1,31 @@
use std::io;
use axum::{
extract::ws::{WebSocket, WebSocketUpgrade},
response::Response,
routing, Router,
};
#[tokio::main]
async fn main() -> io::Result<()> {
env_logger::init();
let router = Router::new().route("/", routing::get(handler));
axum::Server::bind(&"127.0.0.1:8080".parse().unwrap())
.serve(router.into_make_service())
.await
.unwrap();
Ok(())
}
async fn handler(ws: WebSocketUpgrade) -> Response {
ws.on_upgrade(handle_cqhttp)
}
async fn handle_cqhttp(mut socket: WebSocket) {
while let Some(msg) = socket.recv().await {
match msg {
Ok(msg) => log::info!("{:?}", msg),
Err(e) => log::error!("{}", e),
}
}
}