mutiny_rs/context/
mod.rs

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