Better flood handling

This commit is contained in:
Andrea Cavalli 2020-11-26 21:37:34 +01:00
parent 3ba6ef1d2d
commit 8c38d60c72
5 changed files with 33 additions and 6 deletions

View File

@ -52,7 +52,7 @@
<dependency> <dependency>
<groupId>it.tdlight</groupId> <groupId>it.tdlight</groupId>
<artifactId>tdlib-session-container</artifactId> <artifactId>tdlib-session-container</artifactId>
<version>4.0.16</version> <version>4.0.22</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.openjfx</groupId> <groupId>org.openjfx</groupId>

View File

@ -538,6 +538,8 @@ public class TransferServiceImpl implements TransferService {
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.USER_PRIVACY_RESTRICTED, "")).then(Mono.empty()); return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.USER_PRIVACY_RESTRICTED, "")).then(Mono.empty());
} else if (TdLightUtils.errorEquals(new TdError(result.cause().code, result.cause().message), 400, "USER_NOT_MUTUAL_CONTACT")) { } else if (TdLightUtils.errorEquals(new TdError(result.cause().code, result.cause().message), 400, "USER_NOT_MUTUAL_CONTACT")) {
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.USER_NOT_MUTUAL_CONTACT, "")).then(Mono.empty()); 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());
} }
} }
return Mono.just(result); return Mono.just(result);
@ -545,11 +547,20 @@ public class TransferServiceImpl implements TransferService {
.flatMap(MonoUtils::orElseThrow) .flatMap(MonoUtils::orElseThrow)
.timeout(Duration.ofMinutes(2)) .timeout(Duration.ofMinutes(2))
.onErrorResume((error) -> { .onErrorResume((error) -> {
App.getLogService().append(Level.WARN, "Can't add user \"" + getName(user) + "\" to supergroup \"" + destGroup.getSupergroupIdInt() + " " + destGroup.getTitle() + "\""); App.getLogService().append(Level.WARN, "Can't add user \"" + getName(user) + "\" to supergroup \"" + destGroup.getSupergroupIdInt() + " " + destGroup.getTitle() + "\" (" + error.getLocalizedMessage() + ")");
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.CANT_ADD, "Can't add to destination supergroup: " + error.getLocalizedMessage())).then(Mono.empty()); return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.CANT_ADD, "Can't add to destination supergroup: " + error.getLocalizedMessage())).then(Mono.empty());
}) })
.flatMap(_v -> { .flatMap(_v -> {
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.ADDED_AND_WAITING_TO_BE_REMOVED, "")).then(Mono.empty()).thenReturn(user); UserStatusType userStatusType;
if (REMOVE_MEMBERS_FROM_SOURCE_SUPERGROUP) {
userStatusType = UserStatusType.ADDED_AND_WAITING_TO_BE_REMOVED;
} else {
userStatusType = UserStatusType.DONE;
}
return userStatusConsumer
.apply(new UserStatus(getName(user), user.id, userStatusType, ""))
.then(Mono.empty())
.thenReturn(user);
}); });
}) })
.<User>flatMap(user -> { .<User>flatMap(user -> {
@ -576,7 +587,8 @@ public class TransferServiceImpl implements TransferService {
}); });
} else { } else {
// Don't remove the user from the source supergroup // Don't remove the user from the source supergroup
return Mono.just(user); transferredSuccessfullyUsersStats.incrementAndGet();
return userStatusConsumer.apply(new UserStatus(getName(user), user.id, UserStatusType.DONE, "")).then(Mono.empty()).thenReturn(user);
} }
}) })
.delayElements(App.getSettingsService().getDelayBetweenAdds()) .delayElements(App.getSettingsService().getDelayBetweenAdds())

View File

@ -53,6 +53,8 @@ public class UserStatus {
return "❌ Can't add to destination group: this user privacy settings don't allow invitations to groups"; return "❌ Can't add to destination group: this user privacy settings don't allow invitations to groups";
case USER_NOT_MUTUAL_CONTACT: case USER_NOT_MUTUAL_CONTACT:
return "❌ Can't add to destination group: this user only allows mutual contacts to invite it in the destination group"; 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 CANT_ADD: case CANT_ADD:
return "❌ Can't add to destination group"; return "❌ Can't add to destination group";
case UNKNOWN: case UNKNOWN:

View File

@ -1,5 +1,18 @@
package it.cavallium; package it.cavallium;
public enum UserStatusType { public enum UserStatusType {
NO_ACCESS_HASH, NOT_REGULAR_USER, SCAM_USER, RESTRICTED_USER, JUST_FOUND, CANT_ADD, ADDED_AND_WAITING_TO_BE_REMOVED, DONE, CANT_REMOVE, USER_PRIVACY_RESTRICTED, USER_NOT_MUTUAL_CONTACT, CANT_REMOVE_CHAT_OWNER, UNKNOWN NO_ACCESS_HASH,
NOT_REGULAR_USER,
SCAM_USER,
RESTRICTED_USER,
JUST_FOUND,
CANT_ADD,
ADDED_AND_WAITING_TO_BE_REMOVED,
DONE,
CANT_REMOVE,
USER_PRIVACY_RESTRICTED,
USER_NOT_MUTUAL_CONTACT,
CANT_REMOVE_CHAT_OWNER,
ADD_FLOOD,
UNKNOWN
} }

@ -1 +1 @@
Subproject commit b1ab4777479c10d48d2fec8392c52a6b66d66233 Subproject commit a04010d72b8c8eb4165697f07c3da685b1a88a50