create BotInstance::restart_one and restart_all

This commit is contained in:
Akulij 2025-05-31 10:30:39 +05:00
parent 102fae25c7
commit 308b15ed69

View File

@ -17,6 +17,7 @@ pub struct BotInstance {
pub name: String, pub name: String,
pub token: String, pub token: String,
pub script: String, pub script: String,
pub restart_flag: bool,
pub created_at: DateTime<FixedOffset>, pub created_at: DateTime<FixedOffset>,
} }
@ -31,6 +32,7 @@ impl BotInstance {
name, name,
token, token,
script, script,
restart_flag: false,
created_at: Local::now().into(), created_at: Local::now().into(),
} }
} }
@ -54,4 +56,23 @@ impl BotInstance {
Ok(bi.find_one(doc! {"name": name}).await?) Ok(bi.find_one(doc! {"name": name}).await?)
} }
pub async fn restart_one<D: CallDB>(db: &mut D, name: &str, restart: bool) -> DbResult<()> {
let bi = db.get_collection::<Self>().await;
bi.update_one(
doc! {"name": name},
doc! { "$set": { "restart_flag": restart } },
)
.await?;
Ok(())
}
pub async fn restart_all<D: CallDB>(db: &mut D, restart: bool) -> DbResult<()> {
let bi = db.get_collection::<Self>().await;
bi.update_many(doc! {}, doc! { "$set": { "restart_flag": restart } })
.await?;
Ok(())
}
} }