ValidContext

Struct 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§

Source§

impl<'a, 'ph: 'a> ValidContext<'a, 'ph>

Source

pub fn find_context( &self, servname: Option<&str>, channel: Option<&str>, ) -> Option<Context<'ph>>

Finds an open context for the given servname and channel.

Source

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()
}
Source

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.

Source

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()
}
Source

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));
}
Source

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]);
}
Source

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]);
}
Source

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());
        }
    })
}
Source

pub fn get_context(&self) -> Context<'ph>

Returns the current context.

See PluginHandle::get_context.

Source

pub fn set_context(&mut self, ctx: &Context<'ph>) -> bool

Sets the current context.

Returns true if the context is valid, false otherwise.

See PluginHandle::set_context.

Source

pub fn print<T: ToString>(&self, s: T)

Prints to the hexchat buffer.

See PluginHandle::print.

Source

pub fn write_fmt(&self, fmt: Arguments<'_>)

Prints to the hexchat buffer.

Glue for usage of the write! macro with hexchat.

See PluginHandle::write_fmt.

§Panics

This panics if any broken formatting trait implementations are used in the format arguments. See also format!.

Source

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.

See PluginHandle::hook_command.

Source

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.

See PluginHandle::hook_server.

Source

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.

See PluginHandle::hook_server_attrs.

Source

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.

See PluginHandle::hook_print.

Source

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.

See PluginHandle::hook_print_attrs.

Source

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.

See PluginHandle::hook_timer.

Source

pub fn get_info<'b>(&'b self, id: InfoId<'_>) -> Option<Cow<'b, str>>

Returns context and client information.

See PluginHandle::get_info.

Source

pub fn get_libdirfs(&self) -> Option<CString>

Returns the plugin directory.

See PluginHandle::get_libdirfs.

Source

pub fn strip(&self, s: &str, strip: Strip) -> String

Strips attributes from text.

See PluginHandle::strip.

Source

pub fn pluginpref_set( &self, var: &str, value: &str, ) -> Result<(), PluginPrefError>

Sets a pluginpref.

See PluginHandle::pluginpref_set.

Source

pub fn pluginpref_get(&self, var: &str) -> Result<String, PluginPrefError>

Retrieves a pluginpref.

See PluginHandle::pluginpref_get.

Source

pub fn pluginpref_delete(&self, var: &str) -> Result<(), PluginPrefError>

Removes a pluginpref.

See PluginHandle::pluginpref_delete.

Source

pub fn pluginpref_list(&self) -> Result<PluginPrefList, PluginPrefError>

Lists pluginprefs.

See PluginHandle::pluginpref_list.

Methods from Deref<Target = Fields<'a, 'ph, Contexts>>§

Source

pub fn name(&self) -> Option<String>

The context’s name.

Source

pub fn channelkey(&self) -> Option<String>

The channel key.

Source

pub fn chanmodes(&self) -> Option<String>

The server’s channel modes. Requires HexChat 2.12.2+.

Source

pub fn chantypes(&self) -> Option<String>

The server’s channel types.

Source

pub fn context(&self) -> Context<'ph>

The context.

Source

pub fn raw_flags(&self) -> i32

Raw flags about this context.

Source

pub fn server_id(&self) -> i32

The server ID.

Source

pub fn lag(&self) -> i32

The latency to server in milliseconds.

Source

pub fn maxmodes(&self) -> i32

The maximum number of mode changes per line accepted by the server.

Source

pub fn network(&self) -> Option<String>

The network name.

Source

pub fn nickprefixes(&self) -> Option<String>

The server’s nick prefixes.

Source

pub fn nickmodes(&self) -> Option<String>

The server’s nick modes.

Source

pub fn queue_len(&self) -> i32

The current length of the send-queue, in bytes.

Source

pub fn server(&self) -> Option<String>

The server’s name.

Source

pub fn raw_type(&self) -> i32

The context’s raw type.

Source

pub fn users(&self) -> i32

The number of users in the channel.

Trait Implementations§

Source§

impl<'a, 'ph: 'a> Deref for ValidContext<'a, 'ph>

Source§

type Target = Fields<'a, 'ph, Contexts>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'a, 'ph> Freeze for ValidContext<'a, 'ph>

§

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>

§

impl<'a, 'ph> UnwindSafe for ValidContext<'a, 'ph>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.