feat!: Added limit field to quests
- Bump version to 0.12.0 - lib: Changed Quest::complete_for_account behavior - cli: Added limit field for quest create and quest update - discord: Quests are checked for limit on /answer - discord: Added limit field for /quest create and /quest update - discord: Changed behavior of fetch_or_init_account
This commit is contained in:
parent
d188bba16e
commit
2640821a05
16 changed files with 192 additions and 69 deletions
|
|
@ -9,5 +9,5 @@ license.workspace = true
|
|||
chrono = "0.4.42"
|
||||
clap = { version = "4.5.53", features = ["derive"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
squad-quest = { version = "0.11.0", path = ".." }
|
||||
squad-quest = { version = "0.12.0", path = ".." }
|
||||
toml = "0.9.8"
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ pub struct QuestCreateArgs {
|
|||
/// Quest expiration date (format = YYYY-MM-DD, ex. 2025-12-24)
|
||||
#[arg(short,long,value_parser = parse_date)]
|
||||
pub deadline: Option<Date>,
|
||||
/// Limit on how many users can solve the quest (0 = no limit)
|
||||
#[arg(short,long)]
|
||||
pub limit: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
|
|
@ -113,6 +116,9 @@ pub struct QuestUpdateArgs {
|
|||
/// Quest expiration date (format = YYYY-MM-DD, ex. 2025-12-24)
|
||||
#[arg(long,value_parser = parse_date)]
|
||||
pub deadline: Option<Date>,
|
||||
/// Limit on how many users can solve the quest (0 = no limit)
|
||||
#[arg(long)]
|
||||
pub limit: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ fn main() {
|
|||
public: args.public,
|
||||
available_on: args.available.clone(),
|
||||
deadline: args.deadline.clone(),
|
||||
limit: args.limit.unwrap_or_default(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
@ -171,6 +172,7 @@ fn main() {
|
|||
public: args.public.unwrap_or(quest.public),
|
||||
available_on: args.available.clone().or(quest.available_on.clone()),
|
||||
deadline: args.deadline.clone().or(quest.deadline.clone()),
|
||||
limit: args.limit.unwrap_or_default(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
@ -284,10 +286,6 @@ fn main() {
|
|||
do_and_log(account.save(path), !cli.quiet, format!("Updated balance of account \"{}\".", account.id));
|
||||
},
|
||||
AccountCommands::Complete(args) => {
|
||||
let Some(account) = accounts.iter_mut().find(|a| a.id == args.account) else {
|
||||
if !cli.quiet { eprintln!("Error: account \"{}\" not found.", args.account); }
|
||||
return;
|
||||
};
|
||||
|
||||
let quests = config.load_quests();
|
||||
|
||||
|
|
@ -299,9 +297,17 @@ fn main() {
|
|||
},
|
||||
};
|
||||
|
||||
match quest.complete_for_account(account) {
|
||||
let result = quest.complete_for_account(&args.account, &mut accounts);
|
||||
|
||||
match result {
|
||||
Err(error) if !cli.quiet => println!("Error: {error}"),
|
||||
Ok(_) => do_and_log(account.save(path), !cli.quiet, format!("Completed quest #{} on account \"{}\".", args.quest, account.id)),
|
||||
Ok(_) => {
|
||||
let Some(account) = accounts.iter_mut().find(|a| a.id == args.account) else {
|
||||
if !cli.quiet { eprintln!("Error: account \"{}\" not found.", args.account); }
|
||||
return;
|
||||
};
|
||||
do_and_log(account.save(path), !cli.quiet, format!("Completed quest #{} on account \"{}\".", args.quest, account.id));
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue