mirror of
https://github.com/spacebarchat/server.git
synced 2026-09-26 02:25:19 +00:00
Prettier u15
This commit is contained in:
@@ -19,7 +19,8 @@
|
||||
import { handleMessage, postHandleMessage, route } from "@spacebar/api";
|
||||
import {
|
||||
Attachment,
|
||||
AutomodExecutor, AutomodInvocation,
|
||||
AutomodExecutor,
|
||||
AutomodInvocation,
|
||||
AutomodRule,
|
||||
AutomodTriggerTypes,
|
||||
Channel,
|
||||
@@ -443,13 +444,15 @@ router.post(
|
||||
// @ts-ignore
|
||||
message.member.roles = message.member.roles.filter((x) => x.id != x.guild_id).map((x) => x.id);
|
||||
|
||||
const automodResult = await AutomodExecutor.executeInvocation(new AutomodInvocation({
|
||||
eventType: AutomodRuleEventType.MESSAGE_SEND,
|
||||
guildId: message.guild_id,
|
||||
payload: message
|
||||
}));
|
||||
const automodResult = await AutomodExecutor.executeInvocation(
|
||||
new AutomodInvocation({
|
||||
eventType: AutomodRuleEventType.MESSAGE_SEND,
|
||||
guildId: message.guild_id,
|
||||
payload: message,
|
||||
}),
|
||||
);
|
||||
|
||||
if(automodResult.blocked) {
|
||||
if (automodResult.blocked) {
|
||||
throw new HTTPError("Unhandled error sending message", 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,8 +137,7 @@ async function patchUserSettings(userId: string, updatedSettings: PreloadedUserS
|
||||
};
|
||||
}
|
||||
|
||||
if (EnvConfig.get().logging.logProtoUpdates.includes("SETTINGS"))
|
||||
console.log(`Updating user settings for user ${userId} with atomic=${atomic}:`, updatedSettings);
|
||||
if (EnvConfig.get().logging.logProtoUpdates.includes("SETTINGS")) console.log(`Updating user settings for user ${userId} with atomic=${atomic}:`, updatedSettings);
|
||||
|
||||
if (!atomic) {
|
||||
settings = PreloadedUserSettings.fromJson(
|
||||
|
||||
@@ -137,8 +137,7 @@ async function patchUserSettings(userId: string, updatedSettings: FrecencyUserSe
|
||||
};
|
||||
}
|
||||
|
||||
if (EnvConfig.get().logging.logProtoUpdates.includes("FRECENCY"))
|
||||
console.log(`Updating frecency settings for user ${userId} with atomic=${atomic}:`, updatedSettings);
|
||||
if (EnvConfig.get().logging.logProtoUpdates.includes("FRECENCY")) console.log(`Updating frecency settings for user ${userId} with atomic=${atomic}:`, updatedSettings);
|
||||
|
||||
if (!atomic) {
|
||||
settings = FrecencyUserSettings.fromJson(
|
||||
|
||||
@@ -33,7 +33,7 @@ export interface Storage {
|
||||
|
||||
let storage: Storage;
|
||||
|
||||
if (EnvConfig.get().cdn.storageProvider === "file" || !EnvConfig.get().cdn.storageProvider ) {
|
||||
if (EnvConfig.get().cdn.storageProvider === "file" || !EnvConfig.get().cdn.storageProvider) {
|
||||
let location = EnvConfig.get().cdn.storageLocation;
|
||||
if (location) {
|
||||
location = path.resolve(location);
|
||||
|
||||
@@ -79,18 +79,11 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
|
||||
console.log(`[Gateway] New connection from ${ipAddress}, total ${this.clients.size}`);
|
||||
|
||||
if (EnvConfig.get().logging.gatewayLogging.logHttp)
|
||||
[
|
||||
"close",
|
||||
"error",
|
||||
"upgrade",
|
||||
"open",
|
||||
"ping",
|
||||
"pong",
|
||||
"unexpected-response",
|
||||
...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : []),
|
||||
].forEach((x) => {
|
||||
socket.on(x, (y) => console.log(x, y));
|
||||
});
|
||||
["close", "error", "upgrade", "open", "ping", "pong", "unexpected-response", ...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : [])].forEach(
|
||||
(x) => {
|
||||
socket.on(x, (y) => console.log(x, y));
|
||||
},
|
||||
);
|
||||
|
||||
const { searchParams } = new URL(`http://localhost${request.url}`);
|
||||
// @ts-ignore
|
||||
|
||||
@@ -728,5 +728,8 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
||||
|
||||
const setupListenerTime = Date.now();
|
||||
|
||||
console.log(`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, EnvConfig.get().logging.gatewayLogging.logTraces ? JSON.stringify(d._trace, null, 2) : "");
|
||||
console.log(
|
||||
`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`,
|
||||
EnvConfig.get().logging.gatewayLogging.logTraces ? JSON.stringify(d._trace, null, 2) : "",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ const schema = EnvConfig.schema();
|
||||
const keyMap = [
|
||||
{
|
||||
name: "Name",
|
||||
selector: (v: {key: string}) => v.key
|
||||
selector: (v: { key: string }) => v.key,
|
||||
},
|
||||
{
|
||||
name: "Value",
|
||||
selector: (v: {type: string}) => v.type
|
||||
selector: (v: { type: string }) => v.type,
|
||||
},
|
||||
{
|
||||
name: "Description",
|
||||
selector: (v: {description: string}) => v.description
|
||||
}
|
||||
selector: (v: { description: string }) => v.description,
|
||||
},
|
||||
];
|
||||
// --- separators
|
||||
const startOfLine = dim("| "); // <tr>
|
||||
@@ -32,7 +32,7 @@ const headSeparator = dim("-");
|
||||
const pad = true;
|
||||
|
||||
// --- do not touch
|
||||
const colWidths: {[key: string]: number} = {};
|
||||
const colWidths: { [key: string]: number } = {};
|
||||
|
||||
console.log(bgRedBright("Calculating column widths"));
|
||||
for (const key of keyMap) {
|
||||
@@ -72,4 +72,4 @@ for (const entry of schema) {
|
||||
process.stdout.write(cell);
|
||||
}
|
||||
process.stdout.write(endOfLine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ export class AutomodExecutor {
|
||||
result = await this.executeMemberInvocation();
|
||||
} else throw new Error("Unsupported automod invocation type");
|
||||
|
||||
console.log(`[Automod] Executed automod invocation of type ${invocation.eventType} in ${Date.now() - startTime}ms with ${matchingRules.length} matching rules. Result: ${result.blocked ? "blocked" : "allowed"}`);
|
||||
console.log(
|
||||
`[Automod] Executed automod invocation of type ${invocation.eventType} in ${Date.now() - startTime}ms with ${matchingRules.length} matching rules. Result: ${result.blocked ? "blocked" : "allowed"}`,
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ export async function internalExecuteMessageAutomod(context: AutomodMessageInvoc
|
||||
}
|
||||
let triggered = false;
|
||||
// if (rule.trigger_type == AutomodRuleTriggerType.KEYWORD)
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './AutomodExecutor';
|
||||
export * from "./AutomodExecutor";
|
||||
|
||||
@@ -20,21 +20,24 @@ import { arrayOrderBy } from "@spacebar/util";
|
||||
|
||||
export class ConfigurationEnvConfiguration {
|
||||
static get schema() {
|
||||
return arrayOrderBy([
|
||||
{ key: "CONFIG_PATH", type: "string", description: "Path to a JSON file containing configuration data" },
|
||||
{ key: "CONFIG_WRITEBACK", type: "boolean", description: "Whether to write back configuration changes to the specified JSON file" },
|
||||
{
|
||||
key: "CONFIG_MODE",
|
||||
type: "string",
|
||||
description:
|
||||
"How to treat the JSON config.<br/>" +
|
||||
"<ul>" +
|
||||
"<li>**`override`**: Apply overrides without saving</li>" +
|
||||
"<li>**`overwrite`**: Apply overrides, saving changes to the database</li>" +
|
||||
"<li>**`single`**: Ignore database config outright</li>" +
|
||||
"</ul>",
|
||||
},
|
||||
], (e) => e.key);
|
||||
return arrayOrderBy(
|
||||
[
|
||||
{ key: "CONFIG_PATH", type: "string", description: "Path to a JSON file containing configuration data" },
|
||||
{ key: "CONFIG_WRITEBACK", type: "boolean", description: "Whether to write back configuration changes to the specified JSON file" },
|
||||
{
|
||||
key: "CONFIG_MODE",
|
||||
type: "string",
|
||||
description:
|
||||
"How to treat the JSON config.<br/>" +
|
||||
"<ul>" +
|
||||
"<li>**`override`**: Apply overrides without saving</li>" +
|
||||
"<li>**`overwrite`**: Apply overrides, saving changes to the database</li>" +
|
||||
"<li>**`single`**: Ignore database config outright</li>" +
|
||||
"</ul>",
|
||||
},
|
||||
],
|
||||
(e) => e.key,
|
||||
);
|
||||
}
|
||||
|
||||
get enabled(): boolean {
|
||||
|
||||
@@ -27,7 +27,8 @@ export class DatabaseEnvConfiguration {
|
||||
{
|
||||
key: "DB_UNSAFE_SCHEMA_SYNC",
|
||||
type: "boolean",
|
||||
description: "If true, the database schema will be forcibly synchronised. This is unsafe for production environments. **We claim no responsibility for data loss!**",
|
||||
description:
|
||||
"If true, the database schema will be forcibly synchronised. This is unsafe for production environments. **We claim no responsibility for data loss!**",
|
||||
},
|
||||
{
|
||||
key: "DB_DISABLE_JOINS",
|
||||
@@ -37,7 +38,7 @@ export class DatabaseEnvConfiguration {
|
||||
];
|
||||
}
|
||||
|
||||
get url(): (string | undefined) {
|
||||
get url(): string | undefined {
|
||||
return process.env.DATABASE;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,23 +30,34 @@ interface GatewayLoggingConfigValue {
|
||||
|
||||
export class LogEnvConfiguration {
|
||||
static get schema() {
|
||||
return arrayOrderBy([
|
||||
{ key: "LOG_CDN_SIGNATURES", type: "boolean", description: "Log CDN attachment signature checks - very noisy!" },
|
||||
{ key: "LOG_DATABASE_QUERIES", type: "boolean", description: "Enable logging of database queries." },
|
||||
{ key: "LOG_GATEWAY_EVENTS", type: "boolean", description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`." },
|
||||
{ key: "LOG_WEBRTC_EVENTS", type: "boolean", description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`." },
|
||||
{ key: "DUMP_GATEWAY_EVENT_PATH", type: "string", description: "Path to dump gateway events." },
|
||||
{ key: "DUMP_WEBRTC_EVENT_PATH", type: "string", description: "Path to dump gateway events." },
|
||||
{ key: "LOG_PROTO_UPDATES", type: "boolean or string", description: "`true`, or a list of proto schemas to log (`SETTINGS`, `FRECENCY`)" },
|
||||
{
|
||||
key: "LOG_REQUESTS",
|
||||
type: "string",
|
||||
description: "Comma-separated list of requests to log by status code. Negated with a leading `-`. Example: `-204` (log everything except 204 No Content)",
|
||||
},
|
||||
{ key: "LOG_AUTHENTICATION", type: "boolean", description: "Log authentication debug messages - very noisy!" },
|
||||
{ key: "LOG_VALIDATION_ERRORS", type: "boolean", description: "Enable logging of validation errors." },
|
||||
{ key: "LOG_IMPORT_ERRORS", type: "boolean", description: "Enable logging of import errors." },
|
||||
], (e) => e.key);
|
||||
return arrayOrderBy(
|
||||
[
|
||||
{ key: "LOG_CDN_SIGNATURES", type: "boolean", description: "Log CDN attachment signature checks - very noisy!" },
|
||||
{ key: "LOG_DATABASE_QUERIES", type: "boolean", description: "Enable logging of database queries." },
|
||||
{
|
||||
key: "LOG_GATEWAY_EVENTS",
|
||||
type: "boolean",
|
||||
description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`.",
|
||||
},
|
||||
{
|
||||
key: "LOG_WEBRTC_EVENTS",
|
||||
type: "boolean",
|
||||
description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`.",
|
||||
},
|
||||
{ key: "DUMP_GATEWAY_EVENT_PATH", type: "string", description: "Path to dump gateway events." },
|
||||
{ key: "DUMP_WEBRTC_EVENT_PATH", type: "string", description: "Path to dump gateway events." },
|
||||
{ key: "LOG_PROTO_UPDATES", type: "boolean or string", description: "`true`, or a list of proto schemas to log (`SETTINGS`, `FRECENCY`)" },
|
||||
{
|
||||
key: "LOG_REQUESTS",
|
||||
type: "string",
|
||||
description: "Comma-separated list of requests to log by status code. Negated with a leading `-`. Example: `-204` (log everything except 204 No Content)",
|
||||
},
|
||||
{ key: "LOG_AUTHENTICATION", type: "boolean", description: "Log authentication debug messages - very noisy!" },
|
||||
{ key: "LOG_VALIDATION_ERRORS", type: "boolean", description: "Enable logging of validation errors." },
|
||||
{ key: "LOG_IMPORT_ERRORS", type: "boolean", description: "Enable logging of import errors." },
|
||||
],
|
||||
(e) => e.key,
|
||||
);
|
||||
}
|
||||
|
||||
get gatewayLogging(): GatewayLoggingConfigValue {
|
||||
@@ -96,9 +107,7 @@ export class LogEnvConfiguration {
|
||||
logTraces: envVal?.includes("TRACES") || logDeprecated("LOG_WEBRTC_TRACES", "LOG_WEBRTC_EVENTS=TRACES") === "true",
|
||||
logUserId: envVal?.includes("USER_ID") ?? false,
|
||||
logSessionId: envVal?.includes("SESSION_ID") ?? false,
|
||||
logPayload:
|
||||
envVal?.includes("PAYLOAD") ||
|
||||
logDeprecated("WRTC_WS_VERBOSE", "LOG_WEBRTC_EVENTS=PAYLOAD") === "true",
|
||||
logPayload: envVal?.includes("PAYLOAD") || logDeprecated("WRTC_WS_VERBOSE", "LOG_WEBRTC_EVENTS=PAYLOAD") === "true",
|
||||
logHttp: envVal?.includes("HTTP") ?? false,
|
||||
logHttpMessages: envVal?.includes("HTTP_MESSAGES") ?? false,
|
||||
};
|
||||
@@ -111,7 +120,7 @@ export class LogEnvConfiguration {
|
||||
}
|
||||
|
||||
get dumpGatewayEventPath(): string | undefined {
|
||||
if(process.env.DUMP_GATEWAY_EVENT_PATH !== undefined) return process.env.DUMP_GATEWAY_EVENT_PATH;
|
||||
if (process.env.DUMP_GATEWAY_EVENT_PATH !== undefined) return process.env.DUMP_GATEWAY_EVENT_PATH;
|
||||
if (process.env.WS_DUMP !== undefined) {
|
||||
console.warn("[EnvConfig] WS_DUMP is deprecated. Please use DUMP_GATEWAY_EVENT_PATH=./dump instead.");
|
||||
return process.env.WS_DUMP ? "dump" : undefined;
|
||||
@@ -119,7 +128,7 @@ export class LogEnvConfiguration {
|
||||
}
|
||||
|
||||
get dumpWebrtcEventPath(): string | undefined {
|
||||
if(process.env.DUMP_WEBRTC_EVENT_PATH !== undefined) return process.env.DUMP_WEBRTC_EVENT_PATH;
|
||||
if (process.env.DUMP_WEBRTC_EVENT_PATH !== undefined) return process.env.DUMP_WEBRTC_EVENT_PATH;
|
||||
if (process.env.WRTC_DUMP !== undefined) {
|
||||
console.warn("[EnvConfig] WRTC_DUMP is deprecated. Please use DUMP_WEBRTC_EVENT_PATH=./dump_wrtc instead.");
|
||||
return process.env.WRTC_DUMP ? "dump_wrtc" : undefined;
|
||||
|
||||
@@ -20,12 +20,19 @@ import { arrayOrderBy } from "@spacebar/util";
|
||||
|
||||
export class WebRtcEnvConfiguration {
|
||||
static get schema() {
|
||||
return arrayOrderBy([
|
||||
{ key: "WRTC_PUBLIC_IP", type: "string", description: "Public IP of the server running the media server" },
|
||||
{ key: "WRTC_PORT_MIN", type: "number", description: "Minimum port for WebRTC media server" },
|
||||
{ key: "WRTC_PORT_MAX", type: "number", description: "Maximum port for WebRTC media server" },
|
||||
{ key: "WRTC_LIBRARY", type: "string", description: "WebRTC library to use. One of `@spacebarchat/medooze-webrtc` (voice+video) or `@spacebarchat/mediasoup-webrtc` (voice only)" },
|
||||
], (e) => e.key);
|
||||
return arrayOrderBy(
|
||||
[
|
||||
{ key: "WRTC_PUBLIC_IP", type: "string", description: "Public IP of the server running the media server" },
|
||||
{ key: "WRTC_PORT_MIN", type: "number", description: "Minimum port for WebRTC media server" },
|
||||
{ key: "WRTC_PORT_MAX", type: "number", description: "Maximum port for WebRTC media server" },
|
||||
{
|
||||
key: "WRTC_LIBRARY",
|
||||
type: "string",
|
||||
description: "WebRTC library to use. One of `@spacebarchat/medooze-webrtc` (voice+video) or `@spacebarchat/mediasoup-webrtc` (voice only)",
|
||||
},
|
||||
],
|
||||
(e) => e.key,
|
||||
);
|
||||
}
|
||||
|
||||
get publicIp(): string {
|
||||
|
||||
+1
-1
@@ -28,4 +28,4 @@ export * from "./imports";
|
||||
export * from "./config";
|
||||
export * from "./connections";
|
||||
export * from "./Signing";
|
||||
export * from "./automod";
|
||||
export * from "./automod";
|
||||
|
||||
@@ -49,7 +49,7 @@ export type UserTokenData = {
|
||||
};
|
||||
|
||||
function logAuth(text: string) {
|
||||
if(!EnvConfig.get().logging.logAuthentication) return;
|
||||
if (!EnvConfig.get().logging.logAuthentication) return;
|
||||
console.log(`[AUTH] ${text}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ export function arrayPartition<T>(array: T[], filter: (elem: T) => boolean): [T[
|
||||
return [pass, fail];
|
||||
}
|
||||
|
||||
|
||||
export function arrayRemove<T>(array: T[], item: T): void {
|
||||
const index = array.indexOf(item);
|
||||
if (index > -1) {
|
||||
@@ -62,4 +61,4 @@ export function arrayOrderByDescending<T>(array: T[], keySelector: (elem: T) =>
|
||||
if (keyA < keyB) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,11 @@ export async function Connection(this: WS.Server, socket: WebRtcWebSocket, reque
|
||||
console.log("[WebRTC] new connection", request.url);
|
||||
|
||||
if (EnvConfig.get().logging.gatewayLogging.logHttp) {
|
||||
[
|
||||
"close",
|
||||
"error",
|
||||
"upgrade",
|
||||
"open",
|
||||
"ping",
|
||||
"pong",
|
||||
"unexpected-response",
|
||||
...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : []),
|
||||
].forEach((x) => {
|
||||
socket.on(x, (y) => console.log("[WebRTC]", x, y));
|
||||
});
|
||||
["close", "error", "upgrade", "open", "ping", "pong", "unexpected-response", ...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : [])].forEach(
|
||||
(x) => {
|
||||
socket.on(x, (y) => console.log("[WebRTC]", x, y));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(`http://localhost${request.url}`);
|
||||
|
||||
@@ -24,10 +24,7 @@ export async function Send(socket: WebRtcWebSocket, data: VoicePayload) {
|
||||
await fs.mkdir(path.join(dumpPath!, id), {
|
||||
recursive: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
path.join(dumpPath!, id, `${Date.now()}.out.json`),
|
||||
JSON.stringify(data, null, 2),
|
||||
);
|
||||
await fs.writeFile(path.join(dumpPath!, id, `${Date.now()}.out.json`), JSON.stringify(data, null, 2));
|
||||
}
|
||||
|
||||
let buffer: Buffer | string;
|
||||
|
||||
Reference in New Issue
Block a user