sharp-chat/SharpChat/Commands/BroadcastCommand.cs

34 lines
1.1 KiB
C#

using SharpChat.Events;
using SharpChat.S2CPackets;
namespace SharpChat.Commands {
public class BroadcastCommand : IChatCommand {
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("say")
|| ctx.NameEquals("broadcast");
}
public void Dispatch(ChatCommandContext ctx) {
long msgId = ctx.Chat.RandomSnowflake.Next();
if(!ctx.User.Can(ChatUserPermissions.Broadcast)) {
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
return;
}
ctx.Chat.DispatchEvent(new MessageCreateEvent(
msgId,
string.Empty,
ctx.User.UserId,
ctx.User.UserName,
ctx.User.Colour,
ctx.User.Rank,
ctx.User.NickName,
ctx.User.Permissions,
DateTimeOffset.Now,
string.Join(' ', ctx.Args),
false, false, true
));
}
}
}