2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Events;
|
|
|
|
|
using SharpChat.Packet;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
|
|
|
|
public class WhisperCommand : IChatCommand {
|
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("whisper")
|
|
|
|
|
|| ctx.NameEquals("msg");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
|
|
|
if(ctx.Args.Length < 2) {
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.COMMAND_FORMAT_ERROR));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChatUser whisperUser;
|
|
|
|
|
string whisperUserStr = ctx.Args.FirstOrDefault();
|
|
|
|
|
lock(ctx.Chat.UsersAccess)
|
|
|
|
|
whisperUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(whisperUserStr));
|
|
|
|
|
|
|
|
|
|
if(whisperUser == null) {
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.USER_NOT_FOUND, true, whisperUserStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(whisperUser == ctx.User)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string whisperStr = string.Join(' ', ctx.Args.Skip(1));
|
|
|
|
|
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(whisperUser, new ChatMessageAddPacket(new ChatMessage {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
DateTime = DateTimeOffset.Now,
|
2023-02-16 22:47:30 +00:00
|
|
|
|
ChannelName = string.Empty,
|
2023-02-16 20:34:59 +00:00
|
|
|
|
Sender = ctx.User,
|
|
|
|
|
Text = whisperStr,
|
|
|
|
|
Flags = ChatMessageFlags.Private,
|
|
|
|
|
}));
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChatMessageAddPacket(new ChatMessage {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
DateTime = DateTimeOffset.Now,
|
2023-02-16 22:47:30 +00:00
|
|
|
|
ChannelName = string.Empty,
|
2023-02-16 20:34:59 +00:00
|
|
|
|
Sender = ctx.User,
|
|
|
|
|
Text = $"{whisperUser.DisplayName} {whisperStr}",
|
|
|
|
|
Flags = ChatMessageFlags.Private,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|