pub struct ValidContext<'a, 'ph: 'a> { /* private fields */ }Expand description
A PluginHandle operating on a valid context.
Methods that require a valid plugin context are only available through this. Methods that may invalidate the plugin context also consume this.
See also PluginHandle::ensure_valid_context.
Implementations§
Source§impl<'a, 'ph: 'a> ValidContext<'a, 'ph>
impl<'a, 'ph: 'a> ValidContext<'a, 'ph>
Sourcepub fn find_context(
&self,
servname: Option<&str>,
channel: Option<&str>,
) -> Option<Context<'ph>>
pub fn find_context( &self, servname: Option<&str>, channel: Option<&str>, ) -> Option<Context<'ph>>
Finds an open context for the given servname and channel.
Sourcepub fn nickcmp(&self, nick1: &str, nick2: &str) -> Ordering
pub fn nickcmp(&self, nick1: &str, nick2: &str) -> Ordering
Compares two nicks based on the server’s case mapping.
use hexchat_unsafe_plugin::ValidContext;
/// Checks if the two nicks below are equal.
fn compare_nicks(context: ValidContext<'_, '_>) -> bool {
context.nickcmp("hello", "HELLO").is_eq()
}Sourcepub fn send_modes<'b, I: IntoIterator<Item = &'b str>>(
&mut self,
iter: I,
mpl: i32,
sign: char,
mode: char,
)
pub fn send_modes<'b, I: IntoIterator<Item = &'b str>>( &mut self, iter: I, mpl: i32, sign: char, mode: char, )
Sends a list of modes to the current channel.
Sourcepub fn get_prefs(&self, name: &str) -> Option<PrefValue>
pub fn get_prefs(&self, name: &str) -> Option<PrefValue>
Returns a client setting.
§Examples
use hexchat_unsafe_plugin::ValidContext;
/// Returns the user's configured main nick.
fn main_nick(context: ValidContext<'_, '_>) -> String {
context.get_prefs("irc_nick1").unwrap().into_string().unwrap()
}Sourcepub fn command(self, cmd: &str)
pub fn command(self, cmd: &str)
Executes a command.
§Examples
use hexchat_unsafe_plugin::{ValidContext};
fn join(context: ValidContext<'_, '_>, channel: &str) {
context.command(&format!("join {}", channel));
}Sourcepub fn emit_print<'b, I: IntoIterator<Item = &'b str>>(
self,
event: &str,
args: I,
) -> bool
pub fn emit_print<'b, I: IntoIterator<Item = &'b str>>( self, event: &str, args: I, ) -> bool
Prints an event message, and returns a success status (whether or not the event exists).
§Examples
use hexchat_unsafe_plugin::{ValidContext};
fn emit_channel_message(context: ValidContext<'_, '_>, nick: &str, msg: &str) {
context.emit_print("Channel Message", [nick, msg]);
}Sourcepub fn emit_print_attrs<'b, I: IntoIterator<Item = &'b str>>(
self,
attrs: EventAttrs<'_>,
event: &str,
args: I,
) -> bool
pub fn emit_print_attrs<'b, I: IntoIterator<Item = &'b str>>( self, attrs: EventAttrs<'_>, event: &str, args: I, ) -> bool
Prints an event message, and returns a success status (whether or not the event exists).
Also allows setting event attributes.
§Examples
use std::time::SystemTime;
use hexchat_unsafe_plugin::{EventAttrs, ValidContext};
fn emit_channel_message_at(context: ValidContext<'_, '_>, time: Option<SystemTime>, nick: &str, msg: &str) {
let mut attrs = EventAttrs::new();
attrs.server_time = time;
context.emit_print_attrs(attrs, "Channel Message", [nick, msg]);
}Sourcepub fn list<T: List>(&'a self, t: &'a T) -> Entries<'a, 'ph, T>
pub fn list<T: List>(&'a self, t: &'a T) -> Entries<'a, 'ph, T>
Retrieves a list.
§Examples
use hexchat_unsafe_plugin::list::Contexts;
use hexchat_unsafe_plugin::PluginHandle;
fn print_contexts(ph: &mut PluginHandle<'_>) {
ph.ensure_valid_context(|ph| {
let mut contexts = ph.list(&Contexts);
while let Some(context) = contexts.next() {
write!(ph, "{}", context.name().unwrap());
}
})
}Sourcepub fn get_context(&self) -> Context<'ph>
pub fn get_context(&self) -> Context<'ph>
Returns the current context.
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 print<T: ToString>(&self, s: T)
pub fn print<T: ToString>(&self, s: T)
Prints to the hexchat buffer.
See PluginHandle::print.
Sourcepub fn write_fmt(&self, fmt: Arguments<'_>)
pub fn write_fmt(&self, fmt: Arguments<'_>)
Sourcepub fn hook_command<'f, F>(
&self,
cmd: &str,
pri: i32,
help: Option<&str>,
cb: F,
) -> HookHandle<'ph, 'f>
pub fn hook_command<'f, F>( &self, cmd: &str, pri: i32, help: Option<&str>, cb: F, ) -> HookHandle<'ph, 'f>
Sets a command hook.
Sourcepub fn hook_server<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F,
) -> HookHandle<'ph, 'f>
pub fn hook_server<'f, F>( &self, cmd: &str, pri: i32, cb: F, ) -> HookHandle<'ph, 'f>
Sets a server hook.
Sourcepub fn hook_server_attrs<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F,
) -> HookHandle<'ph, 'f>where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_server_attrs<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F,
) -> HookHandle<'ph, 'f>where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a server hook with attributes.
Sourcepub fn hook_print<'f, F>(
&self,
name: &str,
pri: i32,
cb: F,
) -> HookHandle<'ph, 'f>
pub fn hook_print<'f, F>( &self, name: &str, pri: i32, cb: F, ) -> HookHandle<'ph, 'f>
Sets a print hook.
Sourcepub fn hook_print_attrs<'f, F>(
&self,
name: &str,
pri: i32,
cb: F,
) -> HookHandle<'ph, 'f>
pub fn hook_print_attrs<'f, F>( &self, name: &str, pri: i32, cb: F, ) -> HookHandle<'ph, 'f>
Sets a print hook with attributes.
Sourcepub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f>
pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f>
Sets a timer hook.
Sourcepub fn get_info<'b>(&'b self, id: InfoId<'_>) -> Option<Cow<'b, str>>
pub fn get_info<'b>(&'b self, id: InfoId<'_>) -> Option<Cow<'b, str>>
Returns context and client information.
Sourcepub fn get_libdirfs(&self) -> Option<CString>
pub fn get_libdirfs(&self) -> Option<CString>
Returns the plugin directory.
Sourcepub fn strip(&self, s: &str, strip: Strip) -> String
pub fn strip(&self, s: &str, strip: Strip) -> String
Strips attributes from text.
See PluginHandle::strip.
Sourcepub fn pluginpref_set(
&self,
var: &str,
value: &str,
) -> Result<(), PluginPrefError>
pub fn pluginpref_set( &self, var: &str, value: &str, ) -> Result<(), PluginPrefError>
Sets a pluginpref.
Sourcepub fn pluginpref_get(&self, var: &str) -> Result<String, PluginPrefError>
pub fn pluginpref_get(&self, var: &str) -> Result<String, PluginPrefError>
Retrieves a pluginpref.
Sourcepub fn pluginpref_delete(&self, var: &str) -> Result<(), PluginPrefError>
pub fn pluginpref_delete(&self, var: &str) -> Result<(), PluginPrefError>
Removes a pluginpref.
Sourcepub fn pluginpref_list(&self) -> Result<PluginPrefList, PluginPrefError>
pub fn pluginpref_list(&self) -> Result<PluginPrefList, PluginPrefError>
Lists pluginprefs.
Methods from Deref<Target = Fields<'a, 'ph, Contexts>>§
Sourcepub fn channelkey(&self) -> Option<String>
pub fn channelkey(&self) -> Option<String>
The channel key.
Sourcepub fn chanmodes(&self) -> Option<String>
pub fn chanmodes(&self) -> Option<String>
The server’s channel modes. Requires HexChat 2.12.2+.
Sourcepub fn maxmodes(&self) -> i32
pub fn maxmodes(&self) -> i32
The maximum number of mode changes per line accepted by the server.
Sourcepub fn nickprefixes(&self) -> Option<String>
pub fn nickprefixes(&self) -> Option<String>
The server’s nick prefixes.