squad-quest/discord/src/commands/map.rs
2ndbeam b6ea2d8958 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
2025-12-15 15:19:07 +03:00

67 lines
1.6 KiB
Rust

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(())
}