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

Added ParseRawIrcMessage to TwitchClient.cs to access IrcParser #217

Closed
wants to merge 3 commits into from

Conversation

Moerty
Copy link

@Moerty Moerty commented Mar 21, 2023

I want to test my wrapper for TwitchLib, and in order to do so, I need to manually create events that require an IrcMessage as a constructor parameter. (Announcement, CommunitySubscription, ContinuedGiftedSubscription) Unfortunately, accessing the IrcParser externally was not possible due to its internal class setting. Therefore, the "ParseRawIrcMessage" method was added to allow external parsing of IRC messages using the IrcParser.

An alternative approach would be to create an additional constructor that includes all necessary properties of the class as parameters.

Happy to discuss this request.

Mo added 3 commits March 21, 2023 18:06
…ternal parsing of IRC messages using the internal IrcParser class.
@Syzuna
Copy link
Member

Syzuna commented Mar 21, 2023

There actually is a method for that the naming is just awful.
CC: https://github.com/TwitchLib/TwitchLib.Client/blob/master/TwitchLib.Client/TwitchClient.cs#L868

@Moerty
Copy link
Author

Moerty commented Mar 22, 2023

The method also triggers the events, which is not desired in my case.
If it is not intended to edit the TwitchClient.cs class, you could add a public constructor to some classes, for example CommunitySubscription:

        public CommunitySubscription(
            List<KeyValuePair<string, string>> badges,
            List<KeyValuePair<string, string>> badgeInfo,
            string color,
            string displayName,
            string emotes,
            string id,
            string login,
            bool isModerator,
            bool isAnonymous,
            string msgId,
            int msgParamMassGiftCount,
            int msgParamSenderCount,
            SubscriptionPlan msgParamSubPlan,
            string roomId,
            bool isSubscriber,
            string systemMsg,
            string systemMsgParsed,
            string tmiSentTs,
            bool isTurbo,
            string userId,
            UserType userType,
            string msgParamMultiMonthGiftDuration)
        {
            Badges = badges;
            BadgeInfo = badgeInfo;
            Color = color;
            DisplayName = displayName;
            Emotes = emotes;
            Id = id;
            Login = login;
            IsModerator = isModerator;
            IsAnonymous = isAnonymous;
            MsgId = msgId;
            MsgParamMassGiftCount = msgParamMassGiftCount;
            MsgParamSenderCount = msgParamSenderCount;
            MsgParamSubPlan = msgParamSubPlan;
            RoomId = roomId;
            IsSubscriber = isSubscriber;
            SystemMsg = systemMsg;
            SystemMsgParsed = systemMsgParsed;
            TmiSentTs = tmiSentTs;
            IsTurbo = isTurbo;
            UserId = userId;
            UserType = userType;
            MsgParamMultiMonthGiftDuration = msgParamMultiMonthGiftDuration;
        }
    }

This is already implemented for the most events like:

public FailureToReceiveJoinConfirmationException(string channel, string details = null)
{
Channel = channel;
Details = details;
}

public GiftedSubscription(
List<KeyValuePair<string, string>> badges,
List<KeyValuePair<string, string>> badgeInfo,
string color,
string displayName,
string emotes,
string id,
string login,
bool isModerator,
string msgId,
string msgParamMonths,
string msgParamRecipientDisplayName,
string msgParamRecipientId,
string msgParamRecipientUserName,
string msgParamSubPlanName,
string msgMultiMonthDuration,
SubscriptionPlan msgParamSubPlan,
string roomId,
bool isSubscriber,
string systemMsg,
string systemMsgParsed,
string tmiSentTs,
bool isTurbo,
UserType userType,
string userId)
{
Badges = badges;
BadgeInfo = badgeInfo;
Color = color;
DisplayName = displayName;
Emotes = emotes;
Id = id;
Login = login;
IsModerator = isModerator;
MsgId = msgId;
MsgParamMonths = msgParamMonths;
MsgParamRecipientDisplayName = msgParamRecipientDisplayName;
MsgParamRecipientId = msgParamRecipientId;
MsgParamRecipientUserName = msgParamRecipientUserName;
MsgParamSubPlanName = msgParamSubPlanName;
MsgParamSubPlan = msgParamSubPlan;
MsgParamMultiMonthGiftDuration = msgMultiMonthDuration;
RoomId = roomId;
IsSubscriber = isSubscriber;
SystemMsg = systemMsg;
SystemMsgParsed = systemMsgParsed;
TmiSentTs = tmiSentTs;
IsTurbo = isTurbo;
UserType = userType;
UserId = userId;
}

public ChatMessage(
string botUsername,
string userId,
string userName,
string displayName,
string colorHex,
Color color,
EmoteSet emoteSet,
string message,
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)
{
BotUsername = botUsername;
UserId = userId;
DisplayName = displayName;
ColorHex = colorHex;
Color = color;
EmoteSet = emoteSet;
Message = message;
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;
Badges = badges;
CheerBadge = cheerBadge;
Bits = bits;
BitsInDollars = bitsInDollars;
Username = userName;
}

public SentMessage(
List<KeyValuePair<string, string>> badges,
string channel,
string colorHex,
string displayName,
string emoteSet,
bool isModerator,
bool isSubscriber,
Enums.UserType userType,
string message)
{
Badges = badges;
Channel = channel;
ColorHex = colorHex;
DisplayName = displayName;
EmoteSet = emoteSet;
IsModerator = isModerator;
IsSubscriber = isSubscriber;
UserType = userType;
Message = message;
}

If this path is taken, I can gladly adjust the pull request.

@Syzuna
Copy link
Member

Syzuna commented Mar 22, 2023

In that case I understood your requirement wrong. My bad.
I am not against editing TwitchClient at all. Just thought your use case might already be covered

@ghost
Copy link

ghost commented Mar 24, 2023

if this PR #216 gets accepted and goes online,
IrcParser is going to be static and no longer an instance member of TwitchClient
IrcParsers visibility can be changed to public - but only from my point of view

the SentMessage-class would be gone and replaced by ChatMessage

@neon-sunset
Copy link

neon-sunset commented Aug 5, 2023

I don't think this is a right change. Instead, we could simply make IrcParser public. It will produce IrcMessage in the right format and those can't really be corrupted or changed outside aside from Tags being mutable, but then again, if a user removes/changesa tag - they might need to do so and it does not go against the design.

@neon-sunset
Copy link

neon-sunset commented Aug 9, 2023

This can be closed in favour of #247 once it is merged - we can now publicly expose (now static) IrcParser directly.

@Syzuna
Copy link
Member

Syzuna commented Aug 11, 2023

superseded by #247

@Syzuna Syzuna closed this Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants