2023-02-22 00:28:53 +00:00
|
|
|
|
using System;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat {
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public class UserInfo {
|
2023-02-17 22:17:24 +00:00
|
|
|
|
public const int DEFAULT_SIZE = 30;
|
|
|
|
|
public const int DEFAULT_MINIMUM_DELAY = 10000;
|
|
|
|
|
public const int DEFAULT_RISKY_OFFSET = 5;
|
|
|
|
|
|
2023-02-22 00:28:53 +00:00
|
|
|
|
public long UserId { get; }
|
|
|
|
|
public string UserName { get; set; }
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public Colour Colour { get; set; }
|
2022-08-30 15:00:58 +00:00
|
|
|
|
public int Rank { get; set; }
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public UserPermissions Permissions { get; set; }
|
2023-11-07 14:49:12 +00:00
|
|
|
|
public bool IsSuper { get; set; }
|
2023-02-22 00:28:53 +00:00
|
|
|
|
public string NickName { get; set; }
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public UserStatus Status { get; set; }
|
2023-02-22 00:28:53 +00:00
|
|
|
|
public string StatusText { get; set; }
|
2023-02-17 21:47:44 +00:00
|
|
|
|
|
2024-05-09 21:31:19 +00:00
|
|
|
|
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
|
|
|
|
|
2024-05-19 02:17:51 +00:00
|
|
|
|
if(Status == UserStatus.Away)
|
2023-02-22 00:28:53 +00:00
|
|
|
|
sb.AppendFormat("<{0}>_", StatusText[..Math.Min(StatusText.Length, 5)].ToUpperInvariant());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-09 21:31:19 +00:00
|
|
|
|
sb.Append(LegacyName);
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public UserInfo(
|
2023-02-22 00:28:53 +00:00
|
|
|
|
long userId,
|
2024-05-19 01:53:14 +00:00
|
|
|
|
string userName,
|
2024-05-19 02:17:51 +00:00
|
|
|
|
Colour colour,
|
2023-02-22 00:28:53 +00:00
|
|
|
|
int rank,
|
2024-05-19 02:17:51 +00:00
|
|
|
|
UserPermissions perms,
|
2024-05-10 19:18:55 +00:00
|
|
|
|
string? nickName = null,
|
2024-05-19 02:17:51 +00:00
|
|
|
|
UserStatus status = UserStatus.Online,
|
2024-05-10 19:18:55 +00:00
|
|
|
|
string? statusText = null,
|
2023-11-07 14:49:12 +00:00
|
|
|
|
bool isSuper = false
|
2023-02-22 00:28:53 +00:00
|
|
|
|
) {
|
|
|
|
|
UserId = userId;
|
2024-05-19 01:53:14 +00:00
|
|
|
|
UserName = userName;
|
2023-02-22 00:28:53 +00:00
|
|
|
|
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;
|
2023-02-17 21:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 19:18:55 +00:00
|
|
|
|
public bool NameEquals(string? name) {
|
2023-02-22 00:28:53 +00:00
|
|
|
|
return string.Equals(name, UserName, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
|| string.Equals(name, NickName, StringComparison.InvariantCultureIgnoreCase)
|
2024-05-09 21:31:19 +00:00
|
|
|
|
|| string.Equals(name, LegacyName, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
|| string.Equals(name, LegacyNameWithStatus, StringComparison.InvariantCultureIgnoreCase);
|
2023-02-17 21:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public static string GetDMChannelName(UserInfo user1, UserInfo user2) {
|
2023-02-16 22:56:50 +00:00
|
|
|
|
return user1.UserId < user2.UserId
|
|
|
|
|
? $"@{user1.UserId}-{user2.UserId}"
|
|
|
|
|
: $"@{user2.UserId}-{user1.UserId}";
|
|
|
|
|
}
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|