Track pending browsing upvotes
This commit is contained in:
1 parent
540590f43e
commit
1fd154e1eb
13 files changed
+73
-27
No files matched your search
@@ -120,17 +120,27 @@ export class AccountBrowsingSimulationService {
|
||||
if (candidates.length === 0) return { kind: 'scheduled', nextDueAt };
|
||||
|
||||
const selected = candidates[Math.floor(this.random() * candidates.length)];
|
||||
const decision = toDecision(this.options.accountId, selected, 'simulated-upvote', 'Eligible browsing selection', sessionId, now);
|
||||
const voter = settings.autoVoteEnabled && allowVoting && !this.options.dryRun
|
||||
? this.options.voter
|
||||
: undefined;
|
||||
const decision = toDecision(
|
||||
this.options.accountId, selected, 'simulated-upvote',
|
||||
voter ? 'Upvote pending Reddit confirmation' : 'Eligible browsing selection',
|
||||
sessionId, now, voter ? 'pending' : 'simulated',
|
||||
);
|
||||
await this.options.sink.recordSimulation(decision);
|
||||
if (settings.autoVoteEnabled && allowVoting && !this.options.dryRun && this.options.voter) {
|
||||
const result = await this.options.voter.upvote(selected.fullname);
|
||||
if (voter) {
|
||||
const result = await voter.upvote(selected.fullname);
|
||||
if (result.status === 'submitted') {
|
||||
this.options.repository.markVoteSubmitted(this.options.accountId, selected.fullname);
|
||||
decision.voteSubmitted = true;
|
||||
decision.voteStatus = 'submitted';
|
||||
decision.reason = 'Reddit upvote submitted';
|
||||
this.options.logger.info(`Submitted browsing upvote for ${selected.fullname} in r/${selected.subreddit}`);
|
||||
} else {
|
||||
decision.reason = `Reddit upvote not submitted: ${result.reason ?? result.status}`;
|
||||
decision.voteStatus = 'failed';
|
||||
this.options.repository.markVoteFailed(this.options.accountId, selected.fullname, decision.reason);
|
||||
this.options.logger.warn(`Browsing upvote for ${selected.fullname} was not submitted: ${result.reason ?? result.status}`);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +175,7 @@ export class AccountBrowsingSimulationService {
|
||||
}
|
||||
if (!this.options.repository.hasAccountDecision(this.options.accountId, thing.fullname)) {
|
||||
await this.options.sink.recordSimulation(
|
||||
toDecision(this.options.accountId, thing, 'rejected', reason, sessionId, now),
|
||||
toDecision(this.options.accountId, thing, 'rejected', reason, sessionId, now, 'simulated'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -293,6 +303,7 @@ function toDecision(
|
||||
reason: string,
|
||||
sessionId: string,
|
||||
now: number,
|
||||
voteStatus: BrowsingDecisionRecord['voteStatus'],
|
||||
): BrowsingDecisionRecord {
|
||||
return {
|
||||
accountId,
|
||||
@@ -308,5 +319,6 @@ function toDecision(
|
||||
decidedAt: now,
|
||||
scheduledSessionId: sessionId,
|
||||
voteSubmitted: false,
|
||||
voteStatus,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user