countdown command

This commit is contained in:
jellywx 2021-03-21 14:18:35 +00:00
parent 65c59ca889
commit 4eae563a76
2 changed files with 51 additions and 8 deletions

View File

@ -978,12 +978,13 @@ impl Content {
} }
} }
/*
#[command("countdown")] #[command("countdown")]
#[permission_level(Managed)] #[permission_level(Managed)]
async fn countdown(ctx: &Context, msg: &Message, args: String) { async fn countdown(ctx: &Context, msg: &Message, args: String) {
if check_subscription_on_message(&ctx, &msg).await {
let (pool, lm) = get_ctx_data(&ctx).await; let (pool, lm) = get_ctx_data(&ctx).await;
let language = UserData::language_of(&msg.author, &pool).await;
if check_subscription_on_message(&ctx, &msg).await {
let timezone = UserData::timezone_of(&msg.author, &pool).await; let timezone = UserData::timezone_of(&msg.author, &pool).await;
let split_args = args.splitn(3, ' ').collect::<Vec<&str>>(); let split_args = args.splitn(3, ' ').collect::<Vec<&str>>();
@ -1005,8 +1006,8 @@ async fn countdown(ctx: &Context, msg: &Message, args: String) {
if let Ok(interval) = interval_parser.displacement() { if let Ok(interval) = interval_parser.displacement() {
let mut first_time = target_ts; let mut first_time = target_ts;
while first_time + interval < now as i64 { while first_time - interval > now as i64 {
first_time += interval; first_time -= interval;
} }
let description = format!( let description = format!(
@ -1023,7 +1024,8 @@ INSERT INTO embeds (title, description, color) VALUES (?, ?, ?)
*THEME_COLOR *THEME_COLOR
) )
.execute(&pool) .execute(&pool)
.await; .await
.unwrap();
let embed_id = sqlx::query!( let embed_id = sqlx::query!(
" "
@ -1043,7 +1045,8 @@ INSERT INTO messages (embed_id) VALUES (?)
embed_id.id embed_id.id
) )
.execute(&pool) .execute(&pool)
.await; .await
.unwrap();
sqlx::query!( sqlx::query!(
" "
@ -1078,17 +1081,56 @@ INSERT INTO reminders (
target_ts target_ts
) )
.execute(&pool) .execute(&pool)
.await
.unwrap();
let _ = msg.channel_id.send_message(&ctx, |m| {
m.embed(|e| {
e.title(lm.get(&language, "remind/success")).description(
"A new countdown reminder has been created on this channel",
)
})
});
} else {
let _ = msg.channel_id.send_message(&ctx, |m| {
m.embed(|e| {
e.title(lm.get(&language, "remind/issue"))
.description(lm.get(&language, "interval/invalid_interval"))
})
});
}
} else {
let _ = msg.channel_id.send_message(&ctx, |m| {
m.embed(|e| {
e.title(lm.get(&language, "remind/issue"))
.description(lm.get(&language, "remind/invalid_time"))
})
});
}
} else {
command_help(
ctx,
msg,
lm,
&GuildData::prefix_from_id(msg.guild_id, &pool).await,
&language,
"countdown",
)
.await; .await;
} else {
}
} else {
}
} else {
} }
} else { } else {
let _ = msg
.channel_id
.say(
&ctx,
lm.get(&language, "interval/donor").replace(
"{prefix}",
&GuildData::prefix_from_id(msg.guild_id, &pool).await,
),
)
.await;
} }
} }
*/
#[command("remind")] #[command("remind")]
#[permission_level(Managed)] #[permission_level(Managed)]

View File

@ -216,6 +216,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.add_command("natural", &reminder_cmds::NATURAL_COMMAND) .add_command("natural", &reminder_cmds::NATURAL_COMMAND)
.add_command("n", &reminder_cmds::NATURAL_COMMAND) .add_command("n", &reminder_cmds::NATURAL_COMMAND)
.add_command("", &reminder_cmds::NATURAL_COMMAND) .add_command("", &reminder_cmds::NATURAL_COMMAND)
.add_command("countdown", &reminder_cmds::COUNTDOWN_COMMAND)
// management commands // management commands
.add_command("look", &reminder_cmds::LOOK_COMMAND) .add_command("look", &reminder_cmds::LOOK_COMMAND)
.add_command("del", &reminder_cmds::DELETE_COMMAND) .add_command("del", &reminder_cmds::DELETE_COMMAND)