Dough Git

clove/proxyBot

src/commands/switch/mod.rs

back to src/commands/switch

// src/commands/switch/mod.rs

use crate::{Bot, proxy};

impl Bot {
    pub(super) async fn switch(&self, args: &[String]) -> String {
        if args.is_empty() {
            return "Use `d$switch <member>`, like `d$switch c1`, several like `d$sw c1 c2`, or `d$sw out`.".into();
        }

        if args == ["out"] {
            return match self.switch_front(&[]).await {
                Ok(()) => "Switched out. Nobody is fronting.".into(),
                Err(problem) => problem,
            };
        }

        let found = match self.command_members(args).await {
            Ok(found) => found,
            Err(problem) => return problem,
        };

        let ids = found
        .iter()
        .map(|member| member.id.as_str())
        .collect::<Vec<_>>();

        match self.switch_front(&ids).await {
            Ok(()) => {
                let speakers = found.iter().collect::<Vec<_>>();
                format!("Switched in **{}**.", proxy::webhook_name(&speakers, None))
            }
            Err(problem) => problem,
        }
    }
}