Skip to content

Commit

Permalink
Nullable anotation Part2 (+1 small "bux" fix) (TwitchLib#252)
Browse files Browse the repository at this point in the history
* nullable anotation Part 2 (focused on `Twitch.LibClient`)

* fix potential problem when connecting to a channel when `Capabilities.Tags`is set to `false`

* fix `tmiSent`dafault value in `HandleClearMsg`

---------

Co-authored-by: AoshiW <[email protected]>
  • Loading branch information
AoshiW and AoshiW authored Oct 30, 2023
1 parent e014d80 commit 70dead0
Show file tree
Hide file tree
Showing 49 changed files with 857 additions and 474 deletions.
6 changes: 6 additions & 0 deletions TwitchLib.Client.Models/Internal/MsgIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ public static class MsgIds
public const string AlreadyR9KOn = "already_r9k_on";
public const string AlreadySubsOff = "already_subs_off";
public const string AlreadySubsOn = "already_subs_on";
public const string AnonGiftPaidUpgrade = "anongiftpaidupgrade";
public const string Announcement = "announcement";
public const string BadUnbanNoBan = "bad_unban_no_ban";
public const string BanSuccess = "ban_success";
public const string BitsBadgeTier = "bitsbadgetier";
public const string ColorChanged = "color_changed";
public const string CommunityPayForward = "communitypayforward";
public const string EmoteOnlyOff = "emote_only_off";
public const string EmoteOnlyOn = "emote_only_on";
public const string HighlightedMessage = "highlighted-message";
Expand All @@ -40,8 +43,10 @@ public static class MsgIds
public const string RaidErrorSelf = "raid_error_self";
public const string RaidNoticeMature = "raid_notice_mature";
public const string ReSubscription = "resub";
public const string Ritual = "ritual";
public const string R9KOff = "r9k_off";
public const string R9KOn = "r9k_on";
public const string StandardPayForward = "standardpayforward";
public const string SubGift = "subgift";
public const string CommunitySubscription = "submysterygift";
public const string ContinuedGiftedSubscription = "giftpaidupgrade";
Expand All @@ -50,6 +55,7 @@ public static class MsgIds
public const string SubsOn = "subs_on";
public const string TimeoutSuccess = "timeout_success";
public const string UnbanSuccess = "unban_success";
public const string Unraid = "unraid";
public const string UnrecognizedCmd = "unrecognized_cmd";
public const string UserIntro = "user-intro";
public const string VIPsSuccess = "vips_success";
Expand Down
9 changes: 7 additions & 2 deletions TwitchLib.Client.Test/TwitchClientEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task ClientCanJoinChannels()
client.OnConnected += async (sender, e) =>
{
await client.JoinChannelAsync(TWITCH_CHANNEL);
await ReceivedRoomState();
await ReceivedJoin(TWITCH_CHANNEL);
};

await MyAssert.RaisesAsync<OnJoinedChannelArgs>(
Expand Down Expand Up @@ -120,7 +120,7 @@ await MyAssert.RaisesAsync<OnJoinedChannelArgs>(
await client.ConnectAsync();
await ReceivedTwitchConnected();
await client.JoinChannelAsync(TWITCH_CHANNEL);
await ReceivedRoomState();
await ReceivedJoin(TWITCH_CHANNEL);
});
}

Expand Down Expand Up @@ -215,6 +215,11 @@ private async Task ReceivedRoomState()
{
await _mockClient.ReceiveMessage($"@broadcaster-lang=;r9k=0;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #{TWITCH_CHANNEL}");
}

private async Task ReceivedJoin(string channel)
{
await _mockClient.ReceiveMessage($":{TWITCH_BOT_USERNAME}!{TWITCH_BOT_USERNAME}@{TWITCH_BOT_USERNAME}.tmi.twitch.tv JOIN #{channel}");
}
#endregion
}
}
4 changes: 3 additions & 1 deletion TwitchLib.Client/Events/NoticeEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class NoticeEventArgs
/// </summary>
public string Channel { get; }


