Struct hexchat_unsafe_plugin::PluginHandle
source · [−]pub struct PluginHandle<'ph> { /* private fields */ }
Expand description
A hexchat plugin handle, used to register hooks and interact with hexchat.
Examples
use hexchat_unsafe_plugin::{PluginHandle};
fn init(ph: &mut PluginHandle) {
ph.register("myplug", "0.1.0", "my awesome plug");
}
Implementations
sourceimpl<'ph> PluginHandle<'ph>
impl<'ph> PluginHandle<'ph>
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) -> R where
F: for<'a> FnOnce(ValidContext<'a, 'ph>) -> R,
pub fn ensure_valid_context<F, R>(&mut self, f: F) -> R where
F: for<'a> FnOnce(ValidContext<'a, 'ph>) -> 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<'ph>
pub fn get_context(&mut self) -> Context<'ph>
Returns the current context.
Note: The returned context may be invalid. Use set_context
to
check.
sourcepub fn set_context(&mut self, ctx: &Context<'ph>) -> bool
pub fn set_context(&mut self, ctx: &Context<'ph>) -> bool
Sets the current context.
Returns true
if the context is valid, false
otherwise.
sourcepub fn with_context<F, R>(
&mut self,
ctx: &Context<'ph>,
f: F
) -> Result<R, InvalidContextError<F>> where
F: for<'a> FnOnce(ValidContext<'a, 'ph>) -> R,
pub fn with_context<F, R>(
&mut self,
ctx: &Context<'ph>,
f: F
) -> Result<R, InvalidContextError<F>> where
F: for<'a> FnOnce(ValidContext<'a, 'ph>) -> R,
Do something in a valid context.
Note that this changes the active context and doesn’t change it back (but that should be fine for most use-cases).
Errors
Returns Err(InvalidContextError(f))
if the context is invalid. See
set_context
. Otherwise, returns Ok(f(...))
.
Note that InvalidContextError
contains the original closure. This
allows you to retry, if you so wish.
sourcepub fn hook_command<F>(
&mut self,
cmd: &str,
pri: i32,
help: Option<&str>,
cb: F
) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'ph + RefUnwindSafe,
pub fn hook_command<F>(
&mut self,
cmd: &str,
pri: i32,
help: Option<&str>,
cb: F
) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'ph + RefUnwindSafe,
Sets a command hook.
Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};
fn register_commands<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph>> {
vec![
ph.hook_command("hello-world", hexchat_unsafe_plugin::PRI_NORM, Some("prints 'Hello, World!'"), |ph, arg, arg_eol| {
ph.print("Hello, World!");
hexchat_unsafe_plugin::EAT_ALL
}),
]
}
sourcepub fn hook_server<F>(&mut self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'ph + RefUnwindSafe,
pub fn hook_server<F>(&mut self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'ph + RefUnwindSafe,
Sets a server hook.
Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};
fn register_server_hooks<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph>> {
vec![
ph.hook_server("PRIVMSG", hexchat_unsafe_plugin::PRI_NORM, |ph, word, word_eol| {
if word.len() > 0 && word[0].starts_with('@') {
ph.print("We have message tags!?");
}
hexchat_unsafe_plugin::EAT_NONE
}),
]
}
sourcepub fn hook_server_attrs<F>(
&mut self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'ph + RefUnwindSafe,
pub fn hook_server_attrs<F>(
&mut self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'ph + RefUnwindSafe,
Sets a server hook, with attributes.
sourcepub fn hook_print<F>(&mut self, name: &str, pri: i32, cb: F) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>) -> Eat + 'ph + RefUnwindSafe,
pub fn hook_print<F>(&mut self, name: &str, pri: i32, cb: F) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>) -> Eat + 'ph + RefUnwindSafe,
Sets a print hook.
Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};
fn register_print_hooks<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph>> {
vec![
ph.hook_print("Channel Message", hexchat_unsafe_plugin::PRI_NORM, |ph, arg| {
if let Some(nick) = arg.get(0) {
if *nick == "KnOwN_SpAmMeR" {
return hexchat_unsafe_plugin::EAT_ALL
}
}
hexchat_unsafe_plugin::EAT_NONE
}),
]
}
sourcepub fn hook_print_attrs<F>(
&mut self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, EventAttrs<'_>) -> Eat + 'ph + RefUnwindSafe,
pub fn hook_print_attrs<F>(
&mut self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, EventAttrs<'_>) -> Eat + 'ph + RefUnwindSafe,
Sets a print hook, with attributes.
Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};
fn register_print_hooks<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph>> {
vec![
ph.hook_print_attrs("Channel Message", hexchat_unsafe_plugin::PRI_NORM, |ph, arg, attrs| {
if let Some(nick) = arg.get(0) {
if *nick == "KnOwN_SpAmMeR" {
return hexchat_unsafe_plugin::EAT_ALL
}
}
hexchat_unsafe_plugin::EAT_NONE
}),
]
}
sourcepub fn hook_timer<F>(&mut self, timeout: i32, cb: F) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>) -> bool + 'ph + RefUnwindSafe,
pub fn hook_timer<F>(&mut self, timeout: i32, cb: F) -> HookHandle<'ph> where
F: Fn(&mut PluginHandle<'ph>) -> bool + 'ph + RefUnwindSafe,
Sets a timer hook
Examples
use hexchat_unsafe_plugin::{PluginHandle, HookHandle};
fn register_timers<'ph>(ph: &mut PluginHandle<'ph>) -> Vec<HookHandle<'ph>> {
vec![
ph.hook_timer(2000, |ph| {
ph.print("timer up!");
false
}),
]
}
Auto Trait Implementations
impl<'ph> RefUnwindSafe for PluginHandle<'ph>
impl<'ph> !Send for PluginHandle<'ph>
impl<'ph> !Sync for PluginHandle<'ph>
impl<'ph> Unpin for PluginHandle<'ph>
impl<'ph> UnwindSafe for PluginHandle<'ph>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more