mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
Servers: Ban and unban users +
ban list.
This commit is contained in:
@@ -25,7 +25,7 @@ impl Ref {
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
pub async fn fetch<T: DeserializeOwned>(&self, collection: &'static str) -> Result<T> {
|
||||
async fn fetch<T: DeserializeOwned>(&self, collection: &'static str) -> Result<T> {
|
||||
let doc = get_collection(&collection)
|
||||
.find_one(
|
||||
doc! {
|
||||
@@ -84,6 +84,28 @@ impl Ref {
|
||||
})?)
|
||||
}
|
||||
|
||||
pub async fn fetch_ban(&self, server: &str) -> Result<Ban> {
|
||||
let doc = get_collection("server_bans")
|
||||
.find_one(
|
||||
doc! {
|
||||
"_id.user": &self.id,
|
||||
"_id.server": server
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find_one",
|
||||
with: "server_ban",
|
||||
})?
|
||||
.ok_or_else(|| Error::NotFound)?;
|
||||
|
||||
Ok(from_document::<Ban>(doc).map_err(|_| Error::DatabaseError {
|
||||
operation: "from_document",
|
||||
with: "server_ban",
|
||||
})?)
|
||||
}
|
||||
|
||||
pub async fn fetch_message(&self, channel: &Channel) -> Result<Message> {
|
||||
let message: Message = self.fetch("messages").await?;
|
||||
if &message.channel != channel.id() {
|
||||
|
||||
Reference in New Issue
Block a user