mirror of
https://github.com/Noratrieb/discord-court-bot.git
synced 2026-01-16 19:05:01 +01:00
close
This commit is contained in:
parent
2a1d598cca
commit
3b0c9c1b04
3 changed files with 334 additions and 60 deletions
36
src/model.rs
36
src/model.rs
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue