1use crate::client::ClientCache;
2use crate::http;
3use crate::model::user::User;
4use futures_util::stream::SplitSink;
5use std::sync::Arc;
6use tokio::net::TcpStream;
7use tokio::sync::Mutex;
8use tokio_tungstenite::tungstenite::Message as WsMessage;
9use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
10
11pub struct Context {
12 pub token: String,
13 pub http: http::HttpClient,
14 pub json: serde_json::Value,
15 writer: Arc<Mutex<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, WsMessage>>>,
16 pub cache: ClientCache,
17 pub bot: User,
18}
19
20impl Context {
21 pub fn new(
22 token: &str,
23 json: serde_json::Value,
24 writer: Arc<Mutex<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, WsMessage>>>,
25 bot: User,
26 cache: ClientCache,
27 ) -> Self
28 {
29 Self {
30 token: token.to_owned(),
31 http: http::HttpClient::new(token.to_owned()),
32 json,
33 writer,
34 cache,
35 bot,
36 }
37 }
38}