mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-05 18:32:33 +01:00
Start of custom login and discord oauth flow
This commit is contained in:
parent
d5b2c19160
commit
c9f34df53f
@ -23,7 +23,12 @@
|
||||
},
|
||||
{
|
||||
"path": "webrtc"
|
||||
},
|
||||
{
|
||||
"path": "slowcord"
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
"settings": {
|
||||
"typescript.tsdk": "util\\node_modules\\typescript\\lib"
|
||||
}
|
||||
}
|
||||
|
5
slowcord/.env.template
Normal file
5
slowcord/.env.template
Normal file
@ -0,0 +1,5 @@
|
||||
DATABASE=../bundle/database.db
|
||||
PORT=3010
|
||||
DISCORD_CLIENT_ID=
|
||||
DISCORD_SECRET=
|
||||
DISCORD_REDIRECT=
|
14
slowcord/.vscode/launch.json
vendored
Normal file
14
slowcord/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Program",
|
||||
"program": "${workspaceFolder}/build/index.js",
|
||||
"request": "launch",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node",
|
||||
"preLaunchTask": "tsc: build - tsconfig.json"
|
||||
}
|
||||
]
|
||||
}
|
13
slowcord/.vscode/tasks.json
vendored
Normal file
13
slowcord/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"group": "build",
|
||||
"problemMatcher": [],
|
||||
"label": "npm: build",
|
||||
"detail": "tsc -b"
|
||||
}
|
||||
]
|
||||
}
|
1
slowcord/README.md
Normal file
1
slowcord/README.md
Normal file
@ -0,0 +1 @@
|
||||
Additional resources/services for [Slowcord](slowcord.maddy.k.vu)
|
102
slowcord/build/index.js
Normal file
102
slowcord/build/index.js
Normal file
@ -0,0 +1,102 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var _a;
|
||||
import "dotenv/config";
|
||||
import express from "express";
|
||||
import cookieParser from "cookie-parser";
|
||||
import { initDatabase, generateToken, User, Config } from "@fosscord/util";
|
||||
import path from "path";
|
||||
import fetch from "node-fetch";
|
||||
const app = express();
|
||||
app.use(cookieParser());
|
||||
const port = process.env.PORT;
|
||||
class Discord {
|
||||
}
|
||||
_a = Discord;
|
||||
Discord.getAccessToken = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { code } = req.query;
|
||||
const body = new URLSearchParams(Object.entries({
|
||||
client_id: process.env.DISCORD_CLIENT_ID,
|
||||
client_secret: process.env.DISCORD_SECRET,
|
||||
redirect_uri: process.env.DISCORD_REDIRECT,
|
||||
code: code,
|
||||
grant_type: "authorization_code",
|
||||
})).toString();
|
||||
const resp = yield fetch("https://discord.com/api/oauth2/token", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: body
|
||||
});
|
||||
const json = yield resp.json();
|
||||
if (json.error)
|
||||
return null;
|
||||
return {
|
||||
access_token: json.access_token,
|
||||
token_type: json.token_type,
|
||||
expires_in: json.expires_in,
|
||||
refresh_token: json.refresh_token,
|
||||
scope: json.scope,
|
||||
};
|
||||
});
|
||||
Discord.getUserDetails = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const resp = yield fetch("https://discord.com/api/users/@me", {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`,
|
||||
}
|
||||
});
|
||||
const json = yield resp.json();
|
||||
if (!json.username || !json.email)
|
||||
return null; // eh, deal with bad code later
|
||||
return {
|
||||
email: json.email,
|
||||
username: json.username,
|
||||
};
|
||||
});
|
||||
const handlers = {
|
||||
"discord": Discord,
|
||||
};
|
||||
app.get("/oauth/:type", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { type } = req.params;
|
||||
if (!type)
|
||||
return res.sendStatus(400);
|
||||
const handler = handlers[type];
|
||||
if (!handler)
|
||||
return res.sendStatus(400);
|
||||
const data = yield handler.getAccessToken(req, res);
|
||||
if (!data)
|
||||
return res.sendStatus(500);
|
||||
const details = yield handler.getUserDetails(data.access_token);
|
||||
if (!details)
|
||||
return res.sendStatus(500);
|
||||
let user = yield User.findOne({ where: { email: details.email } });
|
||||
if (!user) {
|
||||
user = yield User.register({
|
||||
email: details.email,
|
||||
username: details.username,
|
||||
req
|
||||
});
|
||||
}
|
||||
const token = yield generateToken(user.id);
|
||||
res.cookie("token", token);
|
||||
res.sendFile(path.join(__dirname, "../public/login.html"));
|
||||
}));
|
||||
app.get("*", (req, res) => {
|
||||
res.sendFile(path.join(__dirname, "../public/login.html"));
|
||||
});
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
yield initDatabase();
|
||||
yield Config.init();
|
||||
app.listen(port, () => {
|
||||
console.log(`Listening on port ${port}`);
|
||||
});
|
||||
}))();
|
||||
//# sourceMappingURL=index.js.map
|
1
slowcord/build/index.js.map
Normal file
1
slowcord/build/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC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E,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnE,IAAI,CAAC,IAAI,EAAE;QACV,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC;YAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,GAAG;SACH,CAAC,CAAC;KACH;IAED,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAE3C,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAE3B,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAA,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACzB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AAEH,CAAC,GAAS,EAAE;IACX,MAAM,YAAY,EAAE,CAAC;IACrB,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IAEpB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QACrB,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAA,CAAC,EAAE,CAAC"}
|
1435
slowcord/package-lock.json
generated
Normal file
1435
slowcord/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
slowcord/package.json
Normal file
33
slowcord/package.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "slowcord",
|
||||
"version": "1.0.0",
|
||||
"description": "Slowcord additional services",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"run": "node build/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/maddyunderstars/fosscord-server.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "AGPL-3.0-only",
|
||||
"bugs": {
|
||||
"url": "https://github.com/maddyunderstars/fosscord-server/issues"
|
||||
},
|
||||
"homepage": "https://github.com/maddyunderstars/fosscord-server#readme",
|
||||
"dependencies": {
|
||||
"@fosscord/util": "file:../util",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"node-fetch": "^3.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cookie-parser": "^1.4.3",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/node": "^18.0.0"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
65
slowcord/public/login.html
Normal file
65
slowcord/public/login.html
Normal file
@ -0,0 +1,65 @@
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Slowcord</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="content">
|
||||
<form action="javascript:void(0);">
|
||||
<input type="email" name="email" />
|
||||
<input type="password" name="password" />
|
||||
<input type="submit" />
|
||||
|
||||
<a
|
||||
href="https://discord.com/api/oauth2/authorize?client_id=990585211966324806&redirect_uri=https%3A%2F%2Fslowcord.maddy.k.vu%2Foauth%2Fdiscord&response_type=code&scope=identify%20email">
|
||||
Login with Discord
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
/* https://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript */
|
||||
const getCookieValue = (name) => (
|
||||
document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''
|
||||
);
|
||||
|
||||
let token = getCookieValue("token");
|
||||
if (token) {
|
||||
document.cookie = ""; // don't care
|
||||
window.localStorage.setItem("token", json.token);
|
||||
window.location.href = "/app";
|
||||
}
|
||||
|
||||
token = window.localStorage.getItem("token");
|
||||
if (token) window.location.href = "/app";
|
||||
|
||||
document.forms[0].addEventListener("submit", async (e) => {
|
||||
const data = new FormData(e.target);
|
||||
const email = data.get("email");
|
||||
const password = data.get("password");
|
||||
|
||||
const response = await fetch("/api/v9/auth/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
login: email,
|
||||
password: password,
|
||||
})
|
||||
});
|
||||
|
||||
const json = response.json();
|
||||
if (json.token) {
|
||||
window.localStorage.setItem("token", json.token);
|
||||
window.location.href = "/app";
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
104
slowcord/src/index.ts
Normal file
104
slowcord/src/index.ts
Normal file
@ -0,0 +1,104 @@
|
||||
import "dotenv/config";
|
||||
import express, { Request, Response } from "express";
|
||||
import cookieParser from "cookie-parser";
|
||||
import { initDatabase, generateToken, User, Config } from "@fosscord/util";
|
||||
import path from "path";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
const app = express();
|
||||
app.use(cookieParser());
|
||||
const port = process.env.PORT;
|
||||
|
||||
class Discord {
|
||||
static getAccessToken = async (req: Request, res: Response) => {
|
||||
const { code } = req.query;
|
||||
|
||||
const body = new URLSearchParams(Object.entries({
|
||||
client_id: process.env.DISCORD_CLIENT_ID as string,
|
||||
client_secret: process.env.DISCORD_SECRET as string,
|
||||
redirect_uri: process.env.DISCORD_REDIRECT as string,
|
||||
code: code as string,
|
||||
grant_type: "authorization_code",
|
||||
})).toString();
|
||||
|
||||
const resp = await fetch("https://discord.com/api/oauth2/token", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: body
|
||||
});
|
||||
|
||||
const json = await resp.json() as any;
|
||||
if (json.error) return null;
|
||||
|
||||
return {
|
||||
access_token: json.access_token,
|
||||
token_type: json.token_type,
|
||||
expires_in: json.expires_in,
|
||||
refresh_token: json.refresh_token,
|
||||
scope: json.scope,
|
||||
};
|
||||
};
|
||||
|
||||
static getUserDetails = async (token: string) => {
|
||||
const resp = await fetch("https://discord.com/api/users/@me", {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`,
|
||||
}
|
||||
});
|
||||
|
||||
const json = await resp.json() as any;
|
||||
if (!json.username || !json.email) return null; // eh, deal with bad code later
|
||||
|
||||
return {
|
||||
email: json.email,
|
||||
username: json.username,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
const handlers: { [key: string]: any; } = {
|
||||
"discord": Discord,
|
||||
};
|
||||
|
||||
app.get("/oauth/:type", async (req, res) => {
|
||||
const { type } = req.params;
|
||||
if (!type) return res.sendStatus(400);
|
||||
const handler = handlers[type];
|
||||
if (!handler) return res.sendStatus(400);
|
||||
|
||||
const data = await handler.getAccessToken(req, res);
|
||||
if (!data) return res.sendStatus(500);
|
||||
|
||||
const details = await handler.getUserDetails(data.access_token);
|
||||
if (!details) return res.sendStatus(500);
|
||||
|
||||
let user = await User.findOne({ where: { email: details.email } });
|
||||
if (!user) {
|
||||
user = await User.register({
|
||||
email: details.email,
|
||||
username: details.username,
|
||||
req
|
||||
});
|
||||
}
|
||||
|
||||
const token = await generateToken(user.id);
|
||||
|
||||
res.cookie("token", token);
|
||||
|
||||
res.sendFile(path.join(__dirname, "../public/login.html"));
|
||||
});
|
||||
|
||||
app.get("*", (req, res) => {
|
||||
res.sendFile(path.join(__dirname, "../public/login.html"));
|
||||
});
|
||||
|
||||
(async () => {
|
||||
await initDatabase();
|
||||
await Config.init();
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Listening on port ${port}`);
|
||||
});
|
||||
})();
|
99
slowcord/tsconfig.json
Normal file
99
slowcord/tsconfig.json
Normal file
@ -0,0 +1,99 @@
|
||||
{
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
/* Projects */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
/* Language and Environment */
|
||||
"target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"lib": ["ES2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
||||
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
/* Modules */
|
||||
"module": "ES2020", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
||||
"types": ["node"], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files */
|
||||
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./build", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
||||
"strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
||||
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
@ -245,6 +245,7 @@ export class Channel extends BaseClass {
|
||||
|
||||
static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) {
|
||||
recipients = recipients.unique().filter((x) => x !== creator_user_id);
|
||||
//@ts-ignore some typeorm typescript issue
|
||||
const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })) });
|
||||
|
||||
// TODO: check config for max number of recipients
|
||||
|
@ -62,6 +62,7 @@ export async function listenEvent(event: string, callback: (event: EventOpts) =>
|
||||
msg.type === "event" && msg.id === event && callback({ ...msg.event, cancel });
|
||||
};
|
||||
|
||||
//@ts-ignore apparently theres no function addListener with this signature
|
||||
process.addListener("message", listener);
|
||||
process.setMaxListeners(process.getMaxListeners() + 1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user