use of com.gamebuster19901.excite.util.Named in project ExciteBot by TheGameCommunity.
the class WhoIsCommand method sendResponse.
@SuppressWarnings("serial")
public static int sendResponse(MessageContext context, String lookingFor) {
if (context.isConsoleMessage() || context.isIngameEvent()) {
context.sendMessage("You cannot execute this command as " + context.getEvent().getClass().getSimpleName());
return 1;
}
Wiimmfi wiimmfi = Main.discordBot.getWiimmfi();
EmbedBuilder embed = new EmbedBuilder();
boolean hasMembers = context.isGuildMessage();
if (wiimmfi.getError() == null) {
if (!lookingFor.isEmpty()) {
HashSet<DiscordUser> users = new HashSet<DiscordUser>() {
{
this.addAll(Arrays.asList(DiscordUser.getDiscordUsersWithUsernameOrID(context, lookingFor)));
}
};
HashSet<Player> players = new HashSet<Player>() {
{
this.addAll(Arrays.asList(Player.getPlayersByAnyIdentifier(context, lookingFor)));
}
};
HashSet<Named> matches = new HashSet<Named>();
matches.addAll(users);
matches.addAll(players);
SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd HH:mm z", Locale.ENGLISH);
if (matches.size() == 1) {
Named match = matches.iterator().next();
embed.setTitle("Information about " + match.getIdentifierName());
if (match instanceof DiscordUser) {
DiscordUser user = (DiscordUser) match;
Member member;
embed.setColor(Color.WHITE);
Wii[] wiis = user.getRegisteredWiis();
Set<Player> profiles = user.getProfiles(context);
Duration timeOnline = Duration.ZERO;
Instant lastOnline = TimeUtils.PLAYER_EPOCH;
String profileList = "";
String wiiList = "";
for (Player profile : profiles) {
profileList = profileList + profile.toEmbedstring() + "\n";
timeOnline = timeOnline.plus(profile.getOnlineDuration());
Instant profileLastOnline = profile.getLastOnline();
if (profileLastOnline.isAfter(lastOnline)) {
lastOnline = profileLastOnline;
}
}
for (Wii wii : wiis) {
wiiList = wiiList + wii.getName() + "\n";
}
if (hasMembers && (member = user.getMember(context.getServer())) != null) {
embed.setColor(member.getColor());
embed.setThumbnail(user.getJDAUser().getEffectiveAvatarUrl());
embed.addField("Username:", user.getJDAUser().getName(), false);
embed.addField("Discriminator", user.getJDAUser().getDiscriminator(), false);
// embed.addField("Badges:", "", false);
embed.addField("ID:", "" + user.getID(), false);
embed.addField("Nickname:", member.getNickname() != null ? member.getNickname() : "##Not Nicknamed##", false);
embed.addField("Joined Discord:", date.format(member.getTimeCreated().toInstant().toEpochMilli()), false);
embed.addField("Joined " + context.getServer().getName() + ":", date.format(member.getTimeJoined().toInstant().toEpochMilli()), false);
embed.addField("Member for:", readableDuration(TimeUtils.since(member.getTimeJoined().toInstant()), false), false);
embed.addField("Time Online:", readableDuration(timeOnline, true), false);
embed.addField(profiles.size() + " registered Profiles:", profileList, false);
embed.addField(wiis.length + " registered Wiis:", wiiList, false);
} else {
embed.setThumbnail(user.getJDAUser().getEffectiveAvatarUrl());
embed.addField("Username:", user.getJDAUser().getName(), false);
embed.addField("Discriminator", user.getJDAUser().getDiscriminator(), false);
embed.addField("ID:", "" + user.getID(), false);
embed.addField("Time Online:", readableDuration(timeOnline, true), false);
embed.addField(profiles.size() + " registered Profiles:", profileList, false);
embed.addField(wiis.length + " registered Wiis:", wiiList, false);
embed.appendDescription("For more information, execute this command in a server the user is in.");
}
} else if (match instanceof Player) {
Player profile = (Player) match;
DiscordUser user = DiscordUser.getDiscordUserTreatingUnknownsAsNobody(context, profile.getDiscord());
embed.addField("Name:", profile.getName(), false);
embed.addField("ID:", profile.getID() + "", false);
embed.addField("FC:", profile.getFriendCode(), false);
embed.addField("Owner:", user.toDetailedString(), false);
embed.addField("Time Online:", readableDuration(profile.getOnlineDuration(), true), false);
embed.addField("First Seen:", date.format(profile.getFirstSeen().toEpochMilli()), false);
embed.addField("Last Seen:", date.format(profile.getLastOnline().toEpochMilli()), false);
}
} else if (matches.size() == 0) {
embed.setColor(Color.RED);
embed.setTitle("Target not found");
embed.addField("Target:", lookingFor, true);
} else {
embed.setTitle("Ambigious target string, supply an ID");
embed.setColor(Color.RED);
embed.addField("Target", lookingFor, true);
embed.addField("Ambiguities", "" + matches.size(), true);
if (users.size() > 0) {
embed.appendDescription("Discord users:\n");
String userList = "";
for (DiscordUser user : users) {
Member member;
if (hasMembers && (member = user.getMember(context.getServer())) != null && member.getNickname() != null) {
userList = userList + user.toDetailedString() + " AKA " + member.getEffectiveName() + "#" + member.getIdLong() + "\n";
} else {
userList = userList + user.toDetailedString() + "\n";
}
}
embed.addField("Ambiguous Users:", userList, false);
}
if (players.size() > 0) {
String playerList = "";
for (Player player : players) {
playerList = playerList + player.toFullString() + "\n";
}
embed.addField("Ambiguous Profiles:", playerList, false);
}
}
embed.setTimestamp(Instant.now());
context.sendMessage(embed.build());
}
}
return 1;
}
use of com.gamebuster19901.excite.util.Named in project ExciteBot by TheGameCommunity.
the class MessageContext method getAuthor.
public Named getAuthor() {
Named author;
author = getDiscordAuthor();
if (author == null) {
author = getPlayerAuthor();
}
return author;
}
use of com.gamebuster19901.excite.util.Named in project ExciteBot by TheGameCommunity.
the class Banee method getBanee.
@Nullable
@SuppressWarnings({ "rawtypes", "deprecation" })
public static Banee getBanee(MessageContext context, String name) {
DiscordUser[] discords = DiscordUser.getDiscordUsersWithUsername(context, name);
Player[] players = Player.getPlayersByName(context, name);
int amount = discords.length + players.length;
if (amount == 1) {
if (discords.length == 1) {
return discords[0];
}
return players[0];
} else if (amount < 1) {
context.sendMessage("Could not find a discord user or player named " + name);
} else if (amount > 1) {
String ret = name + " is ambiguous, please supply an ID instead.\n\nAmbiguities\n\n:";
if (discords.length > 0) {
ret = ret + "Discord Users:\n";
for (DiscordUser discord : discords) {
ret = ret + discord.toDetailedString();
}
}
if (players.length > 0) {
ret = ret + "Profiles:\n";
for (Player player : players) {
ret = ret + player.toFullString();
}
}
context.sendMessage(ret);
}
return null;
}
Aggregations