70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace SharpChat {
|
|
public class ChatUser {
|
|
public const int DEFAULT_SIZE = 30;
|
|
public const int DEFAULT_MINIMUM_DELAY = 10000;
|
|
public const int DEFAULT_RISKY_OFFSET = 5;
|
|
|
|
public long UserId { get; }
|
|
public string UserName { get; set; }
|
|
public ChatColour Colour { get; set; }
|
|
public int Rank { get; set; }
|
|
public ChatUserPermissions Permissions { get; set; }
|
|
public bool IsSuper { get; set; }
|
|
public string NickName { get; set; }
|
|
public ChatUserStatus Status { get; set; }
|
|
public string StatusText { get; set; }
|
|
|
|
public string LegacyName => string.IsNullOrWhiteSpace(NickName) ? UserName : $"~{NickName}";
|
|
|
|
public string LegacyNameWithStatus {
|
|
get {
|
|
StringBuilder sb = new();
|
|
|
|
if(Status == ChatUserStatus.Away)
|
|
sb.AppendFormat("<{0}>_", StatusText[..Math.Min(StatusText.Length, 5)].ToUpperInvariant());
|
|
|
|
sb.Append(LegacyName);
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
public ChatUser(
|
|
long userId,
|
|
string userName,
|
|
ChatColour colour,
|
|
int rank,
|
|
ChatUserPermissions perms,
|
|
string? nickName = null,
|
|
ChatUserStatus status = ChatUserStatus.Online,
|
|
string? statusText = null,
|
|
bool isSuper = false
|
|
) {
|
|
UserId = userId;
|
|
UserName = userName;
|
|
Colour = colour;
|
|
Rank = rank;
|
|
Permissions = perms;
|
|
NickName = nickName ?? string.Empty;
|
|
Status = status;
|
|
StatusText = statusText ?? string.Empty;
|
|
IsSuper = isSuper;
|
|
}
|
|
|
|
public bool NameEquals(string? name) {
|
|
return string.Equals(name, UserName, StringComparison.InvariantCultureIgnoreCase)
|
|
|| string.Equals(name, NickName, StringComparison.InvariantCultureIgnoreCase)
|
|
|| string.Equals(name, LegacyName, StringComparison.InvariantCultureIgnoreCase)
|
|
|| string.Equals(name, LegacyNameWithStatus, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public static string GetDMChannelName(ChatUser user1, ChatUser user2) {
|
|
return user1.UserId < user2.UserId
|
|
? $"@{user1.UserId}-{user2.UserId}"
|
|
: $"@{user2.UserId}-{user1.UserId}";
|
|
}
|
|
}
|
|
}
|