mirror of
https://github.com/Noratrieb/discord-court-bot.git
synced 2026-01-16 10:55:01 +01:00
uwu
This commit is contained in:
parent
1f6021b555
commit
ed6b2a7dfb
4 changed files with 87 additions and 18 deletions
38
src/model.rs
38
src/model.rs
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue