1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-20 01:31:34 +02:00

Merge branch 'maddy/refactor' of github.com:fosscord/fosscord-server into maddy/refactor

This commit is contained in:
Madeline 2022-12-21 16:10:26 +11:00
commit b9f171d940
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
12 changed files with 214 additions and 45 deletions

View File

@ -23,7 +23,7 @@
BRAINTREE_KEY: "production_5st77rrc_49pp2rp4phym7387",
STRIPE_KEY: "pk_live_CUQtlpQUF0vufWpnpUmQvcdi",
MARKETING_ENDPOINT: "//discord.com",
RELEASE_CHANNEL: "stable",
RELEASE_CHANNEL: "canary",
ALGOLIA_KEY: "aca0d7082e4e63af5ba5917d5e96bed0"
};
GLOBAL_ENV.MEDIA_PROXY_ENDPOINT = location.protocol + "//" + GLOBAL_ENV.CDN_HOST;
@ -32,12 +32,12 @@
localStorage.setItem("gatewayURL", window.GLOBAL_ENV.GATEWAY_ENDPOINT);
localStorage.setItem(
"DeveloperOptionsStore",
`{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}`
`{"trace":false,"canary":true,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}`
);
</script>
<script src="/assets/38f40c32d3c8a2fdf73b.js" integrity=""></script>
<script src="/assets/aa190934324e05fcc35c.js" integrity=""></script>
<script src="/assets/45664a0209e828a528b4.js" integrity=""></script>
<script src="/assets/1cebe9b2b9ed8283ce52.js" integrity=""></script>
<script src="/assets/b48be57bceaf40c221ac.js" integrity=""></script>
<script src="/assets/b6e25718b296713dc29d.js" integrity=""></script>
</body>
</html>
</html>

View File

@ -24,7 +24,7 @@
INVITE_HOST: `${location.hostname}/invite`,
GUILD_TEMPLATE_HOST: "${location.host}/template",
GIFT_CODE_HOST: "${location.hostname}/gift",
RELEASE_CHANNEL: "stable",
RELEASE_CHANNEL: "canary",
MARKETING_ENDPOINT: "//discord.com",
BRAINTREE_KEY: "production_5st77rrc_49pp2rp4phym7387",
STRIPE_KEY: "pk_live_CUQtlpQUF0vufWpnpUmQvcdi",
@ -33,7 +33,7 @@
ACTIVITY_APPLICATION_HOST: "discordsays.com",
PROJECT_ENV: "production",
REMOTE_AUTH_ENDPOINT: "//localhost:3020",
SENTRY_TAGS: { buildId: "75e36d9", buildType: "normal" },
SENTRY_TAGS: { buildId: "d5b97e42230075cb9634c419c0cf4d2f8f9ada53", buildType: "normal" },
MIGRATION_SOURCE_ORIGIN: "https://${location.hostname}",
MIGRATION_DESTINATION_ORIGIN: "https://${location.hostname}",
HTML_TIMESTAMP: Date.now(),
@ -42,7 +42,7 @@
window.localStorage.setItem("gatewayURL", window.GLOBAL_ENV.GATEWAY_ENDPOINT);
window.localStorage.setItem(
"DeveloperOptionsStore",
`{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}`
`{"trace":false,"canary":true,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}`
);
</script>
@ -128,11 +128,11 @@
<body>
<div id="app-mount"></div>
<script src="/assets/83ace7450e110d16319e.js"></script>
<script src="/assets/e02290aaa8dac5d195c2.js"></script>
<script src="/assets/4f3b3c576b879a5f75d1.js"></script>
<script src="/assets/699456246fdfe7589855.js"></script>
<script src="/assets/b456855ec667950dcf68.js"></script>
<script src="/assets/cfb9efe961b2bf3647bc.js"></script>
<script src="/assets/f98a039261c37f892cbf.js"></script>
<script src="/assets/4470c87bb13810847db0.js"></script>
<!-- plugin marker -->
</body>
</html>
</html>

View File

