components

This commit is contained in:
2021-09-11 20:40:58 +01:00
parent 9b5333dc87
commit 3e547861ea
11 changed files with 310 additions and 237 deletions

View File

@@ -1,14 +1,16 @@
use serde::{Deserialize, Serialize};
use serenity::model::id::ChannelId;
use crate::consts::REGEX_CHANNEL;
#[derive(Serialize, Deserialize)]
pub enum TimeDisplayType {
Absolute,
Relative,
Absolute = 0,
Relative = 1,
}
#[derive(Serialize, Deserialize)]
pub struct LookFlags {
pub limit: u16,
pub show_disabled: bool,
pub channel_id: Option<ChannelId>,
pub time_display: TimeDisplayType,
@@ -16,44 +18,6 @@ pub struct LookFlags {
impl Default for LookFlags {
fn default() -> Self {
Self {
limit: u16::MAX,
show_disabled: true,
channel_id: None,
time_display: TimeDisplayType::Relative,
}
}
}
impl LookFlags {
pub fn from_string(args: &str) -> Self {
let mut new_flags: Self = Default::default();
for arg in args.split(' ') {
match arg {
"enabled" => {
new_flags.show_disabled = false;
}
"time" => {
new_flags.time_display = TimeDisplayType::Absolute;
}
param => {
if let Ok(val) = param.parse::<u16>() {
new_flags.limit = val;
} else if let Some(channel) = REGEX_CHANNEL
.captures(arg)
.map(|cap| cap.get(1))
.flatten()
.map(|c| c.as_str().parse::<u64>().unwrap())
{
new_flags.channel_id = Some(ChannelId(channel));
}
}
}
}
new_flags
Self { show_disabled: true, channel_id: None, time_display: TimeDisplayType::Relative }
}
}