- Added string formatter - Added Strings struct for passing strings from file - Refactored /info and /quest * to use formatter BREAKING CHANGE: Changed DiscordConfig fields
33 lines
932 B
Rust
33 lines
932 B
Rust
use poise::serenity_prelude::UserId;
|
|
use squad_quest::{account::Account, config::Config, map::Map};
|
|
|
|
pub fn fetch_or_init_account(conf: &Config, id: String) -> Account {
|
|
let accounts = conf.load_accounts();
|
|
match accounts.iter().find(|a| a.id == id) {
|
|
Some(a) => a.clone(),
|
|
None => Account {
|
|
id,
|
|
..Default::default()
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn account_rooms_value(account: &Account, map: &Map) -> u32 {
|
|
map.room.iter().filter_map(|r| {
|
|
if account.rooms_unlocked.contains(&r.id) {
|
|
Some(r.value)
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.sum()
|
|
}
|
|
|
|
pub fn account_full_balance(account: &Account, map: &Map) -> u32 {
|
|
let rooms_value = account_rooms_value(account, map);
|
|
account.balance + rooms_value
|
|
}
|
|
|
|
pub fn account_user_id(account: &Account) -> UserId {
|
|
UserId::new(account.id.clone().parse::<u64>().expect("automatically inserted"))
|
|
}
|