@@ -29,6 +29,11 @@ public class TwitchClientProxy : ITwitchClientProxy {
2929 /// </summary>
3030 private static TwitchClientProxy ? instance ;
3131
32+ /// <summary>
33+ /// The callback(s) to invoke when a channel receives a chat message.
34+ /// </summary>
35+ private readonly Dictionary < string , Action < OnMessageReceivedArgs > ? > _onMessageReceived = new ( ) ;
36+
3237 /// <summary>
3338 /// The list of chats we attempted to join with the bot.
3439 /// </summary>
@@ -39,42 +44,37 @@ public class TwitchClientProxy : ITwitchClientProxy {
3944 private readonly HashSet < string > joinedChannels ;
4045
4146 /// <summary>
42- /// A timer used to re-connect the Twitch chat client .
47+ /// The callback(s) to invoke when a channel is raided .
4348 /// </summary>
44- private readonly Timer twitchChatClientReconnect ;
49+ private readonly Dictionary < string , Action < OnRaidNotificationArgs > ? > onRaid = new ( ) ;
4550
4651 /// <summary>
47- /// The lock to prevent mutual exclusion on the <see cref="client" /> object .
52+ /// The callback(s) to invoke when a channel receives a ban message .
4853 /// </summary>
49- private readonly object twitchClientLock = new ( ) ;
54+ private readonly Dictionary < string , Action < OnUserBannedArgs > ? > onUserBanReceived = new ( ) ;
5055
5156 /// <summary>
52- /// The twitch client to send and receive messages with .
57+ /// A timer used to re-connect the Twitch chat client .
5358 /// </summary>
54- private TwitchClient ? client ;
59+ private readonly Timer twitchChatClientReconnect ;
5560
5661 /// <summary>
57- /// The callback(s) to invoke when a channel receives a chat message .
62+ /// The lock to prevent mutual exclusion on the <see cref="client" /> object .
5863 /// </summary>
59- private Dictionary < string , Action < OnMessageReceivedArgs > ? > _onMessageReceived = new ( ) ;
64+ private readonly object twitchClientLock = new ( ) ;
6065
61- /// <summary>
62- /// The callback(s) to invoke when a channel is raided.
63- /// </summary>
64- private Dictionary < string , Action < OnRaidNotificationArgs > ? > onRaid = new ( ) ;
66+ private string ? _twitchOAuthToken ;
6567
6668 /// <summary>
67- /// The callback(s) to invoke when a channel receives a ban message .
69+ /// The twitch client to send and receive messages with .
6870 /// </summary>
69- private Dictionary < string , Action < OnUserBannedArgs > ? > onUserBanReceived = new ( ) ;
71+ private TwitchClient ? client ;
7072
7173 /// <summary>
7274 /// The web socket to connect to twitch chat with.
7375 /// </summary>
7476 private WebSocketClient ? socket ;
7577
76- private string ? _twitchOAuthToken ;
77-
7878 /// <summary>
7979 /// Initializes a new instance of the <see cref="TwitchClientProxy" /> class.
8080 /// </summary>
@@ -109,7 +109,7 @@ public string? TwitchOAuthToken {
109109 get => _twitchOAuthToken ;
110110 set {
111111 _twitchOAuthToken = value ;
112-
112+
113113 // If we have a client, try to connect.
114114 if ( null != client ) {
115115 client . SetConnectionCredentials ( new ConnectionCredentials ( TwitchUsername , value ) ) ;
@@ -169,7 +169,7 @@ public async Task<bool> SendMessage(string channel, string message, uint retryCo
169169 /// <inheritdoc />
170170 public async Task AddMessageCallback ( string channel , Action < OnMessageReceivedArgs > callback ) {
171171 await JoinChannel ( channel ) ;
172- var channelSan = channel . ToLowerInvariant ( ) ;
172+ string channelSan = channel . ToLowerInvariant ( ) ;
173173 lock ( _onMessageReceived ) {
174174 if ( ! _onMessageReceived . TryAdd ( channelSan , callback ) ) {
175175 _onMessageReceived [ channelSan ] += callback ;
@@ -180,10 +180,10 @@ public async Task AddMessageCallback(string channel, Action<OnMessageReceivedArg
180180 /// <inheritdoc />
181181 public void RemoveMessageCallback ( string channel , Action < OnMessageReceivedArgs > callback ) {
182182 bool shouldRemove = false ;
183- var channelSan = channel . ToLowerInvariant ( ) ;
183+ string channelSan = channel . ToLowerInvariant ( ) ;
184184 lock ( _onMessageReceived ) {
185185 if ( _onMessageReceived . ContainsKey ( channelSan ) ) {
186- var item = _onMessageReceived [ channelSan ] ;
186+ Action < OnMessageReceivedArgs > ? item = _onMessageReceived [ channelSan ] ;
187187 item -= callback ;
188188 if ( null == item ) {
189189 _onMessageReceived . Remove ( channelSan ) ;
@@ -196,7 +196,7 @@ public void RemoveMessageCallback(string channel, Action<OnMessageReceivedArgs>
196196
197197 if ( shouldRemove ) {
198198 client ? . LeaveChannel ( channelSan ) ;
199-
199+
200200 // First add the channel to the master list.
201201 lock ( joinedChannels ) {
202202 joinedChannels . Add ( channelSan ) ;
@@ -257,7 +257,7 @@ private async Task<bool> JoinChannel(string channel) {
257257 if ( ! await Connect ( ) ) {
258258 return false ;
259259 }
260-
260+
261261 try {
262262 // If we don't have a client, give up.
263263 if ( null == client ) {
@@ -407,11 +407,11 @@ private Task<bool> Connect() {
407407 /// <param name="e">The event arguments.</param>
408408 private void TwitchChatClient_OnRaidNotification ( object ? sender , OnRaidNotificationArgs e ) {
409409 Action < OnRaidNotificationArgs > ? callback ;
410- var channel = e . Channel . ToLowerInvariant ( ) ;
410+ string channel = e . Channel . ToLowerInvariant ( ) ;
411411 lock ( onRaid ) {
412412 onRaid . TryGetValue ( channel , out callback ) ;
413413 }
414-
414+
415415 Delegate [ ] ? invokeList = callback ? . GetInvocationList ( ) ;
416416 if ( null == invokeList ) {
417417 return ;
@@ -429,7 +429,7 @@ private void TwitchChatClient_OnRaidNotification(object? sender, OnRaidNotificat
429429 /// <param name="e">The event arguments.</param>
430430 private void TwitchChatClient_OnMessageReceived ( object ? sender , OnMessageReceivedArgs e ) {
431431 Action < OnMessageReceivedArgs > ? callbacks = null ;
432- var channelSan = e . ChatMessage . Channel . ToLowerInvariant ( ) ;
432+ string channelSan = e . ChatMessage . Channel . ToLowerInvariant ( ) ;
433433 lock ( _onMessageReceived ) {
434434 if ( _onMessageReceived . TryGetValue ( channelSan , out Action < OnMessageReceivedArgs > ? messageReceivedCallback ) ) {
435435 callbacks = messageReceivedCallback ;
@@ -457,11 +457,11 @@ private void TwitchChatClient_OnMessageReceived(object? sender, OnMessageReceive
457457 /// <param name="e">The event arguments.</param>
458458 private void TwitchChatClient_OnUserBanned ( object ? sender , OnUserBannedArgs e ) {
459459 Action < OnUserBannedArgs > ? callback ;
460- var channel = e . UserBan . Channel . ToLowerInvariant ( ) ;
460+ string channel = e . UserBan . Channel . ToLowerInvariant ( ) ;
461461 lock ( onUserBanReceived ) {
462462 onUserBanReceived . TryGetValue ( channel , out callback ) ;
463463 }
464-
464+
465465 Delegate [ ] ? invokeList = callback ? . GetInvocationList ( ) ;
466466 if ( null == invokeList ) {
467467 return ;
0 commit comments