You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

use std::default::Default;
use mio::Token;
use strum_macros::{Display, EnumIter};
use crate::command::{CommandSetRoomDescription, Parse, ParserError};
use crate::database::Db;
use crate::queue::SendQueue;
/// Set room properties
#[derive(Clone, Debug, Display, EnumIter, Eq, Ord, PartialEq, PartialOrd)]
pub enum CommandSetRoom {
/// Change the room description
Description(CommandSetRoomDescription),
/// Set the room name
Name,
Default,
}
impl Default for CommandSetRoom {
fn default() -> Self {
Self::Default
}
}
impl Parse for CommandSetRoom {
fn help(&self) -> &str {
match self {
Self::Description(_) => "",
Self::Name => "set room name NEW_NAME :: Set room name to NEW_NAME.",
Self::Default => "",
}
}
fn parse_subcommand(&self, s: String) -> Result<(Self, String), ParserError> {
match self {
Self::Description(_) => {
let (command, args) = CommandSetRoomDescription::parse(s)?;
Ok((Self::Description(command), args))
}
Self::Default => Err(ParserError::Default),
_ => Ok((self.clone(), s)),
}
}
fn dispatch_map_subcommand(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
match self {
Self::Description(command) => command.dispatch(command, args, token, db),
_ => SendQueue::new(),
}
}
fn dispatch_map(&self) -> fn(&Self, String, Token, &mut Db) -> SendQueue {
match self {
Self::Description(_) => Self::dispatch_map_subcommand,
Self::Name => Self::dispatch_name,
Self::Default => Self::dispatch_default,
}
}
}