package com.gamebuster19901.excite.bot.command;
import com.gamebuster19901.excite.Main;
import com.gamebuster19901.excite.Player;
import com.gamebuster19901.excite.Wiimmfi;
import com.gamebuster19901.excite.bot.WiimmfiCommand;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
@SuppressWarnings("rawtypes")
public class WhoIsCommand extends WiimmfiCommand{
public static void register(CommandDispatcher<MessageContext> dispatcher) {
dispatcher.register(Commands.literal("!whois")
.then(Commands.argument("player", StringArgumentType.word())).executes((command) -> {
send(getResponse(command.getSource()), command.getSource());
return 1;
})
);
}
@SuppressWarnings("static-access")
public static String getResponse(MessageContext messageContext) {
Wiimmfi wiimmfi = Main.discordBot.getWiimmfi();
if(checkNotErrored(messageContext)) {
Player[] players = wiimmfi.getKnownPlayers();
int maxLines = 10000;
if(messageContext.isGuildMessage() || messageContext.isPrivateMessage()) {
maxLines = 24;
}
String response = "";
for(int i = 0; i < players.length && i < maxLines; i++) {
response += players[i].toString() + '\n';
if (i == maxLines - 1 && players.length > maxLines) {
response += "and (" + (players.length - 24) + ") others";
}
}
return response;
}
return "Bot offline due to an error: " + wiimmfi.getError().getClass().getCanonicalName() + ": " + wiimmfi.getError().getMessage();
}
}
Comments
0 B
|👍
/👎