Merge branch 'master' into slowcord

This commit is contained in:
Madeline 2022-04-19 20:09:22 +10:00
commit b941560d48
40 changed files with 356 additions and 147 deletions

View File

@ -3,7 +3,7 @@
</p> </p>
<h1 align="center">Fosscord Server</h1> <h1 align="center">Fosscord Server</h1>
<p> <p align="center">
<a href="https://discord.gg/ZrnGQP6p3d"> <a href="https://discord.gg/ZrnGQP6p3d">
<img src="https://img.shields.io/discord/806142446094385153?color=7489d5&logo=discord&logoColor=ffffff" /> <img src="https://img.shields.io/discord/806142446094385153?color=7489d5&logo=discord&logoColor=ffffff" />
</a> </a>

View File

@ -7,12 +7,12 @@
"BASE_TYPE_BOOLEAN": "This field must be a boolean", "BASE_TYPE_BOOLEAN": "This field must be a boolean",
"BASE_TYPE_CHOICES": "This field must be one of ({{types}})", "BASE_TYPE_CHOICES": "This field must be one of ({{types}})",
"BASE_TYPE_CLASS": "This field must be an instance of {{type}}", "BASE_TYPE_CLASS": "This field must be an instance of {{type}}",
"BASE_TYPE_OBJECT": "This field must be an object", "BASE_TYPE_OBJECT": "שדה זה חייב להיות אובייקט",
"BASE_TYPE_ARRAY": "This field must be an array", "BASE_TYPE_ARRAY": "שדה זה חייב להיות מערך",
"UNKOWN_FIELD": "Unknown key: {{key}}", "UNKOWN_FIELD": "מפתח לא ידוע: {{key}}",
"BASE_TYPE_CONSTANT": "This field must be {{value}}", "BASE_TYPE_CONSTANT": "שדה זה להיות {{value}}",
"EMAIL_TYPE_INVALID_EMAIL": "Not a well-formed email address", "EMAIL_TYPE_INVALID_EMAIL": "כתובת דואר אלקטרוני לא חוקית",
"DATE_TYPE_PARSE": "Could not parse {{date}}. Should be ISO8601", "DATE_TYPE_PARSE": "לא ניתן לנתח {{date}}. צריך להיות ISO8601",
"BASE_TYPE_BAD_LENGTH": "Must be between {{length}} in length" "BASE_TYPE_BAD_LENGTH": "האורך חייב להיות בין {{length}}"
} }
} }

View File

@ -1,16 +1,16 @@
{ {
"login": { "login": {
"INVALID_LOGIN": "E-Mail or Phone not found", "INVALID_LOGIN": "E-post eller telefon hittades inte",
"INVALID_PASSWORD": "Invalid Password", "INVALID_PASSWORD": "Ogiltigt lösenord",
"ACCOUNT_DISABLED": "This account is disabled" "ACCOUNT_DISABLED": "Detta konto är inaktiverat"
}, },
"register": { "register": {
"REGISTRATION_DISABLED": "New user registration is disabled", "REGISTRATION_DISABLED": "Registrering av nya användare är inaktiverat",
"INVITE_ONLY": "You must be invited to register", "INVITE_ONLY": "Du måste vara inbjuden för att registrera dig",
"EMAIL_INVALID": "Invalid Email", "EMAIL_INVALID": "Ogiltig e-post",
"EMAIL_ALREADY_REGISTERED": "Email is already registered", "EMAIL_ALREADY_REGISTERED": "E-postadressen är redan registrerad",
"DATE_OF_BIRTH_UNDERAGE": "You need to be {{years}} years or older", "DATE_OF_BIRTH_UNDERAGE": "Du måste vara {{years}} år eller äldre",
"CONSENT_REQUIRED": "You must agree to the Terms of Service and Privacy Policy.", "CONSENT_REQUIRED": "Du måste godkänna användarvillkoren och sekretesspolicyn.",
"USERNAME_TOO_MANY_USERS": "Too many users have this username, please try another" "USERNAME_TOO_MANY_USERS": "För många användare har detta användarnamn, försök med ett annat"
} }
} }

View File

@ -1,18 +1,18 @@
{ {
"field": { "field": {
"BASE_TYPE_REQUIRED": "This field is required", "BASE_TYPE_REQUIRED": "Detta fältet krävs",
"BASE_TYPE_STRING": "This field must be a string", "BASE_TYPE_STRING": "Detta fält måste vara en sträng",
"BASE_TYPE_NUMBER": "This field must be a number", "BASE_TYPE_NUMBER": "Detta fält måste vara ett nummer",
"BASE_TYPE_BIGINT": "This field must be a bigint", "BASE_TYPE_BIGINT": "Detta fält måste vara av typen bigint",
"BASE_TYPE_BOOLEAN": "This field must be a boolean", "BASE_TYPE_BOOLEAN": "Detta fält måste vara booleskt",
"BASE_TYPE_CHOICES": "This field must be one of ({{types}})", "BASE_TYPE_CHOICES": "Detta fält måste vara av typen av ett av följande ({{types}})",
"BASE_TYPE_CLASS": "This field must be an instance of {{type}}", "BASE_TYPE_CLASS": "Det här fältet måste vara en instans av {{type}}",
"BASE_TYPE_OBJECT": "This field must be an object", "BASE_TYPE_OBJECT": "Detta fält måste vara ett objekt",
"BASE_TYPE_ARRAY": "This field must be an array", "BASE_TYPE_ARRAY": "Detta fält måste vara en array",
"UNKOWN_FIELD": "Unknown key: {{key}}", "UNKOWN_FIELD": "Okänd nyckel: {{key}}",
"BASE_TYPE_CONSTANT": "This field must be {{value}}", "BASE_TYPE_CONSTANT": "Det här fältet måste vara {{value}}",
"EMAIL_TYPE_INVALID_EMAIL": "Not a well-formed email address", "EMAIL_TYPE_INVALID_EMAIL": "E-postadressen har inte korrekt format",
"DATE_TYPE_PARSE": "Could not parse {{date}}. Should be ISO8601", "DATE_TYPE_PARSE": "Kunde inte tolka {{date}}. Bör vara ISO8601",
"BASE_TYPE_BAD_LENGTH": "Must be between {{length}} in length" "BASE_TYPE_BAD_LENGTH": "Måste vara mellan {{length}} i längd"
} }
} }

