This commit is contained in:
nora 2022-06-16 21:11:36 +02:00
parent 2a1d598cca
commit 3b0c9c1b04
3 changed files with 334 additions and 60 deletions

View file

@ -7,7 +7,7 @@ use std::{
use color_eyre::Result;
use mongodb::{
bson,
bson::{doc, Bson},
bson::{doc, Bson, Uuid},
options::{ClientOptions, Credential},
Client, Collection, Database,
};
@ -227,6 +227,40 @@ impl Mongo {
Ok(())
}
pub async fn set_lawsuit(
&self,
guild_id: SnowflakeId,
lawsuit_id: Uuid,
value: impl Into<Bson>,
) -> Result<()> {
let _ = self.find_or_insert_state(guild_id).await?;
let coll = self.state_coll();
coll.update_one(
doc! { "guild_id": &guild_id, "lawsuit.id": lawsuit_id },
doc! { "$set": value.into() },
None,
)
.await
.wrap_err("set courtroom")?;
Ok(())
}
pub async fn delete_guild(
&self,
guild_id: SnowflakeId,
) -> Result<()> {
let coll = self.state_coll();
coll.delete_one(
doc! { "guild_id": &guild_id },
None,
)
.await
.wrap_err("delete guild")?;
Ok(())
}
fn state_coll(&self) -> Collection<State> {
self.db.collection("state")
}