Struct hexchat_plugin::PluginHandle[][src]

pub struct PluginHandle { /* fields omitted */ }
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

impl PluginHandle[src]

pub fn register(&mut self, name: &str, desc: &str, ver: &str)[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");
}

pub fn get_name(&self) -> &str[src]

Returns this plugin’s registered name.

Panics

This function panics if this plugin is not registered.

pub fn get_description(&self) -> &str[src]

Returns this plugin’s registered description.

Panics

This function panics if this plugin is not registered.

pub fn get_version(&self) -> &str[src]

Returns this plugin’s registered version.

Panics

This function panics if this plugin is not registered.

pub fn ensure_valid_context<F, R>(&mut self, f: F) -> R where
    F: FnOnce(EnsureValidContext<'_>) -> R, 
[src]

Ensures the current context is valid.

Panics

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

pub fn get_context(&mut self) -> Context[src]

Returns the current context.

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

pub fn set_context(&mut self, ctx: &Context) -> bool[src]

Sets the current context.

Returns true if the context is valid, false otherwise.

pub fn with_context<F, R>(
    &mut self,
    ctx: &Context,
    f: F
) -> Result<R, InvalidContextError<F, R>> where
    F: FnOnce(EnsureValidContext<'_>) -> R, 
[src]

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.

pub fn hook_command<F>(
    &mut self,
    cmd: &str,
    cb: F,
    pri: i32,
    help: Option<&str>
) -> CommandHookHandle where
    F: Fn(&mut PluginHandle, Word<'_>, WordEol<'_>) -> Eat + 'static + RefUnwindSafe
[src]

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!'")),
    ]
}

pub fn hook_server<F>(&mut self, cmd: &str, cb: F, pri: i32) -> ServerHookHandle where
    F: Fn(&mut PluginHandle, Word<'_>, WordEol<'_>) -> Eat + 'static + RefUnwindSafe
[src]

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),
    ]
}

pub fn hook_server_attrs<F>(
    &mut self,
    cmd: &str,
    cb: F,
    pri: i32
) -> ServerHookHandle where
    F: Fn(&mut PluginHandle, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'static + RefUnwindSafe
[src]

Sets a server hook, with attributes.

pub fn hook_print<F>(&mut self, name: &str, cb: F, pri: i32) -> PrintHookHandle where
    F: Fn(&mut PluginHandle, Word<'_>) -> Eat + 'static + RefUnwindSafe
[src]

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),
    ]
}

pub fn hook_print_attrs<F>(
    &mut self,
    name: &str,
    cb: F,
    pri: i32
) -> PrintHookHandle where
    F: Fn(&mut PluginHandle, Word<'_>, EventAttrs<'_>) -> Eat + 'static + RefUnwindSafe
[src]

Sets a print hook, with attributes.

pub fn hook_timer<F>(&mut self, timeout: i32, cb: F) -> TimerHookHandle where
    F: Fn(&mut PluginHandle) -> bool + 'static + RefUnwindSafe
[src]

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
    }),
    ]
}

pub fn print<T: ToString>(&mut self, s: T)[src]

Prints to the hexchat buffer.

pub fn get_info(&mut self, id: &InfoId<'_>) -> Option<String>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.