Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved detection of a credentials issue for TwitchChat #271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/TagzApp.Providers.TwitchChat/ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ public void Init()
public string ChatBotName { get; }
public bool IsRunning => _ReceiveMessagesThread.IsAlive;

public bool IsConnected { get; private set; }

private readonly string _OAuthToken;
private readonly CancellationTokenSource _Shutdown;

private void Connect()
{

_TcpClient = new TcpClient("irc.chat.twitch.tv", 80);
_TcpClient = new TcpClient("irc.chat.twitch.tv", 6667);

inputStream = new StreamReader(_TcpClient.GetStream());
outputStream = new StreamWriter(_TcpClient.GetStream());
Expand Down Expand Up @@ -231,10 +233,10 @@ private void ProcessMessage(string msg)
//if (userName.Equals(ChatBotName, StringComparison.InvariantCultureIgnoreCase)) return; // Exit and do not process if the bot posted this message


//if (!string.IsNullOrEmpty(userName) && msg.Contains($" JOIN #{ChannelName}"))
//{
// UserJoined?.Invoke(this, new ChatUserJoinedEventArgs { UserName = userName });
//}
if (msg.Contains($"{ChatBotName} :Welcome, GLHF!",StringComparison.InvariantCultureIgnoreCase))
{
IsConnected = true;
}

// Review messages sent to the channel
if (reChatMessage.IsMatch(msg))
Expand Down
2 changes: 2 additions & 0 deletions src/TagzApp.Providers.TwitchChat/IChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface IChatClient : IDisposable

bool IsRunning { get; }

bool IsConnected { get; }

}
15 changes: 15 additions & 0 deletions src/TagzApp.Providers.TwitchChat/TwitchChatProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private async Task ListenForMessages(IChatClient chatClient = null)
catch (Exception ex)
{
_Logger.LogError(ex, "Failed to identify profile pic for {UserName}", args.UserName);
profileUrl = "about:blank";
}

_Contents.Enqueue(new Content
Expand Down Expand Up @@ -120,6 +121,20 @@ public Task<IEnumerable<Content>> GetContentForHashtag(Hashtag tag, DateTimeOffs

}

if (!_Client.IsConnected)
{

// mark status as unhealthy and return empty list
_Status = SocialMediaStatus.Unhealthy;
_StatusMessage = "TwitchChat client is not logged in - check credentials";

return Task.FromResult(Enumerable.Empty<Content>());

} else {
_Status = SocialMediaStatus.Healthy;
_StatusMessage = "OK";
}

var messages = _Contents.ToList();
if (messages.Count() == 0) return Task.FromResult(Enumerable.Empty<Content>());

Expand Down
3 changes: 0 additions & 3 deletions src/TagzApp.Web/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@
`Received ${result.length} additional messages from server`,
);
result.forEach(function (content) {
console.log(
`Formatting ${content.providerId} with state ${content.state}`,
);
FormatMessageForModeration(content);
});
window.Masonry.resizeAllGridItems();
Expand Down
Loading