/// <summary>
/// Initializes a new instance of the <see cref="NoticeEventArgs"/> class.
/// </summary>
public NoticeEventArgs(string channel, string message)
{
Message = message;
Expand Down
13 changes: 11 additions & 2 deletions TwitchLib.Client/Events/OnAnnouncementArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ public class OnAnnouncementArgs : EventArgs
/// <summary>
/// Property representing the announcement send with the USERNOTICE
/// </summary>
public Announcement Announcement;
public Announcement Announcement { get; }
/// <summary>
/// Property representing channel bot is connected to.
/// </summary>
public string Channel;
public string Channel { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnAnnouncementArgs"/> class.
/// </summary>
public OnAnnouncementArgs(string channel, Announcement announcement)
{
Channel = channel;
Announcement = announcement;
}
}
}
32 changes: 32 additions & 0 deletions TwitchLib.Client/Events/OnAnonGiftPaidUpgradeArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using TwitchLib.Client.Models;
using TwitchLib.Client.Models.Internal;

namespace TwitchLib.Client.Events;

public class OnAnonGiftPaidUpgradeArgs : EventArgs
{
/// <summary>
/// The channel
/// </summary>
public string Channel { get; }

/// <summary>
/// The AnonGiftPaidUpgrade
/// </summary>
public AnonGiftPaidUpgrade AnonGiftPaidUpgrade { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnBitsBadgeTierArgs"/> class.
/// </summary>
public OnAnonGiftPaidUpgradeArgs(string channel, AnonGiftPaidUpgrade anonGiftPaidUpgrade)
{
Channel = channel;
AnonGiftPaidUpgrade = anonGiftPaidUpgrade;
}

internal OnAnonGiftPaidUpgradeArgs(IrcMessage ircMessage)
{
Channel = ircMessage.Channel;
AnonGiftPaidUpgrade = new(ircMessage);
}
}
32 changes: 32 additions & 0 deletions TwitchLib.Client/Events/OnBitsBadgeTierArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using TwitchLib.Client.Models;
using TwitchLib.Client.Models.Internal;

namespace TwitchLib.Client.Events;

public class OnBitsBadgeTierArgs : EventArgs
{
/// <summary>
/// The channel
/// </summary>
public string Channel { get; }

/// <summary>
/// The BitsBadgeTier
/// </summary>
public BitsBadgeTier BitsBadgeTier { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnBitsBadgeTierArgs"/> class.
/// </summary>
public OnBitsBadgeTierArgs(string channel, BitsBadgeTier bitsBadgeTier)
{
Channel = channel;
BitsBadgeTier = bitsBadgeTier;
}

internal OnBitsBadgeTierArgs(IrcMessage ircMessage)
{
Channel = ircMessage.Channel;
BitsBadgeTier = new(ircMessage);
}
}
16 changes: 12 additions & 4 deletions TwitchLib.Client/Events/OnChannelStateChangedArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using TwitchLib.Client.Models;
using TwitchLib.Client.Models;

namespace TwitchLib.Client.Events
{
Expand All @@ -14,10 +13,19 @@ public class OnChannelStateChangedArgs : EventArgs
/// <summary>
/// Property representing the current channel state.
/// </summary>
public ChannelState ChannelState;
public ChannelState ChannelState { get; }
/// <summary>
/// Property representing the channel received state from.
/// </summary>
public string Channel;
public string Channel { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnChannelStateChangedArgs"/> class.
/// </summary>
public OnChannelStateChangedArgs(string channel, ChannelState channelState)
{
Channel = channel;
ChannelState = channelState;
}
}
}
12 changes: 9 additions & 3 deletions TwitchLib.Client/Events/OnChatClearedArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace TwitchLib.Client.Events
namespace TwitchLib.Client.Events
{
/// <summary>
/// Args representing a cleared chat event.
Expand All @@ -14,5 +12,13 @@ public class OnChatClearedArgs : EventArgs
/// Channel that had chat cleared event.
/// </summary>
public string Channel;

/// <summary>
/// Initializes a new instance of the <see cref="OnChatClearedArgs"/> class.
/// </summary>
public OnChatClearedArgs(string channel)
{
Channel = channel;
}
}
}
12 changes: 9 additions & 3 deletions TwitchLib.Client/Events/OnChatColorChangedArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace TwitchLib.Client.Events
namespace TwitchLib.Client.Events
{
/// <summary>
/// Args representing a successful chat color change request.
Expand All @@ -14,5 +12,13 @@ public class OnChatColorChangedArgs : EventArgs
/// Property reprenting the channel the event was received in.
/// </summary>
public string Channel;

/// <summary>
/// Initializes a new instance of the <see cref="OnChatColorChangedArgs"/> class.
/// </summary>
public OnChatColorChangedArgs(string channel)
{
Channel = channel;
}
}
}
32 changes: 32 additions & 0 deletions TwitchLib.Client/Events/OnCommunityPayForwardArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using TwitchLib.Client.Models;
using TwitchLib.Client.Models.Internal;

