2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Packet;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
|
|
|
|
public class WhoCommand : IChatCommand {
|
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("who");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
|
|
|
StringBuilder whoChanSB = new();
|
|
|
|
|
string whoChanStr = ctx.Args.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(whoChanStr)) {
|
2023-02-19 22:27:08 +00:00
|
|
|
|
foreach(ChatUser whoUser in ctx.Chat.Users) {
|
|
|
|
|
whoChanSB.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2023-02-19 22:27:08 +00:00
|
|
|
|
if(whoUser == ctx.User)
|
|
|
|
|
whoChanSB.Append(@" style=""font-weight: bold;""");
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
2023-02-19 22:27:08 +00:00
|
|
|
|
whoChanSB.Append('>');
|
2023-02-22 00:28:53 +00:00
|
|
|
|
whoChanSB.Append(whoUser.LegacyName);
|
2023-02-19 22:27:08 +00:00
|
|
|
|
whoChanSB.Append("</a>, ");
|
|
|
|
|
}
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
if(whoChanSB.Length > 2)
|
|
|
|
|
whoChanSB.Length -= 2;
|
|
|
|
|
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.USERS_LISTING_SERVER, false, whoChanSB));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
} else {
|
2023-02-19 22:27:08 +00:00
|
|
|
|
ChatChannel whoChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(whoChanStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
if(whoChan == null) {
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.CHANNEL_NOT_FOUND, true, whoChanStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(whoChan.Rank > ctx.User.Rank || (whoChan.HasPassword && !ctx.User.Can(ChatUserPermissions.JoinAnyChannel))) {
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.USERS_LISTING_ERROR, true, whoChanStr));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-17 19:02:35 +00:00
|
|
|
|
foreach(ChatUser whoUser in ctx.Chat.GetChannelUsers(whoChan)) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
whoChanSB.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
|
|
|
|
|
|
|
|
|
|
if(whoUser == ctx.User)
|
|
|
|
|
whoChanSB.Append(@" style=""font-weight: bold;""");
|
|
|
|
|
|
|
|
|
|
whoChanSB.Append('>');
|
2023-02-22 00:28:53 +00:00
|
|
|
|
whoChanSB.Append(whoUser.LegacyName);
|
2023-02-16 20:34:59 +00:00
|
|
|
|
whoChanSB.Append("</a>, ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(whoChanSB.Length > 2)
|
|
|
|
|
whoChanSB.Length -= 2;
|
|
|
|
|
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.USERS_LISTING_CHANNEL, false, whoChan.Name, whoChanSB));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|