XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: move createNewEventMessages from inboxService to inboxController (#2828)

This function wasn't used anywhere else and caused a recursive include in inboxService. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2828 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

a8e41c95
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +120 -122
Modified src/controllers/api/inboxController.ts +119 -3
@@ -1,13 +1,13 @@
1 import type { RequestHandler } from "express";
1 import type { Request, RequestHandler } from "express";
2 2 import { Inbox } from "../../models/inboxModel.ts";
3 3 import {
4 4 createMessage,
5 createNewEventMessages,
6 5 deleteAllMessagesRead,
7 6 deleteAllMessagesReadNonCin,
8 7 deleteMessageRead,
9 8 getAllMessagesSorted,
10 getMessage
9 getMessage,
10 type IMessageCreationTemplate
11 11 } from "../../services/inboxService.ts";
12 12 import { getAccountForRequest, getAccountFromSuffixedName, getSuffixedName } from "../../services/loginService.ts";
13 13 import {
@@ -22,6 +22,9 @@ import { ExportFlavour } from "warframe-public-export-plus";
22 22 import { handleStoreItemAcquisition } from "../../services/purchaseService.ts";
23 23 import { fromStoreItem, isStoreItem } from "../../services/itemDataService.ts";
24 24 import type { IOid } from "../../types/commonTypes.ts";
25 import { unixTimesInMs } from "../../constants/timeConstants.ts";
26 import { config } from "../../services/configService.ts";
27 import { Types } from "mongoose";
25 28
26 29 export const inboxController: RequestHandler = async (req, res) => {
27 30 const { deleteId, lastMessage: latestClientMessageId, messageId } = req.query;
@@ -135,6 +138,119 @@ export const inboxController: RequestHandler = async (req, res) => {
135 138 }
136 139 };
137 140
141 const createNewEventMessages = async (req: Request): Promise<void> => {
142 const account = await getAccountForRequest(req);
143 const newEventMessages: IMessageCreationTemplate[] = [];
144
145 // Baro
146 const baroIndex = Math.trunc((Date.now() - 910800000) / (unixTimesInMs.day * 14));
147 const baroStart = baroIndex * (unixTimesInMs.day * 14) + 910800000;
148 const baroActualStart = baroStart + unixTimesInMs.day * (config.worldState?.baroAlwaysAvailable ? 0 : 12);
149 if (Date.now() >= baroActualStart && account.LatestEventMessageDate.getTime() < baroActualStart) {
150 newEventMessages.push({
151 sndr: "/Lotus/Language/G1Quests/VoidTraderName",
152 sub: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceTitle",
153 msg: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceMessage",
154 icon: "/Lotus/Interface/Icons/Npcs/BaroKiTeerPortrait.png",
155 startDate: new Date(baroActualStart),
156 endDate: new Date(baroStart + unixTimesInMs.day * 14),
157 CrossPlatform: true,
158 arg: [
159 {
160 Key: "NODE_NAME",
161 Tag: ["EarthHUB", "MercuryHUB", "SaturnHUB", "PlutoHUB"][baroIndex % 4]
162 }
163 ],
164 date: new Date(baroActualStart)
165 });
166 }
167
168 // BUG: Deleting the inbox message manually means it'll just be automatically re-created. This is because we don't use startDate/endDate for these config-toggled events.
169 const promises = [];
170 if (config.worldState?.creditBoost) {
171 promises.push(
172 (async (): Promise<void> => {
173 if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666672" }))) {
174 newEventMessages.push({
175 globaUpgradeId: new Types.ObjectId("5b23106f283a555109666672"),
176 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
177 sub: "/Lotus/Language/Items/EventDoubleCreditsName",
178 msg: "/Lotus/Language/Items/EventDoubleCreditsDesc",
179 icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
180 startDate: new Date(),
181 CrossPlatform: true
182 });
183 }
184 })()
185 );
186 }
187 if (config.worldState?.affinityBoost) {
188 promises.push(
189 (async (): Promise<void> => {
190 if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666673" }))) {
191 newEventMessages.push({
192 globaUpgradeId: new Types.ObjectId("5b23106f283a555109666673"),
193 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
194 sub: "/Lotus/Language/Items/EventDoubleAffinityName",
195 msg: "/Lotus/Language/Items/EventDoubleAffinityDesc",
196 icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
197 startDate: new Date(),
198 CrossPlatform: true
199 });
200 }
201 })()
202 );
203 }
204 if (config.worldState?.resourceBoost) {
205 promises.push(
206 (async (): Promise<void> => {
207 if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666674" }))) {
208 newEventMessages.push({
209 globaUpgradeId: new Types.ObjectId("5b23106f283a555109666674"),
210 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
211 sub: "/Lotus/Language/Items/EventDoubleResourceName",
212 msg: "/Lotus/Language/Items/EventDoubleResourceDesc",
213 icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
214 startDate: new Date(),
215 CrossPlatform: true
216 });
217 }
218 })()
219 );
220 }
221 if (config.worldState?.galleonOfGhouls) {
222 promises.push(
223 (async (): Promise<void> => {
224 if (!(await Inbox.exists({ ownerId: account._id, goalTag: "GalleonRobbery" }))) {
225 newEventMessages.push({
226 sndr: "/Lotus/Language/Bosses/BossCouncilorVayHek",
227 sub: "/Lotus/Language/Events/GalleonRobberyIntroMsgTitle",
228 msg: "/Lotus/Language/Events/GalleonRobberyIntroMsgDesc",
229 icon: "/Lotus/Interface/Icons/Npcs/VayHekPortrait.png",
230 transmission: "/Lotus/Sounds/Dialog/GalleonOfGhouls/DGhoulsWeekOneInbox0010VayHek",
231 att: ["/Lotus/Upgrades/Skins/Events/OgrisOldSchool"],
232 startDate: new Date(),
233 goalTag: "GalleonRobbery"
234 });
235 }
236 })()
237 );
238 }
239 await Promise.all(promises);
240
241 if (newEventMessages.length === 0) {
242 return;
243 }
244
245 await createMessage(account._id, newEventMessages);
246
247 const latestEventMessage = newEventMessages.reduce((prev, current) =>
248 prev.startDate! > current.startDate! ? prev : current
249 );
250 account.LatestEventMessageDate = new Date(latestEventMessage.startDate!);
251 await account.save();
252 };
253
138 254 // 33.6.0 has query arguments like lastMessage={"$oid":"68112baebf192e786d1502bb"} instead of lastMessage=68112baebf192e786d1502bb
139 255 const parseOid = (oid: string): string => {
140 256 if (oid[0] == "{") {
Modified src/services/inboxService.ts +1 -119
@@ -1,11 +1,6 @@
1 1 import type { IMessageDatabase } from "../models/inboxModel.ts";
2 2 import { Inbox } from "../models/inboxModel.ts";
3 import { getAccountForRequest } from "./loginService.ts";
4 import type { HydratedDocument } from "mongoose";
5 import { Types } from "mongoose";
6 import type { Request } from "express";
7 import { unixTimesInMs } from "../constants/timeConstants.ts";
8 import { config } from "./configService.ts";
3 import type { HydratedDocument, Types } from "mongoose";
9 4
10 5 export const getAllMessagesSorted = async (accountId: string): Promise<HydratedDocument<IMessageDatabase>[]> => {
11 6 const inbox = await Inbox.find({ ownerId: accountId }).sort({ date: -1 });
@@ -33,119 +28,6 @@ export const deleteAllMessagesReadNonCin = async (accountId: string): Promise<vo
33 28 await Inbox.deleteMany({ ownerId: accountId, r: true, cinematic: null });
34 29 };
35 30
36 export const createNewEventMessages = async (req: Request): Promise<void> => {
37 const account = await getAccountForRequest(req);
38 const newEventMessages: IMessageCreationTemplate[] = [];
39
40 // Baro
41 const baroIndex = Math.trunc((Date.now() - 910800000) / (unixTimesInMs.day * 14));
42 const baroStart = baroIndex * (unixTimesInMs.day * 14) + 910800000;
43 const baroActualStart = baroStart + unixTimesInMs.day * (config.worldState?.baroAlwaysAvailable ? 0 : 12);
44 if (Date.now() >= baroActualStart && account.LatestEventMessageDate.getTime() < baroActualStart) {
45 newEventMessages.push({
46 sndr: "/Lotus/Language/G1Quests/VoidTraderName",
47 sub: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceTitle",
48 msg: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceMessage",
49 icon: "/Lotus/Interface/Icons/Npcs/BaroKiTeerPortrait.png",
50 startDate: new Date(baroActualStart),
51 endDate: new Date(baroStart + unixTimesInMs.day * 14),
52 CrossPlatform: true,
53 arg: [
54 {
55 Key: "NODE_NAME",
56 Tag: ["EarthHUB", "MercuryHUB", "SaturnHUB", "PlutoHUB"][baroIndex % 4]
57 }
58 ],
59 date: new Date(baroActualStart)
60 });
61 }
62
63 // BUG: Deleting the inbox message manually means it'll just be automatically re-created. This is because we don't use startDate/endDate for these config-toggled events.
64 const promises = [];
65 if (config.worldState?.creditBoost) {
66 promises.push(
67 (async (): Promise<void> => {
68 if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666672" }))) {
69 newEventMessages.push({
70 globaUpgradeId: new Types.ObjectId("5b23106f283a555109666672"),
71 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
72 sub: "/Lotus/Language/Items/EventDoubleCreditsName",
73 msg: "/Lotus/Language/Items/EventDoubleCreditsDesc",
74 icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
75 startDate: new Date(),
76 CrossPlatform: true
77 });
78 }
79 })()
80 );
81 }
82 if (config.worldState?.affinityBoost) {
83 promises.push(
84 (async (): Promise<void> => {
85 if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666673" }))) {
86 newEventMessages.push({
87 globaUpgradeId: new Types.ObjectId("5b23106f283a555109666673"),
88 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
89 sub: "/Lotus/Language/Items/EventDoubleAffinityName",
90 msg: "/Lotus/Language/Items/EventDoubleAffinityDesc",
91 icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
92 startDate: new Date(),
93 CrossPlatform: true
94 });
95 }
96 })()
97 );
98 }
99 if (config.worldState?.resourceBoost) {
100 promises.push(
101 (async (): Promise<void> => {
102 if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666674" }))) {
103 newEventMessages.push({
104 globaUpgradeId: new Types.ObjectId("5b23106f283a555109666674"),
105 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
106 sub: "/Lotus/Language/Items/EventDoubleResourceName",
107 msg: "/Lotus/Language/Items/EventDoubleResourceDesc",
108 icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
109 startDate: new Date(),
110 CrossPlatform: true
111 });
112 }
113 })()
114 );
115 }
116 if (config.worldState?.galleonOfGhouls) {
117 promises.push(
118 (async (): Promise<void> => {
119 if (!(await Inbox.exists({ ownerId: account._id, goalTag: "GalleonRobbery" }))) {
120 newEventMessages.push({
121 sndr: "/Lotus/Language/Bosses/BossCouncilorVayHek",
122 sub: "/Lotus/Language/Events/GalleonRobberyIntroMsgTitle",
123 msg: "/Lotus/Language/Events/GalleonRobberyIntroMsgDesc",
124 icon: "/Lotus/Interface/Icons/Npcs/VayHekPortrait.png",
125 transmission: "/Lotus/Sounds/Dialog/GalleonOfGhouls/DGhoulsWeekOneInbox0010VayHek",
126 att: ["/Lotus/Upgrades/Skins/Events/OgrisOldSchool"],
127 startDate: new Date(),
128 goalTag: "GalleonRobbery"
129 });
130 }
131 })()
132 );
133 }
134 await Promise.all(promises);
135
136 if (newEventMessages.length === 0) {
137 return;
138 }
139
140 await createMessage(account._id, newEventMessages);
141
142 const latestEventMessage = newEventMessages.reduce((prev, current) =>
143 prev.startDate! > current.startDate! ? prev : current
144 );
145 account.LatestEventMessageDate = new Date(latestEventMessage.startDate!);
146 await account.save();
147 };
148
149 31 export const createMessage = async (
150 32 accountId: string | Types.ObjectId,
151 33 messages: IMessageCreationTemplate[]