Add save command
This commit is contained in:
parent
66dee050a5
commit
96e2448352
|
|
@ -49,6 +49,34 @@ async fn set_activity(ctx: ManifoldContext<'_>, #[rest] #[description="Who to wa
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn commands() -> [poise::Command<ManifoldData, ManifoldError>; 5] {
|
#[poise::command(slash_command, prefix_command, owners_only)]
|
||||||
[dump_config(), get_environment(), get_config(), register_commands(), set_activity()]
|
async fn save_world(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
|
||||||
|
let my_message = ctx.send(|f| f.content("Save call received, saving the world...").reply(true)).await?;
|
||||||
|
|
||||||
|
let mut user_count = 0;
|
||||||
|
|
||||||
|
let db = &ctx.data().database;
|
||||||
|
let userinfo = ctx.data().user_info.lock().await;
|
||||||
|
for user in userinfo.iter() {
|
||||||
|
debug!("Saving user {:?}", user.0);
|
||||||
|
match user.1.insert(db) {
|
||||||
|
Ok(_) => debug!("User {:?} inserted successfully", user.0),
|
||||||
|
Err(e) => {
|
||||||
|
debug!("User {:?} was not inserted: {:?}, attempting to save instead", user.1, e);
|
||||||
|
match user.1.save(db) {
|
||||||
|
Ok(_) => debug!("User {:?} saved successfully, user is saved in database.", user.0),
|
||||||
|
Err(e) => debug!("User {:?} could not be saved: {:?}", user.1, e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
user_count = userinfo.len();
|
||||||
|
}
|
||||||
|
|
||||||
|
my_message.edit(ctx, |f| f.content(format!("Save call complete; Saved {} users.", user_count))).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commands() -> [poise::Command<ManifoldData, ManifoldError>; 6] {
|
||||||
|
[dump_config(), get_environment(), get_config(), register_commands(), set_activity(), save_world()]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ pub async fn time(ctx: ManifoldContext<'_>, target: u64) -> ManifoldResult<()> {
|
||||||
|
|
||||||
let user = match userinfo.get(&target) {
|
let user = match userinfo.get(&target) {
|
||||||
Some(u) => match u.timezone.to_owned() {
|
Some(u) => match u.timezone.to_owned() {
|
||||||
Some(t) => u,
|
Some(_) => u,
|
||||||
None => {ctx.send(|f| f.content(format!("This user hasn't given me their timezone yet. Shame on them!")).reply(true)).await?; Err("NoTZ")?}
|
None => {ctx.send(|f| f.content(format!("This user hasn't given me their timezone yet. Shame on them!")).reply(true)).await?; Err("NoTZ")?}
|
||||||
},
|
},
|
||||||
None => { ctx.send(|f| f.content(format!("Who's that? I don't know them.")).reply(true)).await?; Err("User not found")?}
|
None => { ctx.send(|f| f.content(format!("Who's that? I don't know them.")).reply(true)).await?; Err("User not found")?}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ impl Handler {
|
||||||
match event {
|
match event {
|
||||||
Event::Ready { data_about_bot} => Handler::standard_startup(&ctx, &framework_ctx, data_about_bot).await,
|
Event::Ready { data_about_bot} => Handler::standard_startup(&ctx, &framework_ctx, data_about_bot).await,
|
||||||
Event::Message { new_message } => Handler::message(&ctx, &framework_ctx, &new_message).await,
|
Event::Message { new_message } => Handler::message(&ctx, &framework_ctx, &new_message).await,
|
||||||
Event::MessageUpdate { old_if_available, new, event } => Handler::message_edited(&ctx, &framework_ctx, old_if_available, new).await,
|
Event::MessageUpdate { old_if_available, new, event: _event } => Handler::message_edited(&ctx, &framework_ctx, old_if_available, new).await,
|
||||||
_ => Ok(())
|
_ => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,6 +34,7 @@ impl Handler {
|
||||||
let config = &framework_ctx.user_data().await.bot_config;
|
let config = &framework_ctx.user_data().await.bot_config;
|
||||||
let responses = &framework_ctx.user_data().await.responses;
|
let responses = &framework_ctx.user_data().await.responses;
|
||||||
|
|
||||||
|
|
||||||
let greeting = match responses.get_response(&"bot startup".to_string()) {
|
let greeting = match responses.get_response(&"bot startup".to_string()) {
|
||||||
Some(g) => g.to_owned(),
|
Some(g) => g.to_owned(),
|
||||||
None => "Manifold bot connected to discord and ready to begin broadcast operations.".to_string(),
|
None => "Manifold bot connected to discord and ready to begin broadcast operations.".to_string(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue