sharp-chat/SharpChat.SockChat/PacketsS2C/WhoChannelResponseS2CPacket.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2024-05-14 22:17:25 +00:00
using System;
using System.Text;
namespace SharpChat.SockChat.PacketsS2C {
public class WhoChannelResponseS2CPacket : ISockChatS2CPacket {
private readonly long MessageId;
private readonly DateTimeOffset TimeStamp;
2024-05-14 22:17:25 +00:00
private readonly string ChannelName;
private readonly string[] Users;
private readonly string SelfName;
public WhoChannelResponseS2CPacket(string channelName, string[] users, string selfName) {
MessageId = SharpId.Next();
TimeStamp = DateTimeOffset.UtcNow;
2024-05-14 22:17:25 +00:00
ChannelName = channelName;
Users = users;
SelfName = selfName;
}
public string Pack() {
2024-05-14 22:17:25 +00:00
StringBuilder sb = new();
2024-05-19 21:02:17 +00:00
sb.AppendFormat(
"2\t{0}\t-1\t0\fwhochan\f{1}\f",
TimeStamp.ToUnixTimeSeconds(),
2024-05-19 21:02:17 +00:00
SockChatUtility.SanitiseChannelName(ChannelName)
);
2024-05-14 22:17:25 +00:00
foreach(string userName in Users) {
sb.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
if(userName.Equals(SelfName, StringComparison.InvariantCultureIgnoreCase))
sb.Append(@" style=""font-weight: bold;""");
sb.AppendFormat(@">{0}</a>, ", userName);
}
if(Users.Length > 0)
sb.Length -= 2;
sb.AppendFormat("\t{0}\t10010", MessageId);
2024-05-14 22:17:25 +00:00
return sb.ToString();
}
}
}