Log seen users
This commit is contained in:
parent
3a74997b49
commit
5991b116f3
|
@ -16,6 +16,7 @@ import java.time.Instant;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap.KeySetView;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -53,6 +54,12 @@ public class PeriodicRestarter {
|
||||||
*/
|
*/
|
||||||
private final ConcurrentMap<Long, Boolean> sessionAuthReady = new ConcurrentHashMap<>();
|
private final ConcurrentMap<Long, Boolean> sessionAuthReady = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful to register sessions at startup
|
||||||
|
* User id -> x
|
||||||
|
*/
|
||||||
|
private final KeySetView<Long, Object> seenUsers = new ConcurrentHashMap<Long, Object>().keySet(new Object());
|
||||||
|
|
||||||
public PeriodicRestarter(ReactiveApi api, Duration interval, Set<Long> restartUserIds) {
|
public PeriodicRestarter(ReactiveApi api, Duration interval, Set<Long> restartUserIds) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
|
@ -113,9 +120,12 @@ public class PeriodicRestarter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.update() instanceof UpdateNewMessage) {
|
} else if (event.update() instanceof UpdateNewMessage) {
|
||||||
var wasReady = requireNonNullElse(this.sessionAuthReady.put(event.liveId(), true), false);
|
if (seenUsers.add(event.userId())) {
|
||||||
if (!wasReady) {
|
LOG.info("Found a running bot that wasn't registered: {} (liveId: {})", event.userId(), event.liveId());
|
||||||
onSessionReady(event.liveId(), event.userId());
|
var wasReady = requireNonNullElse(this.sessionAuthReady.put(event.liveId(), true), false);
|
||||||
|
if (!wasReady) {
|
||||||
|
onSessionReady(event.liveId(), event.userId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user