Fix BC online check (reusedname)

This commit is contained in:
jafea7 2025-03-30 16:58:27 +11:00
parent b16189fde6
commit c91b7bee1f
1 changed files with 19 additions and 37 deletions

View File

@ -38,7 +38,7 @@ public class BongaCamsModel extends AbstractModel {
private static final String SUCCESS = "success";
private static final String STATUS = "status";
private static final Pattern ONLINE_BADGE_REGEX = Pattern.compile("class=\"badge_online\s*\"");
// private static final Pattern ONLINE_BADGE_REGEX = Pattern.compile("class=\"badge_online\s*\"");
@Setter
private boolean online = false;
@ -51,13 +51,6 @@ public class BongaCamsModel extends AbstractModel {
@Override
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
if (ignoreCache) {
boolean modelIsConnected = basicOnlineCheck();
if (!modelIsConnected) {
onlineState = OFFLINE;
online = false;
return false;
}
return completeOnlineCheck();
}
return online;
@ -74,44 +67,33 @@ public class BongaCamsModel extends AbstractModel {
String chatType = performerData.optString("showType");
boolean isAway = performerData.optBoolean("isAway");
onlineState = mapState(chatType);
if (onlineState == ONLINE) {
if (isStreamAvailable()) {
if (isAway) {
onlineState = AWAY;
online = false;
// looks like isOnline key is new. Treat it's absence as true (old behavior)
boolean jsonIsOnline = performerData.optBoolean("isOnline", true);
if (!jsonIsOnline) {
onlineState = OFFLINE;
online = false;
} else {
onlineState = mapState(chatType);
if (onlineState == ONLINE) {
if (isStreamAvailable()) {
if (isAway) {
onlineState = AWAY;
online = false;
} else {
online = true;
}
} else {
online = true;
online = false;
onlineState = AWAY;
}
} else {
online = false;
onlineState = AWAY;
}
} else {
online = false;
}
return online;
}
private boolean basicOnlineCheck() {
try {
String url = site.getBaseUrl() + "/profile/" + getName().toLowerCase();
Request req = newRequestBuilder().url(url).build();
try (Response resp = site.getHttpClient().execute(req)) {
if (resp.isSuccessful()) {
String body = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
Matcher m = ONLINE_BADGE_REGEX.matcher(body);
return m.find();
} else {
return false;
}
}
} catch (Exception e) {
log.warn("Couldn't check if model is connected: {}", e.getLocalizedMessage());
return false;
}
}
public State mapState(String roomState) {
return switch (roomState) {
case "private", "fullprivate" -> PRIVATE;