From 4c701bf33e13351d474b9ea6f42e96c98812367c Mon Sep 17 00:00:00 2001 From: LuckyNoS7evin Date: Sun, 18 Mar 2018 22:11:26 +0000 Subject: [PATCH 1/3] Fix for OnBeingHosted event --- TwitchLib.Unity/Client.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/TwitchLib.Unity/Client.cs b/TwitchLib.Unity/Client.cs index 798cd3f..cd5a9b2 100644 --- a/TwitchLib.Unity/Client.cs +++ b/TwitchLib.Unity/Client.cs @@ -1,6 +1,7 @@ using System; using TwitchLib.Client; using TwitchLib.Client.Events; +using TwitchLib.Client.Exceptions; using TwitchLib.Client.Interfaces; using UnityEngine; @@ -8,6 +9,7 @@ namespace TwitchLib.Unity { public class Client : TwitchClient, ITwitchClient { + private readonly GameObject _threadDispatcher; #region Events @@ -205,15 +207,27 @@ public class Client : TwitchClient, ITwitchClient public new event EventHandler OnUnaccountedFor; #endregion + public new bool OverrideBeingHostedCheck { get; set; } public Client() : base(null) { _threadDispatcher = new GameObject("TwitchClientUnityDispatcher"); _threadDispatcher.AddComponent(); UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher); - - base.OnLog += ((object sender, OnLogArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnLog?.Invoke(sender, e)); }); + + base.OverrideBeingHostedCheck = true; + + base.OnLog += (object sender, OnLogArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnLog?.Invoke(sender, e)); }; base.OnConnected += ((object sender, OnConnectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnConnected?.Invoke(sender, e)); }); - base.OnJoinedChannel += ((object sender, OnJoinedChannelArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnJoinedChannel?.Invoke(sender, e)); }); + + base.OnJoinedChannel += ((object sender, OnJoinedChannelArgs e) => { + + ThreadDispatcher.Instance().Enqueue(() => OnJoinedChannel?.Invoke(sender, e)); + + if (OnBeingHosted == null) return; + if (e.Channel.ToLower() != TwitchUsername && !OverrideBeingHostedCheck) + ThreadDispatcher.Instance().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.Instance().Enqueue(() => OnIncorrectLogin?.Invoke(sender, e)); }); base.OnChannelStateChanged += ((object sender, OnChannelStateChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChannelStateChanged?.Invoke(sender, e)); }); base.OnUserStateChanged += ((object sender, OnUserStateChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserStateChanged?.Invoke(sender, e)); }); From 8b4899c0d7411cadd7e71f041a3b7b27e9b71983 Mon Sep 17 00:00:00 2001 From: LuckyNoS7evin Date: Sun, 18 Mar 2018 22:53:29 +0000 Subject: [PATCH 2/3] Better Exception Handling in base TwitchClient --- TwitchLib.Unity/Client.cs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/TwitchLib.Unity/Client.cs b/TwitchLib.Unity/Client.cs index cd5a9b2..bdd1f92 100644 --- a/TwitchLib.Unity/Client.cs +++ b/TwitchLib.Unity/Client.cs @@ -3,14 +3,27 @@ using TwitchLib.Client.Events; using TwitchLib.Client.Exceptions; using TwitchLib.Client.Interfaces; +using TwitchLib.Client.Models; using UnityEngine; namespace TwitchLib.Unity { public class Client : TwitchClient, ITwitchClient { - private readonly GameObject _threadDispatcher; + public new bool OverrideBeingHostedCheck { get; set; } + + public new ConnectionCredentials ConnectionCredentials + { + get => base.ConnectionCredentials; + set + { + if (IsConnected) + ThreadDispatcher.Instance().Enqueue(() => throw new IllegalAssignmentException("While the client is connected, you are unable to change the connection credentials. Please disconnect first and then change them.")); + base.ConnectionCredentials = value; + TwitchUsername = value.TwitchUsername; + } + } #region Events /// @@ -207,7 +220,6 @@ public class Client : TwitchClient, ITwitchClient public new event EventHandler OnUnaccountedFor; #endregion - public new bool OverrideBeingHostedCheck { get; set; } public Client() : base(null) { _threadDispatcher = new GameObject("TwitchClientUnityDispatcher"); @@ -267,6 +279,23 @@ public Client() : base(null) base.OnSelfRaidError += ((object sender, EventArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnSelfRaidError?.Invoke(sender, e)); }); base.OnNoPermissionError += ((object sender, EventArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNoPermissionError?.Invoke(sender, e)); }); } + + /// + /// Sends a request to get channel moderators. You MUST listen to OnModeratorsReceived event./>. + /// + /// JoinedChannel object to designate which channel to send request to. + public new void GetChannelModerators(JoinedChannel channel) + { + if (!IsInitialized) HandleNotInitialized(); + if (OnModeratorsReceived == null) + throw new EventNotHandled("OnModeratorsReceived"); + SendMessage(channel, "/mods"); + } + + private new void HandleNotInitialized() + { + ThreadDispatcher.Instance().Enqueue(() => throw new ClientNotInitializedException("The twitch client has not been initialized and cannot be used. Please call Initialize();")); + } } } From 473b47fe0b8112b802b2718ce4d6d32fce8b4ec5 Mon Sep 17 00:00:00 2001 From: LuckyNoS7evin Date: Sun, 18 Mar 2018 22:55:23 +0000 Subject: [PATCH 3/3] Update Version --- TwitchLib.Unity/TwitchLib.Unity.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TwitchLib.Unity/TwitchLib.Unity.csproj b/TwitchLib.Unity/TwitchLib.Unity.csproj index 13063f8..e039444 100644 --- a/TwitchLib.Unity/TwitchLib.Unity.csproj +++ b/TwitchLib.Unity/TwitchLib.Unity.csproj @@ -3,7 +3,7 @@ net452 TwitchLib.Unity - 0.9.0 + 0.9.1 Unity wrapper system for TwitchLib false LuckyNoS7evin @@ -17,8 +17,8 @@ Git twitch library unity3d unity dotnet c# csharp net standard 2.0 en-US - 0.9.0.0 - 0.9.0.0 + 0.9.1.0 + 0.9.1.0