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 {
|
2024-05-14 22:17:25 +00:00
|
|
|
|
public class MessageWhisperCommand : IChatCommand {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("whisper")
|
|
|
|
|
|| ctx.NameEquals("msg");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
|
|
|
if(ctx.Args.Length < 2) {
|
2024-05-14 19:11:09 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new CommandFormatErrorPacket());
|
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-10 19:18:55 +00:00
|
|
|
|
ChatUser? whisperUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(whisperUserStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
if(whisperUser == null) {
|
2024-05-14 22:17:25 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new UserNotFoundErrorPacket(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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|