Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregation of some bool properties into one struct (UserDetail) #262

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions TwitchLib.Client.Enums/UserDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace TwitchLib.Client.Enums;

[Flags]
public enum UserDetails
{
None = 0,
Moderator = 1,
Turbo = 2,
Subscriber = 4,
Vip = 8,

Partner = 16,
Staff = 32,
}
8 changes: 2 additions & 6 deletions TwitchLib.Client.Models/Announcement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ public Announcement(
string emotes,
string id,
string login,
bool isModerator,
string msgId,
string roomId,
bool isSubscriber,
string systemMsg,
DateTimeOffset tmiSent,
bool isTurbo,
UserDetail userDetail,
string userId,
UserType userType,
Dictionary<string, string>? undocumentedTags,
Expand All @@ -51,13 +49,11 @@ public Announcement(
emotes,
id,
login,
isModerator,
msgId,
roomId,
isSubscriber,
systemMsg,
tmiSent,
isTurbo,
userDetail,
userId,
userType,
undocumentedTags)
Expand Down
8 changes: 2 additions & 6 deletions TwitchLib.Client.Models/AnonGiftPaidUpgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ public AnonGiftPaidUpgrade(
string emotes,
string id,
string login,
bool isModerator,
string msgId,
string roomId,
bool isSubscriber,
string systemMsg,
DateTimeOffset tmiSent,
bool isTurbo,
UserDetail userDetail,
string userId,
UserType userType,
Dictionary<string, string>? undocumentedTags,
Expand All @@ -52,13 +50,11 @@ public AnonGiftPaidUpgrade(
emotes,
id,
login,
isModerator,
msgId,
roomId,
isSubscriber,
systemMsg,
tmiSent,
isTurbo,
userDetail,
userId,
userType,
undocumentedTags)
Expand Down
8 changes: 2 additions & 6 deletions TwitchLib.Client.Models/BitsBadgeTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public BitsBadgeTier(
string emotes,
string id,
string login,
bool isModerator,
string msgId,
string roomId,
bool isSubscriber,
string systemMsg,
DateTimeOffset tmiSent,
bool isTurbo,
UserDetail userDetail,
string userId,
UserType userType,
Dictionary<string, string>? undocumentedTags,
Expand All @@ -46,13 +44,11 @@ public BitsBadgeTier(
emotes,
id,
login,
isModerator,
msgId,
roomId,
isSubscriber,
systemMsg,
tmiSent,
isTurbo,
userDetail,
userId,
userType,
undocumentedTags)
Expand Down
41 changes: 2 additions & 39 deletions TwitchLib.Client.Models/Builders/ChatMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public sealed class ChatMessageBuilder : IBuilder<ChatMessage>
private string _id;
private bool _isBroadcaster;
private bool _isMe;
private bool _isModerator;
private bool _isSubscriber;
private bool _isVip;
private bool _isStaff;
private bool _isPartner;
private string _message;
private Noisy _noisy;
private string _rawIrcMessage;
Expand Down Expand Up @@ -93,33 +88,6 @@ public ChatMessageBuilder WithIsMe(bool isMe)
return this;
}

public ChatMessageBuilder WithIsModerator(bool isModerator)
{
_isModerator = isModerator;
return this;
}

public ChatMessageBuilder WithIsSubscriber(bool isSubscriber)
{
_isSubscriber = isSubscriber;
return this;
}
public ChatMessageBuilder WithIsVip(bool isVip)
{
_isVip = isVip;
return this;
}
public ChatMessageBuilder WithIsStaff(bool isStaff)
{
_isStaff = isStaff;
return this;
}

public ChatMessageBuilder WithIsPartner(bool isPartner)
{
_isPartner = isPartner;
return this;
}
public ChatMessageBuilder WithMessage(string message)
{
_message = message;
Expand Down Expand Up @@ -168,23 +136,18 @@ public ChatMessage Build()
_twitchLibMessage.UserType,
_channel,
_id,
_isSubscriber,
_subscribedMonthCount,
_roomId,
_twitchLibMessage.IsTurbo,
_isModerator,
_isMe,
_isBroadcaster,
_isVip,
_isPartner,
_isStaff,
_noisy,
_rawIrcMessage,
_emoteReplacedMessage,
_twitchLibMessage.Badges,
_cheerBadge,
_bits,
_bitsInDollars);
_bitsInDollars,
_twitchLibMessage.UserDetail);
}
}
}
6 changes: 0 additions & 6 deletions TwitchLib.Client.Models/Builders/TwitchLibMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ public TwitchLibMessageBuilder WithUserId(string userId)
return this;
}

public TwitchLibMessageBuilder WithIsTurbo(bool isTurbo)
{
IsTurbo = isTurbo;
return this;
}

public TwitchLibMessageBuilder WithBotUserName(string botUserName)
{
BotUsername = botUserName;
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Client.Models/Builders/WhisperMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public WhisperMessage Build()
_threadId,
_messageId,
_twitchLibMessage.UserId,
_twitchLibMessage.IsTurbo,
_twitchLibMessage.BotUsername,
_message,
_twitchLibMessage.UserDetail,
_twitchLibMessage.UserType);
}
}
Expand Down
54 changes: 12 additions & 42 deletions TwitchLib.Client.Models/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,9 @@ public class ChatMessage : TwitchLibMessage
/// <summary>Chat message /me identifier flag.</summary>
public bool IsMe { get; }

