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:
Alexey 2025-12-15 15:19:07 +03:00
commit b6ea2d8958
11 changed files with 170 additions and 12 deletions

View file

@ -1,6 +1,7 @@
use std::fmt::Display;
use poise::serenity_prelude as serenity;
use squad_quest::error::MapError;
#[non_exhaustive]
#[derive(Debug)]
@ -15,6 +16,9 @@ pub enum Error {
SquadQuestError(squad_quest::error::Error),
AccountNotFound,
InsufficientFunds(u32),
RoomNotFound(u16),
RoomAlreadyUnlocked(u16),
CannotReach(u16),
}
impl From<serenity::Error> for Error {
@ -29,6 +33,18 @@ impl From<squad_quest::error::Error> for Error {
}
}
impl From<squad_quest::error::MapError> for Error {
fn from(value: squad_quest::error::MapError) -> Self {
match value {
MapError::RoomNotFound(id) => Self::RoomNotFound(id),
MapError::RoomAlreadyUnlocked(id, _) => Self::RoomAlreadyUnlocked(id),
MapError::InsufficientFunds(_, _, amount) => Self::InsufficientFunds(amount),
MapError::CannotReach(id, _) => Self::CannotReach(id),
_ => unreachable!(),
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
@ -41,7 +57,10 @@ impl Display for Error {
Self::SerenityError(_) => write!(f, "discord interaction error"),
Self::SquadQuestError(_) => write!(f, "internal logic error"),
Self::AccountNotFound => write!(f, "account not found"),
Self::InsufficientFunds(amount) => write!(f, "account does not have {amount} points"),
Self::InsufficientFunds(amount) => write!(f, "user does not have {amount} points"),
Self::RoomNotFound(id) => write!(f, "room #{id} not found"),
Self::RoomAlreadyUnlocked(id) => write!(f, "room #{id} is already unlocked for this user"),
Self::CannotReach(id) => write!(f, "user cannot reach room #{id}"),
}
}
}
@ -56,7 +75,10 @@ impl std::error::Error for Error {
Self::NoChannelOrUser |
Self::BothChannelAndUser |
Self::AccountNotFound |
Self::InsufficientFunds(_) => None,
Self::InsufficientFunds(_) |
Self::RoomNotFound(_) |
Self::RoomAlreadyUnlocked(_) |
Self::CannotReach(_) => None,
Self::SerenityError(error) => Some(error),
Self::SquadQuestError(error) => Some(error),
}