pub(crate) fn handle_query(buffer: &Buffer, command: &str) -> ReturnCode {
    if command.len() <= "/query ".len() {
        plugin_print("query requires a username");
        return ReturnCode::Ok;
    }

    if buffer.get_localvar("guildid").is_none() {
        return ReturnCode::Ok;
    };

    let owned_cmd = command.to_owned();
    thread::spawn(move || {
        let ctx = match crate::discord::get_ctx() {
            Some(ctx) => ctx,
            _ => return,
        };
        let current_user = &ctx.cache.read().user;
        let substr = &owned_cmd["/query ".len()..].trim();

        let mut found_members: Vec<User> = Vec::new();
        for private_channel in ctx.cache.read().private_channels.values() {
            if private_channel
                .read()
                .name()
                .to_lowercase()
                .contains(&substr.to_lowercase())
            {
                found_members.push(private_channel.read().recipient.read().clone())
            }
        }

        if found_members.is_empty() {
            let guilds = current_user.guilds(ctx).expect("Unable to fetch guilds");
            for guild in &guilds {
                if let Some(guild) = guild.id.to_guild_cached(ctx) {
                    let guild = guild.read().clone();
                    for m in guild.members_containing(substr, false, true) {
                        found_members.push(m.user.read().clone());
                    }
                }
            }
        }
        found_members.dedup_by_key(|mem| mem.id);

        let current_user_name = current_user.name.clone();

        if let Some(target) = found_members.get(0) {
            if let Ok(chan) = target.create_dm_channel(ctx) {
                on_main(move |weechat| {
                    crate::buffers::create_buffer_from_dm(
                        &weechat,
                        Channel::Private(Arc::new(RwLock::new(chan))),
                        &current_user_name,
                        true,
                    );
                });
                return;
            }
        }

        plugin_print(&format!("Could not find user {:?}", substr));
    });
    ReturnCode::OkEat
}
// TODO: Make this faster
// TODO: Handle command options
Make this faster
TODO: Handle command options
Make this faster TODO : Handle command options
pub(crate) fn handle_query(buffer: &Buffer, command: &str) -> ReturnCode {
    if command.len() <= "/query ".len() {
        plugin_print("query requires a username");
        return ReturnCode::Ok;
    }
    if buffer.get_localvar("guildid").is_none() {
        return ReturnCode::Ok;
    };
    let owned_cmd = command.to_owned();
    thread::spawn(move || {
        let ctx = match crate::discord::get_ctx() {
            Some(ctx) => ctx,
            _ => return,
        };
        let current_user = &ctx.cache.read().user;
        let substr = &owned_cmd["/query ".len()..].trim();
        let mut found_members: Vec<User> = Vec::new();
        for private_channel in ctx.cache.read().private_channels.values() {
            if private_channel
                .read()
                .name()
                .to_lowercase()
                .contains(&substr.to_lowercase())
            {
                found_members.push(private_channel.read().recipient.read().clone())
            }
        }
        if found_members.is_empty() {
            let guilds = current_user.guilds(ctx).expect("Unable to fetch guilds");
            for guild in &guilds {
                if let Some(guild) = guild.id.to_guild_cached(ctx) {
                    let guild = guild.read().clone();
                    for m in guild.members_containing(substr, false, true) {
                        found_members.push(m.user.read().clone());
                    }
                }
            }
        }
        found_members.dedup_by_key(|mem| mem.id);
        let current_user_name = current_user.name.clone();
        if let Some(target) = found_members.get(0) {
            if let Ok(chan) = target.create_dm_channel(ctx) {
                on_main(move |weechat| {
                    crate::buffers::create_buffer_from_dm(
                        &weechat,
                        Channel::Private(Arc::new(RwLock::new(chan))),
                        &current_user_name,
                        true,
                    );
                });
                return;
            }
        }
        plugin_print(&format!("Could not find user {:?}", substr));
    });
    ReturnCode::OkEat
}
pub ( crate ) fn handle_query ( buffer : & Buffer , command : & str ) -> ReturnCode { if command . len ( ) <= " " . len ( ) { plugin_print ( " " ) ; return ReturnCode :: Ok ; } if buffer . get_localvar ( " " ) . is_none ( ) { return ReturnCode :: Ok ; } ; let owned_cmd = command . to_owned ( ) ; thread :: spawn ( move | | { let ctx = match crate :: discord :: get_ctx ( ) { Some ( ctx ) => ctx , _ => return , } ; let current_user = & ctx . cache . read ( ) . user ; let substr = & owned_cmd [ " " . len ( ) .. ] . trim ( ) ; let mut found_members : Vec < User > = Vec :: new ( ) ; for private_channel in ctx . cache . read ( ) . private_channels . values ( ) { if private_channel . read ( ) . name ( ) . to_lowercase ( ) . contains ( & substr . to_lowercase ( ) ) { found_members . push ( private_channel . read ( ) . recipient . read ( ) . clone ( ) ) } } if found_members . is_empty ( ) { let guilds = current_user . guilds ( ctx ) . expect ( " " ) ; for guild in & guilds { if let Some ( guild ) = guild . id . to_guild_cached ( ctx ) { let guild = guild . read ( ) . clone ( ) ; for m in guild . members_containing ( substr , false , true ) { found_members . push ( m . user . read ( ) . clone ( ) ) ; } } } } found_members . dedup_by_key ( | mem | mem . id ) ; let current_user_name = current_user . name . clone ( ) ; if let Some ( target ) = found_members . get ( 0 ) { if let Ok ( chan ) = target . create_dm_channel ( ctx ) { on_main ( move | weechat | { crate :: buffers :: create_buffer_from_dm ( & weechat , Channel :: Private ( Arc :: new ( RwLock :: new ( chan ) ) ) , & current_user_name , true , ) ; } ) ; return ; } } plugin_print ( & format ! ( " " substr ) ) ; } ) ; ReturnCode :: OkEat }
TODO: Make this faster
TODO: Handle command options
TODO : Make this faster TODO : Handle command options
buffer
&Buffer
command
&str
buffer
&Buffer
command
&str