/// <summary>Channel specific moderator status.</summary>
public bool IsModerator { get; }

/// <summary>Message used channel points to skip sub mode</summary>
public bool IsSkippingSubMode { get; internal set; }

/// <summary>Channel specific subscriber status.</summary>
public bool IsSubscriber { get; }

/// <summary>Message is from channel VIP</summary>
public bool IsVip { get; }

/// <summary>Message is from a Twitch Staff member</summary>
public bool IsStaff { get; }

/// <summary>Message is from a Twitch Partner</summary>
public bool IsPartner { get; }

/// <summary>Twitch chat message contents.</summary>
public string Message { get; }

Expand Down Expand Up @@ -125,6 +110,7 @@ public ChatMessage(
Username = ircMessage.User;
Channel = ircMessage.Channel;

var userDetails = UserDetails.None;
foreach (var tag in ircMessage.Tags)
{
var (tagKey, tagValue) = (tag.Key, tag.Value);
Expand All @@ -147,15 +133,7 @@ public ChatMessage(
SubscribedMonthCount = int.Parse(badge.Value);
}
break;
case "vip":
IsVip = true;
break;
case "admin":
case "staff":
IsStaff = true;
break;
case "partner":
IsPartner = true;
default:
break;
}
}
Expand All @@ -166,7 +144,6 @@ public ChatMessage(
var founderBadge = BadgeInfo.Find(b => b.Key == "founder");
if (!founderBadge.Equals(default(KeyValuePair<string, string>)))
{
IsSubscriber = true;
SubscribedMonthCount = int.Parse(founderBadge.Value);
}
else
Expand Down Expand Up @@ -205,7 +182,8 @@ public ChatMessage(
HandleMsgId(tagValue);
break;
case Tags.Mod:
IsModerator = TagHelper.ToBool(tagValue);
if (TagHelper.ToBool(tag.Value))
userDetails |= UserDetails.Moderator;
break;
case Tags.Noisy:
Noisy = TagHelper.ToBool(tagValue) ? Noisy.True : Noisy.False;
Expand All @@ -214,14 +192,15 @@ public ChatMessage(
RoomId = tagValue;
break;
case Tags.Subscriber:
// this check because when founder is set, the subscriber value is actually 0, which is problematic
IsSubscriber = IsSubscriber || TagHelper.ToBool(tagValue);
if (TagHelper.ToBool(tag.Value))
userDetails |= UserDetails.Subscriber;
break;
case Tags.TmiSentTs:
TmiSent = TagHelper.ToDateTimeOffsetFromUnixMs(tagValue);
break;
case Tags.Turbo:
IsTurbo = TagHelper.ToBool(tagValue);
if (TagHelper.ToBool(tag.Value))
userDetails |= UserDetails.Turbo;
break;
case Tags.UserId:
UserId = tagValue;
Expand All @@ -235,6 +214,7 @@ public ChatMessage(
break;
}
}
UserDetail = new(userDetails, Badges);

//Parse the emoteSet
if (_emoteCollection != null && EmoteSet?.Emotes.Count > 0)
Expand Down Expand Up @@ -310,23 +290,18 @@ public ChatMessage(
UserType userType,
string channel,
string id,
bool isSubscriber,
int subscribedMonthCount,
string roomId,
bool isTurbo,
bool isModerator,
bool isMe,
bool isBroadcaster,
bool isVip,
bool isPartner,
bool isStaff,
Noisy noisy,
string rawIrcMessage,
string emoteReplacedMessage,
List<KeyValuePair<string, string>> badges,
CheerBadge cheerBadge,
int bits,
double bitsInDollars)
double bitsInDollars,
UserDetail userDetail)
{
BotUsername = botUsername;
UserId = userId;
Expand All @@ -337,16 +312,10 @@ public ChatMessage(
UserType = userType;
Channel = channel;
Id = id;
IsSubscriber = isSubscriber;
SubscribedMonthCount = subscribedMonthCount;
RoomId = roomId;
IsTurbo = isTurbo;
IsModerator = isModerator;
IsMe = isMe;
IsBroadcaster = isBroadcaster;
IsVip = isVip;
IsPartner = isPartner;
IsStaff = isStaff;
Noisy = noisy;
RawIrcMessage = rawIrcMessage;
EmoteReplacedMessage = emoteReplacedMessage;
Expand All @@ -355,6 +324,7 @@ public ChatMessage(
Bits = bits;
BitsInDollars = bitsInDollars;
Username = userName;
UserDetail = userDetail;
}

private void HandleMsgId(string val)
Expand Down
8 changes: 2 additions & 6 deletions TwitchLib.Client.Models/CommunityPayForward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ public CommunityPayForward(
string emotes,
string id,
string login,
bool isModerator,
string msgId,
string roomId,
bool isSubscriber,
string systemMsg,
DateTimeOffset tmiSent,
bool isTurbo,
UserDetail userDetail,
string userId,
UserType userType,
Dictionary<string, string>? undocumentedTags,
Expand All @@ -52,13 +50,11 @@ public CommunityPayForward(
emotes,
id,
login,
isModerator,
msgId,
roomId,
isSubscriber,
systemMsg,
tmiSent,
isTurbo,
userDetail,
userId,
userType,
undocumentedTags)
Expand Down
Loading
Loading