feat: Completed commands list
- Added MapError::CannotReach variant - Updated Map::unlock_room_for_account to check reachableness - Added /info command - Added /unlock command - Added /move command - Added /reset command
This commit is contained in:
parent
4ba57b925a
commit
b6ea2d8958
11 changed files with 170 additions and 12 deletions
67
discord/src/commands/map.rs
Normal file
67
discord/src/commands/map.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use squad_quest::{SquadObject, map::Map};
|
||||
|
||||
use crate::{Context, account::fetch_or_init_account, error::Error};
|
||||
|
||||
#[poise::command(
|
||||
prefix_command,
|
||||
slash_command,
|
||||
guild_only,
|
||||
)]
|
||||
pub async fn unlock(
|
||||
ctx: Context<'_>,
|
||||
id: u16,
|
||||
) -> Result<(), Error> {
|
||||
let conf = &ctx.data().config;
|
||||
|
||||
let map_path = conf.full_map_path();
|
||||
let map = Map::load(map_path)?;
|
||||
|
||||
let Some(room) = map.room.iter().find(|r| r.id == id) else {
|
||||
return Err(Error::RoomNotFound(id));
|
||||
};
|
||||
|
||||
let acc_id = format!("{}", ctx.author().id.get());
|
||||
let mut account = fetch_or_init_account(conf, acc_id);
|
||||
|
||||
if account.balance < room.value {
|
||||
return Err(Error::InsufficientFunds(room.value));
|
||||
}
|
||||
|
||||
map.unlock_room_for_account(id, &mut account)?;
|
||||
|
||||
let account_path = conf.full_accounts_path();
|
||||
account.save(account_path)?;
|
||||
|
||||
let reply_string = format!("Unlocked room #{id}. Your balance: {} points", account.balance);
|
||||
ctx.reply(reply_string).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[poise::command(
|
||||
prefix_command,
|
||||
slash_command,
|
||||
guild_only,
|
||||
)]
|
||||
pub async fn r#move(
|
||||
ctx: Context<'_>,
|
||||
id: u16,
|
||||
) -> Result<(), Error> {
|
||||
let conf = &ctx.data().config;
|
||||
|
||||
let acc_id = format!("{}", ctx.author().id.get());
|
||||
let mut account = fetch_or_init_account(conf, acc_id);
|
||||
|
||||
if let None = account.rooms_unlocked.iter().find(|rid| **rid == id) {
|
||||
return Err(Error::RoomNotFound(id));
|
||||
}
|
||||
|
||||
account.location = id;
|
||||
let account_path = conf.full_accounts_path();
|
||||
account.save(account_path)?;
|
||||
|
||||
let reply_string = format!("Moved to room #{id}.");
|
||||
ctx.reply(reply_string).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue