mirror of
https://github.com/Ikatono/TwitchIrcClient.git
synced 2025-10-29 04:56:12 -05:00
Minor improvements
This commit is contained in:
@@ -85,9 +85,6 @@ namespace TwitchIrcClient.IRC.Messages
|
|||||||
public string Id => TryGetTag("id");
|
public string Id => TryGetTag("id");
|
||||||
public UserNoticeType? UserNoticeType => Enum.TryParse(TryGetTag("msg-id"), out UserNoticeType type)
|
public UserNoticeType? UserNoticeType => Enum.TryParse(TryGetTag("msg-id"), out UserNoticeType type)
|
||||||
? type : null;
|
? type : null;
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string Login => TryGetTag("login");
|
public string Login => TryGetTag("login");
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the user is a moderator in this channel
|
/// Whether the user is a moderator in this channel
|
||||||
@@ -263,21 +260,15 @@ namespace TwitchIrcClient.IRC.Messages
|
|||||||
public UserType UserType
|
public UserType UserType
|
||||||
{ get
|
{ get
|
||||||
{
|
{
|
||||||
if (!MessageTags.TryGetValue("user-type", out string? value))
|
var value = TryGetTag("user-type");
|
||||||
return UserType.None;
|
return value.ToUpper() switch
|
||||||
switch (value.ToUpper())
|
|
||||||
{
|
{
|
||||||
case "ADMIN":
|
"ADMIN" => UserType.Admin,
|
||||||
return UserType.Admin;
|
"GLOBAL_MOD" => UserType.GlobalMod,
|
||||||
case "GLOBAL_MOD":
|
"STAFF" => UserType.Staff,
|
||||||
return UserType.GlobalMod;
|
"" => UserType.Normal,
|
||||||
case "STAFF":
|
_ => UserType.Normal,
|
||||||
return UserType.Staff;
|
};
|
||||||
case "":
|
|
||||||
return UserType.Normal;
|
|
||||||
default:
|
|
||||||
throw new InvalidDataException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ namespace TwitchIrcClient.IRC
|
|||||||
{
|
{
|
||||||
lock (Semaphore)
|
lock (Semaphore)
|
||||||
{
|
{
|
||||||
Semaphore.Release(MessageLimit - Semaphore.CurrentCount);
|
var count = MessageLimit - Semaphore.CurrentCount;
|
||||||
|
if (count > 0)
|
||||||
|
Semaphore.Release(count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SemaphoreFullException) { }
|
catch (SemaphoreFullException) { }
|
||||||
@@ -96,17 +98,17 @@ namespace TwitchIrcClient.IRC
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region RateLimiter Dispose
|
#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)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!disposedValue)
|
if (Interlocked.Increment(ref _disposedCount) == 1)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
Semaphore?.Dispose();
|
Semaphore?.Dispose();
|
||||||
Timer?.Dispose();
|
Timer?.Dispose();
|
||||||
}
|
}
|
||||||
disposedValue = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ async Task<IrcConnection> CreateConnection(string channel)
|
|||||||
Console.Write("Channel: ");
|
Console.Write("Channel: ");
|
||||||
var channelName = Console.ReadLine();
|
var channelName = Console.ReadLine();
|
||||||
ArgumentNullException.ThrowIfNull(channelName, nameof(Channel));
|
ArgumentNullException.ThrowIfNull(channelName, nameof(Channel));
|
||||||
var connection = CreateConnection(channelName);
|
var connection = await CreateConnection(channelName);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//all the work happens in other threads
|
//all the work happens in other threads
|
||||||
|
|||||||
Reference in New Issue
Block a user