public class OSINTCommand extends Command {
private final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
private final HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(5))
.build();
private File osintDir;
public OSINTCommand() {
super("osint");
}
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(
RequiredArgumentBuilder.<CommandSource, String>argument("playerName", StringArgumentType.string())
.executes(this::executeOSINT)
);
builder.then(literal("dir").executes(context -> {
openDirectory();
return SINGLE_SUCCESS;
}));
}
@Override
public void executeBuild(LiteralArgumentBuilder<CommandSource> builder) {
build(builder);
}
private int executeOSINT(CommandContext<CommandSource> context) {
String playerName = StringArgumentType.getString(context, "playerName");
searchPlayer(playerName);
return SINGLE_SUCCESS;
}
public void searchPlayer(String playerName) {
sendMessage(Formatting.YELLOW + "Начат поиск информации по игроку: " + playerName);
osintDir = new File(mc.runDirectory, "osint");
if (!osintDir.exists()) {
osintDir.mkdirs();
}
File file = new File(osintDir, "Osint" + playerName + ".txt");
String[] sites = {
"https://github.com/",
"https://www.instagram.com/",
"https://twitter.com/",
"https://www.facebook.com/",
"https://www.twitch.tv/",
"https://www.reddit.com/user/",
"https://ru.pinterest.com/",
"https://steamcommunity.com/id/",
"https://vk.com/",
"https://www.linkedin.com/in/",
"https://t.me/", // Telegram
"https://www.behance.net/", // Behance
"https://about.me/", // About.me
"https://www.flickr.com/people/", // Flickr
"https://vimeo.com/",
"https://soundcloud.com/",
"https://deviantart.com/",
"https://ok.ru/",
"https://www.snapchat.com/add/",
"https://www.periscope.tv/",
"https://www.discogs.com/user/",
"https://open.spotify.com/user/",
"https://myspace.com/",
"https://ask.fm/",
"https://www.last.fm/user/",
"https://mixcloud.com/",
"https://www.strava.com/athletes/",
"https://www.ebay.com/usr/",
"https://www.goodreads.com/",
"https://hackerone.com/",
"https://replit.com/",
"https://www.npmjs.com/~",
"https://www.producthunt.com/",
"https://keybase.io/",
"https://www.patreon.com/",
"https://bitbucket.org/",
"https://angel.co/u/",
"https://dribbble.com/",
"https://500px.com/",
"https://www.quora.com/profile/",
"https://www.medium.com/@",
"https://dev.to/",
"https://codepen.io/",
"https://gitlab.com/"
};
List<CompletableFuture<Void>> futures = new ArrayList<>();
try {
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("Результаты поиска по игроку: " + playerName + "\n\n");
for (String site : sites) {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> searchSite(site, playerName, fileWriter), executor);
futures.add(future);
}
CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
allFutures.thenRun(() -> {
try {
sendMessage(Formatting.DARK_PURPLE + "Поиск завершён для ника: " + playerName);
fileWriter.close();
} catch (IOException e) {
sendMessage(Formatting.RED + "Ошибка закрытия файла: " + e.getMessage());
}
});
} catch (IOException e) {
sendMessage(Formatting.RED + "Ошибка при создании файла: " + e.getMessage());
}
}
private void searchSite(String site, String playerName, FileWriter fileWriter) {
try {
URI uri = new URI(site + playerName);
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.GET()
.header("User-Agent", "Mozilla/5.0")
.timeout(Duration.ofSeconds(3))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
synchronized (fileWriter) {
if (response.statusCode() == 200 && response.body().contains(playerName)) {
sendMessage(Formatting.GREEN + "[+] Найден на сайте: " + site + playerName);
fileWriter.write("[+] Найден на сайте: " + site + playerName + "\n");
} else {
sendMessage(Formatting.RED + "[-] Не найден на сайте: " + site + playerName);
fileWriter.write("[-] Не найден на сайте: " + site + playerName + "\n");
}
fileWriter.flush();
}
} catch (Exception e) {
sendMessage(Formatting.YELLOW + "Ошибка при поиске на сайте: " + site);
try {
synchronized (fileWriter) {
fileWriter.write("Ошибка при поиске на сайте: " + site + "\n");
fileWriter.flush();
}
} catch (IOException ioException) {
sendMessage(Formatting.RED + "Ошибка записи в файл: " + ioException.getMessage());
}
}
}
private void openDirectory() {
try {
Runtime.getRuntime().exec("explorer " + osintDir.getAbsolutePath());
} catch (IOException e) {
sendMessage(Formatting.RED + "Ошибка открытия директории: " + e.getMessage());
}
}
}