2023-07-23 21:31:13 +00:00
|
|
|
|
using SharpChat.Events;
|
2024-05-20 23:40:34 +00:00
|
|
|
|
using SharpChat.SockChat.PacketsS2C;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2024-05-20 23:40:34 +00:00
|
|
|
|
namespace SharpChat.SockChat.Commands {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class MessageWhisperCommand : ISockChatClientCommand {
|
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("whisper")
|
|
|
|
|
|| ctx.NameEquals("msg");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
if(ctx.Args.Length < 2) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new CommandFormatErrorS2CPacket());
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 22:17:25 +00:00
|
|
|
|
string whisperUserStr = ctx.Args.FirstOrDefault() ?? string.Empty;
|
2024-05-19 21:02:17 +00:00
|
|
|
|
(string name, UsersContext.NameTarget target) = SockChatUtility.ExplodeUserName(whisperUserStr);
|
|
|
|
|
UserInfo? whisperUser = ctx.Chat.Users.Get(name: name, nameTarget: target);
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
if(whisperUser == null) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new UserNotFoundErrorS2CPacket(whisperUserStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-19 22:27:08 +00:00
|
|
|
|
|
2023-02-16 20:34:59 +00:00
|
|
|
|
if(whisperUser == ctx.User)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-07-23 21:31:13 +00:00
|
|
|
|
ctx.Chat.DispatchEvent(new MessageCreateEvent(
|
2023-02-23 21:46:49 +00:00
|
|
|
|
SharpId.Next(),
|
2024-05-19 02:17:51 +00:00
|
|
|
|
UserInfo.GetDMChannelName(ctx.User, whisperUser),
|
2023-07-23 21:31:13 +00:00
|
|
|
|
ctx.User,
|
|
|
|
|
DateTimeOffset.Now,
|
|
|
|
|
string.Join(' ', ctx.Args.Skip(1)),
|
|
|
|
|
true, false, false
|
2023-02-23 21:46:49 +00:00
|
|
|
|
));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|