mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-14 01:59:05 +03:00
@@ -48,6 +48,7 @@ export async function UpdateGoalsForUser(
|
||||
|
||||
const importInfo = [];
|
||||
const bulkWrite = [];
|
||||
const webhookEventContent = [];
|
||||
|
||||
for (const ret of returns) {
|
||||
if (!ret) {
|
||||
@@ -56,6 +57,10 @@ export async function UpdateGoalsForUser(
|
||||
|
||||
importInfo.push(ret.import);
|
||||
bulkWrite.push(ret.bwrite);
|
||||
|
||||
if (ret.webhookEvent) {
|
||||
webhookEventContent.push(ret.webhookEvent);
|
||||
}
|
||||
}
|
||||
|
||||
if (bulkWrite.length === 0) {
|
||||
@@ -64,6 +69,13 @@ export async function UpdateGoalsForUser(
|
||||
return [];
|
||||
}
|
||||
|
||||
if (webhookEventContent.length !== 0) {
|
||||
await EmitWebhookEvent({
|
||||
type: "goals-achieved/v1",
|
||||
content: { goals: webhookEventContent, userID },
|
||||
});
|
||||
}
|
||||
|
||||
await db["user-goals"].bulkWrite(bulkWrite, { ordered: false });
|
||||
|
||||
return importInfo;
|
||||
@@ -109,19 +121,16 @@ export async function ProcessGoal(
|
||||
achieved: userGoal.achieved,
|
||||
};
|
||||
|
||||
let webhookEvent = null;
|
||||
// if this is a newly-achieved goal
|
||||
if (res.achieved && !userGoal.achieved) {
|
||||
EmitWebhookEvent({
|
||||
type: "goal-achieved/v1",
|
||||
content: {
|
||||
userID,
|
||||
goalID: goal.goalID,
|
||||
old: oldData,
|
||||
new: newData,
|
||||
game: goal.game,
|
||||
playtype: goal.playtype,
|
||||
},
|
||||
});
|
||||
webhookEvent = {
|
||||
goalID: goal.goalID,
|
||||
old: oldData,
|
||||
new: newData,
|
||||
game: goal.game,
|
||||
playtype: goal.playtype,
|
||||
};
|
||||
}
|
||||
|
||||
const bulkWrite = {
|
||||
@@ -147,6 +156,7 @@ export async function ProcessGoal(
|
||||
old: oldData,
|
||||
new: newData,
|
||||
},
|
||||
webhookEvent,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -164,7 +174,7 @@ export async function GetRelevantGoals(
|
||||
chartIDs: Set<string>,
|
||||
logger: KtLogger
|
||||
): Promise<{ goals: GoalDocument[]; userGoalsMap: Map<string, UserGoalDocument> }> {
|
||||
const userGoals = await db["user-goals"].find({ game, userID });
|
||||
const userGoals = await db["user-goals"].find({ game, userID }, { projectID: true });
|
||||
|
||||
logger.verbose(`Found user has ${userGoals.length} goals.`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user