Add proxy
This commit is contained in:
parent
35ef9912f4
commit
a258991e83
@ -15,4 +15,16 @@ public interface SettingsService {
|
||||
void clearPhoneNumbers();
|
||||
|
||||
Set<Long> getPhoneNumbers();
|
||||
|
||||
String getProxyIp();
|
||||
|
||||
void setProxyIp(String value);
|
||||
|
||||
Integer getProxyPort();
|
||||
|
||||
void setProxyPort(int value);
|
||||
|
||||
String getProxySecret();
|
||||
|
||||
void setProxySecret(String value);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import io.vertx.core.impl.ConcurrentHashSet;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -17,13 +16,15 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
public class SettingsServiceImpl implements SettingsService {
|
||||
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private final AtomicReference<Duration> delayBetweenAdds = new AtomicReference<>(Duration.ZERO);
|
||||
private final AtomicReference<String> proxyIp = new AtomicReference<>("proxy.digitalresistance.dog");
|
||||
private final AtomicReference<Integer> proxyPort = new AtomicReference<>(443);
|
||||
private final AtomicReference<String> proxySecret = new AtomicReference<>("d41d8cd98f00b204e9800998ecf8427e");
|
||||
private final ConcurrentHashSet<Long> phoneNumbers = new ConcurrentHashSet<>();
|
||||
|
||||
public SettingsServiceImpl() {
|
||||
@ -41,6 +42,15 @@ public class SettingsServiceImpl implements SettingsService {
|
||||
this.phoneNumbers.add(Long.parseLong(phoneNumber.getAsString()));
|
||||
}
|
||||
});
|
||||
Optional.ofNullable(settings.getAsJsonPrimitive("proxyIp")).ifPresent(value -> {
|
||||
this.proxyIp.set(value.getAsString());
|
||||
});
|
||||
Optional.ofNullable(settings.getAsJsonPrimitive("proxyPort")).ifPresent(value -> {
|
||||
this.proxyPort.set(value.getAsInt());
|
||||
});
|
||||
Optional.ofNullable(settings.getAsJsonPrimitive("proxySecret")).ifPresent(value -> {
|
||||
this.proxySecret.set(value.getAsString());
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -58,6 +68,9 @@ public class SettingsServiceImpl implements SettingsService {
|
||||
phoneNumbers.add("" + phoneNumber);
|
||||
}
|
||||
settings.add("phoneNumbers", phoneNumbers);
|
||||
settings.addProperty("proxyIp", proxyIp.get());
|
||||
settings.addProperty("proxyPort", proxyPort.get());
|
||||
settings.addProperty("proxySecret", proxySecret.get());
|
||||
try {
|
||||
Files.writeString(Paths.get("settings.json"), gson.toJson(settings), StandardCharsets.UTF_8, StandardOpenOption.CREATE);
|
||||
} catch (IOException e) {
|
||||
@ -99,4 +112,37 @@ public class SettingsServiceImpl implements SettingsService {
|
||||
public Set<Long> getPhoneNumbers() {
|
||||
return new HashSet<>(phoneNumbers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProxyIp() {
|
||||
return proxyIp.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxyIp(String value) {
|
||||
this.proxyIp.set(value);
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getProxyPort() {
|
||||
return proxyPort.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxyPort(int value) {
|
||||
this.proxyPort.set(value);
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProxySecret() {
|
||||
return proxySecret.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxySecret(String value) {
|
||||
this.proxySecret.set(value);
|
||||
saveSettings();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package it.cavallium;
|
||||
|
||||
import it.tdlight.jni.TdApi;
|
||||
import it.tdlight.jni.TdApi.AddProxy;
|
||||
import it.tdlight.jni.TdApi.AuthorizationState;
|
||||
import it.tdlight.jni.TdApi.AuthorizationStateReady;
|
||||
import it.tdlight.jni.TdApi.Chat;
|
||||
@ -9,6 +10,7 @@ import it.tdlight.jni.TdApi.ChatMemberStatusCreator;
|
||||
import it.tdlight.jni.TdApi.ChatMemberStatusMember;
|
||||
import it.tdlight.jni.TdApi.GetSupergroupFullInfo;
|
||||
import it.tdlight.jni.TdApi.Object;
|
||||
import it.tdlight.jni.TdApi.ProxyTypeMtproto;
|
||||
import it.tdlight.jni.TdApi.Supergroup;
|
||||
import it.tdlight.jni.TdApi.SupergroupFullInfo;
|
||||
import it.tdlight.jni.TdApi.Update;
|
||||
@ -56,6 +58,18 @@ public class TransferClient {
|
||||
.publishOn(scheduler)
|
||||
.flatMap(this::onUpdate)
|
||||
.subscribe();
|
||||
|
||||
this.setupProxy();
|
||||
}
|
||||
|
||||
private void setupProxy() {
|
||||
var ip = App.getSettingsService().getProxyIp();
|
||||
var port = App.getSettingsService().getProxyPort();
|
||||
var secret = App.getSettingsService().getProxySecret();
|
||||
|
||||
this.client.send(new AddProxy(ip, port, true, new ProxyTypeMtproto(secret))).doOnError(e -> {
|
||||
e.printStackTrace();
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
public User getClientUser() {
|
||||
|
@ -515,6 +515,9 @@ public class TransferServiceImpl implements TransferService {
|
||||
AtomicInteger processedUsersStats = new AtomicInteger(0);
|
||||
return Flux
|
||||
.fromIterable(users)
|
||||
// Apply delay between user
|
||||
.delayElements(App.getSettingsService().getDelayBetweenAdds())
|
||||
|
||||
.flatMap(user -> {
|
||||
return percentageConsumer
|
||||
.apply(20 + processedUsersStats.getAndIncrement() / users.size() * (100 - 20))
|
||||
@ -530,9 +533,16 @@ public class TransferServiceImpl implements TransferService {
|
||||
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.USER_NOT_MUTUAL_CONTACT, "")).then(Mono.empty());
|
||||
} else if (TdLightUtils.errorEquals(new TdError(result.cause().code, result.cause().message), 400, "PEER_FLOOD")) {
|
||||
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.ADD_FLOOD, "")).then(Mono.empty());
|
||||
}
|
||||
}
|
||||
} else if (TdLightUtils.errorEquals(new TdError(result.cause().code, result.cause().message), 429, "Too Many Requests")) {
|
||||
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.ADD_TOO_MANY_REQUESTS, "")).then(Mono.empty());
|
||||
} else if (TdLightUtils.errorEquals(new TdError(result.cause().code, result.cause().message), 403, "USER_CHANNELS_TOO_MUCH")) {
|
||||
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.USER_CHANNELS_TOO_MUCH, "")).then(Mono.empty());
|
||||
} else {
|
||||
return Mono.just(result);
|
||||
}
|
||||
} else {
|
||||
return Mono.just(result);
|
||||
}
|
||||
})
|
||||
.flatMap(MonoUtils::orElseThrow)
|
||||
.timeout(Duration.ofMinutes(2))
|
||||
@ -581,7 +591,6 @@ public class TransferServiceImpl implements TransferService {
|
||||
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.DONE, "")).then(Mono.empty()).thenReturn(user);
|
||||
}
|
||||
})
|
||||
.delayElements(App.getSettingsService().getDelayBetweenAdds())
|
||||
.collect(Collectors.toSet())
|
||||
.map(resolvedUsers -> Tuple3.of(clients, resolvedUsers, totalUsersCount));
|
||||
})
|
||||
|
@ -55,6 +55,10 @@ public class UserStatus {
|
||||
return "❌ Can't add to destination group: this user only allows mutual contacts to invite it in the destination group";
|
||||
case ADD_FLOOD:
|
||||
return "✔️ Can't add to destination group: an userbot has been blocked by telegram for flooding";
|
||||
case USER_CHANNELS_TOO_MUCH:
|
||||
return "✔️ Can't add to destination group: subscribed to too many channels";
|
||||
case ADD_TOO_MANY_REQUESTS:
|
||||
return "✔️ Can't add to destination group: an userbot has been blocked by telegram for making too many requests";
|
||||
case CANT_ADD:
|
||||
return "❌ Can't add to destination group";
|
||||
case UNKNOWN:
|
||||
|
@ -13,6 +13,8 @@ public enum UserStatusType {
|
||||
USER_PRIVACY_RESTRICTED,
|
||||
USER_NOT_MUTUAL_CONTACT,
|
||||
CANT_REMOVE_CHAT_OWNER,
|
||||
USER_CHANNELS_TOO_MUCH,
|
||||
ADD_FLOOD,
|
||||
ADD_TOO_MANY_REQUESTS,
|
||||
UNKNOWN
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user