pub struct PluginHandle<'ph> { /* private fields */ }
Expand description

A hexchat plugin handle, used to register hooks and interact with hexchat.

Examples

use hexchat_unsafe_plugin::{PluginHandle};

fn init(ph: &mut PluginHandle) {
    ph.register("myplug", "0.1.0", "my awesome plug");
}

Implementations

Registers this hexchat plugin. This must be called exactly once when the plugin is loaded.

Panics

This function panics if this plugin is already registered.

Examples
use hexchat_unsafe_plugin::PluginHandle;

fn init(ph: &mut PluginHandle<'_>) {
    ph.register("foo", "0.1.0", "my foo plugin");
}

Returns this plugin’s registered name.

Panics

This function panics if this plugin is not registered.

Returns this plugin’s registered description.

Panics

This function panics if this plugin is not registered.

Returns this plugin’s registered version.

Panics

This function panics if this plugin is not registered.

Ensures the current context is valid.

Panics

This function may panic if it’s called while hexchat is closing.

source

pub fn for_entry_mut<F, R>(
    &mut self,
    entry: &mut PluginEntryHandle<'ph>,
    f: F
) -> R where
    F: FnOnce(&mut PluginHandle<'ph>) -> R, 

Operates on a virtual plugin.

Examples
use hexchat_unsafe_plugin::{PluginHandle};

fn contexts_can_be_passed_around(ph: &mut PluginHandle<'_>) {
    let ctx = ph.get_context();
    let mut vplug = ph.plugingui_add("foo", "bar", "baz", "qux");
    ph.for_entry_mut(&mut vplug, |ph| {
        ph.set_context(&ctx);
        ph.get_context()
    });
}

Registers a virtual plugin.

Returns the current context.

Note: The returned context may be invalid. Use Self::set_context to check.

Sets the current context.

Returns true if the context is valid, false otherwise.

Do something in a valid context.

Note that this changes the active context and doesn’t change it back (but that should be fine for most use-cases).

Errors

Returns Err(InvalidContextError(f)) if the context is invalid. See set_context. Otherwise, returns Ok(f(...)).

Note that InvalidContextError contains the original closure. This allows you to retry, if you so wish.

Sets a command hook.

Panics

Panics if this is a borrowed PluginEntryHandle.

Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};

fn register_commands<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph, 'ph>> {
    vec![
    ph.hook_command("hello-world", hexchat_unsafe_plugin::PRI_NORM, Some("prints 'Hello, World!'"), |ph, arg, arg_eol| {
        ph.print("Hello, World!");
        hexchat_unsafe_plugin::EAT_ALL
    }),
    ]
}

Sets a server hook.

Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};

fn register_server_hooks<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph, 'ph>> {
    vec![
    ph.hook_server("PRIVMSG", hexchat_unsafe_plugin::PRI_NORM, |ph, word, word_eol| {
        if word.len() > 0 && word[0].starts_with('@') {
            ph.print("We have message tags!?");
        }
        hexchat_unsafe_plugin::EAT_NONE
    }),
    ]
}

Sets a server hook, with attributes.

Sets a print hook.

Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};

fn register_print_hooks<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph, 'ph>> {
    vec![
    ph.hook_print("Channel Message", hexchat_unsafe_plugin::PRI_NORM, |ph, arg| {
        if let Some(nick) = arg.get(0) {
            if *nick == "KnOwN_SpAmMeR" {
                return hexchat_unsafe_plugin::EAT_ALL
            }
        }
        hexchat_unsafe_plugin::EAT_NONE
    }),
    ]
}

Sets a print hook, with attributes.

Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};

fn register_print_hooks<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph, 'ph>> {
    vec![
    ph.hook_print_attrs("Channel Message", hexchat_unsafe_plugin::PRI_NORM, |ph, arg, attrs| {
        if let Some(nick) = arg.get(0) {
            if *nick == "KnOwN_SpAmMeR" {
                return hexchat_unsafe_plugin::EAT_ALL
            }
        }
        hexchat_unsafe_plugin::EAT_NONE
    }),
    ]
}

Sets a timer hook

Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};

fn register_timers<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph, 'ph>> {
    vec![
    ph.hook_timer(2000, |ph| {
        ph.print("timer up!");
        false
    }),
    ]
}

Prints to the hexchat buffer.

Prints to this hexchat buffer.

Glue for usage of the write! macro with hexchat.

Panics

This panics if any broken formatting trait implementations are used in the format arguments. See also format!.

Examples
use hexchat_unsafe_plugin::PluginHandle;

fn hello_world(ph: &mut PluginHandle<'_>) {
    write!(ph, "Hello, world!");
}

Returns context and client information.

See InfoId for the kinds of information that can be retrieved.

Examples
use hexchat_unsafe_plugin::{InfoId, PluginHandle};

/// Returns whether we are currently away.
fn is_away(ph: &mut PluginHandle<'_>) -> bool {
    ph.get_info(InfoId::Away).is_some()
}

Returns the path to the plugin directory, used for auto-loading plugins.

The returned CStr is not guaranteed to be valid UTF-8, but local file system encoding.

Examples
use std::path::PathBuf;

use hexchat_unsafe_plugin::PluginHandle;

// On Unix, we can treat this as an array-of-bytes filesystem path.
#[cfg(unix)]
fn plugin_dir(ph: &PluginHandle<'_>) -> PathBuf {
    use std::ffi::OsString;
    use std::os::unix::ffi::OsStringExt;

    let libdirfs = ph.get_libdirfs().expect("should exist");
    OsString::from_vec(libdirfs.into_bytes()).into()
}

Strips attributes from text. See Strip for which attributes can be stripped.

Examples
use hexchat_unsafe_plugin::{PluginHandle, Strip};

/// Removes colors
fn strip_colors(ph: &PluginHandle<'_>, s: &str) -> String {
    ph.strip(s, Strip::new().colors(true))
}

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.