18
api/package-lock.json generated
View File

@ -4607,8 +4607,9 @@
} }
}, },
"../util/node_modules/minimist": { "../util/node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"license": "MIT" "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"../util/node_modules/minipass": { "../util/node_modules/minipass": {
"version": "2.9.0", "version": "2.9.0",
@ -13196,8 +13197,9 @@
} }
}, },
"node_modules/minimist": { "node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"license": "MIT" "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"node_modules/minipass": { "node_modules/minipass": {
"version": "3.1.5", "version": "3.1.5",
@ -19764,7 +19766,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5" "version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",
@ -24388,7 +24392,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5" "version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"minipass": { "minipass": {
"version": "3.1.5", "version": "3.1.5",

View File

@ -15,6 +15,7 @@ export const NO_AUTHORIZATION_ROUTES = [
"/experiments", "/experiments",
"/updates", "/updates",
"/downloads/", "/downloads/",
"/scheduled-maintenances/upcoming.json",
// Public kubernetes integration // Public kubernetes integration
"/-/readyz", "/-/readyz",
"/-/healthz", "/-/healthz",

View File

@ -19,7 +19,8 @@ export interface InviteCreateSchema {
target_user_type?: number; target_user_type?: number;
} }
router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE" }), async (req: Request, res: Response) => { router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE", right: "CREATE_INVITES" }),
async (req: Request, res: Response) => {
const { user_id } = req; const { user_id } = req;
const { channel_id } = req.params; const { channel_id } = req.params;
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] }); const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] });

View File

