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-19 02:17:51 +00:00
|
|
|
|
public class MessageWhisperCommand : IUserCommand {
|
|
|
|
|
public bool IsMatch(UserCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("whisper")
|
|
|
|
|
|| ctx.NameEquals("msg");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-19 02:17:51 +00:00
|
|
|
|
public void Dispatch(UserCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
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-19 02:17:51 +00:00
|
|
|
|
UserInfo? whisperUser = ctx.Chat.Users.Values.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(),
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|