2023-02-23 21:46:49 +00:00
|
|
|
|
using SharpChat.EventStorage;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2024-05-10 15:24:43 +00:00
|
|
|
|
namespace SharpChat.Packet {
|
2024-05-10 18:29:48 +00:00
|
|
|
|
// this entire class is disgusting
|
2024-05-14 22:17:25 +00:00
|
|
|
|
public class MessagePopulatePacket : ServerPacket {
|
2024-05-10 18:29:48 +00:00
|
|
|
|
private readonly StoredEventInfo Event;
|
|
|
|
|
private readonly bool Notify;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-14 22:17:25 +00:00
|
|
|
|
public MessagePopulatePacket(StoredEventInfo evt, bool notify = false) {
|
2024-05-19 01:53:14 +00:00
|
|
|
|
Event = evt;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
Notify = notify;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
private const string V1_CHATBOT = "-1\tChatBot\tinherit\t";
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 15:24:43 +00:00
|
|
|
|
public override string Pack() {
|
2024-05-09 21:31:19 +00:00
|
|
|
|
bool isAction = Event.Flags.HasFlag(StoredEventFlags.Action);
|
|
|
|
|
bool isBroadcast = Event.Flags.HasFlag(StoredEventFlags.Broadcast);
|
|
|
|
|
bool isPrivate = Event.Flags.HasFlag(StoredEventFlags.Private);
|
|
|
|
|
|
2023-02-07 15:01:56 +00:00
|
|
|
|
StringBuilder sb = new();
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
sb.AppendFormat("7\t1\t{0}\t", Event.Created.ToUnixTimeSeconds());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2023-02-23 21:46:49 +00:00
|
|
|
|
switch(Event.Type) {
|
|
|
|
|
case "msg:add":
|
2024-05-09 21:31:19 +00:00
|
|
|
|
if(isBroadcast) {
|
2023-07-23 21:31:13 +00:00
|
|
|
|
sb.Append(V1_CHATBOT);
|
2024-05-09 21:31:19 +00:00
|
|
|
|
} else {
|
2024-05-10 17:28:52 +00:00
|
|
|
|
sb.AppendFormat(
|
|
|
|
|
"{0}\t{1}\t{2}\t{3} {4} {5} {6} {7}",
|
2024-05-10 19:18:55 +00:00
|
|
|
|
Event.Sender?.UserId,
|
|
|
|
|
Event.Sender?.LegacyNameWithStatus,
|
|
|
|
|
Event.Sender?.Colour,
|
|
|
|
|
Event.Sender?.Rank,
|
2024-05-17 23:50:22 +00:00
|
|
|
|
Event.Sender?.Permissions.HasFlag(ChatUserPermissions.KickUser) == true ? 1 : 0,
|
|
|
|
|
Event.Sender?.Permissions.HasFlag(ChatUserPermissions.ViewLogs) == true ? 1 : 0,
|
|
|
|
|
Event.Sender?.Permissions.HasFlag(ChatUserPermissions.SetOwnNickname) == true ? 1 : 0,
|
|
|
|
|
Event.Sender?.Permissions.HasFlag(ChatUserPermissions.CreateChannel) == true ? (
|
|
|
|
|
Event.Sender?.Permissions.HasFlag(ChatUserPermissions.SetChannelPermanent) == true ? 2 : 1
|
|
|
|
|
) : 0
|
2024-05-10 17:28:52 +00:00
|
|
|
|
);
|
2023-07-23 21:31:13 +00:00
|
|
|
|
}
|
2024-05-09 21:31:19 +00:00
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
sb.Append('\t');
|
|
|
|
|
|
|
|
|
|
if(isBroadcast)
|
|
|
|
|
sb.Append("0\fsay\f");
|
2024-05-09 21:31:19 +00:00
|
|
|
|
|
2024-05-13 20:55:54 +00:00
|
|
|
|
string body = SharpUtil.Sanitise(Event.Data.RootElement.GetProperty("text").GetString());
|
2024-05-09 21:31:19 +00:00
|
|
|
|
if(isAction)
|
2024-05-10 17:28:52 +00:00
|
|
|
|
body = string.Format("<i>{0}</i>", body);
|
|
|
|
|
|
|
|
|
|
sb.Append(body);
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2023-02-23 21:46:49 +00:00
|
|
|
|
case "chan:join":
|
2024-05-10 19:18:55 +00:00
|
|
|
|
sb.AppendFormat("{0}\t0\fjchan\f{1}", V1_CHATBOT, Event.Sender?.LegacyName);
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2023-02-23 21:46:49 +00:00
|
|
|
|
case "chan:leave":
|
2024-05-10 19:18:55 +00:00
|
|
|
|
sb.AppendFormat("{0}\t0\flchan\f{1}", V1_CHATBOT, Event.Sender?.LegacyName);
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(
|
2024-05-10 17:28:52 +00:00
|
|
|
|
"\t{0}\t{1}\t{2}{3}{4}{5}{6}",
|
|
|
|
|
Event.Id < 1 ? SequenceId : Event.Id,
|
|
|
|
|
Notify ? 1 : 0,
|
|
|
|
|
1,
|
|
|
|
|
isAction ? 1 : 0,
|
|
|
|
|
0,
|
|
|
|
|
isAction ? 0 : 1,
|
|
|
|
|
isPrivate ? 1 : 0
|
2022-08-30 15:00:58 +00:00
|
|
|
|
);
|
|
|
|
|
|
2024-05-10 15:24:43 +00:00
|
|
|
|
return sb.ToString();
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|