1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-13 06:02:39 +01:00
This commit is contained in:
Flam3rboy 2021-05-05 15:05:41 +02:00
commit 87634d5522
5 changed files with 162 additions and 134 deletions

219
package-lock.json generated
View File

@ -1,7 +1,7 @@
{
"name": "@fosscord/api",
"version": "1.0.0",
"lockfileVersion": 2,
"lockfileVersion": 1,
"requires": true,
"packages": {
"": {
@ -12205,38 +12205,72 @@
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"dev": true,
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
"requires": {
"ajv": "^6.9.2",
"browserify": "^16.2.3",
"concat-stream": "^1.5.2",
"d3-fg": "^6.14.0",
"debounce": "^1.2.0",
"debug": "^4.1.1",
"end-of-stream": "^1.1.0",
"env-string": "^1.0.0",
"escape-string-regexp": "^1.0.5",
"execspawn": "^1.0.1",
"has-unicode": "^2.0.1",
"hsl-to-rgb-for-reals": "^1.1.0",
"jsonstream2": "^1.1.2",
"make-dir": "^1.3.0",
"minimist": "^1.2.0",
"morphdom": "^2.3.3",
"nanohtml": "^1.4.0",
"on-net-listen": "^1.1.0",
"opn": "^5.4.0",
"perf-sym": "^2.0.3",
"pump": "^3.0.0",
"pumpify": "^1.4.0",
"semver": "^5.5.1",
"single-line-log": "^1.0.1",
"split2": "^3.1.0",
"tachyons": "^4.9.1",
"through2": "^2.0.5",
"which": "^1.2.4"
},
"engines": {
"node": ">=8"
"dependencies": {
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"dev": true,
"requires": {
"ms": "2.1.2"
}
},
"make-dir": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
"dev": true,
"requires": {
"pify": "^3.0.0"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
}
}
},
"node_modules/yargs/node_modules/strip-ansi": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
"dev": true,
"dependencies": {
"ansi-regex": "^5.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/yn": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
"dev": true,
"engines": {
"node": ">=6"
}
}
},
"dependencies": {
"@babel/code-frame": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
@ -13658,75 +13692,14 @@
"@zerollup/ts-helpers": "^1.7.18"
}
},
"0x": {
"version": "4.10.2",
"resolved": "https://registry.npmjs.org/0x/-/0x-4.10.2.tgz",
"integrity": "sha512-LXTa7LgSDOns5VsdyMSNTkrXqMZ1cLuPqehojM96WFO9+L2XjmKKTayKi++38CevR1QrjF4EqGDN98oxNhf5uQ==",
"JSONStream": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
"integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==",
"dev": true,
"requires": {
"ajv": "^6.9.2",
"browserify": "^16.2.3",
"concat-stream": "^1.5.2",
"d3-fg": "^6.14.0",
"debounce": "^1.2.0",
"debug": "^4.1.1",
"end-of-stream": "^1.1.0",
"env-string": "^1.0.0",
"escape-string-regexp": "^1.0.5",
"execspawn": "^1.0.1",
"has-unicode": "^2.0.1",
"hsl-to-rgb-for-reals": "^1.1.0",
"jsonstream2": "^1.1.2",
"make-dir": "^1.3.0",
"minimist": "^1.2.0",
"morphdom": "^2.3.3",
"nanohtml": "^1.4.0",
"on-net-listen": "^1.1.0",
"opn": "^5.4.0",
"perf-sym": "^2.0.3",
"pump": "^3.0.0",
"pumpify": "^1.4.0",
"semver": "^5.5.1",
"single-line-log": "^1.0.1",
"split2": "^3.1.0",
"tachyons": "^4.9.1",
"through2": "^2.0.5",
"which": "^1.2.4"
},
"dependencies": {
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"dev": true,
"requires": {
"ms": "2.1.2"
}
},
"make-dir": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
"dev": true,
"requires": {
"pify": "^3.0.0"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
}
"jsonparse": "^1.2.0",
"through": ">=2.2.7 <3"
}
},
"abab": {
@ -14278,9 +14251,9 @@
"integrity": "sha512-erYug8XoqzU3IfcU8fUgyHqyOXqIE4tUTTQ+7mqUjQlvnXkOO6OlT9c/ZoJVHYoAaqGxr09CN53G7XIsO4KtWA==",
"dev": true,
"requires": {
"JSONStream": "^1.0.3",
"combine-source-map": "~0.8.0",
"defined": "^1.0.0",
"JSONStream": "^1.0.3",
"safe-buffer": "^5.1.1",
"through2": "^2.0.0",
"umd": "^3.0.0"
@ -14307,6 +14280,7 @@
"integrity": "sha512-TkOR1cQGdmXU9zW4YukWzWVSJwrxmNdADFbqbE3HFgQWe5wqZmOawqZ7J/8MPCwk/W8yY7Y0h+7mOtcZxLP23g==",
"dev": true,
"requires": {
"JSONStream": "^1.0.3",
"assert": "^1.4.0",
"browser-pack": "^6.0.1",
"browser-resolve": "^2.0.0",
@ -14328,7 +14302,6 @@
"https-browserify": "^1.0.0",
"inherits": "~2.0.1",
"insert-module-globals": "^7.0.0",
"JSONStream": "^1.0.3",
"labeled-stream-splicer": "^2.0.0",
"mkdirp-classic": "^0.5.2",
"module-deps": "^6.2.3",
@ -16672,11 +16645,11 @@
"integrity": "sha512-ufS5Qq9RZN+Bu899eA9QCAYThY+gGW7oRkmb0vC93Vlyu/CFGcH0OYPEjVkDXA5FEbTt1+VWzdoOD3Ny9N+8tg==",
"dev": true,
"requires": {
"JSONStream": "^1.0.3",
"acorn-node": "^1.5.2",
"combine-source-map": "^0.8.0",
"concat-stream": "^1.6.1",
"is-buffer": "^1.1.0",
"JSONStream": "^1.0.3",
"path-is-absolute": "^1.0.1",
"process": "~0.11.0",
"through2": "^2.0.0",
@ -18467,16 +18440,6 @@
"integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=",
"dev": true
},
"JSONStream": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
"integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==",
"dev": true,
"requires": {
"jsonparse": "^1.2.0",
"through": ">=2.2.7 <3"
}
},
"jsonstream2": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/jsonstream2/-/jsonstream2-1.1.2.tgz",
@ -19086,6 +19049,7 @@
"integrity": "sha512-fg7OZaQBcL4/L+AK5f4iVqf9OMbCclXfy/znXRxTVhJSeW5AIlS9AwheYwDaXM3lVW7OBeaeUEY3gbaC6cLlSA==",
"dev": true,
"requires": {
"JSONStream": "^1.0.3",
"browser-resolve": "^2.0.0",
"cached-path-relative": "^1.0.2",
"concat-stream": "~1.6.0",
@ -19093,7 +19057,6 @@
"detective": "^5.2.0",
"duplexer2": "^0.1.2",
"inherits": "^2.0.1",
"JSONStream": "^1.0.3",
"parents": "^1.0.0",
"readable-stream": "^2.0.2",
"resolve": "^1.4.0",
@ -20520,15 +20483,6 @@
}
}
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
"requires": {
"resolve-from": "^2.0.0",
"semver": "^5.1.0"
}
},
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
@ -20541,6 +20495,15 @@
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==",
"dev": true
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
"requires": {
"resolve-from": "^2.0.0",
"semver": "^5.1.0"
}
},
"resolve": {
"version": "1.20.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz",
@ -21410,14 +21373,6 @@
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": {
"safe-buffer": "~5.1.0"
}
},
"string-length": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz",
@ -21455,6 +21410,14 @@
"strip-ansi": "^3.0.0"
}
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": {
"safe-buffer": "~5.1.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",

