diff options
Diffstat (limited to 'src-slowcord')
-rw-r--r-- | src-slowcord/README.md | 2 | ||||
-rw-r--r-- | src-slowcord/bot/.vscode/launch.json | 7 | ||||
-rw-r--r-- | src-slowcord/bot/.vscode/tasks.json | 2 | ||||
-rw-r--r-- | src-slowcord/bot/src/Bot.ts | 16 | ||||
-rw-r--r-- | src-slowcord/bot/src/commands/index.ts | 13 | ||||
-rw-r--r-- | src-slowcord/bot/src/commands/instance.ts | 50 | ||||
-rw-r--r-- | src-slowcord/bot/src/index.ts | 4 | ||||
-rw-r--r-- | src-slowcord/bot/tsconfig.json | 184 | ||||
-rw-r--r-- | src-slowcord/login/public/css/index.css | 9 | ||||
-rw-r--r-- | src-slowcord/login/public/js/handler.js | 13 | ||||
-rw-r--r-- | src-slowcord/login/public/login.html | 212 | ||||
-rw-r--r-- | src-slowcord/login/public/register.html | 152 | ||||
-rw-r--r-- | src-slowcord/login/src/index.ts | 76 | ||||
-rw-r--r-- | src-slowcord/login/tsconfig.json | 40 | ||||
-rw-r--r-- | src-slowcord/rules.md | 16 | ||||
-rw-r--r-- | src-slowcord/status/src/gateway.ts | 51 | ||||
-rw-r--r-- | src-slowcord/status/src/index.ts | 140 | ||||
-rw-r--r-- | src-slowcord/status/tsconfig.json | 38 |
18 files changed, 572 insertions, 453 deletions
diff --git a/src-slowcord/README.md b/src-slowcord/README.md index 892b5763..ac42117a 100644 --- a/src-slowcord/README.md +++ b/src-slowcord/README.md @@ -1 +1 @@ -Additional resources/services for [Slowcord](https://slowcord.maddy.k.vu/login) \ No newline at end of file +Additional resources/services for [Slowcord](https://slowcord.maddy.k.vu/login) diff --git a/src-slowcord/bot/.vscode/launch.json b/src-slowcord/bot/.vscode/launch.json index 92765e22..c1c765a8 100644 --- a/src-slowcord/bot/.vscode/launch.json +++ b/src-slowcord/bot/.vscode/launch.json @@ -4,12 +4,9 @@ "name": "Slowcord Bot", "program": "${workspaceFolder}/build/index.js", "request": "launch", - "skipFiles": [ - "<node_internals>/**" - ], + "skipFiles": ["<node_internals>/**"], "type": "node", "preLaunchTask": "npm: build" } - ] -} \ No newline at end of file +} diff --git a/src-slowcord/bot/.vscode/tasks.json b/src-slowcord/bot/.vscode/tasks.json index 356126d8..be345ecd 100644 --- a/src-slowcord/bot/.vscode/tasks.json +++ b/src-slowcord/bot/.vscode/tasks.json @@ -10,4 +10,4 @@ "detail": "tsc -b" } ] -} \ No newline at end of file +} diff --git a/src-slowcord/bot/src/Bot.ts b/src-slowcord/bot/src/Bot.ts index 45938846..cf3ff09f 100644 --- a/src-slowcord/bot/src/Bot.ts +++ b/src-slowcord/bot/src/Bot.ts @@ -1,11 +1,11 @@ import { Message } from "discord.js"; -import { Client } from "fosscord-gopnik/build/lib"; // huh? oh well. some bugs in my lib Ig +import { Client } from "fosscord-gopnik/build/lib"; // huh? oh well. some bugs in my lib Ig import { Command, getCommands } from "./commands/index.js"; export default class Bot { client: Client; - commands: { [key: string]: Command; } = {}; + commands: { [key: string]: Command } = {}; constructor(client: Client) { this.client = client; @@ -17,10 +17,12 @@ export default class Bot { console.log(`Logged in as ${this.client.user!.tag}`); this.client.user!.setPresence({ - activities: [{ - name: "EVERYTHING", - type: "WATCHING", - }] + activities: [ + { + name: "EVERYTHING", + type: "WATCHING", + }, + ], }); }; @@ -45,4 +47,4 @@ export default class Bot { args: args, }); }; -} \ No newline at end of file +} diff --git a/src-slowcord/bot/src/commands/index.ts b/src-slowcord/bot/src/commands/index.ts index d3b39e0f..0130b2bc 100644 --- a/src-slowcord/bot/src/commands/index.ts +++ b/src-slowcord/bot/src/commands/index.ts @@ -2,11 +2,11 @@ import { Message, GuildMember, Guild, User } from "discord.js"; import fs from "fs"; export type CommandContext = { - user: User, - guild: Guild | null, - member: GuildMember | null, - message: Message, - args: string[], + user: User; + guild: Guild | null; + member: GuildMember | null; + message: Message; + args: string[]; }; export type Command = { @@ -19,8 +19,7 @@ const walk = async (path: string) => { const out = []; for (var file of files) { if (fs.statSync(`${path}/${file}`).isDirectory()) continue; - if (file.indexOf("index") !== -1) - continue; + if (file.indexOf("index") !== -1) continue; if (file.indexOf(".js") !== file.length - 3) continue; var imported = (await import(`./${file}`)).default; out.push(imported); diff --git a/src-slowcord/bot/src/commands/instance.ts b/src-slowcord/bot/src/commands/instance.ts index ac0c9b2d..170d8f76 100644 --- a/src-slowcord/bot/src/commands/instance.ts +++ b/src-slowcord/bot/src/commands/instance.ts @@ -1,7 +1,7 @@ import { Command } from "./index.js"; import { User, Guild, Message } from "@fosscord/util"; -const cache: { [key: string]: number; } = { +const cache: { [key: string]: number } = { users: 0, guilds: 0, messages: 0, @@ -11,7 +11,10 @@ const cache: { [key: string]: number; } = { export default { name: "instance", exec: async ({ message }) => { - if (Date.now() > cache.lastChecked + parseInt(process.env.CACHE_TTL as string)) { + if ( + Date.now() > + cache.lastChecked + parseInt(process.env.CACHE_TTL as string) + ) { cache.users = await User.count(); cache.guilds = await Guild.count(); cache.messages = await Message.count(); @@ -19,18 +22,35 @@ export default { } return message.reply({ - embeds: [{ - title: "Instance Stats", - description: "For more indepth information, check out https://grafana.understars.dev", - footer: { - text: `Last checked: ${Math.floor((Date.now() - cache.lastChecked) / (1000 * 60))} minutes ago`, + embeds: [ + { + title: "Instance Stats", + description: + "For more indepth information, check out https://grafana.understars.dev", + footer: { + text: `Last checked: ${Math.floor( + (Date.now() - cache.lastChecked) / (1000 * 60), + )} minutes ago`, + }, + fields: [ + { + inline: true, + name: "Total Users", + value: cache.users.toString(), + }, + { + inline: true, + name: "Total Guilds", + value: cache.guilds.toString(), + }, + { + inline: true, + name: "Total Messages", + value: cache.messages.toString(), + }, + ], }, - fields: [ - { inline: true, name: "Total Users", value: cache.users.toString() }, - { inline: true, name: "Total Guilds", value: cache.guilds.toString() }, - { inline: true, name: "Total Messages", value: cache.messages.toString() }, - ] - }] + ], }); - } -} as Command; \ No newline at end of file + }, +} as Command; diff --git a/src-slowcord/bot/src/index.ts b/src-slowcord/bot/src/index.ts index 253f759c..fa97313f 100644 --- a/src-slowcord/bot/src/index.ts +++ b/src-slowcord/bot/src/index.ts @@ -1,6 +1,6 @@ import "dotenv/config"; import Fosscord from "fosscord-gopnik"; -import Bot from "./Bot.js"; // huh? +import Bot from "./Bot.js"; // huh? import { initDatabase } from "fosscord-server/src/util"; const client = new Fosscord.Client({ @@ -21,4 +21,4 @@ client.on("messageCreate", bot.onMessageCreate); (async () => { await initDatabase(); await client.login(process.env.TOKEN); -})(); \ No newline at end of file +})(); diff --git a/src-slowcord/bot/tsconfig.json b/src-slowcord/bot/tsconfig.json index 05bfc5c7..f055681a 100644 --- a/src-slowcord/bot/tsconfig.json +++ b/src-slowcord/bot/tsconfig.json @@ -1,101 +1,103 @@ { - "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ + "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. */ + /* 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. */ + /* 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": "CommonJS", /* 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": [], /* 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. */ + /* Modules */ + "module": "CommonJS" /* 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": [], /* 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`. */ + /* 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. */ + /* 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. */ + /* 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. */ + /* 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. */ - } + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } } diff --git a/src-slowcord/login/public/css/index.css b/src-slowcord/login/public/css/index.css index d4f5a4b4..cf294ccb 100644 --- a/src-slowcord/login/public/css/index.css +++ b/src-slowcord/login/public/css/index.css @@ -4,13 +4,13 @@ html { --background-primary: rgb(22, 23, 25); --background-secondary: rgb(15, 16, 18); --foreground-primary: rgb(200, 200, 200); - --background-login-discord: #5865F2; + --background-login-discord: #5865f2; background: url("https://slowcord.maddy.k.vu/assets/background.png"); background-size: 100% 100%; background-repeat: no-repeat; - font-family: 'Montserrat', sans-serif; + font-family: "Montserrat", sans-serif; color: var(--foreground-primary); } @@ -55,7 +55,8 @@ html { text-align: center; } -.header-subtext a, .header-subtext p { +.header-subtext a, +.header-subtext p { display: inline-block; margin: 0 10px 0 10px; } @@ -109,4 +110,4 @@ label { display: flex; justify-content: center; margin-top: 10px; -} \ No newline at end of file +} diff --git a/src-slowcord/login/public/js/handler.js b/src-slowcord/login/public/js/handler.js index 68a656b4..2d7b164b 100644 --- a/src-slowcord/login/public/js/handler.js +++ b/src-slowcord/login/public/js/handler.js @@ -29,13 +29,12 @@ const handleSubmit = async (path, body) => { } // Very fun error message here lol - const error = - json.errors - ? Object.values(json.errors)[0]._errors[0].message - : ( - json.captcha_key ? "Captcha required" : json.message - ); + const error = json.errors + ? Object.values(json.errors)[0]._errors[0].message + : json.captcha_key + ? "Captcha required" + : json.message; failureMessage.innerHTML = error; failureMessage.style.display = "block"; -}; \ No newline at end of file +}; diff --git a/src-slowcord/login/public/login.html b/src-slowcord/login/public/login.html index 8cecd20b..fa367b70 100644 --- a/src-slowcord/login/public/login.html +++ b/src-slowcord/login/public/login.html @@ -1,103 +1,127 @@ <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> - - <link rel="preconnect" href="https://fonts.googleapis.com"> - <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> - <link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet"> - - <link rel="stylesheet" href="./css/index.css"> - <script src="js/handler.js"></script> -</head> - -<body> - <div class="content"> - <div class="login"> - <div class="header"> - <h1>Welcome to Slowcord</h1> - <div class="header-subtext"> - <p>Glad to see you <3 </p> - <a href="/register">Wait, I'm new!</a> + <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> + + <link rel="preconnect" href="https://fonts.googleapis.com" /> + <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> + <link + href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" + rel="stylesheet" + /> + + <link rel="stylesheet" href="./css/index.css" /> + <script src="js/handler.js"></script> + </head> + + <body> + <div class="content"> + <div class="login"> + <div class="header"> + <h1>Welcome to Slowcord</h1> + <div class="header-subtext"> + <p>Glad to see you <3</p> + <a href="/register">Wait, I'm new!</a> + </div> + + <p id="failure">Login failed</p> </div> - <p id="failure">Login failed</p> + <form action="javascript:void(0);" name="login"> + <label for="email">Email</label> + <input type="email" name="email" /> + + <label for="password">Password</label> + <input type="password" name="password" /> + + <input type="submit" value="Login" /> + + <a + id="loginDiscord" + class="oauth" + href="https://discord.com/api/oauth2/authorize?client_id=991688571415175198&redirect_uri=https%3A%2F%2Fslowcord.maddy.k.vu%2Foauth%2Fdiscord&response_type=code&scope=identify%20email" + > + Login with Discord + </a> + + <div + class="h-captcha" + data-sitekey="fa3163ea-79a7-4b7b-b752-b58c545906c8" + data-theme="dark" + ></div> + <script + src="https://js.hcaptcha.com/1/api.js" + async + defer + ></script> + </form> + + <form + action="javascript:void(0);" + name="2fa" + style="display: none" + > + <label for="code">2FA Code</label> + <input type="number" name="code" /> + + <input type="hidden" name="ticket" /> + + <input type="submit" value="Login" /> + </form> </div> - - <form action="javascript:void(0);" name="login"> - <label for="email">Email</label> - <input type="email" name="email" /> - - <label for="password">Password</label> - <input type="password" name="password" /> - - <input type="submit" value="Login" /> - - <a id="loginDiscord" class="oauth" - href="https://discord.com/api/oauth2/authorize?client_id=991688571415175198&redirect_uri=https%3A%2F%2Fslowcord.maddy.k.vu%2Foauth%2Fdiscord&response_type=code&scope=identify%20email"> - Login with Discord - </a> - - <div class="h-captcha" data-sitekey="fa3163ea-79a7-4b7b-b752-b58c545906c8" data-theme="dark"></div> - <script src="https://js.hcaptcha.com/1/api.js" async defer></script> - </form> - - <form action="javascript:void(0);" name="2fa" style="display: none"> - <label for="code">2FA Code</label> - <input type="number" name="code" /> - - <input type="hidden" name="ticket" /> - - <input type="submit" value="Login"/> - </form> </div> - </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.trim().length) { - /* https://stackoverflow.com/a/27374365 */ - // why is clearing cookies so weird? wtf - document.cookie.split(";").forEach(function (c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); }); - window.localStorage.setItem("token", `"${token}"`); - window.location.href = "/app"; - } - - token = window.localStorage.getItem("token"); - if (token) window.location.href = "/app"; - - document.forms["login"].addEventListener("submit", async (e) => { - const data = new FormData(e.target); - const email = data.get("email"); - const password = data.get("password"); - const hcaptcha = data.get("h-captcha-response"); - - await handleSubmit("/api/v9/auth/login", { - login: email, - password: password, - captcha_key: hcaptcha, + + <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.trim().length) { + /* https://stackoverflow.com/a/27374365 */ + // why is clearing cookies so weird? wtf + document.cookie.split(";").forEach(function (c) { + document.cookie = c + .replace(/^ +/, "") + .replace( + /=.*/, + "=;expires=" + new Date().toUTCString() + ";path=/", + ); + }); + window.localStorage.setItem("token", `"${token}"`); + window.location.href = "/app"; + } + + token = window.localStorage.getItem("token"); + if (token) window.location.href = "/app"; + + document.forms["login"].addEventListener("submit", async (e) => { + const data = new FormData(e.target); + const email = data.get("email"); + const password = data.get("password"); + const hcaptcha = data.get("h-captcha-response"); + + await handleSubmit("/api/v9/auth/login", { + login: email, + password: password, + captcha_key: hcaptcha, + }); }); - }) - document.forms["2fa"].addEventListener("submit", async (e) => { - const data = new FormData(e.target); - const code = data.get("code"); - const ticket = data.get("ticket"); + document.forms["2fa"].addEventListener("submit", async (e) => { + const data = new FormData(e.target); + const code = data.get("code"); + const ticket = data.get("ticket"); - await handleSubmit("/api/v9/auth/mfa/totp", { - code: code, - ticket: ticket, + await handleSubmit("/api/v9/auth/mfa/totp", { + code: code, + ticket: ticket, + }); }); - }) - </script> -</body> - -</html> \ No newline at end of file + </script> + </body> +</html> diff --git a/src-slowcord/login/public/register.html b/src-slowcord/login/public/register.html index 40eecdbe..30b560a4 100644 --- a/src-slowcord/login/public/register.html +++ b/src-slowcord/login/public/register.html @@ -1,78 +1,88 @@ <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> - - <link rel="preconnect" href="https://fonts.googleapis.com"> - <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> - <link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet"> - - <link rel="stylesheet" href="./css/index.css"> - <script src="js/handler.js"></script> -</head> - -<body> - <div class="content"> - <div class="login"> - <div class="header"> - <h1>Welcome to Slowcord</h1> - <div class="header-subtext"> - <p>You're new?</p> - <a href="/login">Actually, I'm not!</a> + <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> + + <link rel="preconnect" href="https://fonts.googleapis.com" /> + <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> + <link + href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" + rel="stylesheet" + /> + + <link rel="stylesheet" href="./css/index.css" /> + <script src="js/handler.js"></script> + </head> + + <body> + <div class="content"> + <div class="login"> + <div class="header"> + <h1>Welcome to Slowcord</h1> + <div class="header-subtext"> + <p>You're new?</p> + <a href="/login">Actually, I'm not!</a> + </div> + + <p id="failure">Register failed</p> </div> - <p id="failure">Register failed</p> + <form action="javascript:void(0);"> + <label for="email">Email</label> + <input type="email" name="email" /> + + <label for="username">Username</label> + <input type="username" name="username" /> + + <label for="password">Password</label> + <input type="password" name="password" /> + + <label for="dob">Date of Birth</label> + <input type="date" name="dob" /> + + <input type="submit" value="Register" /> + + <a + id="loginDiscord" + class="oauth" + href="https://discord.com/api/oauth2/authorize?client_id=991688571415175198&redirect_uri=https%3A%2F%2Fslowcord.maddy.k.vu%2Foauth%2Fdiscord&response_type=code&scope=identify%20email" + > + Login with Discord + </a> + + <div + class="h-captcha" + data-sitekey="fa3163ea-79a7-4b7b-b752-b58c545906c8" + ></div> + <script + src="https://js.hcaptcha.com/1/api.js" + async + defer + ></script> + </form> </div> - - - <form action="javascript:void(0);"> - <label for="email">Email</label> - <input type="email" name="email" /> - - <label for="username">Username</label> - <input type="username" name="username" /> - - <label for="password">Password</label> - <input type="password" name="password" /> - - <label for="dob">Date of Birth</label> - <input type="date" name="dob" /> - - <input type="submit" value="Register" /> - - <a id="loginDiscord" class="oauth" - href="https://discord.com/api/oauth2/authorize?client_id=991688571415175198&redirect_uri=https%3A%2F%2Fslowcord.maddy.k.vu%2Foauth%2Fdiscord&response_type=code&scope=identify%20email"> - Login with Discord - </a> - - <div class="h-captcha" data-sitekey="fa3163ea-79a7-4b7b-b752-b58c545906c8"></div> - <script src="https://js.hcaptcha.com/1/api.js" async defer></script> - </form> </div> - </div> - - <script> - document.forms[0].addEventListener("submit", async (e) => { - const data = new FormData(e.target); - const email = data.get("email"); - const username = data.get("username"); - const password = data.get("password"); - const dob = data.get("dob"); - const hcaptcha = data.get("h-captcha-response") - await handleSubmit("/api/v9/auth/register", { - consent: true, - email: email, - username: username, - password: password, - date_of_birth: dob, - captcha_key: hcaptcha, + <script> + document.forms[0].addEventListener("submit", async (e) => { + const data = new FormData(e.target); + const email = data.get("email"); + const username = data.get("username"); + const password = data.get("password"); + const dob = data.get("dob"); + const hcaptcha = data.get("h-captcha-response"); + + await handleSubmit("/api/v9/auth/register", { + consent: true, + email: email, + username: username, + password: password, + date_of_birth: dob, + captcha_key: hcaptcha, + }); }); - }) - </script> -</body> - -</html> \ No newline at end of file + </script> + </body> +</html> diff --git a/src-slowcord/login/src/index.ts b/src-slowcord/login/src/index.ts index 56d0a687..ced35dcf 100644 --- a/src-slowcord/login/src/index.ts +++ b/src-slowcord/login/src/index.ts @@ -1,7 +1,13 @@ import "dotenv/config"; import express, { Request, Response } from "express"; import cookieParser from "cookie-parser"; -import { initDatabase, generateToken, User, Config, handleFile } from "fosscord-server/src/util"; +import { + initDatabase, + generateToken, + User, + Config, + handleFile, +} from "fosscord-server/src/util"; import path from "path"; import fetch from "node-fetch"; @@ -16,8 +22,8 @@ app.use(cookieParser()); const port = process.env.PORT; // ip -> unix epoch that requests will be accepted again -const rateLimits: { [ip: string]: number; } = {}; -const allowRequestsEveryMs = 0.5 * 1000; // every half second +const rateLimits: { [ip: string]: number } = {}; +const allowRequestsEveryMs = 0.5 * 1000; // every half second const allowedRequestsPerSecond = 50; let requestsThisSecond = 0; @@ -36,23 +42,25 @@ 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 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 + body: body, }); - const json = await resp.json() as any; + const json = (await resp.json()) as any; if (json.error) return null; return { @@ -67,24 +75,26 @@ class Discord { static getUserDetails = async (token: string) => { const resp = await fetch("https://discord.com/api/users/@me", { headers: { - "Authorization": `Bearer ${token}`, - } + Authorization: `Bearer ${token}`, + }, }); - const json = await resp.json() as any; - if (!json.username || !json.email) return null; // eh, deal with bad code later + const json = (await resp.json()) as any; + if (!json.username || !json.email) return null; // eh, deal with bad code later return { id: json.id, email: json.email, username: json.username, - avatar_url: json.avatar ? `https://cdn.discordapp.com/avatars/${json.id}/${json.avatar}?size=2048` : null, + avatar_url: json.avatar + ? `https://cdn.discordapp.com/avatars/${json.id}/${json.avatar}?size=2048` + : null, }; }; } -const handlers: { [key: string]: any; } = { - "discord": Discord, +const handlers: { [key: string]: any } = { + discord: Discord, }; app.get("/oauth/:type", async (req, res) => { @@ -92,17 +102,21 @@ app.get("/oauth/:type", async (req, res) => { if (requestsThisSecond > allowedRequestsPerSecond) return res.sendStatus(429); - const ip = (req.headers["x-forwarded-for"] as string) || req.socket.remoteAddress as string; + const ip = + (req.headers["x-forwarded-for"] as string) || + (req.socket.remoteAddress as string); console.log(`${ip}`); if (!rateLimits[ip]) { rateLimits[ip] = Date.now() + allowRequestsEveryMs; - } - else if (rateLimits[ip] > Date.now()) { + } else if (rateLimits[ip] > Date.now()) { rateLimits[ip] += allowRequestsEveryMs; - console.log(`${new Date()} : user ${ip} was timed out for ${(rateLimits[ip] - Date.now()) / 1000}s`); + console.log( + `${new Date()} : user ${ip} was timed out for ${ + (rateLimits[ip] - Date.now()) / 1000 + }s`, + ); return res.sendStatus(429); - } - else { + } else { delete rateLimits[ip]; } @@ -121,16 +135,18 @@ app.get("/oauth/:type", async (req, res) => { user = await User.register({ email: details.email, username: details.username, - req + req, }); if (details.avatar_url) { try { - const avatar = await handleFile(`/avatars/${user.id}`, await toDataURL(details.avatar_url) as string); + const avatar = await handleFile( + `/avatars/${user.id}`, + (await toDataURL(details.avatar_url)) as string, + ); user.avatar = avatar; await user.save(); - } - catch (e) { + } catch (e) { console.error(e); } } @@ -152,4 +168,4 @@ app.use(express.static("public", { extensions: ["html"] })); app.listen(port, () => { console.log(`Listening on port ${port}`); }); -})(); \ No newline at end of file +})(); diff --git a/src-slowcord/login/tsconfig.json b/src-slowcord/login/tsconfig.json index b8a5965d..4d96714c 100644 --- a/src-slowcord/login/tsconfig.json +++ b/src-slowcord/login/tsconfig.json @@ -1,10 +1,6 @@ { - "exclude": [ - "node_modules" - ], - "include": [ - "src/**/*.ts" - ], + "exclude": ["node_modules"], + "include": ["src/**/*.ts"], "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Projects */ @@ -15,10 +11,12 @@ // "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. */ + "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. */ + "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'. */ @@ -27,14 +25,16 @@ // "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. */ + "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. */ + "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. */ + "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. */ @@ -46,9 +46,9 @@ // "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. */ + "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. */ + "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. */ @@ -69,16 +69,16 @@ /* 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. */ + "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. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "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. */ + "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. */ @@ -94,6 +94,6 @@ // "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. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ } -} \ No newline at end of file +} diff --git a/src-slowcord/rules.md b/src-slowcord/rules.md index ffae0846..1097060a 100644 --- a/src-slowcord/rules.md +++ b/src-slowcord/rules.md @@ -3,11 +3,12 @@ Slowcord is a heavily modded Fosscord instance. You can browse it's source here: https://github.com/MaddyUnderStars/fosscord-server/tree/slowcord ## Here are some general instance-wide rules: -* **Harassment, homophobia, transphobia, etc, violence, and hate speech are forbidden.** -* Behaviour that harms the service - be it malicious/intentional or not - is strictly forbidden. This may include API abuse/spam, exploits, etc. -* * If you do discover an exploit/bug, it would be greatly appreciated if you could create an issue in the above repo, or DM @MaddyUnderStars#0000. -* Any content that would be considered illegal in Australia is also forbidden. Additionally, if it is illegal in your own country, it shouldn't be here. -* Bots/selfbots are allowed. If you would like an account to be given bot status, DM @MaddyUnderStars#0000. + +- **Harassment, homophobia, transphobia, etc, violence, and hate speech are forbidden.** +- Behaviour that harms the service - be it malicious/intentional or not - is strictly forbidden. This may include API abuse/spam, exploits, etc. +- - If you do discover an exploit/bug, it would be greatly appreciated if you could create an issue in the above repo, or DM @MaddyUnderStars#0000. +- Any content that would be considered illegal in Australia is also forbidden. Additionally, if it is illegal in your own country, it shouldn't be here. +- Bots/selfbots are allowed. If you would like an account to be given bot status, DM @MaddyUnderStars#0000. These rules are non-exhaustive, but should give a good idea of what will be enforced. @@ -16,5 +17,6 @@ Permanent Slowcord guild invite: https://slowcord.understars.dev/invite/slowcord ### If a message or user breaks these rules, you can report it here: https://forms.gle/sd6RkdM7gRgJLV368 #### Lastly ( and not rules ): -* If you use BetterDiscord or Powercord, and want an easier time accessing Slowcord and other Fosscord instances, check out https://github.com/maddyunderstars/fosscord-bd! -* Also, if you're on Android, you can download the mobile client at https://slowcord.understars.dev/assets/slowcord.apk + +- If you use BetterDiscord or Powercord, and want an easier time accessing Slowcord and other Fosscord instances, check out https://github.com/maddyunderstars/fosscord-bd! +- Also, if you're on Android, you can download the mobile client at https://slowcord.understars.dev/assets/slowcord.apk diff --git a/src-slowcord/status/src/gateway.ts b/src-slowcord/status/src/gateway.ts index 14944d09..bc00c2d4 100644 --- a/src-slowcord/status/src/gateway.ts +++ b/src-slowcord/status/src/gateway.ts @@ -5,14 +5,22 @@ import mysql from "mysql2"; import fetch from "node-fetch"; const dbConn = mysql.createConnection(process.env.DATABASE as string); -const executePromise = (sql: string, args: any[]) => new Promise((resolve, reject) => dbConn.execute(sql, args, (err, res) => { if (err) reject(err); else resolve(res); })); +const executePromise = (sql: string, args: any[]) => + new Promise((resolve, reject) => + dbConn.execute(sql, args, (err, res) => { + if (err) reject(err); + else resolve(res); + }), + ); const savePerf = async (time: number, name: string, error?: string | Error) => { if (error && typeof error != "string") error = error.message; try { - await executePromise("INSERT INTO performance (value, endpoint, timestamp, error) VALUES (?, ?, ?, ?)", [time ?? 0, name, new Date(), error ?? null]); + await executePromise( + "INSERT INTO performance (value, endpoint, timestamp, error) VALUES (?, ?, ?, ?)", + [time ?? 0, name, new Date(), error ?? null], + ); // await executePromise("DELETE FROM performance WHERE DATE(timestamp) < now() - interval ? DAY", [process.env.RETENTION_DAYS]); - } - catch (e) { + } catch (e) { console.error(e); } }; @@ -23,7 +31,11 @@ const doMeasurements = async (channel: Discord.TextChannel) => { timestamp = Date.now(); await channel.send("hello this is a special message kthxbye"); - setTimeout(doMeasurements, parseInt(process.env.MEASURE_INTERVAL as string), channel); + setTimeout( + doMeasurements, + parseInt(process.env.MEASURE_INTERVAL as string), + channel, + ); }; const instance = { @@ -37,8 +49,8 @@ const client = new Fosscord.Client({ intents: [], http: { api: instance.api, - cdn: instance.cdn - } + cdn: instance.cdn, + }, }); client.on("ready", async () => { @@ -52,19 +64,24 @@ client.on("ready", async () => { client.on("messageCreate", async (msg: Discord.Message) => { if (!timestamp) return; - if (msg.author.id != "992745947417141682" - || msg.channel.id != "1019955729054267764" - || msg.content != "hello this is a special message kthxbye") + if ( + msg.author.id != "992745947417141682" || + msg.channel.id != "1019955729054267764" || + msg.content != "hello this is a special message kthxbye" + ) return; await savePerf(Date.now() - timestamp, "messageCreate", undefined); timestamp = undefined; - await fetch(`${instance.api}/channels/1019955729054267764/messages/${msg.id}`, { - method: "DELETE", - headers: { - authorization: instance.token - } - }) + await fetch( + `${instance.api}/channels/1019955729054267764/messages/${msg.id}`, + { + method: "DELETE", + headers: { + authorization: instance.token, + }, + }, + ); }); client.on("error", (error: any) => { @@ -79,4 +96,4 @@ client.on("warn", (msg: any) => { await new Promise((resolve) => dbConn.connect(resolve)); console.log("Connected to db"); await client.login(instance.token); -})(); \ No newline at end of file +})(); diff --git a/src-slowcord/status/src/index.ts b/src-slowcord/status/src/index.ts index 735b8a9b..979469b6 100644 --- a/src-slowcord/status/src/index.ts +++ b/src-slowcord/status/src/index.ts @@ -4,7 +4,13 @@ import mysql from "mysql2"; import fetch from "node-fetch"; const dbConn = mysql.createConnection(process.env.DATABASE as string); -const executePromise = (sql: string, args: any[]) => new Promise((resolve, reject) => dbConn.execute(sql, args, (err, res) => { if (err) reject(err); else resolve(res); })); +const executePromise = (sql: string, args: any[]) => + new Promise((resolve, reject) => + dbConn.execute(sql, args, (err, res) => { + if (err) reject(err); + else resolve(res); + }), + ); const instance = { app: process.env.INSTANCE_WEB_APP as string, @@ -16,73 +22,86 @@ const instance = { const savePerf = async (time: number, name: string, error?: string | Error) => { if (error && typeof error != "string") error = error.message; try { - await executePromise("INSERT INTO performance (value, endpoint, timestamp, error) VALUES (?, ?, ?, ?)", [time ?? 0, name, new Date(), error ?? null]); + await executePromise( + "INSERT INTO performance (value, endpoint, timestamp, error) VALUES (?, ?, ?, ?)", + [time ?? 0, name, new Date(), error ?? null], + ); // await executePromise("DELETE FROM performance WHERE DATE(timestamp) < now() - interval ? DAY", [process.env.RETENTION_DAYS]); - } - catch (e) { + } catch (e) { console.error(e); } }; -const saveSystemUsage = async (load: number, procUptime: number, sysUptime: number, ram: number, sessions: number) => { +const saveSystemUsage = async ( + load: number, + procUptime: number, + sysUptime: number, + ram: number, + sessions: number, +) => { try { - await executePromise("INSERT INTO monitor (time, cpu, procUp, sysUp, ram, sessions) VALUES (?, ?, ?, ?, ?, ?)", [new Date(), load, procUptime, sysUptime, ram, sessions]); - } - catch (e) { + await executePromise( + "INSERT INTO monitor (time, cpu, procUp, sysUp, ram, sessions) VALUES (?, ?, ?, ?, ?, ?)", + [new Date(), load, procUptime, sysUptime, ram, sessions], + ); + } catch (e) { console.error(e); } }; -const makeTimedRequest = (path: string, body?: object): Promise<number> => new Promise((resolve, reject) => { - const opts = { - hostname: new URL(path).hostname, - port: 443, - path: new URL(path).pathname, - method: "GET", - headers: { - "Content-Type": "application/json", - "Authorization": instance.token, - }, - timeout: 1000, - }; - - let start: number, end: number; - const req = https.request(opts, res => { - if (res.statusCode! < 200 || res.statusCode! > 300) { - return reject(`${res.statusCode} ${res.statusMessage}`); - } - - res.on("data", (data) => { +const makeTimedRequest = (path: string, body?: object): Promise<number> => + new Promise((resolve, reject) => { + const opts = { + hostname: new URL(path).hostname, + port: 443, + path: new URL(path).pathname, + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: instance.token, + }, + timeout: 1000, + }; + + let start: number, end: number; + const req = https.request(opts, (res) => { + if (res.statusCode! < 200 || res.statusCode! > 300) { + return reject(`${res.statusCode} ${res.statusMessage}`); + } + + res.on("data", (data) => {}); + + res.on("end", () => { + end = Date.now(); + resolve(end - start); + }); }); - res.on("end", () => { - end = Date.now(); - resolve(end - start); + req.on("finish", () => { + if (body) req.write(JSON.stringify(body)); + start = Date.now(); }); - }); - req.on("finish", () => { - if (body) req.write(JSON.stringify(body)); - start = Date.now(); - }); + req.on("error", (error) => { + reject(error); + }); - req.on("error", (error) => { - reject(error); + req.end(); }); - req.end(); -}); - const measureApi = async (name: string, path: string, body?: object) => { - let error, time = -1; + let error, + time = -1; try { time = await makeTimedRequest(path, body); - } - catch (e) { + } catch (e) { error = e as Error | string; } - console.log(`${name} took ${time}ms ${(error ? "with error" : "")}`, error ?? ""); + console.log( + `${name} took ${time}ms ${error ? "with error" : ""}`, + error ?? "", + ); await savePerf(time, name, error); }; @@ -100,7 +119,11 @@ const app = async () => { console.log("Connected to db"); // await client.login(instance.token); - console.log(`Monitoring performance for instance at ${new URL(instance.api).hostname}`); + console.log( + `Monitoring performance for instance at ${ + new URL(instance.api).hostname + }`, + ); const doMeasurements = async () => { await measureApi("ping", `${instance.api}/ping`); @@ -112,18 +135,25 @@ const app = async () => { const res = await fetch(`${instance.api}/-/monitorz`, { headers: { Authorization: process.env.INSTANCE_TOKEN as string, - } + }, }); - const json = await res.json() as monitorzSchema; - await saveSystemUsage(json.load[1], json.procUptime, json.sysUptime, json.memPercent, json.sessions); - } - catch (e) { - } - - setTimeout(doMeasurements, parseInt(process.env.MEASURE_INTERVAL as string)); + const json = (await res.json()) as monitorzSchema; + await saveSystemUsage( + json.load[1], + json.procUptime, + json.sysUptime, + json.memPercent, + json.sessions, + ); + } catch (e) {} + + setTimeout( + doMeasurements, + parseInt(process.env.MEASURE_INTERVAL as string), + ); }; doMeasurements(); }; -app(); \ No newline at end of file +app(); diff --git a/src-slowcord/status/tsconfig.json b/src-slowcord/status/tsconfig.json index 6d6ec56d..4d96714c 100644 --- a/src-slowcord/status/tsconfig.json +++ b/src-slowcord/status/tsconfig.json @@ -1,10 +1,6 @@ { - "exclude": [ - "node_modules" - ], - "include": [ - "src/**/*.ts" - ], + "exclude": ["node_modules"], + "include": ["src/**/*.ts"], "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Projects */ @@ -15,10 +11,12 @@ // "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. */ + "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. */ + "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'. */ @@ -27,14 +25,16 @@ // "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. */ + "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. */ + "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. */ + "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. */ @@ -46,9 +46,9 @@ // "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. */ + "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. */ + "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. */ @@ -69,16 +69,16 @@ /* 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. */ + "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. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "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. */ + "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. */ @@ -96,4 +96,4 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ } -} \ No newline at end of file +} |