mirror of
https://github.com/Ikatono/TwitchIrcClient.git
synced 2025-10-29 04:56:12 -05:00
Minor improvements
This commit is contained in:
@@ -9,6 +9,6 @@ namespace TwitchIrcClient.IRC
|
||||
{
|
||||
public record struct Badge(string Name, string Version)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user