返回提交历史
Modified
src/controllers/api/addToGuildController.ts
+9
-8
XFEstudio/XFESpaceNinjaServer
feat: handle addToGuild request from old versions (#3289)
Closes #3286 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3289 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
402d253a
代码差异
1 个文件
+9
-8
@@ -16,10 +16,10 @@ import { ExportFlavour } from "warframe-public-export-plus";
16
16
export const addToGuildController: RequestHandler = async (req, res) => {
17
17
const payload = JSON.parse(String(req.body)) as IAddToGuildRequest;
18
18
19
if ("UserName" in payload) {
19
if ("UserName" in payload || "userName" in payload) {
20
20
// Clan recruiter sending an invite
21
21
22
const account = await Account.findOne({ DisplayName: payload.UserName });
22
const account = await Account.findOne({ DisplayName: payload.UserName ?? payload.userName });
23
23
if (!account) {
24
24
res.status(400).json("Username does not exist");
25
25
return;
@@ -36,7 +36,8 @@ export const addToGuildController: RequestHandler = async (req, res) => {
36
36
return;
37
37
}
38
38
39
const guild = (await Guild.findById(payload.GuildId.$oid, "Name Ranks"))!;
39
const senderInventory = await getInventory(senderAccount._id.toString(), "GuildId ActiveAvatarImageType");
40
const guild = (await Guild.findById(senderInventory.GuildId!, "Name Ranks"))!;
40
41
if (!(await hasGuildPermission(guild, senderAccount._id.toString(), GuildPermission.Recruiter))) {
41
42
res.status(400).json("Invalid permission");
42
43
}
@@ -44,7 +45,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
44
45
try {
45
46
await GuildMember.insertOne({
46
47
accountId: account._id,
47
guildId: payload.GuildId.$oid,
48
guildId: senderInventory.GuildId!,
48
49
status: 2 // outgoing invite
49
50
});
50
51
} catch (e) {
@@ -53,7 +54,6 @@ export const addToGuildController: RequestHandler = async (req, res) => {
53
54
return;
54
55
}
55
56
56
const senderInventory = await getInventory(senderAccount._id.toString(), "ActiveAvatarImageType");
57
57
await createMessage(account._id, [
58
58
{
59
59
sndr: getSuffixedName(senderAccount),
@@ -66,7 +66,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
66
66
],
67
67
sub: "/Lotus/Language/Menu/Mailbox_ClanInvite_Title",
68
68
icon: ExportFlavour[getEffectiveAvatarImageType(senderInventory)].icon,
69
contextInfo: payload.GuildId.$oid,
69
contextInfo: senderInventory.GuildId!.toString(),
70
70
highPriority: true,
71
71
acceptAction: "GUILD_INVITE",
72
72
declineAction: "GUILD_INVITE",
@@ -89,7 +89,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
89
89
try {
90
90
await GuildMember.insertOne({
91
91
accountId,
92
guildId: payload.GuildId.$oid,
92
guildId: payload.GuildId!.$oid,
93
93
status: 1, // incoming invite
94
94
RequestMsg: payload.RequestMsg,
95
95
RequestExpiry: new Date(Date.now() + 14 * 86400 * 1000) // TOVERIFY: I can't find any good information about this with regards to live, but 2 weeks seem reasonable.
@@ -107,6 +107,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
107
107
108
108
interface IAddToGuildRequest {
109
109
UserName?: string;
110
GuildId: IOid;
110
userName?: string; // U22.13.4 provides this instead of UserName
111
GuildId?: IOid; // // U22.13.4 does not provide this
111
112
RequestMsg?: string;
112
113
}