@ -10863,6 +10863,10 @@
},
"private_channels_version": {
"type": "integer"
},
"guild_versions": {},
"api_code_version": {
"type": "integer"
}
},
"additionalProperties": false
@ -10885,6 +10889,10 @@
},
"useruserGuildSettingsVersion": {
"type": "integer"
},
"guildVersions": {},
"apiCodeVersion": {
"type": "integer"
}
},
"additionalProperties": false

View File

@ -34,7 +34,9 @@
"devDependencies": {
"@types/amqplib": "^0.8.2",
"@types/bcrypt": "^5.0.0",
"@types/body-parser": "^1.19.2",
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.15",
"@types/i18next-node-fs-backend": "^2.1.1",
"@types/json-bigint": "^1.0.1",
"@types/jsonwebtoken": "^8.5.9",
@ -59,6 +61,7 @@
"ajv-formats": "2.1.1",
"amqplib": "^0.10.3",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.1",
"cheerio": "^1.0.0-rc.12",
"cookie-parser": "^1.4.6",
"dotenv": "^16.0.2",
@ -73,6 +76,7 @@
"json-bigint": "^1.0.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.12",
"missing-native-js-functions": "^1.2.18",
"module-alias": "^2.2.2",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
@ -82,7 +86,9 @@
"picocolors": "^1.0.0",
"probe-image-size": "^7.2.3",
"proxy-agent": "^5.0.0",
"sqlite3": "^5.1.1",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.1.4",
"tslib": "^2.4.1",
"typeorm": "^0.3.10",
"typescript-json-schema": "0.50.1",
"ws": "^8.9.0"

View File

@ -16,7 +16,7 @@ const CACHE_PATH = path.join(__dirname, "..", "assets", "cache");
const CHANGELOG_PATH = path.join(__dirname, "..", "assets", "changelog.txt");
const BASE_URL = "https://discord.com";
const CHANGELOG_SCRIPT = "9c4b2d313c6e1c864e89.js";
const CHANGELOG_SCRIPT = "4ec0b5948572d31df88b.js";
(async () => {
const res = await fetch(`${BASE_URL}/assets/${CHANGELOG_SCRIPT}`);
@ -28,7 +28,7 @@ const CHANGELOG_SCRIPT = "9c4b2d313c6e1c864e89.js";
.replaceAll("\n", "\\n")
.replaceAll("\'", "\\'");
const index = text.indexOf("e.exports='---changelog---") + 11;
const index = text.indexOf("t.exports='---changelog---") + 11;
const endIndex = text.indexOf("'\n", index); // hmm
await fs.writeFile(

View File

@ -35,10 +35,10 @@ const INSTANCE_NAME = "Fosscord";
// Manual for now
const INDEX_SCRIPTS = [
"83ace7450e110d16319e", // 50
"e02290aaa8dac5d195c2", // 1
"4f3b3c576b879a5f75d1", // 0?
"699456246fdfe7589855", // ~4500.
"b456855ec667950dcf68", // 50
"cfb9efe961b2bf3647bc", // 1
"f98a039261c37f892cbf", // 0?
"4470c87bb13810847db0", // ~4500.
];
const doPatch = (content) => {
@ -86,11 +86,11 @@ const doPatch = (content) => {
['"Servers,"', '"Guilds,"'],
[' Servers,"', ' Guilds,"'],
[' Servers,', ' Guilds,'],
['\nServers', '\nGuilds'],
];
serverVariations.forEach(x => serverVariations.push([x[0].toLowerCase(), x[1].toLowerCase()]));
serverVariations.forEach(x => content = content.replaceAll(x[0], x[1]));
// can't match \nServers for some reason
content = content.replaceAll('Servers in the Hub are student-run, but may include non-students."', 'Guilds in the Hub are student-run, but may include non-students."');
// sentry
content = content.replaceAll("https://fa97a90475514c03a42f80cd36d147c4@sentry.io/140984", "https://05e8e3d005f34b7d97e920ae5870a5e5@sentry.thearcanebrony.net/6");
@ -100,17 +100,7 @@ const doPatch = (content) => {
"M23.0212 1.67671C21.3107 0.879656 19.5079 0.318797 17.6584 0C17.4062 0.461742 17.1749 0.934541 16.9708 1.4184C15.003 1.12145 12.9974 1.12145 11.0283 1.4184C10.819 0.934541 10.589 0.461744 10.3368 0.00546311C8.48074 0.324393 6.67795 0.885118 4.96746 1.68231C1.56727 6.77853 0.649666 11.7538 1.11108 16.652C3.10102 18.1418 5.3262 19.2743 7.69177 20C8.22338 19.2743 8.69519 18.4993 9.09812 17.691C8.32996 17.3997 7.58522 17.0424 6.87684 16.6135C7.06531 16.4762 7.24726 16.3387 7.42403 16.1847C11.5911 18.1749 16.408 18.1749 20.5763 16.1847C20.7531 16.3332 20.9351 16.4762 21.1171 16.6135C20.41 17.0369 19.6639 17.3997 18.897 17.691C19.3052 18.4993 19.7718 19.2689 20.3021 19.9945C22.6677 19.2689 24.8929 18.1364 26.8828 16.6466H26.8893C27.43 10.9731 25.9665 6.04728 23.0212 1.67671ZM9.68041 13.6383C8.39754 13.6383 7.34085 12.4453 7.34085 10.994C7.34085 9.54272 8.37155 8.34973 9.68041 8.34973C10.9893 8.34973 12.0395 9.54272 12.0187 10.994C12.0187 12.4453 10.9828 13.6383 9.68041 13.6383ZM18.3161 13.6383C17.0332 13.6383 15.9765 12.4453 15.9765 10.994C15.9765 9.54272 17.0124 8.34973 18.3161 8.34973C19.6184 8.34973 20.6751 9.54272 20.6543 10.994C20.6543 12.4453 19.6184 13.6383 18.3161 13.6383Z",
"M 0,0 47.999993,2.7036528e-4 C 48.001796,3.3028172 47.663993,6.5968018 46.991821,9.8301938 43.116101,28.454191 28.452575,43.116441 9.8293509,46.992163 6.5960834,47.664163 3.3023222,48.001868 0,47.999992 Z m 9.8293509,28.735114 v 9.248482 C 22.673599,33.047696 32.857154,22.749268 37.63852,9.829938 H 9.8293509 v 8.679899 H 22.931288 c -3.554489,3.93617 -7.735383,7.257633 -12.373436,9.829938 -0.241031,0.133684 -0.483864,0.265492 -0.7285011,0.395339 z"
);
content = content.replaceAll('width:n,height:o,viewBox:"0 0 28 20"', 'width:48,height:48,viewBox:"0 0 48 48"');
//save some time on load resolving asset urls...
content = content.replaceAll(
'e.exports = n.p + "',
'e.exports = "/assets/',
);
content = content.replaceAll(
'e.exports = r.p + "',
'e.exports = "/assets/',
);
content = content.replaceAll('width:n,height:c,viewBox:"0 0 28 20"', 'width:50,height:50,viewBox:"0 0 50 50"');
// app download links
// content = content.replaceAll(

View File

@ -22,6 +22,8 @@ import {
IdentifySchema,
DefaultUserGuildSettings,
UserGuildSettings,
ReadyGuildDTO,
Guild,
} from "@fosscord/util";
import { Send } from "../util/Send";
import { CLOSECODES, OPCODES } from "../util/Constants";
@ -255,17 +257,17 @@ export async function onIdentify(this: WebSocket, data: Payload) {
};
const d: ReadyEventData = {
v: 8,
v: 9,
application: { id: application?.id ?? '', flags: application?.flags ?? 0 }, //TODO: check this code!
user: privateUser,
user_settings: user.settings,
// @ts-ignore
guilds: guilds.map((x) => {
// @ts-ignore
x.guild_hashes = {}; // @ts-ignore
x.guild_scheduled_events = []; // @ts-ignore
x.threads = [];
return x;
return {
...new ReadyGuildDTO(x as Guild & { joined_at: Date }).toJSON(),
guild_hashes: {},
joined_at: x.joined_at
};
}),
guild_experiments: [], // TODO
geo_ordered_rtc_regions: [], // TODO
@ -298,8 +300,6 @@ export async function onIdentify(this: WebSocket, data: Payload) {
merged_members: merged_members,
// shard // TODO: only for user sharding
sessions: [], // TODO:
presences: [], // TODO:
tutorial: null,
};
// TODO: send real proper data structure

View File

@ -0,0 +1,153 @@
import { Channel, Emoji, Guild, Member, Role, Sticker } from "../entities";
export interface IReadyGuildDTO {
application_command_counts?: { 1: number; 2: number; 3: number }; // ????????????
channels: Channel[];
data_mode: string; // what is this
emojis: Emoji[];
guild_scheduled_events: any[];
id: string;
large: boolean | undefined;
lazy: boolean;
member_count: number | undefined;
members: Member[];
premium_subscription_count: number | undefined;
properties: {
name: string;
description?: string | null;
icon?: string | null;
splash?: string | null;
banner?: string | null;
features: string[];
preferred_locale?: string | null;
owner_id?: string | null;
application_id?: string | null;
afk_channel_id?: string | null;
afk_timeout: number | undefined;
system_channel_id?: string | null;
verification_level: number | undefined;
explicit_content_filter: number | undefined;
default_message_notifications: number | undefined;
mfa_level: number | undefined;
vanity_url_code?: string | null;
premium_tier: number | undefined;
premium_progress_bar_enabled: boolean;
system_channel_flags: number | undefined;
discovery_splash?: string | null;
rules_channel_id?: string | null;
public_updates_channel_id?: string | null;
max_video_channel_users: number | undefined;
max_members: number | undefined;
nsfw_level: number | undefined;
hub_type?: any | null; // ????
};
roles: Role[];
stage_instances: any[];
stickers: Sticker[];
threads: any[];
version: string;
}
export class ReadyGuildDTO implements IReadyGuildDTO {
application_command_counts?: { 1: number; 2: number; 3: number }; // ????????????
channels: Channel[];
data_mode: string; // what is this
emojis: Emoji[];
guild_scheduled_events: any[];
id: string;
large: boolean | undefined;
lazy: boolean;
member_count: number | undefined;
members: Member[];
premium_subscription_count: number | undefined;
properties: {
name: string;
description?: string | null;
icon?: string | null;
splash?: string | null;
banner?: string | null;
features: string[];
preferred_locale?: string | null;
owner_id?: string | null;
application_id?: string | null;
afk_channel_id?: string | null;
afk_timeout: number | undefined;
system_channel_id?: string | null;
verification_level: number | undefined;
explicit_content_filter: number | undefined;
default_message_notifications: number | undefined;
mfa_level: number | undefined;
vanity_url_code?: string | null;
premium_tier: number | undefined;
premium_progress_bar_enabled: boolean;
system_channel_flags: number | undefined;
discovery_splash?: string | null;
rules_channel_id?: string | null;
public_updates_channel_id?: string | null;
max_video_channel_users: number | undefined;
max_members: number | undefined;
nsfw_level: number | undefined;
hub_type?: any | null; // ????
};
roles: Role[];
stage_instances: any[];
stickers: Sticker[];
threads: any[];
version: string;
constructor(guild: Guild) {
this.application_command_counts = {
1: 5,
2: 2,
3: 2,
}; // ?????
this.channels = guild.channels;
this.data_mode = "full";
this.emojis = guild.emojis;
this.guild_scheduled_events = [];
this.id = guild.id;
this.large = guild.large;
this.lazy = true; // ??????????
this.member_count = guild.member_count;
this.members = guild.members;
this.premium_subscription_count = guild.premium_subscription_count;
this.properties = {
name: guild.name,
description: guild.description,
icon: guild.icon,
splash: guild.splash,
banner: guild.banner,
features: guild.features,
preferred_locale: guild.preferred_locale,
owner_id: guild.owner_id,
application_id: null, // ?????
afk_channel_id: guild.afk_channel_id,
afk_timeout: guild.afk_timeout,
system_channel_id: guild.system_channel_id,
verification_level: guild.verification_level,
explicit_content_filter: guild.explicit_content_filter,
default_message_notifications: guild.default_message_notifications,
mfa_level: guild.mfa_level,
vanity_url_code: null, // ?????
premium_tier: guild.premium_tier,
premium_progress_bar_enabled: guild.premium_progress_bar_enabled,
system_channel_flags: guild.system_channel_flags,
discovery_splash: guild.discovery_splash,
rules_channel_id: guild.rules_channel_id,
public_updates_channel_id: guild.public_updates_channel_id,
max_video_channel_users: guild.max_video_channel_users,
max_members: guild.max_members,
nsfw_level: guild.nsfw_level,
hub_type: null,
};
this.roles = guild.roles;
this.stage_instances = [];
this.stickers = guild.stickers;
this.threads = [];
this.version = "1"; // ??????
}
toJSON() {
return this as IReadyGuildDTO;
}
}

View File

@ -1,2 +1,3 @@
export * from "./DmChannelDTO";
export * from "./ReadyGuildDTO";
export * from "./UserDTO";

View File

@ -29,6 +29,7 @@ import { Role } from "./Role";
import { BaseClassWithoutId } from "./BaseClass";
import { Ban, PublicGuildRelations } from ".";
import { DiscordApiErrors } from "../util/Constants";
import { ReadyGuildDTO } from "../dtos";
export const MemberPrivateProjection: (keyof Member)[] = [
"id",
@ -363,7 +364,7 @@ export class Member extends BaseClassWithoutId {
emitEvent({
event: "GUILD_CREATE",
data: {
...guild,
...new ReadyGuildDTO(guild).toJSON(),
members: [...memberPreview, { ...member, user }],
member_count: memberCount + 1,
guild_hashes: {},
@ -373,6 +374,7 @@ export class Member extends BaseClassWithoutId {
stage_instances: [],
threads: [],
embedded_activities: [],
voice_states: guild.voice_states
},
user_id,
} as GuildCreateEvent),

View File

@ -20,6 +20,7 @@ import {
Status,
Presence,
UserSettings,
IReadyGuildDTO,
} from "@fosscord/util";
export interface Event {
@ -62,7 +63,7 @@ export interface ReadyEventData {
};
private_channels: Channel[]; // this will be empty for bots
session_id: string; // resuming
guilds: Guild[];
guilds: IReadyGuildDTO[];
analytics_token?: string;
connected_accounts?: ConnectedAccount[];
consents?: {
@ -155,7 +156,7 @@ export interface ChannelRecipientRemoveEvent extends Event {
export interface GuildCreateEvent extends Event {
event: "GUILD_CREATE";
data: Guild & {
data: IReadyGuildDTO & {
joined_at: Date;
// TODO: add them to guild
guild_scheduled_events: never[];

View File

@ -44,6 +44,8 @@ export const IdentifySchema = {
$user_settings_version: undefined,
$useruser_guild_settings_version: undefined,
$private_channels_version: Number,
$guild_versions: Object,
$api_code_version: Number,
},
$clientState: {
$guildHashes: Object,
@ -51,6 +53,8 @@ export const IdentifySchema = {
$readStateVersion: Number,
$useruserGuildSettingsVersion: undefined,
$userGuildSettingsVersion: undefined,
$guildVersions: Object,
$apiCodeVersion: Number,
},
$v: Number,
$version: Number,
@ -96,6 +100,8 @@ export interface IdentifySchema {
user_settings_version?: number;
useruser_guild_settings_version?: number;
private_channels_version?: number;
guild_versions?: any;
api_code_version?: number;
};
clientState?: {
guildHashes?: any;
@ -103,6 +109,8 @@ export interface IdentifySchema {
readStateVersion?: number;
userGuildSettingsVersion?: number;
useruserGuildSettingsVersion?: number;
guildVersions?: any;
apiCodeVersion?: number;
};
v?: number;
}