- Added english commands description - Added russian commands description - Changed override option on /quest update to reset dates - Commented out all deadline functionality
90 lines
2.8 KiB
Rust
90 lines
2.8 KiB
Rust
use squad_quest::{SquadObject, map::Map};
|
|
|
|
use crate::{Context, account::fetch_or_init_account, error::Error};
|
|
|
|
/// Unlock specified room if it is reachable and you have required amount of points
|
|
#[poise::command(
|
|
prefix_command,
|
|
slash_command,
|
|
guild_only,
|
|
name_localized("ru", "открыть"),
|
|
description_localized("ru", "Открывает указанную комнату, если хватает очков и до нее можно добраться"),
|
|
)]
|
|
pub async fn unlock(
|
|
ctx: Context<'_>,
|
|
#[description = "Room identifier"]
|
|
#[name_localized("ru", "идентификатор")]
|
|
#[description_localized("ru", "Идентификатор комнаты")]
|
|
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 strings = &ctx.data().strings;
|
|
let formatter = strings.formatter()
|
|
.user(ctx.author())
|
|
.balance(&account, &map)
|
|
.value(id);
|
|
|
|
let reply_string = formatter.fmt(&strings.map.room_unlocked);
|
|
ctx.reply(reply_string).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Move to another unlocked room
|
|
#[poise::command(
|
|
prefix_command,
|
|
slash_command,
|
|
guild_only,
|
|
name_localized("ru", "пойти"),
|
|
description_localized("ru", "Переместиться в другую разблокированную комнату"),
|
|
)]
|
|
pub async fn r#move(
|
|
ctx: Context<'_>,
|
|
#[description = "Identifier of the room to move to"]
|
|
#[name_localized("ru", "идентификатор")]
|
|
#[description_localized("ru", "Идентификатор комнаты, куда переместиться")]
|
|
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 strings = &ctx.data().strings;
|
|
let formatter = strings.formatter()
|
|
.user(ctx.author())
|
|
.value(id);
|
|
|
|
let reply_string = formatter.fmt(&strings.map.moved_to_room);
|
|
ctx.reply(reply_string).await?;
|
|
|
|
Ok(())
|
|
}
|