View File

@ -1,5 +1,5 @@
import { Router } from "express";
import { ChannelCreateEvent, ChannelModel, ChannelType, GuildModel, Snowflake, toObject } from "@fosscord/server-util";
import { ChannelCreateEvent, ChannelModel, ChannelType, GuildModel, Snowflake, toObject, ChannelUpdateEvent } from "@fosscord/server-util";
import { HTTPError } from "lambert-server";
import { ChannelModifySchema } from "../../../schema/Channel";
import { emitEvent } from "../../../util/Event";
@ -37,7 +37,7 @@ router.post("/", check(ChannelModifySchema), async (req, res) => {
}
const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec();
if (!guild) throw new HTTPError("Guild not found", 4040);
if (!guild) throw new HTTPError("Guild not found", 404);
const channel = {
...body,
@ -52,4 +52,24 @@ router.post("/", check(ChannelModifySchema), async (req, res) => {
res.json(channel);
});
router.patch("/", check(ChannelModifySchema), async (req, res) => {
const { guild_id } = req.params;
const body = req.body as ChannelModifySchema;
const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec();
if (!guild) throw new HTTPError("Guild not found", 404);
const channel = {
...body
};
const channelm = await ChannelModel.find({ guild_id }).exec();
if(!channelm) throw new HTTPError("Channel not found", 404);
await new ChannelModel(channel).save();
await emitEvent({ event: "CHANNEL_UPDATE", data: channel } as ChannelUpdateEvent);
res.json(channel);
});
export default router;

View File

@ -1,9 +1,10 @@
import { Request, Response, Router } from "express";
import { GuildModel, MemberModel, toObject } from "@fosscord/server-util";
import { GuildModel, MemberModel, UserModel, toObject, GuildMemberAddEvent } from "@fosscord/server-util";
import { HTTPError } from "lambert-server";
import { instanceOf, Length } from "../../../util/instanceOf";
import { PublicMemberProjection } from "../../../util/Member";
import { PublicUserProjection } from "../../../util/User";
import { PublicMemberProjection, addMember, removeMember } from "../../../util/Member";
import { emitEvent } from "../../../util/Event";
import { getPublicUser } from "../../../util/User";
const router = Router();
@ -47,7 +48,35 @@ router.get("/:member", async (req: Request, res: Response) => {
});
router.put("/:member", async (req: Request, res: Response) => {
const { guild_id } = req.params;
const guild = await GuildModel.findOne({ id: guild_id }).exec();
if (!guild) throw new HTTPError("Guild not found", 404);
const user_id = req.params.member;
const user = await UserModel.findOne({ id: user_id }).exec();
if (!user) throw new HTTPError("User not found", 404);
await addMember(user_id, guild_id);
// https://discord.com/developers/docs/resources/guild#add-guild-member
});
router.delete("/:member", async (req: Request, res: Response) => {
const { guild_id } = req.params;
const guild = await GuildModel.findOne({ id: guild_id }).exec();
if (!guild) throw new HTTPError("Guild not found", 404);
const user_id = req.params.member;
const member = await MemberModel.findOne({ id: user_id, guild_id }).exec();
if (!member) throw new HTTPError("Member not found", 404);
await removeMember(user_id, guild_id);
// https://discord.com/developers/docs/resources/guild#remove-guild-member
});
export default router;

View File

@ -1,6 +1,7 @@
import { Router, Request, Response } from "express";
import { UserModel } from "@fosscord/server-util";
import { HTTPError } from "lambert-server";
import { getPublicUser } from "../../../util/User";
const router: Router = Router();
@ -9,7 +10,9 @@ router.get("/", async (req: Request, res: Response) => {
const user = await UserModel.findOne({ id: req.user_id }).exec();
if (!user) throw new HTTPError("User not found", 404);
res.json(user);
var publicUser = await getPublicUser(user.id);
res.json(publicUser);
});
export default router;

13
src/schema/Member.ts Normal file
View File

@ -0,0 +1,13 @@
export const MemberCreateSchema = {
id: String,
nick: String,
guild_id: String,
joined_at: Date,
};
export interface MemberCreateSchema {
id: string;
nick: string;
guild_id: string;
joined_at: Date;
}