Initial commit
This commit is contained in:
parent
960dc08ecd
commit
31c1bcdce1
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
|
||||||
|
.vscode/
|
1043
Cargo.lock
generated
Normal file
1043
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal 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
1
docker-compose.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
version: 3
|
31
src/main.rs
Normal file
31
src/main.rs
Normal 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user