Last active 2 weeks ago

nuno revised this gist 2 weeks ago. Go to revision

1 file changed, 31 insertions

gistfile1.txt(file created)

@@ -0,0 +1,31 @@
1 + resetWeek(): void {
2 + const now = new Date();
3 + const newWeekKey = WRank.weekKey(now);
4 + const prevWeekKey = WRank.weekKey(new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000));
5 +
6 + // Access internal data via WRank
7 + const prevWeek = WRank.weekFromKey(prevWeekKey);
8 + const newWeek = WRank.currentWeek(); // ensures new week exists
9 +
10 + if (prevWeek) {
11 + const goal = Config.get({ section: "wrank", key: "goal" });
12 + for (const nation of [Nation.Capella, Nation.Procyon]) {
13 + const entries = prevWeek.entries[nation];
14 + const rank1 = entries.find((e) => e.currentRank === 1);
15 +
16 + // Rank 1 with >= goal TGs becomes Bringer — no exceptions
17 + // Officers use Bringer.override() for manual adjustments
18 + if (rank1 && rank1.tgCount >= goal) {
19 + newWeek.bringer[nation] = rank1.characterName;
20 + } else {
21 + newWeek.bringer[nation] = null;
22 + }
23 +
24 + // Overrides do NOT carry forward — each week starts clean
25 + delete (newWeek.bringer as any)[`${nation}Override`];
26 + }
27 + }
28 +
29 + WRank.save();
30 + console.log(`[TG] Week reset to ${newWeekKey}. Bringer:`, newWeek.bringer);
31 + },
Newer Older