bhcli

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

chat.rs (3686B)


      1 use crate::chatops::{ChatCommand, ChatOpError, ChatOpResult, CommandContext};
      2 
      3 /// Chat linking command
      4 pub struct ChatLinkCommand;
      5 
      6 impl ChatCommand for ChatLinkCommand {
      7    fn name(&self) -> &'static str {
      8        "chatlink"
      9    }
     10    fn description(&self) -> &'static str {
     11        "Link to another user's message"
     12    }
     13    fn usage(&self) -> &'static str {
     14        "/chatlink @user <msg_id>"
     15    }
     16 
     17    fn execute(
     18        &self,
     19        args: Vec<String>,
     20        _context: &CommandContext,
     21    ) -> Result<ChatOpResult, ChatOpError> {
     22        if args.len() < 2 {
     23            return Err(ChatOpError::MissingArguments(
     24                "Please specify user and message ID".to_string(),
     25            ));
     26        }
     27 
     28        let user = &args[0];
     29        let msg_id = &args[1];
     30 
     31        // In a real implementation, you'd look up the message in the database
     32        Ok(ChatOpResult::Message(format!(
     33            "🔗 Link to {}'s message #{}: [View Message](#{}/{})",
     34            user, msg_id, user, msg_id
     35        )))
     36    }
     37 }
     38 
     39 /// Quote message command
     40 pub struct QuoteCommand;
     41 
     42 impl ChatCommand for QuoteCommand {
     43    fn name(&self) -> &'static str {
     44        "quote"
     45    }
     46    fn description(&self) -> &'static str {
     47        "Quote a past message"
     48    }
     49    fn usage(&self) -> &'static str {
     50        "/quote <msg_id>"
     51    }
     52 
     53    fn execute(
     54        &self,
     55        args: Vec<String>,
     56        _context: &CommandContext,
     57    ) -> Result<ChatOpResult, ChatOpError> {
     58        if args.is_empty() {
     59            return Err(ChatOpError::MissingArguments(
     60                "Please specify a message ID".to_string(),
     61            ));
     62        }
     63 
     64        let msg_id = &args[0];
     65 
     66        // In a real implementation, you'd look up the message content
     67        Ok(ChatOpResult::Message(format!(
     68            "💬 Quoting message #{}: \"[Message content would be retrieved from logs]\"",
     69            msg_id
     70        )))
     71    }
     72 }
     73 
     74 /// List rooms command
     75 pub struct RoomsCommand;
     76 
     77 impl ChatCommand for RoomsCommand {
     78    fn name(&self) -> &'static str {
     79        "rooms"
     80    }
     81    fn description(&self) -> &'static str {
     82        "List all available chat rooms"
     83    }
     84    fn usage(&self) -> &'static str {
     85        "/rooms"
     86    }
     87 
     88    fn execute(
     89        &self,
     90        _args: Vec<String>,
     91        _context: &CommandContext,
     92    ) -> Result<ChatOpResult, ChatOpError> {
     93        // In a real implementation, you'd query the server for available rooms
     94        let rooms = vec![
     95            "🏠 #general - Main chat room",
     96            "💻 #dev - Development discussions",
     97            "🔒 #staff - Staff only (if you have access)",
     98            "📝 #help - Help and support",
     99        ];
    100 
    101        Ok(ChatOpResult::Block(
    102            rooms.into_iter().map(|s| s.to_string()).collect(),
    103        ))
    104    }
    105 }
    106 
    107 /// Find user location command
    108 pub struct WhereIsCommand;
    109 
    110 impl ChatCommand for WhereIsCommand {
    111    fn name(&self) -> &'static str {
    112        "whereis"
    113    }
    114    fn description(&self) -> &'static str {
    115        "Find which room a user is active in"
    116    }
    117    fn usage(&self) -> &'static str {
    118        "/whereis <username>"
    119    }
    120 
    121    fn execute(
    122        &self,
    123        args: Vec<String>,
    124        _context: &CommandContext,
    125    ) -> Result<ChatOpResult, ChatOpError> {
    126        if args.is_empty() {
    127            return Err(ChatOpError::MissingArguments(
    128                "Please specify a username".to_string(),
    129            ));
    130        }
    131 
    132        let username = &args[0];
    133 
    134        // In a real implementation, you'd query the server for user location
    135        Ok(ChatOpResult::Message(format!(
    136            "📍 User '{}' was last seen in: #general (5 minutes ago)",
    137            username
    138        )))
    139    }
    140 }