@ -4,8 +4,9 @@ import { route } from "@fosscord/api";
const router = Router(); const router = Router();
// TODO: check if message exists // TODO: public read receipts & privacy scoping
// TODO: send read state event to all channel members // TODO: send read state event to all channel members
// TODO: advance-only notification cursor
export interface MessageAcknowledgeSchema { export interface MessageAcknowledgeSchema {
manual?: boolean; manual?: boolean;

View File

@ -1,4 +1,4 @@
import { Channel, emitEvent, getPermission, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util"; import { Channel, emitEvent, getPermission, getRights, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
import { Router, Response, Request } from "express"; import { Router, Response, Request } from "express";
import { route } from "@fosscord/api"; import { route } from "@fosscord/api";
import { handleMessage, postHandleMessage } from "@fosscord/api"; import { handleMessage, postHandleMessage } from "@fosscord/api";
@ -7,7 +7,7 @@ import { MessageCreateSchema } from "../index";
const router = Router(); const router = Router();
// TODO: message content/embed string length limit // TODO: message content/embed string length limit
router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }), async (req: Request, res: Response) => { router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES", right: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params; const { message_id, channel_id } = req.params;
var body = req.body as MessageCreateSchema; var body = req.body as MessageCreateSchema;
@ -15,10 +15,15 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
const permissions = await getPermission(req.user_id, undefined, channel_id); const permissions = await getPermission(req.user_id, undefined, channel_id);
if (req.user_id !== message.author_id) { const rights = await getRights(req.user_id);
permissions.hasThrow("MANAGE_MESSAGES");
body = { flags: body.flags }; // admins can only suppress embeds of other messages if ((req.user_id !== message.author_id)) {
} if (!rights.has("MANAGE_MESSAGES")) {
permissions.hasThrow("MANAGE_MESSAGES");
body = { flags: body.flags };
// guild admins can only suppress embeds of other messages, no such restriction imposed to instance-wide admins
}
} else rights.hasThrow("SELF_EDIT_MESSAGES");
const new_message = await handleMessage({ const new_message = await handleMessage({
...message, ...message,
@ -46,17 +51,32 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
return res.json(message); return res.json(message);
}); });
// permission check only if deletes messagr from other user router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] });
const permissions = await getPermission(req.user_id, undefined, channel_id);
if (message.author_id !== req.user_id) permissions.hasThrow("READ_MESSAGE_HISTORY");
return res.json(message);
});
router.delete("/", route({}), async (req: Request, res: Response) => { router.delete("/", route({}), async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params; const { message_id, channel_id } = req.params;
const channel = await Channel.findOneOrFail({ id: channel_id }); const channel = await Channel.findOneOrFail({ id: channel_id });
const message = await Message.findOneOrFail({ id: message_id }); const message = await Message.findOneOrFail({ id: message_id });
if (message.author_id !== req.user_id) { const rights = await getRights(req.user_id);
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
permission.hasThrow("MANAGE_MESSAGES"); if ((message.author_id !== req.user_id)) {
} if (!rights.has("MANAGE_MESSAGES")) {
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
permission.hasThrow("MANAGE_MESSAGES");
}
} else rights.hasThrow("SELF_DELETE_MESSAGES");
await Message.delete({ id: message_id }); await Message.delete({ id: message_id });

View File

@ -101,7 +101,7 @@ router.get("/:emoji", route({ permission: "VIEW_CHANNEL" }), async (req: Request
res.json(users); res.json(users);
}); });
router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY" }), async (req: Request, res: Response) => { router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY", right: "SELF_ADD_REACTIONS" }), async (req: Request, res: Response) => {
const { message_id, channel_id, user_id } = req.params; const { message_id, channel_id, user_id } = req.params;
if (user_id !== "@me") throw new HTTPError("Invalid user"); if (user_id !== "@me") throw new HTTPError("Invalid user");
const emoji = getEmoji(req.params.emoji); const emoji = getEmoji(req.params.emoji);

View File

@ -8,6 +8,7 @@ import {
Embed, Embed,
emitEvent, emitEvent,
getPermission, getPermission,
getRights,
Message, Message,
MessageCreateEvent, MessageCreateEvent,
uploadFile, uploadFile,
@ -119,7 +120,7 @@ router.get("/", async (req: Request, res: Response) => {
delete x.user_ids; delete x.user_ids;
}); });
// @ts-ignore // @ts-ignore
if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: "0", avatar: null }; if (!x.author) x.author = { id: "4", discriminator: "0000", username: "Fosscord Ghost", public_flags: "0", avatar: null };
x.attachments?.forEach((y: any) => { x.attachments?.forEach((y: any) => {
// dynamically set attachment proxy_url in case the endpoint changed // dynamically set attachment proxy_url in case the endpoint changed
const uri = y.proxy_url.startsWith("http") ? y.proxy_url : `https://example.org${y.proxy_url}`; const uri = y.proxy_url.startsWith("http") ? y.proxy_url : `https://example.org${y.proxy_url}`;
@ -149,7 +150,7 @@ const messageUpload = multer({
}); // max upload 50 mb }); // max upload 50 mb
// TODO: dynamically change limit of MessageCreateSchema with config // TODO: dynamically change limit of MessageCreateSchema with config
// TODO: check: sum of all characters in an embed structure must not exceed 6000 characters // TODO: check: sum of all characters in an embed structure must not exceed instance limits
// https://discord.com/developers/docs/resources/channel#create-message // https://discord.com/developers/docs/resources/channel#create-message
// TODO: text channel slowdown // TODO: text channel slowdown
@ -167,7 +168,7 @@ router.post(
next(); next();
}, },
route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }), route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES", right: "SEND_MESSAGES" }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { channel_id } = req.params; const { channel_id } = req.params;
var body = req.body as MessageCreateSchema; var body = req.body as MessageCreateSchema;

View File

@ -1,5 +1,5 @@
import { Request, Response, Router } from "express"; import { Request, Response, Router } from "express";
import { emitEvent, getPermission, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util"; import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util";
import { HTTPError } from "lambert-server"; import { HTTPError } from "lambert-server";
import { route } from "@fosscord/api"; import { route } from "@fosscord/api";
import "missing-native-js-functions"; import "missing-native-js-functions";
@ -37,9 +37,17 @@ router.get("/", route({}), async (req: Request, res: Response) => {
return res.send(guild); return res.send(guild);
}); });
router.patch("/", route({ body: "GuildUpdateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { router.patch("/", route({ body: "GuildUpdateSchema"}), async (req: Request, res: Response) => {
const body = req.body as GuildUpdateSchema; const body = req.body as GuildUpdateSchema;
const { guild_id } = req.params; const { guild_id } = req.params;
const rights = await getRights(req.user_id);
const permission = await getPermission(req.user_id, guild_id);
if (!rights.has("MANAGE_GUILDS")||!permission.has("MANAGE_GUILD"))
throw DiscordApiErrors.MISSING_PERMISSIONS.withParams("MANAGE_GUILD");
// TODO: guild update check image // TODO: guild update check image
if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon); if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon);

View File

@ -6,7 +6,6 @@ import { HTTPError } from "lambert-server";
const router = Router(); const router = Router();
// TODO: not allowed for user -> only allowed for bots with privileged intents
// TODO: send over websocket // TODO: send over websocket
// TODO: check for GUILD_MEMBERS intent // TODO: check for GUILD_MEMBERS intent

View File

@ -1,5 +1,5 @@
import { Router, Request, Response } from "express"; import { Router, Request, Response } from "express";
import { Role, Guild, Snowflake, Config, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util"; import { Role, Guild, Snowflake, Config, getRights, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util";
import { route } from "@fosscord/api"; import { route } from "@fosscord/api";
import { ChannelModifySchema } from "../channels/#channel_id"; import { ChannelModifySchema } from "../channels/#channel_id";
@ -20,12 +20,13 @@ export interface GuildCreateSchema {
//TODO: create default channel //TODO: create default channel
router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: Response) => { router.post("/", route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }), async (req: Request, res: Response) => {
const body = req.body as GuildCreateSchema; const body = req.body as GuildCreateSchema;
const { maxGuilds } = Config.get().limits.user; const { maxGuilds } = Config.get().limits.user;
const guild_count = await Member.count({ id: req.user_id }); const guild_count = await Member.count({ id: req.user_id });
if (guild_count >= maxGuilds) { const rights = await getRights(req.user_id);
if ((guild_count >= maxGuilds)&&!rights.has("MANAGE_GUILDS")) {
throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds);
} }

View File

@ -13,7 +13,7 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
res.status(200).send(invite); res.status(200).send(invite);
}); });
router.post("/:code", route({}), async (req: Request, res: Response) => { router.post("/:code", route({right: "JOIN_GUILDS"}), async (req: Request, res: Response) => {
const { code } = req.params; const { code } = req.params;
const { guild_id } = await Invite.findOneOrFail({ code }) const { guild_id } = await Invite.findOneOrFail({ code })
const { features } = await Guild.findOneOrFail({ id: guild_id}); const { features } = await Guild.findOneOrFail({ id: guild_id});

View File

@ -0,0 +1,12 @@
import { Router, Request, Response } from "express";
import { route } from "@fosscord/api";
const router = Router();
router.get("/scheduled-maintenances/upcoming.json",route({}), async (req: Request, res: Response) => {
res.json({
"page": {},
"scheduled_maintenances": {}
});
});
export default router;

View File

@ -1,14 +1,39 @@
import { Request, Response, Router } from "express"; import { Request, Response, Router } from "express";
import { route } from "@fosscord/api"; import { route } from "@fosscord/api";
import { User, emitEvent } from "@fosscord/util";
const router: Router = Router(); const router: Router = Router();
router.get("/:id", route({}), async (req: Request, res: Response) => {
const { id } = req.params;
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["notes"] });
const note = user.notes[id];
return res.json({
note: note,
note_user_id: id,
user_id: user.id,
});
});
router.put("/:id", route({}), async (req: Request, res: Response) => { router.put("/:id", route({}), async (req: Request, res: Response) => {
//TODO const { id } = req.params;
res.json({ const user = await User.findOneOrFail({ where: { id: req.user_id } });
message: "Unknown User", const noteUser = await User.findOneOrFail({ where: { id: id }}); //if noted user does not exist throw
code: 10013 const { note } = req.body;
}).status(404);
await User.update({ id: req.user_id }, { notes: { ...user.notes, [noteUser.id]: note } });
await emitEvent({
event: "USER_NOTE_UPDATE",
data: {
note: note,
id: noteUser.id
},
user_id: user.id,
})
return res.status(204);
}); });
export default router; export default router;

View File

@ -7,7 +7,12 @@ config();
import { FosscordServer } from "./Server"; import { FosscordServer } from "./Server";
import cluster from "cluster"; import cluster from "cluster";
import os from "os"; import os from "os";
const cores = Number(process.env.THREADS) || os.cpus().length; var cores = 1;
try {
cores = Number(process.env.THREADS) || os.cpus().length;
} catch {
console.log("[API] Failed to get thread count! Using 1...")
}
if (cluster.isMaster && process.env.NODE_ENV == "production") { if (cluster.isMaster && process.env.NODE_ENV == "production") {
console.log(`Primary ${process.pid} is running`); console.log(`Primary ${process.pid} is running`);

View File

@ -7,6 +7,7 @@ import {
MessageCreateEvent, MessageCreateEvent,
MessageUpdateEvent, MessageUpdateEvent,
getPermission, getPermission,
getRights,
CHANNEL_MENTION, CHANNEL_MENTION,
Snowflake, Snowflake,
USER_MENTION, USER_MENTION,
@ -61,9 +62,10 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
throw new HTTPError("Content length over max character limit") throw new HTTPError("Content length over max character limit")
} }
// TODO: are tts messages allowed in dm channels? should permission be checked?
if (opts.author_id) { if (opts.author_id) {
message.author = await User.getPublicUser(opts.author_id); message.author = await User.getPublicUser(opts.author_id);
const rights = await getRights(opts.author_id);
rights.hasThrow("SEND_MESSAGES");
} }
if (opts.application_id) { if (opts.application_id) {
message.application = await Application.findOneOrFail({ id: opts.application_id }); message.application = await Application.findOneOrFail({ id: opts.application_id });
@ -73,7 +75,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
} }
const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id); const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id);
permission.hasThrow("SEND_MESSAGES"); // TODO: add the rights check permission.hasThrow("SEND_MESSAGES");
if (permission.cache.member) { if (permission.cache.member) {
message.member = permission.cache.member; message.member = permission.cache.member;
} }
@ -81,7 +83,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
if (opts.tts) permission.hasThrow("SEND_TTS_MESSAGES"); if (opts.tts) permission.hasThrow("SEND_TTS_MESSAGES");
if (opts.message_reference) { if (opts.message_reference) {
permission.hasThrow("READ_MESSAGE_HISTORY"); permission.hasThrow("READ_MESSAGE_HISTORY");
// code below has to be redone when we add custom message routing and cross-channel replies // code below has to be redone when we add custom message routing
if (message.guild_id !== null) { if (message.guild_id !== null) {
const guild = await Guild.findOneOrFail({ id: channel.guild_id }); const guild = await Guild.findOneOrFail({ id: channel.guild_id });
if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) { if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
@ -89,7 +91,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel"); if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel");
} }
} }
// TODO: should be checked if the referenced message exists? // Q: should be checked if the referenced message exists? ANSWER: NO
// @ts-ignore // @ts-ignore
message.type = MessageType.REPLY; message.type = MessageType.REPLY;
} }

