This commit is contained in:
nora 2022-06-16 19:47:10 +02:00
parent 1f6021b555
commit ed6b2a7dfb
4 changed files with 87 additions and 18 deletions

View file

@ -183,8 +183,8 @@ impl Mongo {
let _ = self.find_or_insert_state(guild_id).await?;
let coll = self.state_coll();
coll.update_one(
doc! {"guild_id": &guild_id },
doc! {"$push": { "court_rooms": bson::to_bson(room).wrap_err("invalid bson for room")? }},
doc! { "guild_id": &guild_id },
doc! { "$push": { "court_rooms": bson::to_bson(room).wrap_err("invalid bson for room")? }},
None,
)
.await
@ -192,6 +192,40 @@ impl Mongo {
Ok(())
}
pub async fn add_lawsuit(&self, guild_id: SnowflakeId, lawsuit: &Lawsuit) -> Result<()> {
let _ = self.find_or_insert_state(guild_id).await?;
let coll = self.state_coll();
coll.update_one(
doc! { "guild_id": &guild_id },
doc! { "$push": { "lawsuits": bson::to_bson(lawsuit).wrap_err("invalid bson for lawsuit")? } },
None,
)
.await
.wrap_err("push lawsuit")?;
Ok(())
}
pub async fn set_court_room(
&self,
guild_id: SnowflakeId,
channel_id: SnowflakeId,
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, "court_rooms.channel_id": channel_id },
doc! { "$set": value.into() },
None,
)
.await
.wrap_err("set courtroom")?;
Ok(())
}
fn state_coll(&self) -> Collection<State> {
self.db.collection("state")
}