private void Awake() { client = new Twitch.Client(); // Transfert events client.OnDisconnected += (s, e) => OnDisconnected?.Invoke(this, e); client.OnConnectionError += (s, e) => OnConnectionError?.Invoke(this, e); client.OnChatCleared += (s, e) => OnChatCleared?.Invoke(this, e); client.OnUserTimedout += (s, e) => OnUserTimedout?.Invoke(this, e); client.OnLeftChannel += (s, e) => OnLeftChannel?.Invoke(this, e); client.OnUserBanned += (s, e) => OnUserBanned?.Invoke(this, e); client.OnModeratorsReceived += (s, e) => OnModeratorsReceived?.Invoke(this, e); client.OnChatColorChanged += (s, e) => OnChatColorChanged?.Invoke(this, e); client.OnSendReceiveData += (s, e) => OnSendReceiveData?.Invoke(this, e); client.OnNowHosting += (s, e) => OnNowHosting?.Invoke(this, e); //client.OnBeingHosted += (s, e) => OnBeingHosted ?.Invoke(this, e); client.OnRaidNotification += (s, e) => OnRaidNotification?.Invoke(this, e); client.OnGiftedSubscription += (s, e) => OnGiftedSubscription?.Invoke(this, e); client.OnSelfRaidError += (s, e) => OnSelfRaidError?.Invoke(this, e); client.OnNoPermissionError += (s, e) => OnNoPermissionError?.Invoke(this, e); client.OnRaidedChannelIsMatureAudience += (s, e) => OnRaidedChannelIsMatureAudience?.Invoke(this, e); client.OnRitualNewChatter += (s, e) => OnRitualNewChatter?.Invoke(this, e); client.OnHostingStopped += (s, e) => OnHostingStopped?.Invoke(this, e); client.OnHostingStarted += (s, e) => OnHostingStarted?.Invoke(this, e); client.OnUserLeft += (s, e) => OnUserLeft?.Invoke(this, e); client.OnExistingUsersDetected += (s, e) => OnExistingUsersDetected?.Invoke(this, e); client.OnLog += (s, e) => OnLog?.Invoke(this, e); client.OnConnected += (s, e) => OnConnected?.Invoke(this, e); client.OnJoinedChannel += (s, e) => OnJoinedChannel?.Invoke(this, e); client.OnIncorrectLogin += (s, e) => OnIncorrectLogin?.Invoke(this, e); client.OnChannelStateChanged += (s, e) => OnChannelStateChanged?.Invoke(this, e); client.OnUserStateChanged += (s, e) => OnUserStateChanged?.Invoke(this, e); client.OnMessageReceived += (s, e) => OnMessageReceived?.Invoke(this, e); client.OnWhisperReceived += (s, e) => OnWhisperReceived?.Invoke(this, e); client.OnFailureToReceiveJoinConfirmation += (s, e) => OnFailureToReceiveJoinConfirmation?.Invoke(this, e); client.OnMessageSent += (s, e) => OnMessageSent?.Invoke(this, e); client.OnChatCommandReceived += (s, e) => OnChatCommandReceived?.Invoke(this, e); client.OnWhisperCommandReceived += (s, e) => OnWhisperCommandReceived?.Invoke(this, e); client.OnUserJoined += (s, e) => OnUserJoined?.Invoke(this, e); client.OnModeratorJoined += (s, e) => OnModeratorJoined?.Invoke(this, e); client.OnModeratorLeft += (s, e) => OnModeratorLeft?.Invoke(this, e); client.OnNewSubscriber += (s, e) => OnNewSubscriber?.Invoke(this, e); client.OnReSubscriber += (s, e) => OnReSubscriber?.Invoke(this, e); client.OnHostLeft += (s, e) => OnHostLeft?.Invoke(this, e); client.OnWhisperSent += (s, e) => OnWhisperSent?.Invoke(this, e); client.OnUnaccountedFor += (s, e) => OnUnaccountedFor?.Invoke(this, e); // Log client activity client.OnLog += (s, e) => Debug.Log(e.Data); client.OnConnected += (s, e) => NotificationManager.Instance.PushNotification("Connected to Twitch servers", Color.white, Color.green); client.OnJoinedChannel += (s, e) => NotificationManager.Instance.PushNotification($"Joined {e.Channel} channel", Color.white, Color.cyan); client.OnLeftChannel += (s, e) => NotificationManager.Instance.PushNotification($"Left {e.Channel} channel", Color.white, Color.yellow); client.OnDisconnected += (s, e) => NotificationManager.Instance.PushNotification("Disconnected from Twitch servers", Color.white, Color.red); client.OnFailureToReceiveJoinConfirmation += (s, e) => NotificationManager.Instance.PushNotification("Failed to join channel", Color.white, Color.magenta); }
public Client() : base(null) { ThreadDispatcher.EnsureCreated(); base.OverrideBeingHostedCheck = true; base.OnLog += (object sender, OnLogArgs e) => { ThreadDispatcher.Enqueue(() => OnLog?.Invoke(sender, e)); }; base.OnConnected += ((object sender, OnConnectedArgs e) => { ThreadDispatcher.Enqueue(() => OnConnected?.Invoke(sender, e)); }); base.OnJoinedChannel += ((object sender, OnJoinedChannelArgs e) => { ThreadDispatcher.Enqueue(() => OnJoinedChannel?.Invoke(sender, e)); if (OnBeingHosted == null) { return; } if (e.Channel.ToLower() != TwitchUsername && !OverrideBeingHostedCheck) { ThreadDispatcher.Enqueue(() => throw new BadListenException("BeingHosted", "You cannot listen to OnBeingHosted unless you are connected to the broadcaster's channel as the broadcaster. You may override this by setting the TwitchClient property OverrideBeingHostedCheck to true.")); } }); base.OnIncorrectLogin += ((object sender, OnIncorrectLoginArgs e) => { ThreadDispatcher.Enqueue(() => OnIncorrectLogin?.Invoke(sender, e)); }); base.OnChannelStateChanged += ((object sender, OnChannelStateChangedArgs e) => { ThreadDispatcher.Enqueue(() => OnChannelStateChanged?.Invoke(sender, e)); }); base.OnUserStateChanged += ((object sender, OnUserStateChangedArgs e) => { ThreadDispatcher.Enqueue(() => OnUserStateChanged?.Invoke(sender, e)); }); base.OnMessageReceived += ((object sender, OnMessageReceivedArgs e) => { ThreadDispatcher.Enqueue(() => OnMessageReceived?.Invoke(sender, e)); }); base.OnWhisperReceived += ((object sender, OnWhisperReceivedArgs e) => { ThreadDispatcher.Enqueue(() => OnWhisperReceived?.Invoke(sender, e)); }); base.OnMessageSent += ((object sender, OnMessageSentArgs e) => { ThreadDispatcher.Enqueue(() => OnMessageSent?.Invoke(sender, e)); }); base.OnWhisperSent += ((object sender, OnWhisperSentArgs e) => { ThreadDispatcher.Enqueue(() => OnWhisperSent?.Invoke(sender, e)); }); base.OnChatCommandReceived += ((object sender, OnChatCommandReceivedArgs e) => { ThreadDispatcher.Enqueue(() => OnChatCommandReceived?.Invoke(sender, e)); }); base.OnWhisperCommandReceived += ((object sender, OnWhisperCommandReceivedArgs e) => { ThreadDispatcher.Enqueue(() => OnWhisperCommandReceived?.Invoke(sender, e)); }); base.OnUserJoined += ((object sender, OnUserJoinedArgs e) => { ThreadDispatcher.Enqueue(() => OnUserJoined?.Invoke(sender, e)); }); base.OnModeratorJoined += ((object sender, OnModeratorJoinedArgs e) => { ThreadDispatcher.Enqueue(() => OnModeratorJoined?.Invoke(sender, e)); }); base.OnModeratorLeft += ((object sender, OnModeratorLeftArgs e) => { ThreadDispatcher.Enqueue(() => OnModeratorLeft?.Invoke(sender, e)); }); base.OnNewSubscriber += ((object sender, OnNewSubscriberArgs e) => { ThreadDispatcher.Enqueue(() => OnNewSubscriber?.Invoke(sender, e)); }); base.OnReSubscriber += ((object sender, OnReSubscriberArgs e) => { ThreadDispatcher.Enqueue(() => OnReSubscriber?.Invoke(sender, e)); }); base.OnHostLeft += ((object sender, EventArgs arg) => { ThreadDispatcher.Enqueue(() => OnHostLeft?.Invoke(sender, arg)); }); base.OnExistingUsersDetected += ((object sender, OnExistingUsersDetectedArgs e) => { ThreadDispatcher.Enqueue(() => OnExistingUsersDetected?.Invoke(sender, e)); }); base.OnUserLeft += ((object sender, OnUserLeftArgs e) => { ThreadDispatcher.Enqueue(() => OnUserLeft?.Invoke(sender, e)); }); base.OnHostingStarted += ((object sender, OnHostingStartedArgs e) => { ThreadDispatcher.Enqueue(() => OnHostingStarted?.Invoke(sender, e)); }); base.OnHostingStopped += ((object sender, OnHostingStoppedArgs e) => { ThreadDispatcher.Enqueue(() => OnHostingStopped?.Invoke(sender, e)); }); base.OnDisconnected += ((object sender, OnDisconnectedEventArgs e) => { ThreadDispatcher.Enqueue(() => OnDisconnected?.Invoke(sender, e)); }); base.OnConnectionError += ((object sender, OnConnectionErrorArgs e) => { ThreadDispatcher.Enqueue(() => OnConnectionError?.Invoke(sender, e)); }); base.OnChatCleared += ((object sender, OnChatClearedArgs e) => { ThreadDispatcher.Enqueue(() => OnChatCleared?.Invoke(sender, e)); }); base.OnUserTimedout += ((object sender, OnUserTimedoutArgs e) => { ThreadDispatcher.Enqueue(() => OnUserTimedout?.Invoke(sender, e)); }); base.OnLeftChannel += ((object sender, OnLeftChannelArgs e) => { ThreadDispatcher.Enqueue(() => OnLeftChannel?.Invoke(sender, e)); }); base.OnUserBanned += ((object sender, OnUserBannedArgs e) => { ThreadDispatcher.Enqueue(() => OnUserBanned?.Invoke(sender, e)); }); base.OnModeratorsReceived += ((object sender, OnModeratorsReceivedArgs e) => { ThreadDispatcher.Enqueue(() => OnModeratorsReceived?.Invoke(sender, e)); }); base.OnChatColorChanged += ((object sender, OnChatColorChangedArgs e) => { ThreadDispatcher.Enqueue(() => OnChatColorChanged?.Invoke(sender, e)); }); base.OnSendReceiveData += ((object sender, OnSendReceiveDataArgs e) => { ThreadDispatcher.Enqueue(() => OnSendReceiveData?.Invoke(sender, e)); }); base.OnNowHosting += ((object sender, OnNowHostingArgs e) => { ThreadDispatcher.Enqueue(() => OnNowHosting?.Invoke(sender, e)); }); base.OnBeingHosted += ((object sender, OnBeingHostedArgs e) => { ThreadDispatcher.Enqueue(() => OnBeingHosted?.Invoke(sender, e)); }); base.OnRaidNotification += ((object sender, OnRaidNotificationArgs e) => { ThreadDispatcher.Enqueue(() => OnRaidNotification?.Invoke(sender, e)); }); base.OnGiftedSubscription += ((object sender, OnGiftedSubscriptionArgs e) => { ThreadDispatcher.Enqueue(() => OnGiftedSubscription?.Invoke(sender, e)); }); base.OnRaidedChannelIsMatureAudience += ((object sender, EventArgs arg) => { ThreadDispatcher.Enqueue(() => OnRaidedChannelIsMatureAudience?.Invoke(sender, arg)); }); base.OnRitualNewChatter += ((object sender, OnRitualNewChatterArgs e) => { ThreadDispatcher.Enqueue(() => OnRitualNewChatter?.Invoke(sender, e)); }); base.OnFailureToReceiveJoinConfirmation += ((object sender, OnFailureToReceiveJoinConfirmationArgs e) => { ThreadDispatcher.Enqueue(() => OnFailureToReceiveJoinConfirmation?.Invoke(sender, e)); }); base.OnUnaccountedFor += ((object sender, OnUnaccountedForArgs e) => { ThreadDispatcher.Enqueue(() => OnUnaccountedFor?.Invoke(sender, e)); }); base.OnSelfRaidError += ((object sender, EventArgs e) => { ThreadDispatcher.Enqueue(() => OnSelfRaidError?.Invoke(sender, e)); }); base.OnNoPermissionError += ((object sender, EventArgs e) => { ThreadDispatcher.Enqueue(() => OnNoPermissionError?.Invoke(sender, e)); }); base.OnMessageCleared += ((object sender, OnMessageClearedArgs e) => { ThreadDispatcher.Enqueue(() => OnMessageCleared?.Invoke(sender, e)); }); base.OnReconnected += ((object sender, OnReconnectedEventArgs e) => { ThreadDispatcher.Enqueue(() => OnReconnected?.Invoke(sender, e)); }); base.OnWhisperThrottled += ((object sender, OnWhisperThrottledEventArgs e) => { ThreadDispatcher.Enqueue(() => OnWhisperThrottled?.Invoke(sender, e)); }); base.OnMessageThrottled += ((object sender, OnMessageThrottledEventArgs e) => { ThreadDispatcher.Enqueue(() => OnMessageThrottled?.Invoke(sender, e)); }); base.OnCommunitySubscription += ((object sender, OnCommunitySubscriptionArgs e) => { ThreadDispatcher.Enqueue(() => OnCommunitySubscription?.Invoke(sender, e)); }); base.OnError += ((object sender, OnErrorEventArgs e) => { ThreadDispatcher.Enqueue(() => OnError?.Invoke(sender, e)); }); base.OnVIPsReceived += ((object sender, OnVIPsReceivedArgs e) => { ThreadDispatcher.Enqueue(() => OnVIPsReceived?.Invoke(sender, e)); }); }