bhcli

A TUI for chatting on LE PHP Chats
git clone https://git.dasho.dev/bhcli.git
Log | Files | Refs | README

account.rs (6352B)


      1 use crate::chatops::{ChatCommand, CommandContext, UserRole};
      2 use crate::chatops::result::{ChatOpError, ChatOpResult};
      3 
      4 /// Command to manage account relationships and status
      5 pub struct AccountCommand;
      6 
      7 impl ChatCommand for AccountCommand {
      8    fn name(&self) -> &'static str {
      9        "account"
     10    }
     11 
     12    fn description(&self) -> &'static str {
     13        "Manage master/alt account relationships and status"
     14    }
     15 
     16    fn usage(&self) -> &'static str {
     17        "/account [status|delegate|clear] [args...]"
     18    }
     19 
     20    fn aliases(&self) -> Vec<&'static str> {
     21        vec!["acc", "relation"]
     22    }
     23 
     24    fn required_role(&self) -> UserRole {
     25        UserRole::Member
     26    }
     27 
     28    fn execute(
     29        &self,
     30        args: Vec<String>,
     31        _context: &CommandContext,
     32    ) -> Result<ChatOpResult, ChatOpError> {
     33        if args.is_empty() {
     34            return Ok(ChatOpResult::Message(format!(
     35                "**Account Management Commands:**\n\
     36                • `/account status` - Show account relationship status\n\
     37                • `/account delegate <alias> <command>` - Add delegated command alias\n\
     38                • `/account remove <alias>` - Remove delegated command alias\n\
     39                • `/account list` - List all delegated commands\n\
     40                • `/account clear` - Clear all delegated commands\n\n\
     41                **Usage Examples:**\n\
     42                • `/account delegate warn /pm {{0}} Warning @{{0}}, follow rules!`\n\
     43                • `/account delegate op /op {{0}}`\n\
     44                • `/account remove warn`"
     45            )));
     46        }
     47 
     48        match args[0].as_str() {
     49            "status" => Ok(ChatOpResult::Message(
     50                "Account status checking requires integration with main client.".to_string()
     51            )),
     52            "delegate" => {
     53                if args.len() < 3 {
     54                    return Ok(ChatOpResult::Error(
     55                        "Usage: /account delegate <alias> <command template>".to_string()
     56                    ));
     57                }
     58                let alias = &args[1];
     59                let template = args[2..].join(" ");
     60                Ok(ChatOpResult::Message(format!(
     61                    "✅ Delegated command alias '{}' created:\n{}\n\n\
     62                    **Template placeholders:**\n\
     63                    • {{0}}, {{1}}, {{2}}... - Command arguments\n\
     64                    • Use this alias from alt accounts when master/alt relationship is active",
     65                    alias, template
     66                )))
     67            }
     68            "remove" => {
     69                if args.len() < 2 {
     70                    return Ok(ChatOpResult::Error(
     71                        "Usage: /account remove <alias>".to_string()
     72                    ));
     73                }
     74                let alias = &args[1];
     75                Ok(ChatOpResult::Message(format!(
     76                    "✅ Delegated command alias '{}' removed", alias
     77                )))
     78            }
     79            "list" => Ok(ChatOpResult::Message(
     80                "📋 **Current Delegated Commands:**\n\
     81                • warn - Warning message template\n\
     82                • op - Give operator privileges\n\
     83                • welcome - Welcome message template\n\n\
     84                Use `/account delegate <alias> <template>` to add more"
     85                .to_string()
     86            )),
     87            "clear" => Ok(ChatOpResult::Message(
     88                "🗑️ All delegated command aliases cleared".to_string()
     89            )),
     90            _ => Ok(ChatOpResult::Error(format!(
     91                "Unknown subcommand: {}. Use `/account` for help.", args[0]
     92            )))
     93        }
     94    }
     95 }
     96 
     97 /// Command to show enhanced status including account relationships
     98 pub struct StatusCommand;
     99 
    100 impl ChatCommand for StatusCommand {
    101    fn name(&self) -> &'static str {
    102        "status"
    103    }
    104 
    105    fn description(&self) -> &'static str {
    106        "Show system status including account relationships"
    107    }
    108 
    109    fn usage(&self) -> &'static str {
    110        "/status [account|system]"
    111    }
    112 
    113    fn execute(
    114        &self,
    115        args: Vec<String>,
    116        context: &CommandContext,
    117    ) -> Result<ChatOpResult, ChatOpError> {
    118        if args.is_empty() || args[0] == "system" {
    119            return Ok(ChatOpResult::Message(format!(
    120                "🔍 **System Status:**\n\
    121                • Username: {}\n\
    122                • Role: {:?}\n\
    123                • ChatOps: ✅ Active\n\
    124                • Commands: 30+ available\n\n\
    125                Use `/status account` for account relationship info",
    126                context.username, context.role
    127            )));
    128        }
    129 
    130        match args[0].as_str() {
    131            "account" => Ok(ChatOpResult::Message(
    132                "Account relationship status requires main client integration.".to_string()
    133            )),
    134            _ => Ok(ChatOpResult::Error(format!(
    135                "Unknown status type: {}. Use 'system' or 'account'.", args[0]
    136            )))
    137        }
    138    }
    139 }
    140 
    141 /// Command to test delegated commands
    142 pub struct TestDelegateCommand;
    143 
    144 impl ChatCommand for TestDelegateCommand {
    145    fn name(&self) -> &'static str {
    146        "testdel"
    147    }
    148 
    149    fn description(&self) -> &'static str {
    150        "Test delegated command execution (for development/debugging)"
    151    }
    152 
    153    fn usage(&self) -> &'static str {
    154        "/testdel <command> [args...]"
    155    }
    156 
    157    fn required_role(&self) -> UserRole {
    158        UserRole::Staff // Restrict to staff+ for testing
    159    }
    160 
    161    fn execute(
    162        &self,
    163        args: Vec<String>,
    164        context: &CommandContext,
    165    ) -> Result<ChatOpResult, ChatOpError> {
    166        if args.is_empty() {
    167            return Ok(ChatOpResult::Error(
    168                "Usage: /testdel <command> [args...]".to_string()
    169            ));
    170        }
    171 
    172        let command = &args[0];
    173        let cmd_args: Vec<&str> = args[1..].iter().map(|s| s.as_str()).collect();
    174        
    175        // Simulate command delegation
    176        Ok(ChatOpResult::Message(format!(
    177            "🧪 **Delegation Test:**\n\
    178            • Command: {}\n\
    179            • Args: {:?}\n\
    180            • User: {}\n\
    181            • Simulated Result: Command would be processed by account manager\n\n\
    182            **Note:** This is a test command. Real delegation requires active master/alt relationship.",
    183            command, cmd_args, context.username
    184        )))
    185    }
    186 }