sharp-chat/SharpChat/Commands/MessageWhisperCommand.cs

42 lines
1.3 KiB
C#
Raw Normal View History

using SharpChat.Events;
using SharpChat.Packet;
using System;
using System.Linq;
namespace SharpChat.Commands {
public class MessageWhisperCommand : IUserCommand {
public bool IsMatch(UserCommandContext ctx) {
return ctx.NameEquals("whisper")
|| ctx.NameEquals("msg");
}
public void Dispatch(UserCommandContext ctx) {
if(ctx.Args.Length < 2) {
ctx.Chat.SendTo(ctx.User, new CommandFormatErrorPacket());
return;
}
2024-05-14 22:17:25 +00:00
string whisperUserStr = ctx.Args.FirstOrDefault() ?? string.Empty;
2024-05-19 21:02:17 +00:00
(string name, UsersContext.NameTarget target) = SockChatUtility.ExplodeUserName(whisperUserStr);
UserInfo? whisperUser = ctx.Chat.Users.Get(name: name, nameTarget: target);
if(whisperUser == null) {
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new UserNotFoundErrorPacket(whisperUserStr));
return;
}
2023-02-19 22:27:08 +00:00
if(whisperUser == ctx.User)
return;
ctx.Chat.DispatchEvent(new MessageCreateEvent(
SharpId.Next(),
UserInfo.GetDMChannelName(ctx.User, whisperUser),
ctx.User,
DateTimeOffset.Now,
string.Join(' ', ctx.Args.Skip(1)),
true, false, false
));
}
}
}