pub struct PluginHandle { /* private fields */ }
Expand description

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

Examples

use hexchat_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_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.

Returns the current context.

Note: The returned context may be invalid. Use 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.

Errors

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

Note that InvalidContextError contains the original closure. This allows you to retry.

Sets a command hook.

Examples
use hexchat_plugin::{PluginHandle, CommandHookHandle};

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

Sets a server hook.

Examples
use hexchat_plugin::{PluginHandle, ServerHookHandle};

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

Sets a server hook, with attributes.

Sets a print hook.

Examples
use hexchat_plugin::{PluginHandle, PrintHookHandle};

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

Sets a print hook, with attributes.

Sets a timer hook

Examples
use hexchat_plugin::{PluginHandle, TimerHookHandle};

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

Prints to the hexchat buffer.

Returns information on the current context.

Note: InfoId::Libdirfs may return None or broken results if the result wouldn’t be (valid) UTF-8.

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.