Struct irclap::IrclapSimpleContextMapping [] [src]

pub struct IrclapSimpleContextMapping {
    pub channel: Option<String>,
    pub username: Option<String>,
}

Supports extracting common context values from IRC messages into args for processing.

Commonly, an app may need to know the username and possibly the channel a message was sent on. irclap handles this by including them as arguments to the clap::App for parsing, as this potentially allows reusing the App in CLI scenarios.

Fields

Methods

impl IrclapSimpleContextMapping
[src]

[src]

A context that doesn't pass any values along. Useful for context-insensitive applications including factoids, unit conversion, and basically anything stateless.

[src]

Maps the username of the message to an argument. Does not map the channel at all.

Example:

//Context, along with a message "arg1 arg2" from 'someuser'
let context_mapping = IrclapSimpleContextMapping::user_only("--profile-name".to_owned());
let message = Message::new(Some("someuser"), "PRIVMSG", vec!["mybot"], Some("arg1 arg2")).unwrap();

//Usually irclap extracts this from the message for us, but we'll hardcode it here
let message_args = vec!["arg1", "arg2"];

// Now we proces the message and we get username passed as an argument.
let mapped = context_mapping.prepare_command_args(message_args, &message);
assert_eq!(vec!["arg1", "arg2", "--profile-name", "someuser"], mapped);

Trait Implementations

impl IrclapContextMapper for IrclapSimpleContextMapping
[src]

[src]

Performs mapping from an original semi-parsed message to a full command. Read more

Auto Trait Implementations