TransferBot/src/main/java/it/cavallium/UserStatus.java
Andrea Cavalli a258991e83 Add proxy
2020-12-06 15:38:49 +01:00

129 lines
3.5 KiB
Java

package it.cavallium;
import java.util.StringJoiner;
import javafx.beans.property.SimpleStringProperty;
public class UserStatus {
private final String name;
private final int id;
private final UserStatusType statusType;
private final String errorDescription;
private final SimpleStringProperty user = new SimpleStringProperty("");
private final SimpleStringProperty status = new SimpleStringProperty("");
public UserStatus(String name, int id, UserStatusType statusType, String errorDescription) {
this.name = name;
this.id = id;
this.statusType = statusType;
this.errorDescription = errorDescription;
this.user.set(name);
this.status.set(errorDescription.isBlank() ? escapeeStatusType(translateStatusType(statusType)) : errorDescription);
}
private String escapeeStatusType(String statusText) {
return statusText
.replace("", "[ OK ]")
.replace("", "[ ** ]")
.replace("", "[WARN]")
.replace("", "[ERR!]")
.replace("", "[ ?? ]");
}
private String translateStatusType(UserStatusType statusType) {
switch (statusType) {
case DONE:
return "✔️ Done".substring(2);
case NOT_REGULAR_USER:
return "✔️ Not a regular user, skipped";
case SCAM_USER:
return "✔️ Scam user, skipped";
case CANT_REMOVE_CHAT_OWNER:
return "✔️ Chat owner, skipped";
case JUST_FOUND:
return "⏳ Found";
case ADDED_AND_WAITING_TO_BE_REMOVED:
return "⏳ Added to destination group, still not removed from source group";
case NO_ACCESS_HASH:
return "⚠️ No access hash, skipped";
case RESTRICTED_USER:
return "⚠️ User restricted, skipped";
case CANT_REMOVE:
return "⚠️ Can't remove from source group";
case USER_PRIVACY_RESTRICTED:
return "❌ Can't add to destination group: this user privacy settings don't allow invitations to groups";
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";
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:
return "❓ Unknown";
default:
return statusType.toString();
}
}
public int getId() {
return id;
}
public String getErrorDescription() {
return errorDescription;
}
public String getName() {
return name;
}
public UserStatusType getStatusType() {
return statusType;
}
public String getUser() {
return user.get();
}
public String getStatus() {
return status.get();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
UserStatus that = (UserStatus) o;
if (id != that.id) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + id;
return result;
}
@Override
public String toString() {
return new StringJoiner(", ", UserStatus.class.getSimpleName() + "[", "]")
.add("name='" + name + "'")
.add("id=" + id)
.add("errorType=" + statusType)
.add("errorDescription='" + errorDescription + "'")
.toString();
}
}