39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using SharpChat.Events;
|
|
using SharpChat.SockChat.PacketsS2C;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat.SockChat.Commands {
|
|
public class MessageWhisperCommand : ISockChatClientCommand {
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
|
return ctx.NameEquals("whisper")
|
|
|| ctx.NameEquals("msg");
|
|
}
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
|
if(ctx.Args.Length < 2) {
|
|
ctx.Chat.SendTo(ctx.User, new CommandFormatErrorS2CPacket());
|
|
return;
|
|
}
|
|
|
|
string whisperUserStr = ctx.Args.FirstOrDefault() ?? string.Empty;
|
|
(string name, UsersContext.NameTarget target) = SockChatUtility.ExplodeUserName(whisperUserStr);
|
|
UserInfo? whisperUser = ctx.Chat.Users.Get(name: name, nameTarget: target);
|
|
|
|
if(whisperUser == null) {
|
|
ctx.Chat.SendTo(ctx.User, new UserNotFoundErrorS2CPacket(whisperUserStr));
|
|
return;
|
|
}
|
|
|
|
if(whisperUser == ctx.User)
|
|
return;
|
|
|
|
ctx.Chat.Events.Dispatch(
|
|
"msg:add",
|
|
UserInfo.GetDMChannelName(ctx.User, whisperUser),
|
|
ctx.User,
|
|
new MessageAddEventData(string.Join(' ', ctx.Args.Skip(1)))
|
|
);
|
|
}
|
|
}
|
|
}
|