[][src]Struct twitchchat::messages::Whisper

pub struct Whisper<'t> {
    pub name: Cow<'t, str>,
    pub data: Cow<'t, str>,
    pub tags: Tags<'t>,
}

Message sent by a user

Fields

name: Cow<'t, str>

User who sent this messages

data: Cow<'t, str>

Data that the user provided

tags: Tags<'t>

Tags attached to the message

Implementations

impl<'t> Whisper<'t>[src]

pub fn badges(&'t self) -> Vec<Badge<'t>>[src]

Badges attached to this message

pub fn color(&self) -> Option<Color>[src]

The color of the user who sent this message, if set

pub fn display_name(&'t self) -> Option<Cow<'t, str>>[src]

Returns the display name of the user, if set.

Users can changed the casing and encoding of their names, if they choose to.

By default, their display name is not set. If the user foo changes their display name to FOO then this'll return that FOO. Otherwise it'll return None. This also applies to users who have decided to user a localized version of their name.

You can get their username with the field name.

// without their display name set
let data = ":foo!foo@foo WHISPER testing :this is a test.\r\n";
let msg = decode(data).next().unwrap().unwrap();
let pm = Whisper::parse(&msg).unwrap();
assert_eq!(pm.name, "foo");
assert!(pm.display_name().is_none());

// with their display name set
let data = "@display-name=FOO :foo!foo@foo WHISPER testing :this is a test.\r\n";
let msg = decode(data).next().unwrap().unwrap();
let pm = Whisper::parse(&msg).unwrap();
assert_eq!(pm.name, "foo");
assert_eq!(pm.display_name().unwrap(), "FOO");

A useful thing to do is to try to get the display_name and fallback to the username.

use std::borrow::Cow;
fn get_user_or_display<'a>(msg: &'a Whisper<'_>) -> Cow<'a, str> {
    msg.display_name()
        .unwrap_or_else(|| Cow::Borrowed(&*msg.name))
}

let data = ":foo!foo@foo WHISPER testing :this is a test.\r\n";
let msg = decode(data).next().unwrap().unwrap();
let pm = Whisper::parse(&msg).unwrap();

let name = get_user_or_display(&pm);
assert_eq!(name, "foo");

let data = "@display-name=FOO :foo!foo@foo WHISPER testing :this is a test.\r\n";
let msg = decode(data).next().unwrap().unwrap();
let pm = Whisper::parse(&msg).unwrap();

let name = get_user_or_display(&pm);
assert_eq!(name, "FOO");    

pub fn emotes(&self) -> Vec<Emotes>[src]

Emotes attached to this message

pub fn is_staff(&self) -> bool[src]

Whether the user sending this message was a staff member

pub fn is_turbo(&self) -> bool[src]

Whether the user sending this message had turbo

pub fn is_global_moderator(&self) -> bool[src]

Whether the user sending this message was a global moderator

pub fn tmi_sent_ts(&self) -> Option<u64>[src]

The timestamp of when this message was received by Twitch

pub fn user_id(&self) -> Option<u64>[src]

The id of the user who sent this message

Trait Implementations

impl<'t> AsOwned for Whisper<'t>[src]

type Owned = Whisper<'static>

The owned type

impl<'t> Clone for Whisper<'t>[src]

impl<'t> Debug for Whisper<'t>[src]

impl<'de, 't> Deserialize<'de> for Whisper<'t>[src]

impl<'a: 't, 't> Extract<'a, &'a Whisper<'t>> for &'a AllCommands<'t>[src]

impl<'t> From<Whisper<'t>> for AllCommands<'t>[src]

impl<'a: 't, 't> Parse<&'a Message<'t>> for Whisper<'t>[src]

impl<'t> PartialEq<Whisper<'t>> for Whisper<'t>[src]

impl<'t> Serialize for Whisper<'t>[src]

impl<'t> StructuralPartialEq for Whisper<'t>[src]

Auto Trait Implementations

impl<'t> RefUnwindSafe for Whisper<'t>

impl<'t> Send for Whisper<'t>

impl<'t> Sync for Whisper<'t>

impl<'t> Unpin for Whisper<'t>

impl<'t> UnwindSafe for Whisper<'t>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.