feat: alliance motd #1438

Merged
Sainan merged 1 commits from alliance-motd into main 2025-04-03 10:38:38 -07:00
4 changed files with 46 additions and 20 deletions

View File

@ -1,21 +1,44 @@
import { Guild } from "@/src/models/guildModel"; import { Alliance, Guild, GuildMember } from "@/src/models/guildModel";
import { hasGuildPermission } from "@/src/services/guildService"; import { hasGuildPermissionEx } from "@/src/services/guildService";
import { getInventory } from "@/src/services/inventoryService"; import { getInventory } from "@/src/services/inventoryService";
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService"; import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
import { GuildPermission } from "@/src/types/guildTypes"; import { GuildPermission, ILongMOTD } from "@/src/types/guildTypes";
import { RequestHandler } from "express"; import { RequestHandler } from "express";
export const setGuildMotdController: RequestHandler = async (req, res) => { export const setGuildMotdController: RequestHandler = async (req, res) => {
const account = await getAccountForRequest(req); const account = await getAccountForRequest(req);
const inventory = await getInventory(account._id.toString(), "GuildId"); const inventory = await getInventory(account._id.toString(), "GuildId");
const guild = (await Guild.findById(inventory.GuildId!))!; const guild = (await Guild.findById(inventory.GuildId!))!;
if (!(await hasGuildPermission(guild, account._id, GuildPermission.Herald))) { const member = (await GuildMember.findOne({ accountId: account._id, guildId: guild._id }))!;
const IsLongMOTD = "longMOTD" in req.query;
const MOTD = req.body ? String(req.body) : undefined;
if ("alliance" in req.query) {
if (member.rank > 1) {
res.status(400).json("Invalid permission"); res.status(400).json("Invalid permission");
return; return;
} }
const IsLongMOTD = "longMOTD" in req.query; const alliance = (await Alliance.findById(guild.AllianceId!))!;
const MOTD = req.body ? String(req.body) : undefined; const motd = MOTD
? ({
message: MOTD,
authorName: getSuffixedName(account),
authorGuildName: guild.Name
} satisfies ILongMOTD)
: undefined;
if (IsLongMOTD) {
alliance.LongMOTD = motd;
} else {
alliance.MOTD = motd;
}
await alliance.save();
} else {
if (!hasGuildPermissionEx(guild, member, GuildPermission.Herald)) {
res.status(400).json("Invalid permission");
return;
}
if (IsLongMOTD) { if (IsLongMOTD) {
if (MOTD) { if (MOTD) {
@ -30,6 +53,7 @@ export const setGuildMotdController: RequestHandler = async (req, res) => {
guild.MOTD = MOTD ?? ""; guild.MOTD = MOTD ?? "";
} }
await guild.save(); await guild.save();
}
res.json({ IsLongMOTD, MOTD }); res.json({ IsLongMOTD, MOTD });
}; };

View File

@ -71,7 +71,8 @@ const techProjectSchema = new Schema<ITechProjectDatabase>(
const longMOTDSchema = new Schema<ILongMOTD>( const longMOTDSchema = new Schema<ILongMOTD>(
{ {
message: String, message: String,
authorName: String authorName: String,
authorGuildName: String
}, },
{ _id: false } { _id: false }
); );

View File

@ -581,6 +581,8 @@ export const getAllianceClient = async (
return { return {
_id: toOid(alliance._id), _id: toOid(alliance._id),
Name: alliance.Name, Name: alliance.Name,
MOTD: alliance.MOTD,
LongMOTD: alliance.LongMOTD,
Clans: clans, Clans: clans,
AllianceVault: { AllianceVault: {
DojoRefundRegularCredits: alliance.VaultRegularCredits DojoRefundRegularCredits: alliance.VaultRegularCredits

View File

@ -64,7 +64,7 @@ export interface IGuildDatabase {
export interface ILongMOTD { export interface ILongMOTD {
message: string; message: string;
authorName: string; authorName: string;
authorGuildName?: ""; authorGuildName?: string;
} }
// 32 seems to be reserved // 32 seems to be reserved
@ -320,4 +320,3 @@ export interface IAllianceMemberDatabase {
// TODO: GET /api/divvyAllianceVault.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0&allianceId=000000000000000000000069&credits=0 // TODO: GET /api/divvyAllianceVault.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0&allianceId=000000000000000000000069&credits=0
// TODO: GET /api/removeFromAlliance.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0 // TODO: GET /api/removeFromAlliance.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0
// TODO: GET /api/setAllianceGuildPermissions.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=000000000000000000000042&perms=2 // TODO: GET /api/setAllianceGuildPermissions.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=000000000000000000000042&perms=2
// TODO: Handle alliance in setGuildMotd