sharp-chat/SharpChat/ChatUser.cs

71 lines
2.4 KiB
C#
Raw Normal View History

using System;
2022-08-30 15:00:58 +00:00
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; }
2022-08-30 15:00:58 +00:00
public ChatColour Colour { get; set; }
public int Rank { get; set; }
public ChatUserPermissions Permissions { get; set; }
2023-11-07 14:49:12 +00:00
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 {
2022-08-30 15:00:58 +00:00
get {
2023-02-07 15:01:56 +00:00
StringBuilder sb = new();
2022-08-30 15:00:58 +00:00
if(Status == ChatUserStatus.Away)
sb.AppendFormat("<{0}>_", StatusText[..Math.Min(StatusText.Length, 5)].ToUpperInvariant());
2022-08-30 15:00:58 +00:00
sb.Append(LegacyName);
2022-08-30 15:00:58 +00:00
return sb.ToString();
}
}
public ChatUser(
long userId,
string userName,
ChatColour colour,
int rank,
ChatUserPermissions perms,
2024-05-10 19:18:55 +00:00
string? nickName = null,
ChatUserStatus status = ChatUserStatus.Online,
2024-05-10 19:18:55 +00:00
string? statusText = null,
2023-11-07 14:49:12 +00:00
bool isSuper = false
) {
UserId = userId;
UserName = userName;
Colour = colour;
Rank = rank;
Permissions = perms;
NickName = nickName ?? string.Empty;
Status = status;
StatusText = statusText ?? string.Empty;
2024-05-10 17:28:52 +00:00
IsSuper = isSuper;
}
2024-05-10 19:18:55 +00:00
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);
}
2023-02-16 22:56:50 +00:00
public static string GetDMChannelName(ChatUser user1, ChatUser user2) {
return user1.UserId < user2.UserId
? $"@{user1.UserId}-{user2.UserId}"
: $"@{user2.UserId}-{user1.UserId}";
}
2022-08-30 15:00:58 +00:00
}
}