Files
continuwuity/src/admin/command.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
958 B
Rust
Raw Normal View History

2025-01-04 16:57:07 +00:00
use std::{fmt, time::SystemTime};
2025-01-04 16:57:07 +00:00
use conduwuit::Result;
2024-12-14 21:58:01 -05:00
use conduwuit_service::Services;
2025-01-04 16:57:07 +00:00
use futures::{
Future, FutureExt,
2025-01-04 16:57:07 +00:00
io::{AsyncWriteExt, BufWriter},
lock::Mutex,
};
2024-08-28 04:09:46 +00:00
use ruma::EventId;
2024-07-27 00:11:41 +00:00
pub(crate) struct Command<'a> {
pub(crate) services: &'a Services,
pub(crate) body: &'a [&'a str],
pub(crate) timer: SystemTime,
2024-08-28 04:09:46 +00:00
pub(crate) reply_id: Option<&'a EventId>,
2025-01-04 16:57:07 +00:00
pub(crate) output: Mutex<BufWriter<Vec<u8>>>,
}
impl Command<'_> {
pub(crate) fn write_fmt(
&self,
arguments: fmt::Arguments<'_>,
) -> impl Future<Output = Result> + Send + '_ + use<'_> {
2025-01-04 16:57:07 +00:00
let buf = format!("{arguments}");
self.output.lock().then(|mut output| async move {
output.write_all(buf.as_bytes()).await.map_err(Into::into)
})
}
pub(crate) fn write_str<'a>(
&'a self,
s: &'a str,
) -> impl Future<Output = Result> + Send + 'a {
self.output.lock().then(move |mut output| async move {
output.write_all(s.as_bytes()).await.map_err(Into::into)
})
}
2024-07-27 00:11:41 +00:00
}