[−][src]Struct hexchat_plugin::PluginHandle
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]
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]
F: FnOnce(EnsureValidContext) -> R,
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]
&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.
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]
&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!'")), ] }
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]
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), ] }
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]
&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.
pub fn hook_print<F>(&mut self, name: &str, cb: F, pri: i32) -> PrintHookHandle where
F: Fn(&mut PluginHandle, Word) -> Eat + 'static + RefUnwindSafe,
[src]
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), ] }
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]
&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.
pub fn hook_timer<F>(&mut self, timeout: i32, cb: F) -> TimerHookHandle where
F: Fn(&mut PluginHandle) -> bool + 'static + RefUnwindSafe,
[src]
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 }), ] }
pub fn print(&mut self, s: &str)
[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
impl !Send for PluginHandle
impl !Sync for PluginHandle
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,