namespace TwitchLib.Client.Events;

public class OnCommunityPayForwardArgs : EventArgs
{
/// <summary>
/// The channel
/// </summary>
public string Channel { get; }

/// <summary>
/// The CommunityPayForward
/// </summary>
public CommunityPayForward CommunityPayForward { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnCommunityPayForwardArgs"/> class.
/// </summary>
public OnCommunityPayForwardArgs(string channel, CommunityPayForward communityPayForward)
{
Channel = channel;
CommunityPayForward = communityPayForward;
}

internal OnCommunityPayForwardArgs(IrcMessage ircMessage)
{
Channel = ircMessage.Channel;
CommunityPayForward = new(ircMessage);
}
}
13 changes: 11 additions & 2 deletions TwitchLib.Client/Events/OnCommunitySubscriptionArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ public class OnCommunitySubscriptionArgs : EventArgs
/// <summary>
/// Property representing the information of the community subscription.
/// </summary>
public CommunitySubscription GiftedSubscription;
public CommunitySubscription GiftedSubscription { get; }
/// <summary>
/// Property representing the Twitch channel this event fired from.
/// </summary>
public string Channel;
public string Channel { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnCommunitySubscriptionArgs"/> class.
/// </summary>
public OnCommunitySubscriptionArgs(string channel, CommunitySubscription giftedSubscription)
{
Channel = channel;
GiftedSubscription = giftedSubscription;
}
}
}
10 changes: 9 additions & 1 deletion TwitchLib.Client/Events/OnConnectedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ public class OnConnectedEventArgs : EventArgs
/// <summary>
/// Property representing bot username.
/// </summary>
public string BotUsername;
public string BotUsername { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnConnectedEventArgs"/> class.
/// </summary>
public OnConnectedEventArgs(string botUsername)
{
BotUsername = botUsername;
}
}
16 changes: 12 additions & 4 deletions TwitchLib.Client/Events/OnConnectionErrorArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using TwitchLib.Client.Models;
using TwitchLib.Client.Models;

namespace TwitchLib.Client.Events
{
Expand All @@ -14,10 +13,19 @@ public class OnConnectionErrorArgs : EventArgs
/// <summary>
/// The error
/// </summary>
public ErrorEvent Error;
public ErrorEvent Error { get; }
/// <summary>
/// Username of the bot that suffered connection error.
/// </summary>
public string BotUsername;
public string BotUsername { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnConnectionErrorArgs"/> class.
/// </summary>
public OnConnectionErrorArgs(string botUsername, ErrorEvent error)
{
BotUsername = botUsername;
Error = error;
}
}
}
16 changes: 12 additions & 4 deletions TwitchLib.Client/Events/OnContinuedGiftedSubscriptionArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using TwitchLib.Client.Models;
using TwitchLib.Client.Models;

namespace TwitchLib.Client.Events
{
Expand All @@ -13,10 +12,19 @@ public class OnContinuedGiftedSubscriptionArgs : EventArgs
/// <summary>
/// Property representing the information of the subscription that was originally gifted, and is now continued by the user.
/// </summary>
public ContinuedGiftedSubscription ContinuedGiftedSubscription;
public ContinuedGiftedSubscription ContinuedGiftedSubscription { get; }
/// <summary>
/// Property representing the Twitch channel this event fired from.
/// </summary>
public string Channel;
public string Channel { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnContinuedGiftedSubscriptionArgs"/> class.
/// </summary>
public OnContinuedGiftedSubscriptionArgs(string channel, ContinuedGiftedSubscription continuedGiftedSubscription)
{
Channel = channel;
ContinuedGiftedSubscription = continuedGiftedSubscription;
}
}
}
14 changes: 10 additions & 4 deletions TwitchLib.Client/Events/OnDisconnectedArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace TwitchLib.Client.Events
namespace TwitchLib.Client.Events
{
/// <summary>
/// Args representing client disconnect event.
Expand All @@ -13,6 +11,14 @@ public class OnDisconnectedArgs : EventArgs
/// <summary>
/// Username of the bot that was disconnected.
/// </summary>
public string BotUsername;
public string BotUsername { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OnDisconnectedArgs"/> class.
/// </summary>
public OnDisconnectedArgs(string botUsername)
{
BotUsername = botUsername;
}
}
}
Loading

0 comments on commit 70dead0

Please sign in to comment.