Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
attempt to fix issues where badges/cheermotes/third party emotes don'…
Browse files Browse the repository at this point in the history
…t appear in chat
  • Loading branch information
brian91292 committed Apr 8, 2019
1 parent fb4b6b2 commit 214096f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
27 changes: 17 additions & 10 deletions EnhancedStreamChat/Chat/ChatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class ChatHandler : MonoBehaviour
public static ChatHandler Instance = null;
public static ConcurrentQueue<ChatMessage> RenderQueue = new ConcurrentQueue<ChatMessage>();
public static Func<TwitchMessage, bool> ChatMessageFilters;

public bool displayStatusMessage = false;

public Image lockButtonImage;
public Image background;
public GameObject lockButtonPrimitive;
Expand All @@ -52,6 +51,8 @@ public class ChatHandler : MonoBehaviour
private string _lastFontName;
private CustomText _testMessage = null;
private readonly WaitUntil _delay = new WaitUntil(() => { return Instance._waitForFrames == 0; });
private bool _hasDisplayedStatus = false;
private DateTime _startupTime = DateTime.Now;

public static void OnLoad()
{
Expand Down Expand Up @@ -130,31 +131,38 @@ private void OnConfigChanged()
background.color = ChatConfig.Instance.BackgroundColor;
}

public void FixedUpdate()
public void Update()
{
if (Drawing.MaterialsCached)
{
// Wait a few seconds after we've connect to the chat, then send our welcome message
if (displayStatusMessage && TwitchWebSocketClient.Initialized && (TwitchWebSocketClient.IsChannelValid || (DateTime.Now - TwitchWebSocketClient.ConnectionTime).TotalSeconds >= 10))
if (!_hasDisplayedStatus && TwitchWebSocketClient.Initialized && (TwitchWebSocketClient.IsChannelValid || ((DateTime.Now - _startupTime).TotalSeconds >= 10 && (DateTime.Now - TwitchWebSocketClient.ConnectionTime).TotalSeconds >= 10)))
{
string msg;
if (TwitchWebSocketClient.Connected && TwitchWebSocketClient.LoggedIn)
{
ImageDownloader.Instance.Init();

if (TwitchLoginConfig.Instance.TwitchChannelName == String.Empty)
{
msg = $"Welcome to Enhanced Stream Chat! To continue, enter your Twitch channel name in the Enhanced Stream Chat settings submenu, or manually in TwitchLoginInfo.ini, which is located in your Beat Saber\\UserData\\StreamCore directory.";
}
else if (TwitchWebSocketClient.IsChannelValid)
{
ImageDownloader.Instance.Init();
msg = $"Success joining channel \"{TwitchLoginConfig.Instance.TwitchChannelName}\"";
}
else
{
msg = $"Failed to join channel \"{TwitchLoginConfig.Instance.TwitchChannelName}\". Please enter a valid Twitch channel name in the Enhanced Twitch Chat settings submenu, or manually in TwitchLoginInfo.ini, then try again.";
}
}
else
msg = "Failed to login to Twitch! Please check your login info in UserData\\StreamCore\\TwitchLoginInfo.ini, then try again.";

//msg += $" Connected: {TwitchWebSocketClient.Connected}, LoggedIn: {TwitchWebSocketClient.LoggedIn}, ChannelValid: {TwitchWebSocketClient.IsChannelValid}, TimeDiff: {(DateTime.Now - _startupTime).TotalSeconds}";

RenderQueue.Enqueue(new ChatMessage(msg, new TwitchMessage()));

displayStatusMessage = false;
_hasDisplayedStatus = true;
}

if (_configChanged)
Expand Down Expand Up @@ -203,7 +211,6 @@ public void FixedUpdate()
}
StartCoroutine(AddNewChatMessage(messageToSend.msg, messageToSend));
}

}
// Save images to file when we're at the main menu
else if (Globals.IsAtMainMenu && ImageDownloader.ImageSaveQueue.Count > 0 && ImageDownloader.ImageSaveQueue.TryDequeue(out var saveInfo))
Expand Down Expand Up @@ -234,8 +241,8 @@ public void LateUpdate()

private void RegisterMessageHandlers()
{
TwitchWebSocketClient.OnTwitchChannelUpdated += (newChannel) => displayStatusMessage = true;
TwitchWebSocketClient.OnConnected += () => displayStatusMessage = true;
TwitchWebSocketClient.OnTwitchChannelUpdated += (newChannel) => _hasDisplayedStatus = false;
TwitchWebSocketClient.OnConnected += () => _hasDisplayedStatus = false;

// PRIVMSG handler
TwitchMessageHandlers.PRIVMSG += (twitchMsg) =>
Expand Down
2 changes: 1 addition & 1 deletion EnhancedStreamChat/Images/ImageDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void OnLoad()
{
if (Instance) return;

new GameObject("EnhancedTwitchChatImageDownloader").AddComponent<ImageDownloader>();
new GameObject("EnhancedStreamChatImageDownloader").AddComponent<ImageDownloader>();
}

public void Awake()
Expand Down
2 changes: 1 addition & 1 deletion EnhancedStreamChat/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Plugin : IPlugin
{
public static readonly string ModuleName = "EnhancedStreamChat";
public string Name => ModuleName;
public string Version => "2.0.1";
public string Version => "2.0.2";

public static Plugin Instance { get; private set; }

Expand Down
4 changes: 2 additions & 2 deletions EnhancedStreamChat/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyVersion("2.0.2.0")]
[assembly: AssemblyFileVersion("2.0.2.0")]
2 changes: 1 addition & 1 deletion EnhancedStreamChat/UI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void OnLoad()

//MenuButtonUI.AddButton("Restart Game", () => { System.Diagnostics.Process.Start(Path.Combine(Environment.CurrentDirectory, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), Environment.CommandLine); Application.Quit(); });

var menu = SettingsUI.CreateSubMenu("Enhanced Twitch Chat");
var menu = SettingsUI.CreateSubMenu("Enhanced Stream Chat");
var channelName = menu.AddString("Twitch Channel Name", "The name of the channel you want Enhanced Twitch Chat to monitor");
channelName.SetValue += (channel) => { TwitchLoginConfig.Instance.TwitchChannelName = channel; };
channelName.GetValue += () => { return TwitchLoginConfig.Instance.TwitchChannelName; };
Expand Down

0 comments on commit 214096f

Please sign in to comment.