PluginHandle

Struct PluginHandle 

Source
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§

Source§

impl PluginHandle

Source

pub fn register(&mut self, name: &str, desc: &str, ver: &str)

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

pub fn get_name(&self) -> &str

Returns this plugin’s registered name.

§Panics

This function panics if this plugin is not registered.

Source

pub fn get_description(&self) -> &str

Returns this plugin’s registered description.

§Panics

This function panics if this plugin is not registered.

Source

pub fn get_version(&self) -> &str

Returns this plugin’s registered version.

§Panics

This function panics if this plugin is not registered.

Source

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

Ensures the current context is valid.

§Panics

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

Source

pub fn get_context(&mut self) -> Context

Returns the current context.

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

Source

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

Sets the current context.

Returns true if the context is valid, false otherwise.

Source

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

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.

Source

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,

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

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

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

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,

Sets a server hook, with attributes.

Source

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

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

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,

Sets a print hook, with attributes.

Source

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

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

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

Prints to the hexchat buffer.

Source

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

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.