sharp-chat/SharpChat/Commands/JoinChannelCommand.cs
flashwave e17aed7c25
Switched to Index brand random Snowflakes instead of SharpIds.
If you were still handling message ids as integers in an environment that can't handle signed 64-bit integers you're going to be having a fun time after this update!
2025-04-25 20:05:57 +00:00

23 lines
861 B
C#

using SharpChat.Packet;
namespace SharpChat.Commands {
public class JoinChannelCommand : IChatCommand {
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("join");
}
public void Dispatch(ChatCommandContext ctx) {
long msgId = ctx.Chat.RandomSnowflake.Next();
string joinChanStr = ctx.Args.FirstOrDefault() ?? "Channel";
ChatChannel? joinChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(joinChanStr));
if(joinChan is null) {
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(msgId, LCR.CHANNEL_NOT_FOUND, true, joinChanStr));
ctx.Chat.ForceChannel(ctx.User);
return;
}
ctx.Chat.SwitchChannel(ctx.User, joinChan, string.Join(' ', ctx.Args.Skip(1)));
}
}
}