mutiny_rs/
context.rs

1use crate::http;
2use crate::model::user::User;
3use futures_util::stream::SplitSink;
4use std::sync::Arc;
5use tokio::net::TcpStream;
6use tokio::sync::Mutex;
7use tokio_tungstenite::tungstenite::Message as WsMessage;
8use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
9use crate::client::ClientCache;
10
11pub struct Context {
12    pub token: String,
13    pub http: http::Http,
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::Http::new(token.to_owned()),
32            json,
33            writer,
34            cache,
35            bot,
36        }
37    }
38}