using SharpChat.Events; using SharpChat.Packet; using System; using System.Linq; namespace SharpChat.Commands { public class MessageWhisperCommand : IChatCommand { public bool IsMatch(ChatCommandContext ctx) { return ctx.NameEquals("whisper") || ctx.NameEquals("msg"); } public void Dispatch(ChatCommandContext ctx) { if(ctx.Args.Length < 2) { ctx.Chat.SendTo(ctx.User, new CommandFormatErrorPacket()); return; } string whisperUserStr = ctx.Args.FirstOrDefault() ?? string.Empty; ChatUser? whisperUser = ctx.Chat.Users.Values.FirstOrDefault(u => u.NameEquals(whisperUserStr)); if(whisperUser == null) { ctx.Chat.SendTo(ctx.User, new UserNotFoundErrorPacket(whisperUserStr)); return; } if(whisperUser == ctx.User) return; ctx.Chat.DispatchEvent(new MessageCreateEvent( SharpId.Next(), ChatUser.GetDMChannelName(ctx.User, whisperUser), ctx.User, DateTimeOffset.Now, string.Join(' ', ctx.Args.Skip(1)), true, false, false )); } } }