1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 02:12:40 +01:00

Merge branch 'master' into feat/federation

This commit is contained in:
Madeline 2023-09-22 15:39:15 +10:00
commit 3c46914992
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
22 changed files with 398 additions and 376 deletions

View File

@ -2,9 +2,9 @@ name: Build
on: on:
push: push:
branches: [ "**" ] branches: [ "master" ]
pull_request: pull_request:
branches: [ "**" ] branches: [ "master" ]
jobs: jobs:
build: build:

View File

@ -2,9 +2,9 @@ name: Style
on: on:
push: push:
branches: [ "**" ] branches: [ "master" ]
pull_request: pull_request:
branches: [ "**" ] branches: [ "master" ]
jobs: jobs:
build: build:

View File

@ -16,6 +16,9 @@
## [About](https://spacebar.chat) ## [About](https://spacebar.chat)
Spacebar/server is a Discord backend re-implementation and extension.
We aim to reverse engineer and add additional features to the Discord backend, while remaining completely backwards compatible with existing bots, applications, and clients.
This repository contains: This repository contains:
- [Spacebar HTTP API Server](/src/api) - [Spacebar HTTP API Server](/src/api)
@ -23,6 +26,13 @@ This repository contains:
- [HTTP CDN Server](/src/cdn) - [HTTP CDN Server](/src/cdn)
- [Utility and Database Models](/src/util) - [Utility and Database Models](/src/util)
## [Documentation](https://docs.spacebar.chat)
## [Contributing](https://docs.spacebar.chat/contributing/) ## [Contributing](https://docs.spacebar.chat/contributing/)
## [Setup](https://docs.spacebar.chat/setup/server/) ## Clients
You *should* be able to use any client designed for Discord.com to connect to a Spacebar instance.
However, some incompatibilities still exist between Spacebar and Discord. For this reason, not every client will connect.
The [WIP official Spacebar client](https://github.com/spacebarchat/client) will always work.
You can find a [live version here](https://app.spacebar.chat).

View File

@ -1348,7 +1348,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -4912,7 +4911,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -8476,7 +8474,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -12035,7 +12032,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -15630,7 +15626,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -19194,7 +19189,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -22749,7 +22743,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -26307,7 +26300,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -29874,7 +29866,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -33429,7 +33420,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -36984,7 +36974,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -40558,7 +40547,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -44116,7 +44104,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -47734,7 +47721,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -51311,7 +51297,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -55029,7 +55014,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -58605,7 +58589,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -62191,7 +62174,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -65759,7 +65741,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -69333,7 +69314,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -72897,7 +72877,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -76456,7 +76435,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -80119,7 +80097,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -83779,7 +83756,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -87334,7 +87310,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -90897,7 +90872,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -94453,7 +94427,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -98009,7 +97982,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -101600,7 +101572,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -105156,7 +105127,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -108711,7 +108681,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -112281,7 +112250,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -115840,7 +115808,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -119473,7 +119440,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -123028,7 +122994,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -126583,7 +126548,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -130135,7 +130099,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -133693,7 +133656,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -137261,7 +137223,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -140813,7 +140774,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -144414,7 +144374,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -148001,7 +147960,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -151553,7 +151511,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -155130,7 +155087,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -157694,6 +157650,16 @@
"UserSettingsSchema": { "UserSettingsSchema": {
"type": "object", "type": "object",
"properties": { "properties": {
"status": {
"enum": [
"dnd",
"idle",
"invisible",
"offline",
"online"
],
"type": "string"
},
"afk_timeout": { "afk_timeout": {
"type": "integer" "type": "integer"
}, },
@ -157791,16 +157757,6 @@
"show_current_game": { "show_current_game": {
"type": "boolean" "type": "boolean"
}, },
"status": {
"enum": [
"dnd",
"idle",
"invisible",
"offline",
"online"
],
"type": "string"
},
"stream_notifications_enabled": { "stream_notifications_enabled": {
"type": "boolean" "type": "boolean"
}, },
@ -158796,7 +158752,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -162347,7 +162302,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -165937,7 +165891,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -169515,7 +169468,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -173145,7 +173097,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -176697,7 +176648,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -180257,7 +180207,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -183807,7 +183756,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -187363,7 +187311,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -190919,7 +190866,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -194475,7 +194421,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -198035,7 +197980,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -201591,7 +201535,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -205158,7 +205101,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -208739,7 +208681,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -212291,7 +212232,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -215846,7 +215786,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -219430,7 +219369,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -222982,7 +222920,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -226613,7 +226550,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -230172,7 +230108,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -233724,7 +233659,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -237276,7 +237210,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -240835,7 +240768,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -244391,7 +244323,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -247943,7 +247874,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -251570,7 +251500,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -255133,7 +255062,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -258697,7 +258625,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -262311,7 +262238,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -265884,7 +265810,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -269463,7 +269388,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -273036,7 +272960,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -276588,7 +276511,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -280168,7 +280090,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -283760,7 +283681,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -287306,7 +287226,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -290862,7 +290781,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -294414,7 +294332,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -297973,7 +297890,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -301613,7 +301529,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -305157,7 +305072,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -308701,7 +308615,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -312245,7 +312158,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -315812,7 +315724,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -319372,7 +319283,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -323041,7 +322951,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -326611,7 +326520,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -330175,7 +330083,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -333731,7 +333638,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -337297,7 +337203,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -340853,7 +340758,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -344396,7 +344300,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -347951,7 +347854,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -351521,7 +351423,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -355095,7 +354996,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -358648,7 +358548,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -362200,7 +362099,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -365752,7 +365650,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",
@ -369310,7 +369207,6 @@
"created_at", "created_at",
"default_thread_rate_limit_per_user", "default_thread_rate_limit_per_user",
"flags", "flags",
"guild",
"id", "id",
"nsfw", "nsfw",
"owner", "owner",

122
package-lock.json generated
View File

@ -11,9 +11,8 @@
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.385.0", "@aws-sdk/client-s3": "^3.385.0",
"@sentry/integrations": "^7.61.1", "@sentry/integrations": "^7.66.0",
"@sentry/node": "^7.61.1", "@sentry/node": "^7.66.0",
"@sentry/tracing": "^7.61.1",
"ajv": "8.6.2", "ajv": "8.6.2",
"ajv-formats": "2.1.1", "ajv-formats": "2.1.1",
"amqplib": "^0.10.3", "amqplib": "^0.10.3",
@ -1249,40 +1248,13 @@
"node": "6.* || 8.* || >=10.*" "node": "6.* || 8.* || >=10.*"
} }
}, },
"node_modules/@sentry-internal/tracing": {
"version": "7.63.0",
"resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.63.0.tgz",
"integrity": "sha512-Fxpc53p6NGvLSURg3iRvZA0k10K9yfeVhtczvJnpX30POBuV41wxpkLHkb68fjksirjEma1K3Ut1iLOEEDpPQg==",
"dependencies": {
"@sentry/core": "7.63.0",
"@sentry/types": "7.63.0",
"@sentry/utils": "7.63.0",
"tslib": "^2.4.1 || ^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/core": {
"version": "7.63.0",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.63.0.tgz",
"integrity": "sha512-13Ljiq8hv6ieCkO+Am99/PljYJO5ynKT/hRQrWgGy9IIEgUr8sV3fW+1W6K4/3MCeOJou0HsiGBjOD1mASItVg==",
"dependencies": {
"@sentry/types": "7.63.0",
"@sentry/utils": "7.63.0",
"tslib": "^2.4.1 || ^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/integrations": { "node_modules/@sentry/integrations": {
"version": "7.63.0", "version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/integrations/-/integrations-7.63.0.tgz", "resolved": "https://registry.npmjs.org/@sentry/integrations/-/integrations-7.66.0.tgz",
"integrity": "sha512-+P8GNqFZNH/yS/KPbvUfUDERneoRNUrqp9ayvvp8aq4cTtrBdM72CYgI21oG6cti42SSM1VDLYZomTV3ElPzSg==", "integrity": "sha512-2PNEnihG9e9Rjbz205+A4BYtFcS2XdgwsN6obAU6Yir7VIbskwZXxx87lKZuz6S53sOWPHleC7uvUBjL+Q6vYg==",
"dependencies": { "dependencies": {
"@sentry/types": "7.63.0", "@sentry/types": "7.66.0",
"@sentry/utils": "7.63.0", "@sentry/utils": "7.66.0",
"localforage": "^1.8.1", "localforage": "^1.8.1",
"tslib": "^2.4.1 || ^1.9.3" "tslib": "^2.4.1 || ^1.9.3"
}, },
@ -1290,15 +1262,35 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/@sentry/node": { "node_modules/@sentry/integrations/node_modules/@sentry/types": {
"version": "7.63.0", "version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.63.0.tgz", "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.66.0.tgz",
"integrity": "sha512-tSMyfQNbfjX1w8vJDZtvWeaD4QQ/Z4zVW/TLXfL/JZFIIksPgDZmqLdF+NJS4bSGTU5JiHiUh4pYhME4mHgNBQ==", "integrity": "sha512-uUMSoSiar6JhuD8p7ON/Ddp4JYvrVd2RpwXJRPH1A4H4Bd4DVt1mKJy1OLG6HdeQv39XyhB1lPZckKJg4tATPw==",
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/integrations/node_modules/@sentry/utils": {
"version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.66.0.tgz",
"integrity": "sha512-9GYUVgXjK66uXXcLXVMXVzlptqMtq1eJENCuDeezQiEFrNA71KkLDg00wESp+LL+bl3wpVTBApArpbF6UEG5hQ==",
"dependencies": { "dependencies": {
"@sentry-internal/tracing": "7.63.0", "@sentry/types": "7.66.0",
"@sentry/core": "7.63.0", "tslib": "^2.4.1 || ^1.9.3"
"@sentry/types": "7.63.0", },
"@sentry/utils": "7.63.0", "engines": {
"node": ">=8"
}
},
"node_modules/@sentry/node": {
"version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.66.0.tgz",
"integrity": "sha512-PxqIqLr4Sh5xcDfECiBQ4PuZ7v8yTgLhaRkruWrZPYxQrcJFPkwbFkw/IskzVnhT2VwXUmeWEIlRMQKBJ0t83A==",
"dependencies": {
"@sentry-internal/tracing": "7.66.0",
"@sentry/core": "7.66.0",
"@sentry/types": "7.66.0",
"@sentry/utils": "7.66.0",
"cookie": "^0.4.1", "cookie": "^0.4.1",
"https-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0",
"lru_map": "^0.3.3", "lru_map": "^0.3.3",
@ -1308,31 +1300,47 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/@sentry/tracing": { "node_modules/@sentry/node/node_modules/@sentry-internal/tracing": {
"version": "7.63.0", "version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.63.0.tgz", "resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.66.0.tgz",
"integrity": "sha512-91gjqM/3CD6XdN1JVSLnUTD7HAI77NodP48+FZ2kgRkNmD2jojJBWsTC9NHG4UEO0PppjjwDPPJR1iHwybaO8g==", "integrity": "sha512-3vCgC2hC3T45pn53yTDVcRpHoJTBxelDPPZVsipAbZnoOVPkj7n6dNfDhj3I3kwWCBPahPkXmE+R4xViR8VqJg==",
"dependencies": { "dependencies": {
"@sentry-internal/tracing": "7.63.0" "@sentry/core": "7.66.0",
"@sentry/types": "7.66.0",
"@sentry/utils": "7.66.0",
"tslib": "^2.4.1 || ^1.9.3"
}, },
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/@sentry/types": { "node_modules/@sentry/node/node_modules/@sentry/core": {
"version": "7.63.0", "version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.63.0.tgz", "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.66.0.tgz",
"integrity": "sha512-pZNwJVW7RqNLGuTUAhoygt0c9zmc0js10eANAz0MstygJRhQI1tqPDuiELVdujPrbeL+IFKF+7NvRDAydR2Niw==", "integrity": "sha512-WMAEPN86NeCJ1IT48Lqiz4MS5gdDjBwP4M63XP4msZn9aujSf2Qb6My5uT87AJr9zBtgk8MyJsuHr35F0P3q1w==",
"dependencies": {
"@sentry/types": "7.66.0",
"@sentry/utils": "7.66.0",
"tslib": "^2.4.1 || ^1.9.3"
},
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/@sentry/utils": { "node_modules/@sentry/node/node_modules/@sentry/types": {
"version": "7.63.0", "version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.63.0.tgz", "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.66.0.tgz",
"integrity": "sha512-7FQv1RYAwnuTuarruP+1+Jd6YQuN7i/Y7KltwPMVEwU7j5mzYQaexLr/Jz1XIdR2KYVdkbXQyP8jj8BmA6u9Jw==", "integrity": "sha512-uUMSoSiar6JhuD8p7ON/Ddp4JYvrVd2RpwXJRPH1A4H4Bd4DVt1mKJy1OLG6HdeQv39XyhB1lPZckKJg4tATPw==",
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/node/node_modules/@sentry/utils": {
"version": "7.66.0",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.66.0.tgz",
"integrity": "sha512-9GYUVgXjK66uXXcLXVMXVzlptqMtq1eJENCuDeezQiEFrNA71KkLDg00wESp+LL+bl3wpVTBApArpbF6UEG5hQ==",
"dependencies": { "dependencies": {
"@sentry/types": "7.63.0", "@sentry/types": "7.66.0",
"tslib": "^2.4.1 || ^1.9.3" "tslib": "^2.4.1 || ^1.9.3"
}, },
"engines": { "engines": {

View File

@ -68,9 +68,8 @@
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.385.0", "@aws-sdk/client-s3": "^3.385.0",
"@sentry/integrations": "^7.61.1", "@sentry/integrations": "^7.66.0",
"@sentry/node": "^7.61.1", "@sentry/node": "^7.66.0",
"@sentry/tracing": "^7.61.1",
"ajv": "8.6.2", "ajv": "8.6.2",
"ajv-formats": "2.1.1", "ajv-formats": "2.1.1",
"amqplib": "^0.10.3", "amqplib": "^0.10.3",

View File

@ -72,6 +72,7 @@ function main() {
(x.endsWith("Schema") || (x.endsWith("Schema") ||
x.endsWith("Response") || x.endsWith("Response") ||
x.startsWith("API")) && x.startsWith("API")) &&
!x.startsWith("AP") &&
!Excluded.includes(x) !Excluded.includes(x)
); );
}); });

View File

@ -126,7 +126,7 @@ export const messageFromAP = async (data: APNote): Promise<Message> => {
const member = const member =
channel instanceof Channel channel instanceof Channel
? await Member.findOneOrFail({ ? await Member.findOneOrFail({
where: { id: user.id, guild_id: channel.guild.id }, where: { id: user.id, guild_id: channel.guild!.id },
}) })
: undefined; : undefined;

View File

@ -40,7 +40,13 @@ import {
import { Request, Response, Router } from "express"; import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server"; import { HTTPError } from "lambert-server";
import multer from "multer"; import multer from "multer";
import { FindManyOptions, FindOperator, LessThan, MoreThan } from "typeorm"; import {
FindManyOptions,
FindOperator,
LessThan,
MoreThan,
MoreThanOrEqual,
} from "typeorm";
import { URL } from "url"; import { URL } from "url";
const router: Router = Router(); const router: Router = Router();
@ -122,12 +128,24 @@ router.get(
if (around) { if (around) {
query.take = Math.floor(limit / 2); query.take = Math.floor(limit / 2);
if (query.take != 0) {
const [right, left] = await Promise.all([ const [right, left] = await Promise.all([
Message.find({ ...query, where: { id: LessThan(around) } }), Message.find({ ...query, where: { id: LessThan(around) } }),
Message.find({ ...query, where: { id: MoreThan(around) } }), Message.find({
...query,
where: { id: MoreThanOrEqual(around) },
}),
]); ]);
right.push(...left); left.push(...right);
messages = right; messages = left;
} else {
query.take = 1;
const message = await Message.findOne({
...query,
where: { id: around },
});
messages = message ? [message] : [];
}
} else { } else {
if (after) { if (after) {
if (BigInt(after) > BigInt(Snowflake.generate())) if (BigInt(after) > BigInt(Snowflake.generate()))

View File

@ -18,6 +18,7 @@
import { route } from "@spacebar/api"; import { route } from "@spacebar/api";
import { import {
DiscordApiErrors,
emitEvent, emitEvent,
Emoji, Emoji,
getPermission, getPermission,
@ -198,7 +199,9 @@ router.put(
member_id = req.user_id; member_id = req.user_id;
rights.hasThrow("JOIN_GUILDS"); rights.hasThrow("JOIN_GUILDS");
} else { } else {
// TODO: join others by controller // TODO: check oauth2 scope
throw DiscordApiErrors.MISSING_REQUIRED_OAUTH2_SCOPE;
} }
const guild = await Guild.findOneOrFail({ const guild = await Guild.findOneOrFail({

View File

@ -16,12 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { Config, Embed, EmbedType } from "@spacebar/util"; import { Config, Embed, EmbedImage, EmbedType } from "@spacebar/util";
import fetch, { RequestInit } from "node-fetch";
import * as cheerio from "cheerio"; import * as cheerio from "cheerio";
import probe from "probe-image-size";
import crypto from "crypto"; import crypto from "crypto";
import fetch, { RequestInit } from "node-fetch";
import { yellow } from "picocolors"; import { yellow } from "picocolors";
import probe from "probe-image-size";
export const DEFAULT_FETCH_OPTIONS: RequestInit = { export const DEFAULT_FETCH_OPTIONS: RequestInit = {
redirect: "follow", redirect: "follow",
@ -35,6 +35,20 @@ export const DEFAULT_FETCH_OPTIONS: RequestInit = {
method: "GET", method: "GET",
}; };
const makeEmbedImage = (
url: string | undefined,
width: number | undefined,
height: number | undefined,
): Required<EmbedImage> | undefined => {
if (!url || !width || !height) return undefined;
return {
url,
width,
height,
proxy_url: getProxyUrl(new URL(url), width, height),
};
};
let hasWarnedAboutImagor = false; let hasWarnedAboutImagor = false;
export const getProxyUrl = ( export const getProxyUrl = (
@ -78,13 +92,24 @@ export const getProxyUrl = (
const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => { const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => {
let elem = $(`meta[property="${name}"]`); let elem = $(`meta[property="${name}"]`);
if (!elem.length) elem = $(`meta[name="${name}"]`); if (!elem.length) elem = $(`meta[name="${name}"]`);
return elem.attr("content") || elem.text(); const ret = elem.attr("content") || elem.text();
return ret.trim().length == 0 ? undefined : ret;
};
const tryParseInt = (str: string | undefined) => {
if (!str) return undefined;
try {
return parseInt(str);
} catch (e) {
return undefined;
}
}; };
export const getMetaDescriptions = (text: string) => { export const getMetaDescriptions = (text: string) => {
const $ = cheerio.load(text); const $ = cheerio.load(text);
return { return {
type: getMeta($, "og:type"),
title: getMeta($, "og:title") || $("title").first().text(), title: getMeta($, "og:title") || $("title").first().text(),
provider_name: getMeta($, "og:site_name"), provider_name: getMeta($, "og:site_name"),
author: getMeta($, "article:author"), author: getMeta($, "article:author"),
@ -92,10 +117,13 @@ export const getMetaDescriptions = (text: string) => {
image: getMeta($, "og:image") || getMeta($, "twitter:image"), image: getMeta($, "og:image") || getMeta($, "twitter:image"),
image_fallback: $(`image`).attr("src"), image_fallback: $(`image`).attr("src"),
video_fallback: $(`video`).attr("src"), video_fallback: $(`video`).attr("src"),
width: parseInt(getMeta($, "og:image:width") || "0"), width: tryParseInt(getMeta($, "og:image:width")),
height: parseInt(getMeta($, "og:image:height") || "0"), height: tryParseInt(getMeta($, "og:image:height")),
url: getMeta($, "og:url"), url: getMeta($, "og:url"),
youtube_embed: getMeta($, "og:video:secure_url"), youtube_embed: getMeta($, "og:video:secure_url"),
site_name: getMeta($, "og:site_name"),
$,
}; };
}; };
@ -116,13 +144,11 @@ const genericImageHandler = async (url: URL): Promise<Embed | null> => {
method: "HEAD", method: "HEAD",
}); });
let width, height, image; let image;
if (type.headers.get("content-type")?.indexOf("image") !== -1) { if (type.headers.get("content-type")?.indexOf("image") !== -1) {
const result = await probe(url.href); const result = await probe(url.href);
width = result.width; image = makeEmbedImage(url.href, result.width, result.height);
height = result.height;
image = url.href;
} else if (type.headers.get("content-type")?.indexOf("video") !== -1) { } else if (type.headers.get("content-type")?.indexOf("video") !== -1) {
// TODO // TODO
return null; return null;
@ -131,22 +157,19 @@ const genericImageHandler = async (url: URL): Promise<Embed | null> => {
const response = await doFetch(url); const response = await doFetch(url);
if (!response) return null; if (!response) return null;
const metas = getMetaDescriptions(await response.text()); const metas = getMetaDescriptions(await response.text());
width = metas.width; image = makeEmbedImage(
height = metas.height; metas.image || metas.image_fallback,
image = metas.image || metas.image_fallback; metas.width,
metas.height,
);
} }
if (!width || !height || !image) return null; if (!image) return null;
return { return {
url: url.href, url: url.href,
type: EmbedType.image, type: EmbedType.image,
thumbnail: { thumbnail: image,
width: width,
height: height,
url: url.href,
proxy_url: getProxyUrl(new URL(image), width, height),
},
}; };
}; };
@ -165,7 +188,8 @@ export const EmbedHandlers: {
const response = await doFetch(url); const response = await doFetch(url);
if (!response) return null; if (!response) return null;
const metas = getMetaDescriptions(await response.text()); const text = await response.text();
const metas = getMetaDescriptions(text);
// TODO: handle video // TODO: handle video
@ -178,26 +202,27 @@ export const EmbedHandlers: {
} }
if (!metas.image && (!metas.title || !metas.description)) { if (!metas.image && (!metas.title || !metas.description)) {
// we don't have any content to display
return null; return null;
} }
let embedType = EmbedType.link;
if (metas.type == "article") embedType = EmbedType.article;
if (metas.type == "object") embedType = EmbedType.article; // github
if (metas.type == "rich") embedType = EmbedType.rich;
return { return {
url: url.href, url: url.href,
type: EmbedType.link, type: embedType,
title: metas.title, title: metas.title,
thumbnail: { thumbnail: makeEmbedImage(metas.image, metas.width, metas.height),
width: metas.width,
height: metas.height,
url: metas.image,
proxy_url: metas.image
? getProxyUrl(
new URL(metas.image),
metas.width,
metas.height,
)
: undefined,
},
description: metas.description, description: metas.description,
provider: metas.site_name
? {
name: metas.site_name,
url: url.origin,
}
: undefined,
}; };
}, },
@ -207,12 +232,23 @@ export const EmbedHandlers: {
"c.tenor.com": genericImageHandler, "c.tenor.com": genericImageHandler,
"media.tenor.com": genericImageHandler, "media.tenor.com": genericImageHandler,
// TODO: facebook "facebook.com": (url) => EmbedHandlers["www.facebook.com"](url),
// have to use their APIs or something because they don't send the metas in initial html "www.facebook.com": async (url: URL) => {
const response = await doFetch(url);
if (!response) return null;
const metas = getMetaDescriptions(await response.text());
"twitter.com": (url: URL) => { return {
return EmbedHandlers["www.twitter.com"](url); url: url.href,
type: EmbedType.link,
title: metas.title,
description: metas.description,
thumbnail: makeEmbedImage(metas.image, 640, 640),
color: 16777215,
};
}, },
"twitter.com": (url) => EmbedHandlers["www.twitter.com"](url),
"www.twitter.com": async (url: URL) => { "www.twitter.com": async (url: URL) => {
const token = Config.get().external.twitter; const token = Config.get().external.twitter;
if (!token) return null; if (!token) return null;
@ -330,14 +366,7 @@ export const EmbedHandlers: {
type: EmbedType.link, type: EmbedType.link,
title: metas.title, title: metas.title,
description: metas.description, description: metas.description,
thumbnail: { thumbnail: makeEmbedImage(metas.image, 640, 640),
width: 640,
height: 640,
proxy_url: metas.image
? getProxyUrl(new URL(metas.image), 640, 640)
: undefined,
url: metas.image,
},
provider: { provider: {
url: "https://spotify.com", url: "https://spotify.com",
name: "Spotify", name: "Spotify",
@ -345,32 +374,25 @@ export const EmbedHandlers: {
}; };
}, },
"pixiv.net": (url: URL) => { // TODO: docs: Pixiv won't work without Imagor
return EmbedHandlers["www.pixiv.net"](url); "pixiv.net": (url) => EmbedHandlers["www.pixiv.net"](url),
},
"www.pixiv.net": async (url: URL) => { "www.pixiv.net": async (url: URL) => {
const response = await doFetch(url); const response = await doFetch(url);
if (!response) return null; if (!response) return null;
const metas = getMetaDescriptions(await response.text()); const metas = getMetaDescriptions(await response.text());
// TODO: doesn't show images. think it's a bug in the cdn if (!metas.image) return null;
return { return {
url: url.href, url: url.href,
type: EmbedType.image, type: EmbedType.image,
title: metas.title, title: metas.title,
description: metas.description, description: metas.description,
image: { image: makeEmbedImage(
width: metas.width, metas.image || metas.image_fallback,
height: metas.height,
url: url.href,
proxy_url: metas.image
? getProxyUrl(
new URL(metas.image),
metas.width, metas.width,
metas.height, metas.height,
) ),
: undefined,
},
provider: { provider: {
url: "https://pixiv.net", url: "https://pixiv.net",
name: "Pixiv", name: "Pixiv",
@ -382,6 +404,42 @@ export const EmbedHandlers: {
const response = await doFetch(url); const response = await doFetch(url);
if (!response) return null; if (!response) return null;
const metas = getMetaDescriptions(await response.text()); const metas = getMetaDescriptions(await response.text());
const numReviews = metas.$("#review_summary_num_reviews").val() as
| string
| undefined;
const price = metas
.$(".game_purchase_price.price")
.data("price-final") as number | undefined;
const releaseDate = metas
.$(".release_date")
.find("div.date")
.text()
.trim();
const isReleased = new Date(releaseDate) < new Date();
const fields: Embed["fields"] = [];
if (numReviews)
fields.push({
name: "Reviews",
value: numReviews,
inline: true,
});
if (price)
fields.push({
name: "Price",
value: `$${price / 100}`,
inline: true,
});
// if the release date is in the past, it's already out
if (releaseDate && !isReleased)
fields.push({
name: "Release Date",
value: releaseDate,
inline: true,
});
return { return {
url: url.href, url: url.href,
@ -402,14 +460,12 @@ export const EmbedHandlers: {
url: "https://store.steampowered.com", url: "https://store.steampowered.com",
name: "Steam", name: "Steam",
}, },
// TODO: fields for release date fields,
// TODO: Video // TODO: Video
}; };
}, },
"reddit.com": (url: URL) => { "reddit.com": (url) => EmbedHandlers["www.reddit.com"](url),
return EmbedHandlers["www.reddit.com"](url);
},
"www.reddit.com": async (url: URL) => { "www.reddit.com": async (url: URL) => {
const res = await EmbedHandlers["default"](url); const res = await EmbedHandlers["default"](url);
return { return {
@ -420,49 +476,65 @@ export const EmbedHandlers: {
}, },
}; };
}, },
"youtu.be": (url: URL) => {
return EmbedHandlers["www.youtube.com"](url); "youtu.be": (url) => EmbedHandlers["www.youtube.com"](url),
}, "youtube.com": (url) => EmbedHandlers["www.youtube.com"](url),
"youtube.com": (url: URL) => {
return EmbedHandlers["www.youtube.com"](url);
},
"www.youtube.com": async (url: URL): Promise<Embed | null> => { "www.youtube.com": async (url: URL): Promise<Embed | null> => {
const response = await doFetch(url); const response = await doFetch(url);
if (!response) return null; if (!response) return null;
const metas = getMetaDescriptions(await response.text()); const metas = getMetaDescriptions(await response.text());
return { return {
video: { video: makeEmbedImage(
// TODO: does this adjust with aspect ratio? metas.youtube_embed,
width: metas.width,
height: metas.height,
url: metas.youtube_embed,
},
url: url.href,
type: EmbedType.video,
title: metas.title,
thumbnail: {
width: metas.width,
height: metas.height,
url: metas.image,
proxy_url: metas.image
? getProxyUrl(
new URL(metas.image),
metas.width, metas.width,
metas.height, metas.height,
) ),
: undefined, url: url.href,
}, type: metas.youtube_embed ? EmbedType.video : EmbedType.link,
title: metas.title,
thumbnail: makeEmbedImage(
metas.image || metas.image_fallback,
metas.width,
metas.height,
),
provider: { provider: {
url: "https://www.youtube.com", url: "https://www.youtube.com",
name: "YouTube", name: "YouTube",
}, },
description: metas.description, description: metas.description,
color: 16711680, color: 16711680,
author: { author: metas.author
? {
name: metas.author, name: metas.author,
// TODO: author channel url // TODO: author channel url
}
: undefined,
};
}, },
"www.xkcd.com": (url) => EmbedHandlers["xkcd.com"](url),
"xkcd.com": async (url) => {
const response = await doFetch(url);
if (!response) return null;
const metas = getMetaDescriptions(await response.text());
const hoverText = metas.$("#comic img").attr("title");
if (!metas.image) return null;
const { width, height } = await probe(metas.image);
return {
url: url.href,
type: EmbedType.rich,
title: `xkcd: ${metas.title}`,
image: makeEmbedImage(metas.image, width, height),
footer: hoverText
? {
text: hoverText,
}
: undefined,
}; };
}, },

View File

@ -16,15 +16,15 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { WebSocket, Payload, CLOSECODES, OPCODES } from "@spacebar/gateway";
import OPCodeHandlers from "../opcodes";
import { check } from "../opcodes/instanceOf";
import WS from "ws";
import { PayloadSchema, ErlpackType } from "@spacebar/util";
import * as Sentry from "@sentry/node"; import * as Sentry from "@sentry/node";
import { CLOSECODES, OPCODES, Payload, WebSocket } from "@spacebar/gateway";
import { ErlpackType, PayloadSchema } from "@spacebar/util";
import fs from "fs/promises";
import BigIntJson from "json-bigint"; import BigIntJson from "json-bigint";
import path from "path"; import path from "path";
import fs from "fs/promises"; import WS from "ws";
import OPCodeHandlers from "../opcodes";
import { check } from "../opcodes/instanceOf";
const bigIntJson = BigIntJson({ storeAsString: true }); const bigIntJson = BigIntJson({ storeAsString: true });
let erlpack: ErlpackType | null = null; let erlpack: ErlpackType | null = null;
@ -88,33 +88,28 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
return; return;
} }
const transaction = try {
data.op != 1 return await Sentry.startActiveSpan(
? Sentry.startTransaction({ {
op: OPCODES[data.op], op: "websocket.server",
name: `GATEWAY ${OPCODES[data.op]}`, name: `GATEWAY ${OPCODES[data.op]}`,
data: { data: {
...data.d, ...data.d,
token: data?.d?.token ? "[Redacted]" : undefined, token: data?.d?.token ? "[Redacted]" : undefined,
}, },
}) },
: undefined; async () => {
try {
const ret = await OPCodeHandler.call(this, data); const ret = await OPCodeHandler.call(this, data);
Sentry.withScope((scope) => { Sentry.setUser({ id: this.user_id });
scope.setSpan(transaction);
scope.setUser({ id: this.user_id });
transaction?.finish();
});
return ret; return ret;
},
);
} catch (error) { } catch (error) {
Sentry.withScope((scope) => { Sentry.captureException(error, {
scope.setSpan(transaction); user: {
if (this.user_id) scope.setUser({ id: this.user_id }); id: this.user_id,
Sentry.captureException(error); },
}); });
transaction?.finish();
console.error(`Error: Op ${data.op}`, error); console.error(`Error: Op ${data.op}`, error);
// if (!this.CLOSED && this.CLOSING) // if (!this.CLOSED && this.CLOSING)
return this.close(CLOSECODES.Unknown_error); return this.close(CLOSECODES.Unknown_error);

View File

@ -17,49 +17,57 @@
*/ */
import { import {
WebSocket,
Payload,
setupListener,
Capabilities,
CLOSECODES, CLOSECODES,
Capabilities,
OPCODES, OPCODES,
Payload,
Send, Send,
WebSocket,
setupListener,
} from "@spacebar/gateway"; } from "@spacebar/gateway";
import { import {
checkToken, Application,
Config,
DMChannel,
DefaultUserGuildSettings,
EVENTEnum,
Guild,
GuildOrUnavailable,
IdentifySchema,
Intents, Intents,
Member, Member,
ReadyEventData,
Session,
EVENTEnum,
Config,
PublicUser,
PrivateUserProjection,
ReadState,
Application,
emitEvent,
SessionsReplace,
PrivateSessionProjection,
MemberPrivateProjection, MemberPrivateProjection,
PresenceUpdateEvent,
IdentifySchema,
DefaultUserGuildSettings,
ReadyGuildDTO,
Guild,
PublicUserProjection,
ReadyUserGuildSettingsEntries,
UserSettings,
Permissions,
DMChannel,
GuildOrUnavailable,
Recipient,
OPCodes, OPCodes,
Permissions,
PresenceUpdateEvent,
PrivateSessionProjection,
PrivateUserProjection,
PublicUser,
PublicUserProjection,
ReadState,
ReadyEventData,
ReadyGuildDTO,
ReadyUserGuildSettingsEntries,
Recipient,
Session,
SessionsReplace,
UserSettings,
checkToken,
emitEvent,
} from "@spacebar/util"; } from "@spacebar/util";
import { check } from "./instanceOf"; import { check } from "./instanceOf";
// TODO: user sharding // TODO: user sharding
// TODO: check privileged intents, if defined in the config // TODO: check privileged intents, if defined in the config
const tryGetUserFromToken = async (...args: Parameters<typeof checkToken>) => {
try {
return (await checkToken(...args)).user;
} catch (e) {
return null;
}
};
export async function onIdentify(this: WebSocket, data: Payload) { export async function onIdentify(this: WebSocket, data: Payload) {
if (this.user_id) { if (this.user_id) {
// we've already identified // we've already identified
@ -74,7 +82,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
this.capabilities = new Capabilities(identify.capabilities || 0); this.capabilities = new Capabilities(identify.capabilities || 0);
const { user } = await checkToken(identify.token, { const user = await tryGetUserFromToken(identify.token, {
relations: ["relationships", "relationships.to", "settings"], relations: ["relationships", "relationships.to", "settings"],
select: [...PrivateUserProjection, "relationships"], select: [...PrivateUserProjection, "relationships"],
}); });
@ -332,10 +340,9 @@ export async function onIdentify(this: WebSocket, data: Payload) {
// TODO how is active determined? // TODO how is active determined?
// in our lazy request impl, we just pick the 'most relevant' session // in our lazy request impl, we just pick the 'most relevant' session
active: x.session_id == session.session_id, active: x.session_id == session.session_id,
activities: x.activities, activities: x.activities ?? [],
client_info: x.client_info, client_info: x.client_info,
// TODO: what does all mean? session_id: x.session_id, // TODO: discord.com sends 'all', what is that???
session_id: x.session_id == session.session_id ? "all" : x.session_id,
status: x.status, status: x.status,
})); }));

View File

@ -102,10 +102,11 @@ export class Channel extends BaseClass {
guild_id?: string; guild_id?: string;
@JoinColumn({ name: "guild_id" }) @JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, { @ManyToOne(() => Guild, (guild) => guild.channels, {
onDelete: "CASCADE", onDelete: "CASCADE",
nullable: true,
}) })
guild: Guild; guild?: Guild;
@Column({ nullable: true }) @Column({ nullable: true })
@RelationId((channel: Channel) => channel.parent) @RelationId((channel: Channel) => channel.parent)
@ -571,7 +572,6 @@ export interface DMChannel extends Omit<Channel, "type" | "recipients"> {
export function isTextChannel(type: ChannelType): boolean { export function isTextChannel(type: ChannelType): boolean {
switch (type) { switch (type) {
case ChannelType.GUILD_STORE: case ChannelType.GUILD_STORE:
case ChannelType.GUILD_VOICE:
case ChannelType.GUILD_STAGE_VOICE: case ChannelType.GUILD_STAGE_VOICE:
case ChannelType.GUILD_CATEGORY: case ChannelType.GUILD_CATEGORY:
case ChannelType.GUILD_FORUM: case ChannelType.GUILD_FORUM:
@ -580,6 +580,7 @@ export function isTextChannel(type: ChannelType): boolean {
case ChannelType.DM: case ChannelType.DM:
case ChannelType.GROUP_DM: case ChannelType.GROUP_DM:
case ChannelType.GUILD_NEWS: case ChannelType.GUILD_NEWS:
case ChannelType.GUILD_VOICE:
case ChannelType.GUILD_NEWS_THREAD: case ChannelType.GUILD_NEWS_THREAD:
case ChannelType.GUILD_PUBLIC_THREAD: case ChannelType.GUILD_PUBLIC_THREAD:
case ChannelType.GUILD_PRIVATE_THREAD: case ChannelType.GUILD_PRIVATE_THREAD:

View File

@ -33,7 +33,7 @@ export class Emoji extends BaseClass {
guild_id: string; guild_id: string;
@JoinColumn({ name: "guild_id" }) @JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, { @ManyToOne(() => Guild, (guild) => guild.emojis, {
onDelete: "CASCADE", onDelete: "CASCADE",
}) })
guild: Guild; guild: Guild;

View File

@ -53,7 +53,7 @@ export class Invite extends BaseClassWithoutId {
guild_id: string; guild_id: string;
@JoinColumn({ name: "guild_id" }) @JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, { @ManyToOne(() => Guild, (guild) => guild.invites, {
onDelete: "CASCADE", onDelete: "CASCADE",
}) })
guild: Guild; guild: Guild;

View File

@ -327,6 +327,7 @@ export class Member extends BaseClassWithoutId {
id: guild_id, id: guild_id,
}, },
relations: PublicGuildRelations, relations: PublicGuildRelations,
relationLoadStrategy: "query",
}); });
const memberCount = await Member.count({ where: { guild_id } }); const memberCount = await Member.count({ where: { guild_id } });

View File

@ -23,12 +23,12 @@ import { Guild } from "./Guild";
@Entity("roles") @Entity("roles")
export class Role extends BaseClass { export class Role extends BaseClass {
@Column({ nullable: true }) @Column()
@RelationId((role: Role) => role.guild) @RelationId((role: Role) => role.guild)
guild_id: string; guild_id: string;
@JoinColumn({ name: "guild_id" }) @JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, { @ManyToOne(() => Guild, (guild) => guild.roles, {
onDelete: "CASCADE", onDelete: "CASCADE",
}) })
guild: Guild; guild: Guild;

View File

@ -17,9 +17,9 @@
*/ */
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { User } from "./User";
import { BaseClass } from "./BaseClass"; import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild"; import { Guild } from "./Guild";
import { User } from "./User";
export enum StickerType { export enum StickerType {
STANDARD = 1, STANDARD = 1,
@ -62,7 +62,7 @@ export class Sticker extends BaseClass {
guild_id?: string; guild_id?: string;
@JoinColumn({ name: "guild_id" }) @JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, { @ManyToOne(() => Guild, (guild) => guild.stickers, {
onDelete: "CASCADE", onDelete: "CASCADE",
}) })
guild?: Guild; guild?: Guild;

View File

@ -20,8 +20,8 @@ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass"; import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel"; import { Channel } from "./Channel";
import { Guild } from "./Guild"; import { Guild } from "./Guild";
import { User } from "./User";
import { Member } from "./Member"; import { Member } from "./Member";
import { User } from "./User";
//https://gist.github.com/vassjozsef/e482c65df6ee1facaace8b3c9ff66145#file-voice_state-ex //https://gist.github.com/vassjozsef/e482c65df6ee1facaace8b3c9ff66145#file-voice_state-ex
@Entity("voice_states") @Entity("voice_states")
@ -31,7 +31,7 @@ export class VoiceState extends BaseClass {
guild_id: string; guild_id: string;
@JoinColumn({ name: "guild_id" }) @JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild, { @ManyToOne(() => Guild, (guild) => guild.voice_states, {
onDelete: "CASCADE", onDelete: "CASCADE",
}) })
guild?: Guild; guild?: Guild;

View File

@ -16,12 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { DataSource } from "typeorm";
import { yellow, green, red } from "picocolors";
import { Migration } from "../entities/Migration";
import { ConfigEntity } from "../entities/Config";
import { config } from "dotenv"; import { config } from "dotenv";
import path from "path"; import path from "path";
import { green, red, yellow } from "picocolors";
import { DataSource } from "typeorm";
import { ConfigEntity } from "../entities/Config";
import { Migration } from "../entities/Migration";
// UUID extension option is only supported with postgres // UUID extension option is only supported with postgres
// We want to generate all id's with Snowflakes that's why we have our own BaseEntity class // We want to generate all id's with Snowflakes that's why we have our own BaseEntity class
@ -50,7 +50,7 @@ const DataSourceOptions = new DataSource({
database: isSqlite ? dbConnectionString : undefined, database: isSqlite ? dbConnectionString : undefined,
entities: [path.join(__dirname, "..", "entities", "*.js")], entities: [path.join(__dirname, "..", "entities", "*.js")],
synchronize: !!process.env.DB_SYNC, synchronize: !!process.env.DB_SYNC,
logging: false, logging: !!process.env.DB_LOGGING,
bigNumberStrings: false, bigNumberStrings: false,
supportBigNumbers: true, supportBigNumbers: true,
name: "default", name: "default",
@ -129,7 +129,7 @@ export async function initDatabase(): Promise<DataSource> {
return dbConnection; return dbConnection;
} }
export { dbConnection, DataSourceOptions, DatabaseType }; export { DataSourceOptions, DatabaseType, dbConnection };
export async function closeDatabase() { export async function closeDatabase() {
await dbConnection?.destroy(); await dbConnection?.destroy();

View File

@ -16,13 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { Config } from "./Config";
import { yellow } from "picocolors"; import { yellow } from "picocolors";
import { Config } from "./Config";
import express from "express";
import * as SentryNode from "@sentry/node";
import * as Tracing from "@sentry/tracing";
import * as Integrations from "@sentry/integrations"; import * as Integrations from "@sentry/integrations";
import * as SentryNode from "@sentry/node";
import express from "express";
// Work around for when bundle calls api/etc // Work around for when bundle calls api/etc
let errorHandlersUsed = false; let errorHandlersUsed = false;
@ -46,16 +45,28 @@ export const Sentry = {
); );
} }
SentryNode.init({ const integrations = [
dsn: endpoint,
integrations: [
new SentryNode.Integrations.Http({ tracing: true }), new SentryNode.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({ app }),
new Tracing.Integrations.Mysql(),
new Integrations.RewriteFrames({ new Integrations.RewriteFrames({
root: __dirname, root: __dirname,
}), }),
], new SentryNode.Integrations.Http({
tracing: true,
breadcrumbs: true,
}),
...SentryNode.autoDiscoverNodePerformanceMonitoringIntegrations(),
];
if (app)
integrations.push(
new SentryNode.Integrations.Express({
app,
}),
);
SentryNode.init({
dsn: endpoint,
integrations,
tracesSampleRate: traceSampleRate, // naming? tracesSampleRate: traceSampleRate, // naming?
environment, environment,
}); });