[−][src]Struct twitchchat::messages::Privmsg
Message sent by a user
Fields
name: Cow<'t, str>
User who sent this messages
channel: Cow<'t, str>
Channel this message was sent on
data: Cow<'t, str>
Data that the user provided
Tags attached to the message
ctcp: Option<Ctcp<'t>>
The kind of CTCP this message contains, if any.
Implementations
impl<'t> Privmsg<'t>
[src]
pub fn badge_info(&'t self) -> Vec<BadgeInfo<'t>>
[src]
Metadata related to the chat badges
Currently used only for subscriber
, to indicate the exact number of months the user has been a subscriber
pub fn badges(&'t self) -> Vec<Badge<'t>>
[src]
Badges attached to this message
pub fn bits(&self) -> Option<u64>
[src]
How many bits were 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 PRIVMSG #testing :this is a test.\r\n"; let msg = decode(data).next().unwrap().unwrap(); let pm = Privmsg::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 PRIVMSG #testing :this is a test.\r\n"; let msg = decode(data).next().unwrap().unwrap(); let pm = Privmsg::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 Privmsg<'_>) -> Cow<'a, str> { msg.display_name() .unwrap_or_else(|| Cow::Borrowed(&*msg.name)) } let data = ":foo!foo@foo PRIVMSG #testing :this is a test.\r\n"; let msg = decode(data).next().unwrap().unwrap(); let pm = Privmsg::parse(&msg).unwrap(); let name = get_user_or_display(&pm); assert_eq!(name, "foo"); let data = "@display-name=FOO :foo!foo@foo PRIVMSG #testing :this is a test.\r\n"; let msg = decode(data).next().unwrap().unwrap(); let pm = Privmsg::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_action(&self) -> bool
[src]
Whether this message was an Action (a /me
or /action
)
pub fn ctcp(&'t self) -> Option<Ctcp<'t>>
[src]
Gets the 'CTCP' kind associated with this message, if any;
pub fn is_broadcaster(&self) -> bool
[src]
Whether the user sending this message was a broadcaster
pub fn is_moderator(&self) -> bool
[src]
Whether the user sending this message was a moderator
pub fn is_vip(&self) -> bool
[src]
Whether the user sending this message was a vip
pub fn is_subscriber(&self) -> bool
[src]
Whether the user sending this message was a susbcriber
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 room_id(&self) -> Option<u64>
[src]
The id of the room this message was sent to
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 Privmsg<'t>
[src]
impl<'t> Clone for Privmsg<'t>
[src]
impl<'t> Debug for Privmsg<'t>
[src]
impl<'de, 't> Deserialize<'de> for Privmsg<'t>
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<'t> From<Privmsg<'t>> for AllCommands<'t>
[src]
impl<'a: 't, 't> Parse<&'a Message<'t>> for Privmsg<'t>
[src]
fn parse(msg: &'a Message<'t>) -> Result<Self, InvalidMessage>
[src]
impl<'t> PartialEq<Privmsg<'t>> for Privmsg<'t>
[src]
impl<'t> Serialize for Privmsg<'t>
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'t> StructuralPartialEq for Privmsg<'t>
[src]
Auto Trait Implementations
impl<'t> RefUnwindSafe for Privmsg<'t>
impl<'t> Send for Privmsg<'t>
impl<'t> Sync for Privmsg<'t>
impl<'t> Unpin for Privmsg<'t>
impl<'t> UnwindSafe for Privmsg<'t>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,