diff --git a/src/Server.ts b/src/Server.ts
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/api/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts
index 0b6b81ce7..f14bcef4a 100644
--- a/src/api/middlewares/ErrorHandler.ts
+++ b/src/api/middlewares/ErrorHandler.ts
@@ -38,6 +38,7 @@ export function ErrorHandler(
if (error instanceof HTTPError && error.code) {
code = httpcode = error.code;
+ // @ts-expect-error - we make it exist
if (error.data) data = error.data;
} else if (error instanceof ApiError) {
code = error.code;
diff --git a/src/api/middlewares/RateLimit.ts b/src/api/middlewares/RateLimit.ts
index f5bfbb4f0..92ba45963 100644
--- a/src/api/middlewares/RateLimit.ts
+++ b/src/api/middlewares/RateLimit.ts
@@ -16,8 +16,7 @@
along with this program. If not, see .
*/
-import { getIpAdress } from "@spacebar/api";
-import { Config, getRights, listenEvent } from "@spacebar/util";
+import { Config, getRights, listenEvent, getIpAdress } from "@spacebar/util";
import { NextFunction, Request, Response, Router } from "express";
import { API_PREFIX_TRAILING_SLASH } from "./Authentication";
diff --git a/src/api/routes/auth/forgot.ts b/src/api/routes/auth/forgot.ts
index d5a8a2f40..61c03110b 100644
--- a/src/api/routes/auth/forgot.ts
+++ b/src/api/routes/auth/forgot.ts
@@ -16,8 +16,8 @@
along with this program. If not, see .
*/
-import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
-import { Config, Email, ForgotPasswordSchema, User } from "@spacebar/util";
+import { route, verifyCaptcha } from "@spacebar/api";
+import { Config, Email, ForgotPasswordSchema, getIpAdress, User } from "@spacebar/util";
import { Request, Response, Router } from "express";
const router = Router();
diff --git a/src/api/routes/auth/generate-registration-tokens.ts b/src/api/routes/auth/generate-registration-tokens.ts
index 303c6ab56..7707fd37d 100644
--- a/src/api/routes/auth/generate-registration-tokens.ts
+++ b/src/api/routes/auth/generate-registration-tokens.ts
@@ -16,8 +16,8 @@
along with this program. If not, see .
*/
-import { random, route } from "@spacebar/api";
-import { Config, ValidRegistrationToken } from "@spacebar/util";
+import { route } from "@spacebar/api";
+import { Config, generateRandomString, ValidRegistrationToken } from "@spacebar/util";
import { Request, Response, Router } from "express";
const router: Router = Router();
@@ -51,7 +51,7 @@ router.get(
for (let i = 0; i < count; i++) {
const token = ValidRegistrationToken.create({
- token: random(length),
+ token: generateRandomString(length),
expires_at: new Date(
Date.now() +
Config.get().security
diff --git a/src/api/routes/auth/location-metadata.ts b/src/api/routes/auth/location-metadata.ts
index 28293e59c..3e4ea980f 100644
--- a/src/api/routes/auth/location-metadata.ts
+++ b/src/api/routes/auth/location-metadata.ts
@@ -16,8 +16,9 @@
along with this program. If not, see .
*/
-import { IPAnalysis, getIpAdress, route } from "@spacebar/api";
+import { route } from "@spacebar/api";
import { Request, Response, Router } from "express";
+import { getIpAdress, IPAnalysis } from "@spacebar/util";
const router = Router();
router.get(
diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts
index a2100333e..03fa60338 100644
--- a/src/api/routes/auth/login.ts
+++ b/src/api/routes/auth/login.ts
@@ -16,7 +16,7 @@
along with this program. If not, see .
*/
-import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
+import { route, verifyCaptcha } from "@spacebar/api";
import {
Config,
FieldErrors,
@@ -24,7 +24,7 @@ import {
User,
WebAuthn,
generateToken,
- generateWebAuthnTicket,
+ generateWebAuthnTicket, getIpAdress,
} from "@spacebar/util";
import bcrypt from "bcrypt";
import crypto from "crypto";
diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts
index 9e9d2c987..2a5ab5d87 100644
--- a/src/api/routes/auth/register.ts
+++ b/src/api/routes/auth/register.ts
@@ -17,9 +17,6 @@
*/
import {
- IPAnalysis,
- getIpAdress,
- isProxy,
route,
verifyCaptcha,
} from "@spacebar/api";
@@ -30,7 +27,7 @@ import {
RegisterSchema,
User,
ValidRegistrationToken,
- generateToken,
+ generateToken, getIpAdress, IPAnalysis, isProxy,
} from "@spacebar/util";
import bcrypt from "bcrypt";
import { Request, Response, Router } from "express";
diff --git a/src/api/routes/auth/verify/index.ts b/src/api/routes/auth/verify/index.ts
index 32c3f3058..a6b8dff88 100644
--- a/src/api/routes/auth/verify/index.ts
+++ b/src/api/routes/auth/verify/index.ts
@@ -16,12 +16,12 @@
along with this program. If not, see .
*/
-import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
+import { route, verifyCaptcha } from "@spacebar/api";
import {
checkToken,
Config,
FieldErrors,
- generateToken,
+ generateToken, getIpAdress,
User,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
diff --git a/src/api/routes/channels/#channel_id/invites.ts b/src/api/routes/channels/#channel_id/invites.ts
index ae32e80de..0d3724ff3 100644
--- a/src/api/routes/channels/#channel_id/invites.ts
+++ b/src/api/routes/channels/#channel_id/invites.ts
@@ -16,7 +16,7 @@
along with this program. If not, see .
*/
-import { random, route } from "@spacebar/api";
+import { route } from "@spacebar/api";
import {
Channel,
Guild,
@@ -26,7 +26,7 @@ import {
PublicInviteRelation,
User,
emitEvent,
- isTextChannel,
+ isTextChannel, generateRandomString,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
@@ -70,7 +70,7 @@ router.post(
: new Date(body.max_age * 1000 + Date.now());
const invite = await Invite.create({
- code: random(),
+ code: generateRandomString(),
temporary: body.temporary || true,
uses: 0,
max_uses: body.max_uses ? Math.max(0, body.max_uses) : 0,
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index 1bcf3f16e..6cba92288 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -427,17 +427,18 @@ router.post(
read_state = ReadState.create({ user_id: req.user_id, channel_id });
read_state.last_message_id = message.id;
- let blocks = (
+ const blocks = (
await PluginEventHandler.preMessageEvent({
message
} as PreMessageEventArgs)
).filter((x) => x.cancel);
- if (blocks.length > 0)
+ if (blocks.length > 0) {
+ console.log("[Message] Pre-message event handler blocked message send:", message, blocks)
throw new HTTPError(
"Message denied.",
400,
- blocks.filter((x) => x.blockReason).map((x) => x.blockReason)
);
+ }
await Promise.all([
read_state.save(),
diff --git a/src/api/routes/guilds/#guild_id/bans.ts b/src/api/routes/guilds/#guild_id/bans.ts
index 789519542..d20914728 100644
--- a/src/api/routes/guilds/#guild_id/bans.ts
+++ b/src/api/routes/guilds/#guild_id/bans.ts
@@ -16,7 +16,7 @@
along with this program. If not, see .
*/
-import { getIpAdress, route } from "@spacebar/api";
+import { route } from "@spacebar/api";
import {
APIBansArray,
Ban,
@@ -27,7 +27,7 @@ import {
GuildBansResponse,
Member,
User,
- emitEvent,
+ emitEvent, getIpAdress,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
diff --git a/src/api/routes/guilds/#guild_id/bulk-ban.ts b/src/api/routes/guilds/#guild_id/bulk-ban.ts
index e5f7a0d8e..b6c1b2733 100644
--- a/src/api/routes/guilds/#guild_id/bulk-ban.ts
+++ b/src/api/routes/guilds/#guild_id/bulk-ban.ts
@@ -16,14 +16,14 @@
along with this program. If not, see .
*/
-import { getIpAdress, route } from "@spacebar/api";
+import { route } from "@spacebar/api";
import {
Ban,
DiscordApiErrors,
GuildBanAddEvent,
Member,
User,
- emitEvent,
+ emitEvent, getIpAdress,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
diff --git a/src/api/routes/guilds/#guild_id/regions.ts b/src/api/routes/guilds/#guild_id/regions.ts
index b0ae0602d..bd107e966 100644
--- a/src/api/routes/guilds/#guild_id/regions.ts
+++ b/src/api/routes/guilds/#guild_id/regions.ts
@@ -16,8 +16,8 @@
along with this program. If not, see .
*/
-import { getIpAdress, getVoiceRegions, route } from "@spacebar/api";
-import { Guild } from "@spacebar/util";
+import { getVoiceRegions, route } from "@spacebar/api";
+import { getIpAdress, Guild } from "@spacebar/util";
import { Request, Response, Router } from "express";
const router = Router();
diff --git a/src/api/routes/guilds/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts
index a9c6182f0..89beb8b70 100644
--- a/src/api/routes/guilds/#guild_id/templates.ts
+++ b/src/api/routes/guilds/#guild_id/templates.ts
@@ -16,8 +16,8 @@
along with this program. If not, see .
*/
-import { generateCode, route } from "@spacebar/api";
-import { Guild, Template } from "@spacebar/util";
+import { route } from "@spacebar/api";
+import { generateCode, Guild, Template } from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
diff --git a/src/api/routes/guilds/#guild_id/widget.json.ts b/src/api/routes/guilds/#guild_id/widget.json.ts
index 5d9f28c2e..a6804f28e 100644
--- a/src/api/routes/guilds/#guild_id/widget.json.ts
+++ b/src/api/routes/guilds/#guild_id/widget.json.ts
@@ -16,7 +16,7 @@
along with this program. If not, see .
*/
-import { random, route } from "@spacebar/api";
+import { route } from "@spacebar/api";
import {
Channel,
DiscordApiErrors,
@@ -24,6 +24,7 @@ import {
Invite,
Member,
Permissions,
+ generateRandomString
} from "@spacebar/util";
import { Request, Response, Router } from "express";
@@ -77,7 +78,7 @@ router.get(
const expires_at = new Date(max_age * 1000 + Date.now());
invite = await Invite.create({
- code: random(),
+ code: generateRandomString(),
temporary: false,
uses: 0,
max_uses: 0,
diff --git a/src/api/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts
index 6553a7b8a..362152d7f 100644
--- a/src/api/routes/users/@me/mfa/totp/disable.ts
+++ b/src/api/routes/users/@me/mfa/totp/disable.ts
@@ -26,7 +26,6 @@ import {
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { verifyToken } from "node-2fa";
-import { route } from "../../../../..";
const router = Router();
diff --git a/src/api/routes/voice/regions.ts b/src/api/routes/voice/regions.ts
index 10a8b21d7..2df074e82 100644
--- a/src/api/routes/voice/regions.ts
+++ b/src/api/routes/voice/regions.ts
@@ -16,7 +16,8 @@
along with this program. If not, see .
*/
-import { getIpAdress, getVoiceRegions, route } from "@spacebar/api";
+import { getVoiceRegions, route } from "@spacebar/api";
+import { getIpAdress } from "@spacebar/util";
import { Request, Response, Router } from "express";
const router: Router = Router();
diff --git a/src/api/util/handlers/Voice.ts b/src/api/util/handlers/Voice.ts
index db06bd33c..74e8e712e 100644
--- a/src/api/util/handlers/Voice.ts
+++ b/src/api/util/handlers/Voice.ts
@@ -16,8 +16,7 @@
along with this program. If not, see .
*/
-import { Config } from "@spacebar/util";
-import { distanceBetweenLocations, IPAnalysis } from "../utility/ipAddress";
+import { Config, distanceBetweenLocations, IPAnalysis } from "@spacebar/util";
export async function getVoiceRegions(ipAddress: string, vip: boolean) {
const regions = Config.get().regions;
diff --git a/src/api/util/index.ts b/src/api/util/index.ts
index cb26d4f54..7ed0bf956 100644
--- a/src/api/util/index.ts
+++ b/src/api/util/index.ts
@@ -16,13 +16,8 @@
along with this program. If not, see .
*/
-export * from "./utility/Base64";
-export * from "./utility/ipAddress";
export * from "./handlers/Message";
-export * from "./utility/passwordStrength";
-export * from "./utility/RandomInviteID";
export * from "./handlers/route";
-export * from "./utility/String";
export * from "./handlers/Voice";
export * from "./utility/captcha";
export * from "./utility/EmbedHandlers";
diff --git a/src/api/util/utility/String.ts b/src/api/util/utility/String.ts
deleted file mode 100644
index eef69e39b..000000000
--- a/src/api/util/utility/String.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
- Copyright (C) 2023 Spacebar and Spacebar Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-*/
-
-import { Request } from "express";
-import { ntob } from "./Base64";
-import { FieldErrors } from "@spacebar/util";
-
-export function checkLength(
- str: string,
- min: number,
- max: number,
- key: string,
- req: Request,
-) {
- if (str.length < min || str.length > max) {
- throw FieldErrors({
- [key]: {
- code: "BASE_TYPE_BAD_LENGTH",
- message: req.t("common:field.BASE_TYPE_BAD_LENGTH", {
- length: `${min} - ${max}`,
- }),
- },
- });
- }
-}
-
-export function generateCode() {
- return ntob(Date.now() + Math.randomIntBetween(0, 10000));
-}
diff --git a/src/plugins/example-plugin/TestPlugin.ts b/src/plugins/example-plugin/TestPlugin.ts
index da25c474b..e4ff55434 100644
--- a/src/plugins/example-plugin/TestPlugin.ts
+++ b/src/plugins/example-plugin/TestPlugin.ts
@@ -7,7 +7,7 @@ import {
PluginManifest,
PreMessageEventArgs,
PreMessageEventResult
-} from "@fosscord/util";
+} from "@spacebar/util";
import { TestSettings } from "./TestSettings";
export default class TestPlugin implements Plugin {
diff --git a/src/util/migrations/postgres/1660404619978-PluginConfigs.ts b/src/util/migrations/postgres/1660404619978-PluginConfigs.ts
deleted file mode 100644
index 21d4757c6..000000000
--- a/src/util/migrations/postgres/1660404619978-PluginConfigs.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { MigrationInterface, QueryRunner } from "typeorm";
-
-export class PluginConfigs1660404619978 implements MigrationInterface {
- name = "PluginConfigs1660404619978";
-
- public async up(queryRunner: QueryRunner): Promise {
- await queryRunner.query(`
- CREATE TABLE "plugin_config" (
- "key" character varying NOT NULL,
- "value" text,
- CONSTRAINT "PK_aa929ece56c59233b85a16f62ef" PRIMARY KEY ("key")
- )
- `);
- }
-
- public async down(queryRunner: QueryRunner): Promise {
- await queryRunner.query(`
- DROP TABLE "plugin_config"
- `);
- }
-}
diff --git a/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts b/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts
deleted file mode 100644
index 8f5e364b0..000000000
--- a/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts
+++ /dev/null
@@ -1,828 +0,0 @@
-import { MigrationInterface, QueryRunner } from "typeorm";
-
-export class UpdateMigrations1660534525799 implements MigrationInterface {
- name = "UpdateMigrations1660534525799";
-
- public async up(queryRunner: QueryRunner): Promise {
- await queryRunner.query(`
- CREATE TABLE "temporary_applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "rpc_origins" text,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "primary_sku_id" varchar,
- "slug" varchar,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "guild_id" varchar,
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "temporary_applications"(
- "id",
- "name",
- "icon",
- "description",
- "rpc_origins",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "primary_sku_id",
- "slug",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "guild_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "rpc_origins",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "primary_sku_id",
- "slug",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "guild_id"
- FROM "applications"
- `);
- await queryRunner.query(`
- DROP TABLE "applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "temporary_applications"
- RENAME TO "applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "temporary_applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "temporary_applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- FROM "applications"
- `);
- await queryRunner.query(`
- DROP TABLE "applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "temporary_applications"
- RENAME TO "applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "temporary_applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "type" text,
- "hook" boolean NOT NULL,
- "redirect_uris" text,
- "rpc_application_state" integer,
- "store_application_state" integer,
- "verification_state" integer,
- "interactions_endpoint_url" varchar,
- "integration_public" boolean,
- "integration_require_code_grant" boolean,
- "discoverability_state" integer,
- "discovery_eligibility_flags" integer,
- "tags" text,
- "install_params" text,
- "bot_user_id" varchar,
- CONSTRAINT "UQ_b7f6e13565e920916d902e1f431" UNIQUE ("bot_user_id"),
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "temporary_applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- FROM "applications"
- `);
- await queryRunner.query(`
- DROP TABLE "applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "temporary_applications"
- RENAME TO "applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "temporary_applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" integer NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "type" text,
- "hook" boolean NOT NULL,
- "redirect_uris" text,
- "rpc_application_state" integer,
- "store_application_state" integer,
- "verification_state" integer,
- "interactions_endpoint_url" varchar,
- "integration_public" boolean,
- "integration_require_code_grant" boolean,
- "discoverability_state" integer,
- "discovery_eligibility_flags" integer,
- "tags" text,
- "install_params" text,
- "bot_user_id" varchar,
- CONSTRAINT "UQ_b7f6e13565e920916d902e1f431" UNIQUE ("bot_user_id"),
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "temporary_applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- FROM "applications"
- `);
- await queryRunner.query(`
- DROP TABLE "applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "temporary_applications"
- RENAME TO "applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "temporary_applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" integer NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "type" text,
- "hook" boolean NOT NULL,
- "redirect_uris" text,
- "rpc_application_state" integer,
- "store_application_state" integer,
- "verification_state" integer,
- "interactions_endpoint_url" varchar,
- "integration_public" boolean,
- "integration_require_code_grant" boolean,
- "discoverability_state" integer,
- "discovery_eligibility_flags" integer,
- "tags" text,
- "install_params" text,
- "bot_user_id" varchar,
- CONSTRAINT "UQ_b7f6e13565e920916d902e1f431" UNIQUE ("bot_user_id"),
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT "FK_2ce5a55796fe4c2f77ece57a647" FOREIGN KEY ("bot_user_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "temporary_applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- FROM "applications"
- `);
- await queryRunner.query(`
- DROP TABLE "applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "temporary_applications"
- RENAME TO "applications"
- `);
- }
-
- public async down(queryRunner: QueryRunner): Promise {
- await queryRunner.query(`
- ALTER TABLE "applications"
- RENAME TO "temporary_applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" integer NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "type" text,
- "hook" boolean NOT NULL,
- "redirect_uris" text,
- "rpc_application_state" integer,
- "store_application_state" integer,
- "verification_state" integer,
- "interactions_endpoint_url" varchar,
- "integration_public" boolean,
- "integration_require_code_grant" boolean,
- "discoverability_state" integer,
- "discovery_eligibility_flags" integer,
- "tags" text,
- "install_params" text,
- "bot_user_id" varchar,
- CONSTRAINT "UQ_b7f6e13565e920916d902e1f431" UNIQUE ("bot_user_id"),
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- FROM "temporary_applications"
- `);
- await queryRunner.query(`
- DROP TABLE "temporary_applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "applications"
- RENAME TO "temporary_applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "type" text,
- "hook" boolean NOT NULL,
- "redirect_uris" text,
- "rpc_application_state" integer,
- "store_application_state" integer,
- "verification_state" integer,
- "interactions_endpoint_url" varchar,
- "integration_public" boolean,
- "integration_require_code_grant" boolean,
- "discoverability_state" integer,
- "discovery_eligibility_flags" integer,
- "tags" text,
- "install_params" text,
- "bot_user_id" varchar,
- CONSTRAINT "UQ_b7f6e13565e920916d902e1f431" UNIQUE ("bot_user_id"),
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "type",
- "hook",
- "redirect_uris",
- "rpc_application_state",
- "store_application_state",
- "verification_state",
- "interactions_endpoint_url",
- "integration_public",
- "integration_require_code_grant",
- "discoverability_state",
- "discovery_eligibility_flags",
- "tags",
- "install_params",
- "bot_user_id"
- FROM "temporary_applications"
- `);
- await queryRunner.query(`
- DROP TABLE "temporary_applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "applications"
- RENAME TO "temporary_applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- FROM "temporary_applications"
- `);
- await queryRunner.query(`
- DROP TABLE "temporary_applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "applications"
- RENAME TO "temporary_applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "rpc_origins" text,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "primary_sku_id" varchar,
- "slug" varchar,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "guild_id" varchar,
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "applications"(
- "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "cover_image",
- "flags",
- "owner_id",
- "team_id"
- FROM "temporary_applications"
- `);
- await queryRunner.query(`
- DROP TABLE "temporary_applications"
- `);
- await queryRunner.query(`
- ALTER TABLE "applications"
- RENAME TO "temporary_applications"
- `);
- await queryRunner.query(`
- CREATE TABLE "applications" (
- "id" varchar PRIMARY KEY NOT NULL,
- "name" varchar NOT NULL,
- "icon" varchar,
- "description" varchar NOT NULL,
- "rpc_origins" text,
- "bot_public" boolean NOT NULL,
- "bot_require_code_grant" boolean NOT NULL,
- "terms_of_service_url" varchar,
- "privacy_policy_url" varchar,
- "summary" varchar,
- "verify_key" varchar NOT NULL,
- "primary_sku_id" varchar,
- "slug" varchar,
- "cover_image" varchar,
- "flags" varchar NOT NULL,
- "owner_id" varchar,
- "team_id" varchar,
- "guild_id" varchar,
- CONSTRAINT "FK_e5bf78cdbbe9ba91062d74c5aba" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT "FK_a36ed02953077f408d0f3ebc424" FOREIGN KEY ("team_id") REFERENCES "teams" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
- CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
- )
- `);
- await queryRunner.query(`
- INSERT INTO "applications"(
- "id",
- "name",
- "icon",
- "description",
- "rpc_origins",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "primary_sku_id",
- "slug",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "guild_id"
- )
- SELECT "id",
- "name",
- "icon",
- "description",
- "rpc_origins",
- "bot_public",
- "bot_require_code_grant",
- "terms_of_service_url",
- "privacy_policy_url",
- "summary",
- "verify_key",
- "primary_sku_id",
- "slug",
- "cover_image",
- "flags",
- "owner_id",
- "team_id",
- "guild_id"
- FROM "temporary_applications"
- `);
- await queryRunner.query(`
- DROP TABLE "temporary_applications"
- `);
- }
-}
diff --git a/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts b/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts
deleted file mode 100644
index 17f1fb162..000000000
--- a/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { MigrationInterface, QueryRunner } from "typeorm";
-
-export class syncRebase15aug20221660565540177 implements MigrationInterface {
- name = "syncRebase15aug20221660565540177";
-
- public async up(queryRunner: QueryRunner): Promise {
- await queryRunner.query(`
- CREATE TABLE "plugin_config" ("key" varchar PRIMARY KEY NOT NULL, "value" text)
- `);
- }
-
- public async down(queryRunner: QueryRunner): Promise {
- await queryRunner.query(`
- DROP TABLE "plugin_config"
- `);
- }
-}
diff --git a/src/util/util/RandomInviteID.ts b/src/util/util/RandomInviteID.ts
index 926750d35..ed5154896 100644
--- a/src/util/util/RandomInviteID.ts
+++ b/src/util/util/RandomInviteID.ts
@@ -22,7 +22,7 @@ import crypto from "crypto";
// TODO: 'random'? seriously? who named this?
// And why is this even here? Just use cryto.randomBytes?
-export function random(length = 6) {
+export function generateRandomString(length = 6) {
// Declare all characters
const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -51,5 +51,5 @@ export function snowflakeBasedInvite() {
snowflake = snowflake / base;
}
- return str.substr(3, 8).split("").reverse().join("");
+ return str.substring(3, 8).split("").reverse().join("");
}
diff --git a/src/util/util/String.ts b/src/util/util/String.ts
index 2d2e132a7..71faaea5c 100644
--- a/src/util/util/String.ts
+++ b/src/util/util/String.ts
@@ -17,6 +17,7 @@
*/
import { SPECIAL_CHAR } from "./Regex";
+import { ntob } from "./Base64";
export function trimSpecial(str?: string): string {
if (!str) return "";
@@ -37,4 +38,8 @@ export function centerString(str: string, len: number): string {
const pad = len - str.length;
const padLeft = Math.floor(pad / 2) + str.length;
return str.padStart(padLeft).padEnd(len);
-}
\ No newline at end of file
+}
+
+export function generateCode() {
+ return ntob(Date.now() + Math.randomIntBetween(0, 10000));
+}
diff --git a/src/util/util/index.ts b/src/util/util/index.ts
index 41da86a82..36d43014d 100644
--- a/src/util/util/index.ts
+++ b/src/util/util/index.ts
@@ -50,4 +50,5 @@ export * from "./NameValidation";
export * from "./InvisibleCharacters";
export * from "./Environment";
export * from "./Logo";
-export * from "./Paths";
\ No newline at end of file
+export * from "./ipAddress";
+export * from "./RandomInviteID";
\ No newline at end of file