2023-07-23 21:31:13 +00:00
|
|
|
|
using SharpChat.Events;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Packet;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2023-07-23 21:31:13 +00:00
|
|
|
|
namespace SharpChat.Commands {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string whisperUserStr = ctx.Args.FirstOrDefault();
|
2023-02-19 22:27:08 +00:00
|
|
|
|
ChatUser whisperUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(whisperUserStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
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(),
|
2023-07-23 21:31:13 +00:00
|
|
|
|
ChatUser.GetDMChannelName(ctx.User, whisperUser),
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|