Minor improvements

This commit is contained in:
Cameron
2024-03-24 08:07:44 -05:00
parent e9bffa4dea
commit 81651a0e59
4 changed files with 17 additions and 24 deletions

View File

@@ -9,6 +9,6 @@ namespace TwitchIrcClient.IRC
{
public record struct Badge(string Name, string Version)
{
}
}

View File

@@ -85,9 +85,6 @@ namespace TwitchIrcClient.IRC.Messages
public string Id => TryGetTag("id");
public UserNoticeType? UserNoticeType => Enum.TryParse(TryGetTag("msg-id"), out UserNoticeType type)
? type : null;
/// <summary>
///
/// </summary>
public string Login => TryGetTag("login");
/// <summary>
/// Whether the user is a moderator in this channel
@@ -263,21 +260,15 @@ namespace TwitchIrcClient.IRC.Messages
public UserType UserType
{ get
{
if (!MessageTags.TryGetValue("user-type", out string? value))
return UserType.None;
switch (value.ToUpper())
var value = TryGetTag("user-type");
return value.ToUpper() switch
{
case "ADMIN":
return UserType.Admin;
case "GLOBAL_MOD":
return UserType.GlobalMod;
case "STAFF":
return UserType.Staff;
case "":
return UserType.Normal;
default:
throw new InvalidDataException();
}
"ADMIN" => UserType.Admin,
"GLOBAL_MOD" => UserType.GlobalMod,
"STAFF" => UserType.Staff,
"" => UserType.Normal,
_ => UserType.Normal,
};
}
}
/// <summary>

View File

@@ -88,25 +88,27 @@ namespace TwitchIrcClient.IRC
{
lock (Semaphore)
{
Semaphore.Release(MessageLimit - Semaphore.CurrentCount);
var count = MessageLimit - Semaphore.CurrentCount;
if (count > 0)
Semaphore.Release(count);
}
}
catch (SemaphoreFullException) { }
catch (SemaphoreFullException) { }
catch (ObjectDisposedException) { }
}
#region RateLimiter Dispose
private bool disposedValue;
//https://stackoverflow.com/questions/8927878/what-is-the-correct-way-of-adding-thread-safety-to-an-idisposable-object
private int _disposedCount;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (Interlocked.Increment(ref _disposedCount) == 1)
{
if (disposing)
{
Semaphore?.Dispose();
Timer?.Dispose();
}
disposedValue = true;
}
}

View File

@@ -52,7 +52,7 @@ async Task<IrcConnection> CreateConnection(string channel)
Console.Write("Channel: ");
var channelName = Console.ReadLine();
ArgumentNullException.ThrowIfNull(channelName, nameof(Channel));
var connection = CreateConnection(channelName);
var connection = await CreateConnection(channelName);
while (true)
{
//all the work happens in other threads