Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vsevolodmelnyk authored May 26, 2023
1 parent 4fb96e9 commit 09166f1
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 0 deletions.
Binary file added java_core/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
22 changes: 22 additions & 0 deletions java_core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>java_core</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.0.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
139 changes: 139 additions & 0 deletions java_core/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package org.example;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import javax.imageio.ImageIO;
import java.io.BufferedReader;

import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import com.google.common.hash.Hashing;

import java.io.*;

import static org.apache.commons.io.IOUtils.length;

public class Main{
static int width = 512;
static int height = 512;
static String[] bot_tokens = new String[]{};
static String ChatID = "-1001966701084";
static String post_link = "https://t.me/TheLibraryofBabelImg";
static String temp_file_path = "img.png";

public static void main(String[] args) {

int current_bot_index = 0;
while (true) {

int[][] collors = new int[width][height];
int nohash = 0;


Random random = new Random();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
collors[i][j] = random.nextInt(16777216) + 1;
}
}
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
int color = collors[h][w];
nohash = nohash + color;
int red = (color / 65536) % 256;
int green = (color / 256) % 256;
int blue = color % 256;
int rgb = (red << 16) | (green << 8) | blue;
image.setRGB(w, h, rgb);
}
}
File outputFile = new File(temp_file_path);
try {
ImageIO.write(image, "png", outputFile);
} catch (IOException e) {
e.printStackTrace();
}
String current_bot_token = bot_tokens[current_bot_index];

String hashed = Hashing.sha256().hashString(String.valueOf(nohash), StandardCharsets.UTF_8).toString();
System.out.println("hash " + hashed);

try {
URL url = new URL("https://api.telegram.org/bot" + current_bot_token + "/getChatHistory");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
String parameters = "chat_id=" + ChatID + "&text=" + hashed;
byte[] postData = parameters.getBytes("UTF-8");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", String.valueOf(postData.length));
OutputStream outputStream = connection.getOutputStream();
outputStream.write(postData);
int responseCode = connection.getResponseCode();
if (responseCode != 404) {
break;
}


} catch (IOException e) {
e.printStackTrace();
}

try {
URL url = new URL("https://api.telegram.org/bot" + current_bot_token + "/sendPhoto");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setChunkedStreamingMode(0);
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
String boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
String CRLF = "\r\n";
String postData = "--" + boundary + CRLF
+ "Content-Disposition: form-data; name=\"chat_id\"" + CRLF + CRLF
+ ChatID + CRLF
+ "--" + boundary + CRLF
+ "Content-Disposition: form-data; name=\"photo\"; filename=\"" + temp_file_path + "\"" + CRLF
+ "Content-Type: png" + CRLF + CRLF;
OutputStream outputStream = connection.getOutputStream();
outputStream.write(postData.getBytes());
File imageFile = new File(temp_file_path);
FileInputStream fileInputStream = new FileInputStream(imageFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.write((CRLF + "--" + boundary + CRLF).getBytes());
outputStream.write(("Content-Disposition: form-data; name=\"caption\"" + CRLF + CRLF + hashed + " " + post_link + CRLF).getBytes());
outputStream.write((CRLF + "--" + boundary + "--" + CRLF).getBytes());
outputStream.flush();
outputStream.close();
int responseCode = connection.getResponseCode();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
connection.disconnect();
if (responseCode == 200){
System.out.println("Image sent successfully using Bot " + current_bot_index);
}
current_bot_index = (current_bot_index + 1) % length(bot_tokens);

} catch (IOException e) {
e.printStackTrace();
}

}
}

}
3 changes: 3 additions & 0 deletions java_core/src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: org.example.Main

3 changes: 3 additions & 0 deletions java_core/target/classes/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: org.example.Main

Binary file added java_core/target/classes/org/example/Main.class
Binary file not shown.
Binary file added python_core/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions python_core/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from PIL import Image
import requests
import time
import random
import hashlib

bot_tokens = []

width, height = 512, 512
current_bot_index = 0

while True:
# Создание двумерного массива
collors = [[0] * width for _ in range(height)]

# Заполнение массива случайными числами
for i in range(512):
for j in range(512):
collors[i][j] = random.randint(1, 16777216)
nohash = 0

image = Image.new('RGB', (width, height))

for h in range(512):
for w in range(512):
color = collors[h][w]
R = (color // 65536) % 256
G = (color // 256) % 256
B = color % 256
image.putpixel((w, h), (R, G, B))
nohash += color


temp_file_path = f'img.png'
image.save(temp_file_path)

current_bot_token = bot_tokens[current_bot_index]
files = {'photo': open(temp_file_path, 'rb')}
ChatID = '-1001966701084'
post_link = f'https://t.me/TheLibraryofBabelImg'


hash = hashlib.sha256(str(nohash).encode('utf-8')).hexdigest()

while True:
url = f'https://api.telegram.org/bot{current_bot_token}/getChatHistory'
params = {
'chat_id': ChatID,
'text': hash
}
response = requests.get(url, params=params)
if response.status_code != 404:
break

url = f'https://api.telegram.org/bot{current_bot_token}/sendPhoto'
with open(f'{temp_file_path}', 'rb') as photo:
# Создаем данные для отправки
data = {'chat_id': ChatID, 'caption': f'{hash} https://t.me/TheLibraryofBabelImg'}
files = {'photo': photo}
# Отправляем запрос с помощью метода POST
response = requests.post(url, data=data, files=files)
if response.status_code == 200:
print(f"Image sent successfully using Bot {current_bot_index+1}")
#time.sleep(0.2)
break # Выход из цикла, если отправка прошла успешно
print(f"Failed to send image: {response.text}")
print("Retrying after 5 seconds...")
time.sleep(5) # Пауза перед повторной попыткой отправки
current_bot_index = (current_bot_index + 1) % len(bot_tokens)

0 comments on commit 09166f1

Please sign in to comment.