View File

@ -6,6 +6,7 @@ import {
FieldErrors, FieldErrors,
FosscordApiErrors, FosscordApiErrors,
getPermission, getPermission,
getRights,
PermissionResolvable, PermissionResolvable,
Permissions, Permissions,
RightResolvable, RightResolvable,
@ -105,6 +106,8 @@ export function route(opts: RouteOptions) {
if (opts.right) { if (opts.right) {
const required = new Rights(opts.right); const required = new Rights(opts.right);
req.rights = await getRights(req.user_id);
if (!req.rights || !req.rights.has(required)) { if (!req.rights || !req.rights.has(required)) {
throw FosscordApiErrors.MISSING_RIGHTS.withParams(opts.right as string); throw FosscordApiErrors.MISSING_RIGHTS.withParams(opts.right as string);
} }

View File

@ -13,6 +13,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored
* - min <n> numbers * - min <n> numbers
* - min <n> symbols * - min <n> symbols
* - min <n> uppercase chars * - min <n> uppercase chars
* - shannon entropy folded into [0, 1) interval
* *
* Returns: 0 > pw > 1 * Returns: 0 > pw > 1
*/ */
@ -22,22 +23,22 @@ export function checkPassword(password: string): number {
// checks for total password len // checks for total password len
if (password.length >= minLength - 1) { if (password.length >= minLength - 1) {
strength += 0.25; strength += 0.05;
} }
// checks for amount of Numbers // checks for amount of Numbers
if (password.count(reNUMBER) >= minNumbers - 1) { if (password.count(reNUMBER) >= minNumbers - 1) {
strength += 0.25; strength += 0.05;
} }
// checks for amount of Uppercase Letters // checks for amount of Uppercase Letters
if (password.count(reUPPERCASELETTER) >= minUpperCase - 1) { if (password.count(reUPPERCASELETTER) >= minUpperCase - 1) {
strength += 0.25; strength += 0.05;
} }
// checks for amount of symbols // checks for amount of symbols
if (password.replace(reSYMBOLS, "").length >= minSymbols - 1) { if (password.replace(reSYMBOLS, "").length >= minSymbols - 1) {
strength += 0.25; strength += 0.05;
} }
// checks if password only consists of numbers or only consists of chars // checks if password only consists of numbers or only consists of chars
@ -45,5 +46,15 @@ export function checkPassword(password: string): number {
strength = 0; strength = 0;
} }
let entropyMap: { [key: string]: number } = {};
for (let i = 0; i < password.length; i++) {
if (entropyMap[password[i]]) entropyMap[password[i]]++;
else entropyMap[password[i]] = 1;
}
let entropies = Object.values(entropyMap);
entropies.map(x => (x / entropyMap.length));
strength += entropies.reduceRight((a: number, x: number) => a - (x * Math.log2(x))) / Math.log2(password.length);
return strength; return strength;
} }

View File

@ -7350,8 +7350,9 @@
} }
}, },
"node_modules/minimist": { "node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"node_modules/minipass": { "node_modules/minipass": {
"version": "3.1.5", "version": "3.1.5",
@ -16582,8 +16583,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.6",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"minipass": { "minipass": {
"version": "3.1.5", "version": "3.1.5",

View File

@ -3,8 +3,13 @@ const cluster = require("cluster");
const WebSocket = require("ws"); const WebSocket = require("ws");
const endpoint = process.env.GATEWAY || "ws://localhost:3001"; const endpoint = process.env.GATEWAY || "ws://localhost:3001";
const connections = Number(process.env.CONNECTIONS) || 50; const connections = Number(process.env.CONNECTIONS) || 50;
const threads = Number(process.env.THREADS) || require("os").cpus().length || 1;
const token = process.env.TOKEN; const token = process.env.TOKEN;
var cores = 1;
try {
cores = Number(process.env.THREADS) || os.cpus().length;
} catch {
console.log("[Bundle] Failed to get thread count! Using 1...")
}
if (!token) { if (!token) {
console.error("TOKEN env var missing"); console.error("TOKEN env var missing");

View File

@ -9,7 +9,12 @@ config();
import { execSync } from "child_process"; import { execSync } from "child_process";
// TODO: add socket event transmission // TODO: add socket event transmission
let cores = Number(process.env.THREADS) || os.cpus().length; var cores = 1;
try {
cores = Number(process.env.THREADS) || os.cpus().length;
} catch {
console.log("[API] Failed to get thread count! Using 1...")
}
if (cluster.isMaster) { if (cluster.isMaster) {
function getCommitOrFail() { function getCommitOrFail() {

View File

@ -4,7 +4,13 @@ import { red } from "picocolors";
export function initStats() { export function initStats() {
console.log(`[Path] running in ${__dirname}`); console.log(`[Path] running in ${__dirname}`);
console.log(`[CPU] ${osu.cpu.model()} Cores x${osu.cpu.count()}`); try {
console.log(`[CPU] ${osu.cpu.model()} Cores x${osu.cpu.count()}`);
}
catch {
console.log('[CPU] Failed to get cpu model!')
}
console.log(`[System] ${os.platform()} ${os.arch()}`); console.log(`[System] ${os.platform()} ${os.arch()}`);
console.log(`[Process] running with PID: ${process.pid}`); console.log(`[Process] running with PID: ${process.pid}`);
if (process.getuid && process.getuid() === 0) { if (process.getuid && process.getuid() === 0) {

12
cdn/package-lock.json generated
View File

@ -5739,9 +5739,9 @@
} }
}, },
"node_modules/minimist": { "node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"node_modules/minipass": { "node_modules/minipass": {
"version": "3.1.6", "version": "3.1.6",
@ -12301,9 +12301,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"minipass": { "minipass": {
"version": "3.1.6", "version": "3.1.6",

View File

@ -4479,8 +4479,9 @@
} }
}, },
"../util/node_modules/minimist": { "../util/node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"../util/node_modules/minipass": { "../util/node_modules/minipass": {
"version": "2.9.0", "version": "2.9.0",
@ -8768,8 +8769,9 @@
} }
}, },
"node_modules/minimist": { "node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true "dev": true
}, },
"node_modules/minipass": { "node_modules/minipass": {
@ -13666,8 +13668,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.6",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",
@ -16870,8 +16873,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.6",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true "dev": true
}, },
"minipass": { "minipass": {

View File

@ -29,8 +29,8 @@ const experiments: any = [];
import { check } from "./instanceOf"; import { check } from "./instanceOf";
import { Recipient } from "@fosscord/util"; import { Recipient } from "@fosscord/util";
// TODO: bot sharding // TODO: user sharding
// TODO: check priviliged intents // TODO: check privileged intents, if defined in the config
// TODO: check if already identified // TODO: check if already identified
export async function onIdentify(this: WebSocket, data: Payload) { export async function onIdentify(this: WebSocket, data: Payload) {
@ -87,7 +87,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
user_id: this.user_id, user_id: this.user_id,
session_id: session_id, session_id: session_id,
// TODO: check if status is only one of: online, dnd, offline, idle // TODO: check if status is only one of: online, dnd, offline, idle
status: identify.presence?.status || "online", //does the session always start as online? status: identify.presence?.status || "offline", //does the session always start as online?
client_info: { client_info: {
//TODO read from identity //TODO read from identity
client: "desktop", client: "desktop",
@ -101,7 +101,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
if (!user) return this.close(CLOSECODES.Authentication_failed); if (!user) return this.close(CLOSECODES.Authentication_failed);
if (!identify.intents) identify.intents = BigInt("0b11111111111111"); if (!identify.intents) identify.intents = BigInt("0x6ffffffff");
this.intents = new Intents(identify.intents); this.intents = new Intents(identify.intents);
if (identify.shard) { if (identify.shard) {
this.shard_id = identify.shard[0]; this.shard_id = identify.shard[0];
@ -271,7 +271,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
guild_join_requests: [], // TODO what is this? guild_join_requests: [], // TODO what is this?
users: users.filter((x) => x).unique(), users: users.filter((x) => x).unique(),
merged_members: merged_members, merged_members: merged_members,
// shard // TODO: only for bots sharding // shard // TODO: only for user sharding
}; };
// TODO: send real proper data structure // TODO: send real proper data structure

12
util/package-lock.json generated
View File

@ -5003,9 +5003,9 @@
} }
}, },
"node_modules/minimist": { "node_modules/minimist": {
"version": "1.2.5", "version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"node_modules/minipass": { "node_modules/minipass": {
"version": "2.9.0", "version": "2.9.0",
@ -12060,9 +12060,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",

View File

@ -20,13 +20,17 @@ export enum ChannelType {
GROUP_DM = 3, // a direct message between multiple users GROUP_DM = 3, // a direct message between multiple users
GUILD_CATEGORY = 4, // an organizational category that contains zero or more channels GUILD_CATEGORY = 4, // an organizational category that contains zero or more channels
GUILD_NEWS = 5, // a channel that users can follow and crosspost into a guild or route GUILD_NEWS = 5, // a channel that users can follow and crosspost into a guild or route
GUILD_STORE = 6, // a channel in which game developers can sell their game on Discord GUILD_STORE = 6, // a channel in which game developers can sell their things
ENCRYPTED = 7, // end-to-end encrypted channel ENCRYPTED = 7, // end-to-end encrypted channel
ENCRYPTED_THREAD = 8, // end-to-end encrypted thread channel ENCRYPTED_THREAD = 8, // end-to-end encrypted thread channel
TRANSACTIONAL = 9, // event chain style transactional channel
GUILD_NEWS_THREAD = 10, // a temporary sub-channel within a GUILD_NEWS channel GUILD_NEWS_THREAD = 10, // a temporary sub-channel within a GUILD_NEWS channel
GUILD_PUBLIC_THREAD = 11, // a temporary sub-channel within a GUILD_TEXT channel GUILD_PUBLIC_THREAD = 11, // a temporary sub-channel within a GUILD_TEXT channel
GUILD_PRIVATE_THREAD = 12, // a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission GUILD_PRIVATE_THREAD = 12, // a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
GUILD_STAGE_VOICE = 13, // a voice channel for hosting events with an audience GUILD_STAGE_VOICE = 13, // a voice channel for hosting events with an audience
TICKET_TRACKER = 33, // ticket tracker, individual ticket items shall have type 12
KANBAN = 34, // confluence like kanban board
VOICELESS_WHITEBOARD = 35, // whiteboard but without voice (whiteboard + voice is the same as stage)
CUSTOM_START = 64, // start custom channel types from here CUSTOM_START = 64, // start custom channel types from here
UNHANDLED = 255 // unhandled unowned pass-through channel type UNHANDLED = 255 // unhandled unowned pass-through channel type
} }

View File

@ -0,0 +1,35 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { PublicUserProjection, User } from "./User";
import { HTTPError } from "lambert-server";
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util";
import { BitField, BitFieldResolvable, BitFlag } from "../util/BitField";
import { Recipient } from "./Recipient";
import { Message } from "./Message";
import { ReadState } from "./ReadState";
import { Invite } from "./Invite";
import { DmChannelDTO } from "../dtos";
@Entity("security_settings")
export class SecuritySettings extends BaseClass {
@Column({nullable: true})
guild_id: Snowflake;
@Column({nullable: true})
channel_id: Snowflake;
@Column()
encryption_permission_mask: BitField;
@Column()
allowed_algorithms: string[];
@Column()
current_algorithm: string;
@Column({nullable: true})
used_since_message: Snowflake;
}

View File

@ -187,11 +187,11 @@ export class Guild extends BaseClass {
@Column({ nullable: true }) @Column({ nullable: true })
@RelationId((guild: Guild) => guild.owner) @RelationId((guild: Guild) => guild.owner)
owner_id: string; owner_id?: string; // optional to allow for ownerless guilds
@JoinColumn({ name: "owner_id", referencedColumnName: "id" }) @JoinColumn({ name: "owner_id", referencedColumnName: "id" })
@ManyToOne(() => User) @ManyToOne(() => User)
owner: User; owner?: User; // optional to allow for ownerless guilds
@Column({ nullable: true }) @Column({ nullable: true })
preferred_locale?: string; preferred_locale?: string;
@ -200,7 +200,7 @@ export class Guild extends BaseClass {
premium_subscription_count?: number; premium_subscription_count?: number;
@Column({ nullable: true }) @Column({ nullable: true })
premium_tier?: number; // nitro boost level premium_tier?: number; // crowd premium level
@Column({ nullable: true }) @Column({ nullable: true })
@RelationId((guild: Guild) => guild.public_updates_channel) @RelationId((guild: Guild) => guild.public_updates_channel)
@ -270,6 +270,10 @@ export class Guild extends BaseClass {
@Column({ nullable: true }) @Column({ nullable: true })
nsfw?: boolean; nsfw?: boolean;
// TODO: nested guilds
@Column({ nullable: true })
parent?: string;
// only for developer portal // only for developer portal
permissions?: number; permissions?: number;
@ -308,7 +312,7 @@ export class Guild extends BaseClass {
verification_level: 0, verification_level: 0,
welcome_screen: { welcome_screen: {
enabled: false, enabled: false,
description: "No description", description: "Fill in your description",
welcome_channels: [], welcome_channels: [],
}, },
widget_enabled: true, // NB: don't set it as false to prevent artificial restrictions widget_enabled: true, // NB: don't set it as false to prevent artificial restrictions

View File

@ -85,8 +85,8 @@ export class Member extends BaseClassWithoutId {
@Column() @Column()
joined_at: Date; joined_at: Date;
@Column() @Column({ type: "bigint", nullable: true })
premium_since?: Date; premium_since?: number;
@Column() @Column()
deaf: boolean; deaf: boolean;
@ -103,7 +103,16 @@ export class Member extends BaseClassWithoutId {
@Column({ nullable: true }) @Column({ nullable: true })
last_message_id?: string; last_message_id?: string;
// TODO: update /**
@JoinColumn({ name: "id" })
@ManyToOne(() => User, {
onDelete: "DO NOTHING",
// do not auto-kick force-joined members just because their joiners left the server
}) **/
@Column({ nullable: true})
joined_by?: string;
// TODO: add this when we have proper read receipts
// @Column({ type: "simple-json" }) // @Column({ type: "simple-json" })
// read_state: ReadState; // read_state: ReadState;
@ -245,7 +254,7 @@ export class Member extends BaseClassWithoutId {
nick: undefined, nick: undefined,
roles: [guild_id], // @everyone role roles: [guild_id], // @everyone role
joined_at: new Date(), joined_at: new Date(),
premium_since: new Date(), premium_since: (new Date()).getTime(),
deaf: false, deaf: false,
mute: false, mute: false,
pending: false, pending: false,

View File

@ -41,8 +41,14 @@ export enum MessageType {
CHANNEL_FOLLOW_ADD = 12, CHANNEL_FOLLOW_ADD = 12,
GUILD_DISCOVERY_DISQUALIFIED = 14, GUILD_DISCOVERY_DISQUALIFIED = 14,
GUILD_DISCOVERY_REQUALIFIED = 15, GUILD_DISCOVERY_REQUALIFIED = 15,
ENCRYPTED = 16,
REPLY = 19, REPLY = 19,
APPLICATION_COMMAND = 20, APPLICATION_COMMAND = 20,
ROUTE_ADDED = 41, // custom message routing: new route affecting that channel
ROUTE_DISABLED = 42, // custom message routing: given route no longer affecting that channel
ENCRYPTION = 50,
CUSTOM_START = 63,
UNHANDLED = 255
} }
@Entity("messages") @Entity("messages")
@ -84,7 +90,7 @@ export class Message extends BaseClass {
@RelationId((message: Message) => message.member) @RelationId((message: Message) => message.member)
member_id: string; member_id: string;
@JoinColumn({ name: "author_id", referencedColumnName: "id" }) @JoinColumn({ name: "member_id", referencedColumnName: "id" })
@ManyToOne(() => User, { @ManyToOne(() => User, {
onDelete: "CASCADE", onDelete: "CASCADE",
}) })
@ -203,6 +209,7 @@ export interface MessageComponent {
} }
export enum MessageComponentType { export enum MessageComponentType {
Script = 0, // self command script
ActionRow = 1, ActionRow = 1,
Button = 2, Button = 2,
} }

View File

@ -49,6 +49,7 @@ export class ReadState extends BaseClass {
@Column({ nullable: true }) @Column({ nullable: true })
mention_count: number; mention_count: number;
@Column({ nullable: true }) // @Column({ nullable: true })
// TODO: derive this from (last_message_id=notifications_cursor=public_ack)=true
manual: boolean; manual: boolean;
} }

View File

@ -60,7 +60,7 @@ export class User extends BaseClass {
username: string; // username max length 32, min 2 (should be configurable) username: string; // username max length 32, min 2 (should be configurable)
@Column() @Column()
discriminator: string; // #0001 4 digit long string from #0001 - #9999 discriminator: string; // opaque string: 4 digits on discord.com
setDiscriminator(val: string) { setDiscriminator(val: string) {
const number = Number(val); const number = Number(val);
@ -88,10 +88,10 @@ export class User extends BaseClass {
mobile: boolean; // if the user has mobile app installed mobile: boolean; // if the user has mobile app installed
@Column() @Column()
premium: boolean; // if user bought nitro premium: boolean; // if user bought individual premium
@Column() @Column()
premium_type: number; // nitro level premium_type: number; // individual premium level
@Column() @Column()
bot: boolean; // if user is bot bot: boolean; // if user is bot
@ -100,10 +100,10 @@ export class User extends BaseClass {
bio: string; // short description of the user (max 190 chars -> should be configurable) bio: string; // short description of the user (max 190 chars -> should be configurable)
@Column() @Column()
system: boolean; // shouldn't be used, the api sents this field type true, if the generated message comes from a system generated author system: boolean; // shouldn't be used, the api sends this field type true, if the generated message comes from a system generated author
@Column({ select: false }) @Column({ select: false })
nsfw_allowed: boolean; // if the user is older than 18 (resp. Config) nsfw_allowed: boolean; // if the user can do age-restricted actions (NSFW channels/guilds/commands)
@Column({ select: false }) @Column({ select: false })
mfa_enabled: boolean; // if multi factor authentication is enabled mfa_enabled: boolean; // if multi factor authentication is enabled
@ -132,7 +132,7 @@ export class User extends BaseClass {
@Column() @Column()
public_flags: number; public_flags: number;
@Column() @Column({ type: "bigint" })
rights: string; // Rights rights: string; // Rights
@OneToMany(() => Session, (session: Session) => session.user) @OneToMany(() => Session, (session: Session) => session.user)
@ -164,6 +164,9 @@ export class User extends BaseClass {
@Column({ type: "simple-json", select: false }) @Column({ type: "simple-json", select: false })
settings: UserSettings; settings: UserSettings;
@Column({ type: "simple-json" })
notes: { [key: string]: string }; //key is ID of user
toPublicUser() { toPublicUser() {
const user: any = {}; const user: any = {};
PublicUserProjection.forEach((x) => { PublicUserProjection.forEach((x) => {
@ -271,6 +274,7 @@ export class User extends BaseClass {
}, },
settings: { ...defaultSettings, locale: language }, settings: { ...defaultSettings, locale: language },
fingerprints: [], fingerprints: [],
notes: {},
}); });
await user.save(); await user.save();

View File

@ -623,6 +623,7 @@ export type EVENT =
| "PRESENCE_UPDATE" | "PRESENCE_UPDATE"
| "TYPING_START" | "TYPING_START"
| "USER_UPDATE" | "USER_UPDATE"
| "USER_NOTE_UPDATE"
| "WEBHOOKS_UPDATE" | "WEBHOOKS_UPDATE"
| "INTERACTION_CREATE" | "INTERACTION_CREATE"
| "VOICE_STATE_UPDATE" | "VOICE_STATE_UPDATE"

View File

@ -13,7 +13,12 @@ export function adjustEmail(email?: string): string | undefined {
// TODO: check accounts with uncommon email domains // TODO: check accounts with uncommon email domains
if (domain === "gmail.com" || domain === "googlemail.com") { if (domain === "gmail.com" || domain === "googlemail.com") {
// replace .dots and +alternatives -> Gmail Dot Trick https://support.google.com/mail/answer/7436150 and https://generator.email/blog/gmail-generator // replace .dots and +alternatives -> Gmail Dot Trick https://support.google.com/mail/answer/7436150 and https://generator.email/blog/gmail-generator
return user.replace(/[.]|(\+.*)/g, "") + "@gmail.com"; let v = user.replace(/[.]|(\+.*)/g, "") + "@gmail.com";
}
if (domain === "google.com") {
// replace .dots and +alternatives -> Google Staff GMail Dot Trick
let v = user.replace(/[.]|(\+.*)/g, "") + "@google.com";
} }
return email; return email;

View File

@ -2,20 +2,31 @@ import { BitField } from "./BitField";
export class Intents extends BitField { export class Intents extends BitField {
static FLAGS = { static FLAGS = {
GUILDS: BigInt(1) << BigInt(0), GUILDS: BigInt(1) << BigInt(0), // guilds and guild merge-split events affecting the user
GUILD_MEMBERS: BigInt(1) << BigInt(1), GUILD_MEMBERS: BigInt(1) << BigInt(1), // memberships
GUILD_BANS: BigInt(1) << BigInt(2), GUILD_BANS: BigInt(1) << BigInt(2), // bans and ban lists
GUILD_EMOJIS: BigInt(1) << BigInt(3), GUILD_EMOJIS: BigInt(1) << BigInt(3), // custom emojis
GUILD_INTEGRATIONS: BigInt(1) << BigInt(4), GUILD_INTEGRATIONS: BigInt(1) << BigInt(4), // applications
GUILD_WEBHOOKS: BigInt(1) << BigInt(5), GUILD_WEBHOOKS: BigInt(1) << BigInt(5), // webhooks
GUILD_INVITES: BigInt(1) << BigInt(6), GUILD_INVITES: BigInt(1) << BigInt(6), // mass invites (no user can receive user specific invites of another user)
GUILD_VOICE_STATES: BigInt(1) << BigInt(7), GUILD_VOICE_STATES: BigInt(1) << BigInt(7), // voice updates
GUILD_PRESENCES: BigInt(1) << BigInt(8), GUILD_PRESENCES: BigInt(1) << BigInt(8), // presence updates
GUILD_MESSAGES: BigInt(1) << BigInt(9), GUILD_MESSAGES_METADATA: BigInt(1) << BigInt(9), // guild message metadata
GUILD_MESSAGE_REACTIONS: BigInt(1) << BigInt(10), GUILD_MESSAGE_REACTIONS: BigInt(1) << BigInt(10), // guild message reactions
GUILD_MESSAGE_TYPING: BigInt(1) << BigInt(11), GUILD_MESSAGE_TYPING: BigInt(1) << BigInt(11), // guild channel typing notifications
DIRECT_MESSAGES: BigInt(1) << BigInt(12), DIRECT_MESSAGES: BigInt(1) << BigInt(12), // DM or orphan channels
DIRECT_MESSAGE_REACTIONS: BigInt(1) << BigInt(13), DIRECT_MESSAGE_REACTIONS: BigInt(1) << BigInt(13), // DM or orphan channel message reactions
DIRECT_MESSAGE_TYPING: BigInt(1) << BigInt(14), DIRECT_MESSAGE_TYPING: BigInt(1) << BigInt(14), // DM typing notifications
GUILD_MESSAGES_CONTENT: BigInt(1) << BigInt(15), // guild message content
LIVE_MESSAGE_COMPOSITION: BigInt(1) << BigInt(32), // allow composing messages using the gateway
GUILD_ROUTES: BigInt(1) << BigInt(41), // message routes affecting the guild
DIRECT_MESSAGES_THREADS: BigInt(1) << BigInt(42), // direct message threads
JUMBO_EVENTS: BigInt(1) << BigInt(43), // jumbo events (size limits to be defined later)
LOBBIES: BigInt(1) << BigInt(44), // lobbies
INSTANCE_ROUTES: BigInt(1) << BigInt(60), // all message route changes
INSTANCE_GUILD_CHANGES: BigInt(1) << BigInt(61), // all guild create, guild object patch, split, merge and delete events
INSTANCE_POLICY_UPDATES: BigInt(1) << BigInt(62), // all instance policy updates
INSTANCE_USER_UPDATES: BigInt(1) << BigInt(63) // all instance user updates
}; };
} }

View File

@ -1,6 +1,7 @@
import { BitField } from "./BitField"; import { BitField } from "./BitField";
import "missing-native-js-functions"; import "missing-native-js-functions";
import { BitFieldResolvable, BitFlag } from "./BitField"; import { BitFieldResolvable, BitFlag } from "./BitField";
import { User } from "../entities";
var HTTPError: any; var HTTPError: any;
@ -85,6 +86,15 @@ export class Rights extends BitField {
// @ts-ignore // @ts-ignore
throw new HTTPError(`You are missing the following rights ${permission}`, 403); throw new HTTPError(`You are missing the following rights ${permission}`, 403);
} }
} }
const ALL_RIGHTS = Object.values(Rights.FLAGS).reduce((total, val) => total | val, BigInt(0)); const ALL_RIGHTS = Object.values(Rights.FLAGS).reduce((total, val) => total | val, BigInt(0));
export async function getRights( user_id: string
/**, opts: {
in_behalf?: (keyof User)[];
} = {} **/) {
let user = await User.findOneOrFail({ where: { id: user_id } });
return new Rights(user.rights);
}