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
channel: Option<String>
username: Option<String>
Methods
impl IrclapSimpleContextMapping
[src]
pub fn none() -> IrclapSimpleContextMapping
[src]
A context that doesn't pass any values along. Useful for context-insensitive applications including factoids, unit conversion, and basically anything stateless.
pub fn user_only(username: String) -> IrclapSimpleContextMapping
[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);