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

Finds an open context for the given servname and channel.

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

Sends a list of modes to the current channel.

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

Executes a command.

Examples
use hexchat_unsafe_plugin::{ValidContext};

fn join(context: ValidContext<'_, '_>, channel: &str) {
    context.command(&format!("join {}", channel));
}

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

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

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

Returns the current context.

See PluginHandle::get_context.

Sets the current context.

Returns true if the context is valid, false otherwise.

See PluginHandle::set_context.

Prints to the hexchat buffer.

See PluginHandle::print.

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!.

Sets a command hook.

See PluginHandle::hook_command.

Sets a server hook.

See PluginHandle::hook_server.

Sets a server hook with attributes.

See PluginHandle::hook_server_attrs.

Sets a print hook.

See PluginHandle::hook_print.

Sets a print hook with attributes.

See PluginHandle::hook_print_attrs.

Sets a timer hook.

See PluginHandle::hook_timer.

Returns context and client information.

See PluginHandle::get_info.

Returns the plugin directory.

See PluginHandle::get_libdirfs.

Strips attributes from text.

See PluginHandle::strip.

Sets a pluginpref.

See PluginHandle::pluginpref_set.

Retrieves a pluginpref.

See PluginHandle::pluginpref_get.

Removes a pluginpref.

See PluginHandle::pluginpref_delete.

Lists pluginprefs.

See PluginHandle::pluginpref_list.

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

The context’s name.

The channel key.

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

The server’s channel types.

The context.

Raw flags about this context.

The server ID.

The latency to server in milliseconds.

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

The network name.

The server’s nick prefixes.

The server’s nick modes.

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

The server’s name.

The context’s raw type.

The number of users in the channel.

The raw 32-bit IPv4 address of the remote user.

The transfer rate (speed), in bytes per second.

The destination file path.

The filename.

The remote user’s nick.

The listener’s port number.

File position, LSB 32 bits.

File position, MSB 32 bits.

Resumed position, LSB 32 bits.

Resumed position, MSB 32 bits.

File size, LSB 32 bits.

File size, MSB 32 bits.

Raw DCC status.

Raw type.

The ignore mask.

Raw ignore flags.

Comma-separated list of networks this notify entry applies to.

The nick.

Raw flags.

Time when the user went online.

Time when the user went offline.

Time when the user was last seen.

Account name.

Whether the user is away.

Time when the user last talked.

User’s nick.

User’s user and hostname (user@host).

User’s prefix.

User’s userdata.

Whether the user is selected in the UI.

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.