Struct hexchat_plugin::PluginHandle[][src]

pub struct PluginHandle { /* fields omitted */ }

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");
}

Methods

impl PluginHandle
[src]

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;

fn register_commands(ph: &mut PluginHandle) {
    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;

fn register_server_hooks(ph: &mut PluginHandle) {
    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;

fn register_print_hooks(ph: &mut PluginHandle) {
    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;

fn register_timers(ph: &mut PluginHandle) {
    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

impl !Send for PluginHandle

impl !Sync for PluginHandle