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
impl PluginHandle
Sourcepub fn get_name(&self) -> &str
pub fn get_name(&self) -> &str
Returns this plugin’s registered name.
§Panics
This function panics if this plugin is not registered.
Sourcepub fn get_description(&self) -> &str
pub fn get_description(&self) -> &str
Returns this plugin’s registered description.
§Panics
This function panics if this plugin is not registered.
Sourcepub fn get_version(&self) -> &str
pub fn get_version(&self) -> &str
Returns this plugin’s registered version.
§Panics
This function panics if this plugin is not registered.
Sourcepub fn ensure_valid_context<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(EnsureValidContext<'_>) -> R,
pub fn ensure_valid_context<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(EnsureValidContext<'_>) -> R,
Ensures the current context is valid.
§Panics
This function may panic if it’s called while hexchat is closing.
Sourcepub fn get_context(&mut self) -> Context
pub fn get_context(&mut self) -> Context
Returns the current context.
Note: The returned context may be invalid. Use set_context to check.
Sourcepub fn set_context(&mut self, ctx: &Context) -> bool
pub fn set_context(&mut self, ctx: &Context) -> bool
Sets the current context.
Returns true if the context is valid, false otherwise.
Sourcepub fn with_context<F, R>(
&mut self,
ctx: &Context,
f: F,
) -> Result<R, InvalidContextError<F, R>>where
F: FnOnce(EnsureValidContext<'_>) -> R,
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.
Sourcepub fn hook_command<F>(
&mut self,
cmd: &str,
cb: F,
pri: i32,
help: Option<&str>,
) -> CommandHookHandle
pub fn hook_command<F>( &mut self, cmd: &str, cb: F, pri: i32, help: Option<&str>, ) -> CommandHookHandle
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!'")),
]
}Sourcepub fn hook_server<F>(&mut self, cmd: &str, cb: F, pri: i32) -> ServerHookHandle
pub fn hook_server<F>(&mut self, cmd: &str, cb: F, pri: i32) -> ServerHookHandle
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),
]
}Sourcepub fn hook_server_attrs<F>(
&mut self,
cmd: &str,
cb: F,
pri: i32,
) -> ServerHookHandlewhere
F: Fn(&mut PluginHandle, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'static + RefUnwindSafe,
pub fn hook_server_attrs<F>(
&mut self,
cmd: &str,
cb: F,
pri: i32,
) -> ServerHookHandlewhere
F: Fn(&mut PluginHandle, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'static + RefUnwindSafe,
Sets a server hook, with attributes.
Sourcepub fn hook_print<F>(&mut self, name: &str, cb: F, pri: i32) -> PrintHookHandle
pub fn hook_print<F>(&mut self, name: &str, cb: F, pri: i32) -> PrintHookHandle
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),
]
}Sourcepub fn hook_print_attrs<F>(
&mut self,
name: &str,
cb: F,
pri: i32,
) -> PrintHookHandle
pub fn hook_print_attrs<F>( &mut self, name: &str, cb: F, pri: i32, ) -> PrintHookHandle
Sets a print hook, with attributes.
Sourcepub fn hook_timer<F>(&mut self, timeout: i32, cb: F) -> TimerHookHandle
pub fn hook_timer<F>(&mut self, timeout: i32, cb: F) -> TimerHookHandle
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
}),
]
}