Struct hexchat_unsafe_plugin::ValidContext
source · [−]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
sourceimpl<'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> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_command<'f, F>(
&self,
cmd: &str,
pri: i32,
help: Option<&str>,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a command hook.
sourcepub fn hook_server<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_server<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
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> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_print<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a print hook.
sourcepub fn hook_print_attrs<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_print_attrs<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a print hook with attributes.
sourcepub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe,
'f: 'ph,
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.
sourcepub fn raw_poshigh(&self) -> i32
pub fn raw_poshigh(&self) -> i32
File position, MSB 32 bits.
sourcepub fn raw_resume(&self) -> i32
pub fn raw_resume(&self) -> i32
Resumed position, LSB 32 bits.
sourcepub fn raw_resumehigh(&self) -> i32
pub fn raw_resumehigh(&self) -> i32
Resumed position, MSB 32 bits.
sourcepub fn raw_sizehigh(&self) -> i32
pub fn raw_sizehigh(&self) -> i32
File size, MSB 32 bits.
sourcepub fn raw_status(&self) -> i32
pub fn raw_status(&self) -> i32
Raw DCC status.
sourcepub fn raw_lasttalk(&self) -> time_t
pub fn raw_lasttalk(&self) -> time_t
Time when the user last talked.
Trait Implementations
Auto Trait Implementations
impl<'a, 'ph> RefUnwindSafe for ValidContext<'a, 'ph>
impl<'a, 'ph> !Send for ValidContext<'a, 'ph>
impl<'a, 'ph> !Sync for ValidContext<'a, 'ph>
impl<'a, 'ph> Unpin for ValidContext<'a, 'ph> where
'ph: 'a,
impl<'a, 'ph> UnwindSafe for ValidContext<'a, '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