Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19e26674e6 | ||
|
|
daf6b9420c | ||
|
|
fab784bfd8 | ||
|
|
17c1938b4c | ||
|
|
ca9f032234 | ||
|
|
5c4527f1b2 | ||
|
|
11b1ea5aa6 | ||
|
|
d7292a0706 | ||
|
|
9eaf213091 | ||
|
|
c8c00a42bb | ||
|
|
2182c0d38f | ||
|
|
d92d7c4314 | ||
|
|
5c22ed85a7 | ||
|
|
98e5e9de4a | ||
|
|
820951cb6e | ||
|
|
52ebc21d9b | ||
|
|
16469259f7 | ||
|
|
d2988096e4 | ||
|
|
3f7622be19 | ||
|
|
40a6992151 | ||
|
|
111824486b | ||
|
|
d4e7289315 | ||
|
|
e2151defc6 | ||
|
|
30c2cd94a7 | ||
|
|
847d4cb98e | ||
|
|
9fd89cdfc5 | ||
|
|
dc4538aab6 | ||
|
|
a6fca7ce43 | ||
|
|
d69e4e9881 | ||
|
|
ccc6c77911 |
10
.github/ISSUE_TEMPLATE/bug.md
vendored
10
.github/ISSUE_TEMPLATE/bug.md
vendored
@@ -1,14 +1,16 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: If something is definitely wrong in the bridge (rather than just a setup issue),
|
about: If something is definitely wrong in the bridge (rather than just a setup issue),
|
||||||
file a bug report. Remember to include relevant logs.
|
file a bug report. Remember to include relevant logs. Asking in the Matrix room first
|
||||||
labels: bug
|
is strongly recommended.
|
||||||
|
type: Bug
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Remember to include relevant logs, the bridge version and any other details.
|
Remember to include relevant logs, the bridge version and any other details.
|
||||||
|
|
||||||
If you aren't sure what's needed, ask in the Matrix room rather than opening an
|
It's always best to ask in the Matrix room first, especially if you aren't sure
|
||||||
incomplete issue. Issues with insufficient detail will likely just be ignored.
|
what details are needed. Issues with insufficient detail will likely just be
|
||||||
|
ignored or closed immediately.
|
||||||
-->
|
-->
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/enhancement.md
vendored
2
.github/ISSUE_TEMPLATE/enhancement.md
vendored
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Enhancement request
|
name: Enhancement request
|
||||||
about: Submit a feature request or other suggestion
|
about: Submit a feature request or other suggestion
|
||||||
labels: enhancement
|
type: Feature
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@@ -8,8 +8,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
go-version: ["1.23", "1.24"]
|
go-version: ["1.25", "1.26"]
|
||||||
name: Lint ${{ matrix.go-version == '1.24' && '(latest)' || '(old)' }}
|
name: Lint ${{ matrix.go-version == '1.26' && '(latest)' || '(old)' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|||||||
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,3 +1,35 @@
|
|||||||
|
# v0.7.6 (2026-02-16)
|
||||||
|
|
||||||
|
* Bumped minimum Go version to 1.25.
|
||||||
|
* Updated Docker image to Alpine 3.23.
|
||||||
|
* Added support for following tombstones.
|
||||||
|
* Added support for disabling link previews in messages sent to Discord using
|
||||||
|
[MSC4095].
|
||||||
|
* Added support for federation thumbnail endpoint when using direct media.
|
||||||
|
* Disabled using `restricted` join rules by default.
|
||||||
|
|
||||||
|
[MSC4095]: https://github.com/matrix-org/matrix-spec-proposals/pull/4095
|
||||||
|
|
||||||
|
# v0.7.5 (2025-07-16)
|
||||||
|
|
||||||
|
* Fixed federation key response when using direct media.
|
||||||
|
* Changed `prefix_webhook_messages` option to generate [MSC4144] fallbacks,
|
||||||
|
so that any compatible clients will hide the prefix.
|
||||||
|
* Changed new room creation to hardcode room v11 to avoid v12 rooms being
|
||||||
|
created before proper support for them can be added.
|
||||||
|
|
||||||
|
# v0.7.4 (2025-06-16)
|
||||||
|
|
||||||
|
* Added support for forwarded messages
|
||||||
|
* Added support for [MSC4193] media spoilers (thanks to [@LeaPhant] in [#189]).
|
||||||
|
* Added support for [MSC4190] for MAS-compatible encryption.
|
||||||
|
* Updated Docker image to Alpine 3.22
|
||||||
|
|
||||||
|
[MSC4193]: https://github.com/matrix-org/matrix-spec-proposals/pull/4193
|
||||||
|
[MSC4190]: https://github.com/matrix-org/matrix-spec-proposals/pull/4190
|
||||||
|
[@LeaPhant]: https://github.com/mautrix/discord/pull/189
|
||||||
|
[#189]: https://github.com/mautrix/discord/pull/189
|
||||||
|
|
||||||
# v0.7.3 (2025-04-16)
|
# v0.7.3 (2025-04-16)
|
||||||
|
|
||||||
* Added support for sending no-mention replies from Matrix
|
* Added support for sending no-mention replies from Matrix
|
||||||
|
|||||||
12
Dockerfile
12
Dockerfile
@@ -1,6 +1,4 @@
|
|||||||
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.18 AS lottie
|
FROM golang:1-alpine3.23 AS builder
|
||||||
|
|
||||||
FROM golang:1-alpine3.18 AS builder
|
|
||||||
|
|
||||||
RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev
|
RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev
|
||||||
|
|
||||||
@@ -8,19 +6,17 @@ COPY . /build
|
|||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
RUN go build -o /usr/bin/mautrix-discord
|
RUN go build -o /usr/bin/mautrix-discord
|
||||||
|
|
||||||
FROM alpine:3.18
|
FROM alpine:3.23
|
||||||
|
|
||||||
ENV UID=1337 \
|
ENV UID=1337 \
|
||||||
GID=1337
|
GID=1337
|
||||||
|
|
||||||
RUN apk add --no-cache ffmpeg su-exec ca-certificates olm bash jq yq curl \
|
RUN apk add --no-cache ffmpeg su-exec ca-certificates olm bash jq curl yq-go lottieconverter
|
||||||
zlib libpng giflib libstdc++ libgcc
|
|
||||||
|
|
||||||
COPY --from=lottie /usr/lib/librlottie.so* /usr/lib/
|
|
||||||
COPY --from=lottie /usr/local/bin/lottieconverter /usr/local/bin/lottieconverter
|
|
||||||
COPY --from=builder /usr/bin/mautrix-discord /usr/bin/mautrix-discord
|
COPY --from=builder /usr/bin/mautrix-discord /usr/bin/mautrix-discord
|
||||||
COPY --from=builder /build/example-config.yaml /opt/mautrix-discord/example-config.yaml
|
COPY --from=builder /build/example-config.yaml /opt/mautrix-discord/example-config.yaml
|
||||||
COPY --from=builder /build/docker-run.sh /docker-run.sh
|
COPY --from=builder /build/docker-run.sh /docker-run.sh
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
|
WORKDIR /data
|
||||||
|
|
||||||
CMD ["/docker-run.sh"]
|
CMD ["/docker-run.sh"]
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.18 AS lottie
|
FROM alpine:3.23
|
||||||
|
|
||||||
FROM alpine:3.18
|
|
||||||
|
|
||||||
ENV UID=1337 \
|
ENV UID=1337 \
|
||||||
GID=1337
|
GID=1337
|
||||||
|
|
||||||
RUN apk add --no-cache ffmpeg su-exec ca-certificates bash jq curl yq \
|
RUN apk add --no-cache ffmpeg su-exec ca-certificates bash jq curl yq-go lottieconverter
|
||||||
zlib libpng giflib libstdc++ libgcc
|
|
||||||
|
|
||||||
COPY --from=lottie /usr/lib/librlottie.so* /usr/lib/
|
|
||||||
COPY --from=lottie /usr/local/bin/lottieconverter /usr/local/bin/lottieconverter
|
|
||||||
ARG EXECUTABLE=./mautrix-discord
|
ARG EXECUTABLE=./mautrix-discord
|
||||||
COPY $EXECUTABLE /usr/bin/mautrix-discord
|
COPY $EXECUTABLE /usr/bin/mautrix-discord
|
||||||
COPY ./example-config.yaml /opt/mautrix-discord/example-config.yaml
|
COPY ./example-config.yaml /opt/mautrix-discord/example-config.yaml
|
||||||
COPY ./docker-run.sh /docker-run.sh
|
COPY ./docker-run.sh /docker-run.sh
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
|
WORKDIR /data
|
||||||
|
|
||||||
CMD ["/docker-run.sh"]
|
CMD ["/docker-run.sh"]
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.18 AS lottie
|
|
||||||
|
|
||||||
FROM golang:1-alpine3.18 AS builder
|
|
||||||
|
|
||||||
RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev bash jq yq curl \
|
|
||||||
zlib libpng giflib libstdc++ libgcc
|
|
||||||
|
|
||||||
COPY --from=lottie /usr/lib/librlottie.so* /usr/lib/
|
|
||||||
COPY --from=lottie /usr/local/bin/lottieconverter /usr/local/bin/lottieconverter
|
|
||||||
COPY . /build
|
|
||||||
WORKDIR /build
|
|
||||||
RUN go build -o /usr/bin/mautrix-discord
|
|
||||||
|
|
||||||
# Setup development stack using gow
|
|
||||||
RUN go install github.com/mitranim/gow@latest
|
|
||||||
RUN echo 'gow run /build $@' > /usr/bin/mautrix-discord \
|
|
||||||
&& chmod +x /usr/bin/mautrix-discord
|
|
||||||
VOLUME /data
|
|
||||||
@@ -99,6 +99,7 @@ func DoUpgrade(helper *up.Helper) {
|
|||||||
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "appservice")
|
helper.Copy(up.Bool, "bridge", "encryption", "appservice")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "msc4190")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "allow_key_sharing")
|
helper.Copy(up.Bool, "bridge", "encryption", "allow_key_sharing")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "plaintext_mentions")
|
helper.Copy(up.Bool, "bridge", "encryption", "plaintext_mentions")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_outbound_on_ack")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_outbound_on_ack")
|
||||||
|
|||||||
20
database/json.go
Normal file
20
database/json.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.mau.fi/util/dbutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Backported from mautrix/go-util@e5cb5e96d15cb87ffe6e5970c2f90ee47980e715.
|
||||||
|
|
||||||
|
// JSONPtr is a convenience function for wrapping a pointer to a value in the JSON utility, but removing typed nils
|
||||||
|
// (i.e. preventing nils from turning into the string "null" in the database).
|
||||||
|
func JSONPtr[T any](val *T) dbutil.JSON {
|
||||||
|
return dbutil.JSON{Data: UntypedNil(val)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UntypedNil[T any](val *T) any {
|
||||||
|
if val == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
-- v0 -> v23 (compatible with v19+): Latest revision
|
-- v0 -> v24 (compatible with v19+): Latest revision
|
||||||
|
|
||||||
CREATE TABLE guild (
|
CREATE TABLE guild (
|
||||||
dcid TEXT PRIMARY KEY,
|
dcid TEXT PRIMARY KEY,
|
||||||
@@ -92,7 +92,8 @@ CREATE TABLE "user" (
|
|||||||
space_room TEXT,
|
space_room TEXT,
|
||||||
dm_space_room TEXT,
|
dm_space_room TEXT,
|
||||||
|
|
||||||
read_state_version INTEGER NOT NULL DEFAULT 0
|
read_state_version INTEGER NOT NULL DEFAULT 0,
|
||||||
|
heartbeat_session jsonb
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE user_portal (
|
CREATE TABLE user_portal (
|
||||||
|
|||||||
2
database/upgrades/24-user-heartbeat-session.sql
Normal file
2
database/upgrades/24-user-heartbeat-session.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- v24 (compatible with v19+): Add persisted heartbeat sessions
|
||||||
|
ALTER TABLE "user" ADD COLUMN heartbeat_session jsonb;
|
||||||
@@ -3,6 +3,7 @@ package database
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
"go.mau.fi/util/dbutil"
|
"go.mau.fi/util/dbutil"
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@@ -21,18 +22,18 @@ func (uq *UserQuery) New() *User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
|
func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
|
||||||
query := `SELECT mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version FROM "user" WHERE mxid=$1`
|
query := `SELECT mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version, heartbeat_session FROM "user" WHERE mxid=$1`
|
||||||
return uq.New().Scan(uq.db.QueryRow(query, userID))
|
return uq.New().Scan(uq.db.QueryRow(query, userID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) GetByID(id string) *User {
|
func (uq *UserQuery) GetByID(id string) *User {
|
||||||
query := `SELECT mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version FROM "user" WHERE dcid=$1`
|
query := `SELECT mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version, heartbeat_session FROM "user" WHERE dcid=$1`
|
||||||
return uq.New().Scan(uq.db.QueryRow(query, id))
|
return uq.New().Scan(uq.db.QueryRow(query, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) GetAllWithToken() []*User {
|
func (uq *UserQuery) GetAllWithToken() []*User {
|
||||||
query := `
|
query := `
|
||||||
SELECT mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version
|
SELECT mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version, heartbeat_session
|
||||||
FROM "user" WHERE discord_token IS NOT NULL
|
FROM "user" WHERE discord_token IS NOT NULL
|
||||||
`
|
`
|
||||||
rows, err := uq.db.Query(query)
|
rows, err := uq.db.Query(query)
|
||||||
@@ -54,19 +55,20 @@ type User struct {
|
|||||||
db *Database
|
db *Database
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
MXID id.UserID
|
MXID id.UserID
|
||||||
DiscordID string
|
DiscordID string
|
||||||
DiscordToken string
|
DiscordToken string
|
||||||
ManagementRoom id.RoomID
|
ManagementRoom id.RoomID
|
||||||
SpaceRoom id.RoomID
|
SpaceRoom id.RoomID
|
||||||
DMSpaceRoom id.RoomID
|
DMSpaceRoom id.RoomID
|
||||||
|
HeartbeatSession *discordgo.HeartbeatSession
|
||||||
|
|
||||||
ReadStateVersion int
|
ReadStateVersion int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) Scan(row dbutil.Scannable) *User {
|
func (u *User) Scan(row dbutil.Scannable) *User {
|
||||||
var discordID, managementRoom, spaceRoom, dmSpaceRoom, discordToken sql.NullString
|
var discordID, managementRoom, spaceRoom, dmSpaceRoom, discordToken sql.NullString
|
||||||
err := row.Scan(&u.MXID, &discordID, &discordToken, &managementRoom, &spaceRoom, &dmSpaceRoom, &u.ReadStateVersion)
|
err := row.Scan(&u.MXID, &discordID, &discordToken, &managementRoom, &spaceRoom, &dmSpaceRoom, &u.ReadStateVersion, dbutil.JSON{Data: &u.HeartbeatSession})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
u.log.Errorln("Database scan failed:", err)
|
u.log.Errorln("Database scan failed:", err)
|
||||||
@@ -83,8 +85,8 @@ func (u *User) Scan(row dbutil.Scannable) *User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) Insert() {
|
func (u *User) Insert() {
|
||||||
query := `INSERT INTO "user" (mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version) VALUES ($1, $2, $3, $4, $5, $6, $7)`
|
query := `INSERT INTO "user" (mxid, dcid, discord_token, management_room, space_room, dm_space_room, read_state_version, heartbeat_session) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`
|
||||||
_, err := u.db.Exec(query, u.MXID, strPtr(u.DiscordID), strPtr(u.DiscordToken), strPtr(string(u.ManagementRoom)), strPtr(string(u.SpaceRoom)), strPtr(string(u.DMSpaceRoom)), u.ReadStateVersion)
|
_, err := u.db.Exec(query, u.MXID, strPtr(u.DiscordID), strPtr(u.DiscordToken), strPtr(string(u.ManagementRoom)), strPtr(string(u.SpaceRoom)), strPtr(string(u.DMSpaceRoom)), u.ReadStateVersion, JSONPtr(u.HeartbeatSession))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.log.Warnfln("Failed to insert %s: %v", u.MXID, err)
|
u.log.Warnfln("Failed to insert %s: %v", u.MXID, err)
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -92,8 +94,8 @@ func (u *User) Insert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) Update() {
|
func (u *User) Update() {
|
||||||
query := `UPDATE "user" SET dcid=$1, discord_token=$2, management_room=$3, space_room=$4, dm_space_room=$5, read_state_version=$6 WHERE mxid=$7`
|
query := `UPDATE "user" SET dcid=$1, discord_token=$2, management_room=$3, space_room=$4, dm_space_room=$5, read_state_version=$6, heartbeat_session=$7 WHERE mxid=$8`
|
||||||
_, err := u.db.Exec(query, strPtr(u.DiscordID), strPtr(u.DiscordToken), strPtr(string(u.ManagementRoom)), strPtr(string(u.SpaceRoom)), strPtr(string(u.DMSpaceRoom)), u.ReadStateVersion, u.MXID)
|
_, err := u.db.Exec(query, strPtr(u.DiscordID), strPtr(u.DiscordToken), strPtr(string(u.ManagementRoom)), strPtr(string(u.SpaceRoom)), strPtr(string(u.DMSpaceRoom)), u.ReadStateVersion, JSONPtr(u.HeartbeatSession), u.MXID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.log.Warnfln("Failed to update %q: %v", u.MXID, err)
|
u.log.Warnfln("Failed to update %q: %v", u.MXID, err)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ func newDirectMediaAPI(br *DiscordBridge) *DirectMediaAPI {
|
|||||||
addRoutes("r0")
|
addRoutes("r0")
|
||||||
addRoutes("v1")
|
addRoutes("v1")
|
||||||
federationRouter.HandleFunc("/v1/media/download/{mediaID}", dma.DownloadMedia).Methods(http.MethodGet)
|
federationRouter.HandleFunc("/v1/media/download/{mediaID}", dma.DownloadMedia).Methods(http.MethodGet)
|
||||||
|
federationRouter.HandleFunc("/v1/media/thumbnail/{mediaID}", dma.DownloadMedia).Methods(http.MethodGet)
|
||||||
federationRouter.HandleFunc("/v1/version", dma.ks.GetServerVersion).Methods(http.MethodGet)
|
federationRouter.HandleFunc("/v1/version", dma.ks.GetServerVersion).Methods(http.MethodGet)
|
||||||
mediaRouter.NotFoundHandler = http.HandlerFunc(dma.UnknownEndpoint)
|
mediaRouter.NotFoundHandler = http.HandlerFunc(dma.UnknownEndpoint)
|
||||||
mediaRouter.MethodNotAllowedHandler = http.HandlerFunc(dma.UnsupportedMethod)
|
mediaRouter.MethodNotAllowedHandler = http.HandlerFunc(dma.UnsupportedMethod)
|
||||||
@@ -556,7 +557,7 @@ func (dma *DirectMediaAPI) proxyDownload(ctx context.Context, w http.ResponseWri
|
|||||||
func (dma *DirectMediaAPI) DownloadMedia(w http.ResponseWriter, r *http.Request) {
|
func (dma *DirectMediaAPI) DownloadMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
log := zerolog.Ctx(ctx)
|
log := zerolog.Ctx(ctx)
|
||||||
isNewFederation := strings.HasPrefix(r.URL.Path, "/_matrix/federation/v1/media/download/")
|
isNewFederation := strings.HasPrefix(r.URL.Path, "/_matrix/federation/v1/media/")
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
if !isNewFederation && vars["serverName"] != dma.cfg.ServerName {
|
if !isNewFederation && vars["serverName"] != dma.cfg.ServerName {
|
||||||
jsonResponse(w, http.StatusNotFound, &mautrix.RespError{
|
jsonResponse(w, http.StatusNotFound, &mautrix.RespError{
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ bridge:
|
|||||||
# .System - Whether the user is an official system user
|
# .System - Whether the user is an official system user
|
||||||
# .Webhook - Whether the user is a webhook and is not an application
|
# .Webhook - Whether the user is a webhook and is not an application
|
||||||
# .Application - Whether the user is an application
|
# .Application - Whether the user is an application
|
||||||
displayname_template: '{{or .GlobalName .Username}}{{if .Bot}} (bot){{end}}'
|
displayname_template: '{{if .Webhook}}Webhook{{else}}{{or .GlobalName .Username}}{{if .Bot}} (bot){{end}}{{end}}'
|
||||||
# Displayname template for Discord channels (bridged as rooms, or spaces when type=4).
|
# Displayname template for Discord channels (bridged as rooms, or spaces when type=4).
|
||||||
# Available variables:
|
# Available variables:
|
||||||
# .Name - Channel name, or user displayname (pre-formatted with displayname_template) in DMs.
|
# .Name - Channel name, or user displayname (pre-formatted with displayname_template) in DMs.
|
||||||
@@ -130,7 +130,7 @@ bridge:
|
|||||||
message_error_notices: true
|
message_error_notices: true
|
||||||
# Should the bridge use space-restricted join rules instead of invite-only for guild rooms?
|
# Should the bridge use space-restricted join rules instead of invite-only for guild rooms?
|
||||||
# This can avoid unnecessary invite events in guild rooms when members are synced in.
|
# This can avoid unnecessary invite events in guild rooms when members are synced in.
|
||||||
restricted_rooms: true
|
restricted_rooms: false
|
||||||
# Should the bridge automatically join the user to threads on Discord when the thread is opened on Matrix?
|
# Should the bridge automatically join the user to threads on Discord when the thread is opened on Matrix?
|
||||||
# This only works with clients that support thread read receipts (MSC3771 added in Matrix v1.4).
|
# This only works with clients that support thread read receipts (MSC3771 added in Matrix v1.4).
|
||||||
autojoin_thread_on_open: true
|
autojoin_thread_on_open: true
|
||||||
@@ -161,9 +161,12 @@ bridge:
|
|||||||
federate_rooms: true
|
federate_rooms: true
|
||||||
# Prefix messages from webhooks with the profile info? This can be used along with a custom displayname_template
|
# Prefix messages from webhooks with the profile info? This can be used along with a custom displayname_template
|
||||||
# to better handle webhooks that change their name all the time (like ones used by bridges).
|
# to better handle webhooks that change their name all the time (like ones used by bridges).
|
||||||
prefix_webhook_messages: false
|
#
|
||||||
|
# This will use the fallback mode in MSC4144, which means clients that support MSC4144 will not show the prefix
|
||||||
|
# (and will instead show the name and avatar as the message sender).
|
||||||
|
prefix_webhook_messages: true
|
||||||
# Bridge webhook avatars?
|
# Bridge webhook avatars?
|
||||||
enable_webhook_avatars: true
|
enable_webhook_avatars: false
|
||||||
# Should the bridge upload media to the Discord CDN directly before sending the message when using a user token,
|
# Should the bridge upload media to the Discord CDN directly before sending the message when using a user token,
|
||||||
# like the official client does? The other option is sending the media in the message send request as a form part
|
# like the official client does? The other option is sending the media in the message send request as a form part
|
||||||
# (which is always used by bots and webhooks).
|
# (which is always used by bots and webhooks).
|
||||||
@@ -266,7 +269,13 @@ bridge:
|
|||||||
# This will cause the bridge bot to be in private chats for the encryption to work properly.
|
# This will cause the bridge bot to be in private chats for the encryption to work properly.
|
||||||
default: false
|
default: false
|
||||||
# Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data.
|
# Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data.
|
||||||
|
# Changing this option requires updating the appservice registration file.
|
||||||
appservice: false
|
appservice: false
|
||||||
|
# Whether to use MSC4190 instead of appservice login to create the bridge bot device.
|
||||||
|
# Requires the homeserver to support MSC4190 and the device masquerading parts of MSC3202.
|
||||||
|
# Only relevant when using end-to-bridge encryption, required when using encryption with next-gen auth (MSC3861).
|
||||||
|
# Changing this option requires updating the appservice registration file.
|
||||||
|
msc4190: false
|
||||||
# Require encryption, drop any unencrypted messages.
|
# Require encryption, drop any unencrypted messages.
|
||||||
require: false
|
require: false
|
||||||
# Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled.
|
# Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled.
|
||||||
|
|||||||
22
formatter.go
22
formatter.go
@@ -74,7 +74,7 @@ var discordRendererWithInlineLinks = goldmark.New(
|
|||||||
fixIndentedParagraphs, format.HTMLOptions, discordExtensions,
|
fixIndentedParagraphs, format.HTMLOptions, discordExtensions,
|
||||||
)
|
)
|
||||||
|
|
||||||
func (portal *Portal) renderDiscordMarkdownOnlyHTML(text string, allowInlineLinks bool) string {
|
func (portal *Portal) renderDiscordMarkdownOnlyHTMLNoUnwrap(text string, allowInlineLinks bool) string {
|
||||||
text = escapeFixer.ReplaceAllStringFunc(text, escapeReplacement)
|
text = escapeFixer.ReplaceAllStringFunc(text, escapeReplacement)
|
||||||
|
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
@@ -88,12 +88,17 @@ func (portal *Portal) renderDiscordMarkdownOnlyHTML(text string, allowInlineLink
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("markdown parser errored: %w", err))
|
panic(fmt.Errorf("markdown parser errored: %w", err))
|
||||||
}
|
}
|
||||||
return format.UnwrapSingleParagraph(buf.String())
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) renderDiscordMarkdownOnlyHTML(text string, allowInlineLinks bool) string {
|
||||||
|
return format.UnwrapSingleParagraph(portal.renderDiscordMarkdownOnlyHTMLNoUnwrap(text, allowInlineLinks))
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatterContextPortalKey = "fi.mau.discord.portal"
|
const formatterContextPortalKey = "fi.mau.discord.portal"
|
||||||
const formatterContextAllowedMentionsKey = "fi.mau.discord.allowed_mentions"
|
const formatterContextAllowedMentionsKey = "fi.mau.discord.allowed_mentions"
|
||||||
const formatterContextInputAllowedMentionsKey = "fi.mau.discord.input_allowed_mentions"
|
const formatterContextInputAllowedMentionsKey = "fi.mau.discord.input_allowed_mentions"
|
||||||
|
const formatterContextInputAllowedLinkPreviewsKey = "fi.mau.discord.input_allowed_link_previews"
|
||||||
|
|
||||||
func appendIfNotContains(arr []string, newItem string) []string {
|
func appendIfNotContains(arr []string, newItem string) []string {
|
||||||
for _, item := range arr {
|
for _, item := range arr {
|
||||||
@@ -217,16 +222,24 @@ var matrixHTMLParser = &format.HTMLParser{
|
|||||||
return fmt.Sprintf("||%s||", text)
|
return fmt.Sprintf("||%s||", text)
|
||||||
},
|
},
|
||||||
LinkConverter: func(text, href string, ctx format.Context) string {
|
LinkConverter: func(text, href string, ctx format.Context) string {
|
||||||
|
linkPreviews := ctx.ReturnData[formatterContextInputAllowedLinkPreviewsKey].([]string)
|
||||||
|
allowPreview := linkPreviews == nil || slices.Contains(linkPreviews, href)
|
||||||
if text == href {
|
if text == href {
|
||||||
|
if !allowPreview {
|
||||||
|
return fmt.Sprintf("<%s>", text)
|
||||||
|
}
|
||||||
return text
|
return text
|
||||||
} else if !discordLinkRegexFull.MatchString(href) {
|
} else if !discordLinkRegexFull.MatchString(href) {
|
||||||
return fmt.Sprintf("%s (%s)", escapeDiscordMarkdown(text), escapeDiscordMarkdown(href))
|
return fmt.Sprintf("%s (%s)", escapeDiscordMarkdown(text), escapeDiscordMarkdown(href))
|
||||||
|
} else if !allowPreview {
|
||||||
|
return fmt.Sprintf("[%s](<%s>)", escapeDiscordMarkdown(text), href)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("[%s](%s)", escapeDiscordMarkdown(text), href)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("[%s](%s)", escapeDiscordMarkdown(text), href)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) parseMatrixHTML(content *event.MessageEventContent) (string, *discordgo.MessageAllowedMentions) {
|
func (portal *Portal) parseMatrixHTML(content *event.MessageEventContent, allowedLinkPreviews []string) (string, *discordgo.MessageAllowedMentions) {
|
||||||
allowedMentions := &discordgo.MessageAllowedMentions{
|
allowedMentions := &discordgo.MessageAllowedMentions{
|
||||||
Parse: []discordgo.AllowedMentionType{},
|
Parse: []discordgo.AllowedMentionType{},
|
||||||
Users: []string{},
|
Users: []string{},
|
||||||
@@ -234,6 +247,7 @@ func (portal *Portal) parseMatrixHTML(content *event.MessageEventContent) (strin
|
|||||||
}
|
}
|
||||||
if content.Format == event.FormatHTML && len(content.FormattedBody) > 0 {
|
if content.Format == event.FormatHTML && len(content.FormattedBody) > 0 {
|
||||||
ctx := format.NewContext()
|
ctx := format.NewContext()
|
||||||
|
ctx.ReturnData[formatterContextInputAllowedLinkPreviewsKey] = allowedLinkPreviews
|
||||||
ctx.ReturnData[formatterContextPortalKey] = portal
|
ctx.ReturnData[formatterContextPortalKey] = portal
|
||||||
ctx.ReturnData[formatterContextAllowedMentionsKey] = allowedMentions
|
ctx.ReturnData[formatterContextAllowedMentionsKey] = allowedMentions
|
||||||
if content.Mentions != nil {
|
if content.Mentions != nil {
|
||||||
|
|||||||
25
go.mod
25
go.mod
@@ -1,31 +1,32 @@
|
|||||||
module go.mau.fi/mautrix-discord
|
module go.mau.fi/mautrix-discord
|
||||||
|
|
||||||
go 1.23.0
|
go 1.25.0
|
||||||
|
|
||||||
toolchain go1.24.2
|
toolchain go1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bwmarrin/discordgo v0.27.0
|
github.com/bwmarrin/discordgo v0.27.0
|
||||||
github.com/gabriel-vasile/mimetype v1.4.8
|
github.com/gabriel-vasile/mimetype v1.4.9
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
github.com/mattn/go-sqlite3 v1.14.27
|
github.com/mattn/go-sqlite3 v1.14.28
|
||||||
github.com/rs/zerolog v1.34.0
|
github.com/rs/zerolog v1.34.0
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
github.com/yuin/goldmark v1.7.10
|
github.com/yuin/goldmark v1.7.12
|
||||||
go.mau.fi/util v0.2.2-0.20231228160422-22fdd4bbddeb
|
go.mau.fi/util v0.2.2-0.20231228160422-22fdd4bbddeb
|
||||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0
|
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc
|
||||||
golang.org/x/sync v0.13.0
|
golang.org/x/sync v0.16.0
|
||||||
maunium.net/go/maulogger/v2 v2.4.1
|
maunium.net/go/maulogger/v2 v2.4.1
|
||||||
maunium.net/go/mautrix v0.16.3-0.20240712164054-e6046fbf432c
|
maunium.net/go/mautrix v0.16.3-0.20250810202616-6bc5698125c2
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
@@ -34,12 +35,12 @@ require (
|
|||||||
github.com/tidwall/pretty v1.2.1 // indirect
|
github.com/tidwall/pretty v1.2.1 // indirect
|
||||||
github.com/tidwall/sjson v1.2.5 // indirect
|
github.com/tidwall/sjson v1.2.5 // indirect
|
||||||
go.mau.fi/zeroconfig v0.1.2 // indirect
|
go.mau.fi/zeroconfig v0.1.2 // indirect
|
||||||
golang.org/x/crypto v0.37.0 // indirect
|
golang.org/x/crypto v0.40.0 // indirect
|
||||||
golang.org/x/net v0.39.0 // indirect
|
golang.org/x/net v0.42.0 // indirect
|
||||||
golang.org/x/sys v0.32.0 // indirect
|
golang.org/x/sys v0.34.0 // indirect
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
maunium.net/go/mauflag v1.0.0 // indirect
|
maunium.net/go/mauflag v1.0.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20250320154217-0d7f942e6b38
|
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20260215125047-ccf8cbaa0a9f
|
||||||
|
|||||||
42
go.sum
42
go.sum
@@ -1,16 +1,18 @@
|
|||||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||||
github.com/beeper/discordgo v0.0.0-20250320154217-0d7f942e6b38 h1:1WoSvVGM1pI9f+x7EGD2QPaXSUQeF3B7Lox7bmVe//s=
|
github.com/beeper/discordgo v0.0.0-20260215125047-ccf8cbaa0a9f h1:A+SRmETpSnFixbP1x6u7sQdoi8cOuYfL5bkDJy9F/Pg=
|
||||||
github.com/beeper/discordgo v0.0.0-20250320154217-0d7f942e6b38/go.mod h1:59+AOzzjmL6onAh62nuLXmn7dJCaC/owDLWbGtjTcFA=
|
github.com/beeper/discordgo v0.0.0-20260215125047-ccf8cbaa0a9f/go.mod h1:lioivnibvB8j1KcF5TVpLdRLKCKHtcl8A03GpxRCre4=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
@@ -22,8 +24,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
|||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.27 h1:drZCnuvf37yPfs95E5jd9s3XhdVWLal+6BOK6qrv6IU=
|
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
||||||
github.com/mattn/go-sqlite3 v1.14.27/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
@@ -44,25 +46,25 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
|||||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||||
github.com/yuin/goldmark v1.7.10 h1:S+LrtBjRmqMac2UdtB6yyCEJm+UILZ2fefI4p7o0QpI=
|
github.com/yuin/goldmark v1.7.12 h1:YwGP/rrea2/CnCtUHgjuolG/PnMxdQtPMO5PvaE2/nY=
|
||||||
github.com/yuin/goldmark v1.7.10/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
github.com/yuin/goldmark v1.7.12/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||||
go.mau.fi/util v0.2.2-0.20231228160422-22fdd4bbddeb h1:Is+6vDKgINRy9KHodvi7NElxoDaWA8sc2S3cF3+QWjs=
|
go.mau.fi/util v0.2.2-0.20231228160422-22fdd4bbddeb h1:Is+6vDKgINRy9KHodvi7NElxoDaWA8sc2S3cF3+QWjs=
|
||||||
go.mau.fi/util v0.2.2-0.20231228160422-22fdd4bbddeb/go.mod h1:tiBX6nxVSOjU89jVQ7wBh3P8KjM26Lv1k7/I5QdSvBw=
|
go.mau.fi/util v0.2.2-0.20231228160422-22fdd4bbddeb/go.mod h1:tiBX6nxVSOjU89jVQ7wBh3P8KjM26Lv1k7/I5QdSvBw=
|
||||||
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
|
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
|
||||||
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||||
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
|
||||||
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
|
||||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM=
|
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc h1:TS73t7x3KarrNd5qAipmspBDS1rkMcgVG/fS1aRb4Rc=
|
||||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8=
|
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc=
|
||||||
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
|
||||||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
|
||||||
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||||
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
|
||||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||||
@@ -73,5 +75,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
|||||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||||
maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8=
|
maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8=
|
||||||
maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho=
|
maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho=
|
||||||
maunium.net/go/mautrix v0.16.3-0.20240712164054-e6046fbf432c h1:LHjqti3fFzrC8LXkkxxKYlLbuI/CJcwa2JN4Ppg2GK0=
|
maunium.net/go/mautrix v0.16.3-0.20250810202616-6bc5698125c2 h1:8PdwIklPNHTL/tI9tG2S0Tf9UvAgRt8yZjJbjV0XIpA=
|
||||||
maunium.net/go/mautrix v0.16.3-0.20240712164054-e6046fbf432c/go.mod h1:gCgLw/4c1a8QsiOWTdUdXlt5cYdE0rJ9wLeZQKPD58Q=
|
maunium.net/go/mautrix v0.16.3-0.20250810202616-6bc5698125c2/go.mod h1:gCgLw/4c1a8QsiOWTdUdXlt5cYdE0rJ9wLeZQKPD58Q=
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ func (guild *Guild) CreateMatrixRoom(user *User, meta *discordgo.Guild) error {
|
|||||||
Preset: "private_chat",
|
Preset: "private_chat",
|
||||||
InitialState: initialState,
|
InitialState: initialState,
|
||||||
CreationContent: creationContent,
|
CreationContent: creationContent,
|
||||||
|
RoomVersion: "11",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guild.log.Warnln("Failed to create room:", err)
|
guild.log.Warnln("Failed to create room:", err)
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -26,6 +26,7 @@ import (
|
|||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
"maunium.net/go/mautrix/bridge"
|
"maunium.net/go/mautrix/bridge"
|
||||||
"maunium.net/go/mautrix/bridge/commands"
|
"maunium.net/go/mautrix/bridge/commands"
|
||||||
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"go.mau.fi/mautrix-discord/config"
|
"go.mau.fi/mautrix-discord/config"
|
||||||
@@ -95,6 +96,7 @@ func (br *DiscordBridge) GetConfigPtr() interface{} {
|
|||||||
func (br *DiscordBridge) Init() {
|
func (br *DiscordBridge) Init() {
|
||||||
br.CommandProcessor = commands.NewProcessor(&br.Bridge)
|
br.CommandProcessor = commands.NewProcessor(&br.Bridge)
|
||||||
br.RegisterCommands()
|
br.RegisterCommands()
|
||||||
|
br.EventProcessor.On(event.StateTombstone, br.HandleTombstone)
|
||||||
|
|
||||||
matrixHTMLParser.PillConverter = br.pillConverter
|
matrixHTMLParser.PillConverter = br.pillConverter
|
||||||
|
|
||||||
@@ -185,7 +187,7 @@ func main() {
|
|||||||
Name: "mautrix-discord",
|
Name: "mautrix-discord",
|
||||||
URL: "https://github.com/mautrix/discord",
|
URL: "https://github.com/mautrix/discord",
|
||||||
Description: "A Matrix-Discord puppeting bridge.",
|
Description: "A Matrix-Discord puppeting bridge.",
|
||||||
Version: "0.7.3",
|
Version: "0.7.6",
|
||||||
ProtocolName: "Discord",
|
ProtocolName: "Discord",
|
||||||
BeeperServiceName: "discordgo",
|
BeeperServiceName: "discordgo",
|
||||||
BeeperNetworkName: "discord",
|
BeeperNetworkName: "discord",
|
||||||
|
|||||||
147
portal.go
147
portal.go
@@ -489,6 +489,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
|
|||||||
IsDirect: portal.IsPrivateChat(),
|
IsDirect: portal.IsPrivateChat(),
|
||||||
InitialState: initialState,
|
InitialState: initialState,
|
||||||
CreationContent: creationContent,
|
CreationContent: creationContent,
|
||||||
|
RoomVersion: "11",
|
||||||
}
|
}
|
||||||
if !portal.shouldSetDMRoomMetadata() && !portal.FriendNick {
|
if !portal.shouldSetDMRoomMetadata() && !portal.FriendNick {
|
||||||
req.Name = ""
|
req.Name = ""
|
||||||
@@ -1521,9 +1522,15 @@ func (portal *Portal) RefererOptIfUser(sess *discordgo.Session, threadID string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
||||||
if portal.IsPrivateChat() && sender.DiscordID != portal.Key.Receiver {
|
if portal.IsPrivateChat() {
|
||||||
go portal.sendMessageMetrics(evt, errUserNotReceiver, "Ignoring")
|
if !sender.IsLoggedIn() {
|
||||||
return
|
go portal.sendMessageMetrics(evt, errUserNotLoggedIn, "Ignoring")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sender.DiscordID != portal.Key.Receiver {
|
||||||
|
go portal.sendMessageMetrics(evt, errUserNotReceiver, "Ignoring")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content, ok := evt.Content.Parsed.(*event.MessageEventContent)
|
content, ok := evt.Content.Parsed.(*event.MessageEventContent)
|
||||||
@@ -1544,7 +1551,8 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
|||||||
if editMXID := content.GetRelatesTo().GetReplaceID(); editMXID != "" && content.NewContent != nil {
|
if editMXID := content.GetRelatesTo().GetReplaceID(); editMXID != "" && content.NewContent != nil {
|
||||||
edits := portal.bridge.DB.Message.GetByMXID(portal.Key, editMXID)
|
edits := portal.bridge.DB.Message.GetByMXID(portal.Key, editMXID)
|
||||||
if edits != nil {
|
if edits != nil {
|
||||||
discordContent, allowedMentions := portal.parseMatrixHTML(content.NewContent)
|
newContentRaw, _ := evt.Content.Raw["m.new_content"].(map[string]any)
|
||||||
|
discordContent, allowedMentions := portal.parseMatrixHTML(content.NewContent, parseAllowedLinkPreviews(newContentRaw))
|
||||||
var err error
|
var err error
|
||||||
var msg *discordgo.Message
|
var msg *discordgo.Message
|
||||||
if !isWebhookSend {
|
if !isWebhookSend {
|
||||||
@@ -1623,7 +1631,7 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
|||||||
}
|
}
|
||||||
switch content.MsgType {
|
switch content.MsgType {
|
||||||
case event.MsgText, event.MsgEmote, event.MsgNotice:
|
case event.MsgText, event.MsgEmote, event.MsgNotice:
|
||||||
sendReq.Content, sendReq.AllowedMentions = portal.parseMatrixHTML(content)
|
sendReq.Content, sendReq.AllowedMentions = portal.parseMatrixHTML(content, parseAllowedLinkPreviews(evt.Content.Raw))
|
||||||
if content.MsgType == event.MsgEmote {
|
if content.MsgType == event.MsgEmote {
|
||||||
sendReq.Content = fmt.Sprintf("_%s_", sendReq.Content)
|
sendReq.Content = fmt.Sprintf("_%s_", sendReq.Content)
|
||||||
}
|
}
|
||||||
@@ -1636,21 +1644,30 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
|||||||
filename := content.Body
|
filename := content.Body
|
||||||
if content.FileName != "" && content.FileName != content.Body {
|
if content.FileName != "" && content.FileName != content.Body {
|
||||||
filename = content.FileName
|
filename = content.FileName
|
||||||
sendReq.Content, sendReq.AllowedMentions = portal.parseMatrixHTML(content)
|
sendReq.Content, sendReq.AllowedMentions = portal.parseMatrixHTML(content, parseAllowedLinkPreviews(evt.Content.Raw))
|
||||||
|
}
|
||||||
|
|
||||||
|
if evt.Content.Raw["page.codeberg.everypizza.msc4193.spoiler"] == true {
|
||||||
|
filename = "SPOILER_" + filename
|
||||||
}
|
}
|
||||||
|
|
||||||
if portal.bridge.Config.Bridge.UseDiscordCDNUpload && !isWebhookSend && sess.IsUser {
|
if portal.bridge.Config.Bridge.UseDiscordCDNUpload && !isWebhookSend && sess.IsUser {
|
||||||
att := &discordgo.MessageAttachment{
|
att := &discordgo.MessageAttachment{
|
||||||
ID: "0",
|
ID: "0",
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
Description: description,
|
Description: description,
|
||||||
|
OriginalContentType: content.Info.MimeType,
|
||||||
}
|
}
|
||||||
sendReq.Attachments = []*discordgo.MessageAttachment{att}
|
sendReq.Attachments = []*discordgo.MessageAttachment{att}
|
||||||
|
isClip := false
|
||||||
prep, err := sender.Session.ChannelAttachmentCreate(channelID, &discordgo.ReqPrepareAttachments{
|
prep, err := sender.Session.ChannelAttachmentCreate(channelID, &discordgo.ReqPrepareAttachments{
|
||||||
Files: []*discordgo.FilePrepare{{
|
Files: []*discordgo.FilePrepare{{
|
||||||
Size: len(data),
|
Size: len(data),
|
||||||
Name: att.Filename,
|
Name: att.Filename,
|
||||||
ID: sender.NextDiscordUploadID(),
|
ID: sender.NextDiscordUploadID(),
|
||||||
|
|
||||||
|
IsClip: &isClip,
|
||||||
|
OriginalContentType: att.OriginalContentType,
|
||||||
}},
|
}},
|
||||||
}, portal.RefererOpt(threadID))
|
}, portal.RefererOpt(threadID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1740,6 +1757,28 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseAllowedLinkPreviews(raw map[string]any) []string {
|
||||||
|
if raw == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
linkPreviews, ok := raw["com.beeper.linkpreviews"].([]any)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
allowedLinkPreviews := make([]string, 0, len(linkPreviews))
|
||||||
|
for _, preview := range linkPreviews {
|
||||||
|
previewMap, ok := preview.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
matchedURL, _ := previewMap["matched_url"].(string)
|
||||||
|
if matchedURL != "" {
|
||||||
|
allowedLinkPreviews = append(allowedLinkPreviews, matchedURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allowedLinkPreviews
|
||||||
|
}
|
||||||
|
|
||||||
func (portal *Portal) sendDeliveryReceipt(eventID id.EventID) {
|
func (portal *Portal) sendDeliveryReceipt(eventID id.EventID) {
|
||||||
if portal.bridge.Config.Bridge.DeliveryReceipts {
|
if portal.bridge.Config.Bridge.DeliveryReceipts {
|
||||||
err := portal.bridge.Bot.MarkRead(portal.MXID, eventID)
|
err := portal.bridge.Bot.MarkRead(portal.MXID, eventID)
|
||||||
@@ -1890,12 +1929,13 @@ func (portal *Portal) getMatrixUsers() ([]id.UserID, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) {
|
func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) {
|
||||||
|
if !sender.IsLoggedIn() {
|
||||||
|
go portal.sendMessageMetrics(evt, errUserNotLoggedIn, "Ignoring")
|
||||||
|
return
|
||||||
|
}
|
||||||
if portal.IsPrivateChat() && sender.DiscordID != portal.Key.Receiver {
|
if portal.IsPrivateChat() && sender.DiscordID != portal.Key.Receiver {
|
||||||
go portal.sendMessageMetrics(evt, errUserNotReceiver, "Ignoring")
|
go portal.sendMessageMetrics(evt, errUserNotReceiver, "Ignoring")
|
||||||
return
|
return
|
||||||
} else if !sender.IsLoggedIn() {
|
|
||||||
//go portal.sendMessageMetrics(evt, errReactionUserNotLoggedIn, "Ignoring")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reaction := evt.Content.AsReaction()
|
reaction := evt.Content.AsReaction()
|
||||||
@@ -2073,9 +2113,15 @@ func (portal *Portal) handleDiscordReaction(user *User, reaction *discordgo.Mess
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleMatrixRedaction(sender *User, evt *event.Event) {
|
func (portal *Portal) handleMatrixRedaction(sender *User, evt *event.Event) {
|
||||||
if portal.IsPrivateChat() && sender.DiscordID != portal.Key.Receiver {
|
if portal.IsPrivateChat() {
|
||||||
go portal.sendMessageMetrics(evt, errUserNotReceiver, "Ignoring")
|
if !sender.IsLoggedIn() {
|
||||||
return
|
go portal.sendMessageMetrics(evt, errUserNotLoggedIn, "Ignoring")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sender.DiscordID != portal.Key.Receiver {
|
||||||
|
go portal.sendMessageMetrics(evt, errUserNotReceiver, "Ignoring")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := sender.Session
|
sess := sender.Session
|
||||||
@@ -2530,3 +2576,74 @@ func (portal *Portal) UpdateInfo(source *User, meta *discordgo.Channel) *discord
|
|||||||
}
|
}
|
||||||
return meta
|
return meta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (br *DiscordBridge) HandleTombstone(evt *event.Event) {
|
||||||
|
if evt.StateKey == nil || *evt.StateKey != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
content, ok := evt.Content.Parsed.(*event.TombstoneEventContent)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer br.MatrixHandler.TrackEventDuration(evt.Type)()
|
||||||
|
portal := br.GetPortalByMXID(evt.RoomID)
|
||||||
|
if portal == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logEvt := portal.log.Debug().
|
||||||
|
Stringer("sender", evt.Sender).
|
||||||
|
Stringer("replacement_room", content.ReplacementRoom).
|
||||||
|
Str("body", content.Body)
|
||||||
|
if content.ReplacementRoom == "" {
|
||||||
|
logEvt.Msg("Received tombstone event with no replacement room, cleaning up portal")
|
||||||
|
portal.cleanup(true)
|
||||||
|
portal.RemoveMXID()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logEvt.Msg("Received tombstone event, joining new room")
|
||||||
|
_, err := br.Bot.JoinRoom(content.ReplacementRoom.String(), evt.Sender.Homeserver(), nil)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Err(err).Msg("Failed to join replacement room")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = br.Bot.State(content.ReplacementRoom)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Err(err).Msg("Failed to get state of replacement room")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
encrypted := br.AS.StateStore.IsEncrypted(portal.MXID)
|
||||||
|
br.portalsLock.Lock()
|
||||||
|
defer br.portalsLock.Unlock()
|
||||||
|
if portal.MXID != evt.RoomID {
|
||||||
|
portal.log.Warn().
|
||||||
|
Stringer("old_mxid", evt.RoomID).
|
||||||
|
Stringer("new_mxid", portal.MXID).
|
||||||
|
Msg("Portal MXID changed while processing tombstone event, not updating")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, alreadyAPortal := br.portalsByMXID[content.ReplacementRoom]
|
||||||
|
if alreadyAPortal {
|
||||||
|
portal.log.Warn().
|
||||||
|
Stringer("replacement_room", content.ReplacementRoom).
|
||||||
|
Msg("Replacement room is already a portal, not updating")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(portal.bridge.portalsByMXID, portal.MXID)
|
||||||
|
portal.MXID = content.ReplacementRoom
|
||||||
|
portal.bridge.portalsByMXID[portal.MXID] = portal
|
||||||
|
portal.log = portal.bridge.ZLog.With().
|
||||||
|
Str("channel_id", portal.Key.ChannelID).
|
||||||
|
Str("channel_receiver", portal.Key.Receiver).
|
||||||
|
Str("room_id", portal.MXID.String()).
|
||||||
|
Logger()
|
||||||
|
portal.AvatarSet = false
|
||||||
|
portal.NameSet = false
|
||||||
|
portal.TopicSet = false
|
||||||
|
portal.Encrypted = encrypted
|
||||||
|
portal.InSpace = ""
|
||||||
|
portal.FirstEventID = ""
|
||||||
|
portal.Update()
|
||||||
|
portal.log.Info().Msg("Followed tombstone and updated portal MXID")
|
||||||
|
portal.UpdateBridgeInfo()
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import (
|
|||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/format"
|
"maunium.net/go/mautrix/format"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
|
"go.mau.fi/mautrix-discord/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConvertedMessage struct {
|
type ConvertedMessage struct {
|
||||||
@@ -154,24 +156,27 @@ func (portal *Portal) convertDiscordAttachment(ctx context.Context, intent *apps
|
|||||||
Size: att.Size,
|
Size: att.Size,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var extra = make(map[string]any)
|
||||||
|
|
||||||
|
if strings.HasPrefix(att.Filename, "SPOILER_") {
|
||||||
|
extra["page.codeberg.everypizza.msc4193.spoiler"] = true
|
||||||
|
}
|
||||||
|
|
||||||
if att.Description != "" {
|
if att.Description != "" {
|
||||||
content.Body = att.Description
|
content.Body = att.Description
|
||||||
content.FileName = att.Filename
|
content.FileName = att.Filename
|
||||||
}
|
}
|
||||||
|
|
||||||
var extra map[string]any
|
|
||||||
|
|
||||||
switch strings.ToLower(strings.Split(att.ContentType, "/")[0]) {
|
switch strings.ToLower(strings.Split(att.ContentType, "/")[0]) {
|
||||||
case "audio":
|
case "audio":
|
||||||
content.MsgType = event.MsgAudio
|
content.MsgType = event.MsgAudio
|
||||||
if att.Waveform != nil {
|
if att.Waveform != nil {
|
||||||
// TODO convert waveform
|
// TODO convert waveform
|
||||||
extra = map[string]any{
|
extra["org.matrix.msc1767.audio"] = map[string]any{
|
||||||
"org.matrix.msc1767.audio": map[string]any{
|
"duration": int(att.DurationSeconds * 1000),
|
||||||
"duration": int(att.DurationSeconds * 1000),
|
|
||||||
},
|
|
||||||
"org.matrix.msc3245.voice": map[string]any{},
|
|
||||||
}
|
}
|
||||||
|
extra["org.matrix.msc3245.voice"] = map[string]any{}
|
||||||
}
|
}
|
||||||
case "image":
|
case "image":
|
||||||
content.MsgType = event.MsgImage
|
content.MsgType = event.MsgImage
|
||||||
@@ -398,10 +403,20 @@ func (puppet *Puppet) addWebhookMeta(part *ConvertedMessage, msg *discordgo.Mess
|
|||||||
"avatar_mxc": avatarURL.String(),
|
"avatar_mxc": avatarURL.String(),
|
||||||
}
|
}
|
||||||
profileID := sha256.Sum256(fmt.Appendf(nil, "%s:%s", msg.Author.Username, msg.Author.Avatar))
|
profileID := sha256.Sum256(fmt.Appendf(nil, "%s:%s", msg.Author.Username, msg.Author.Avatar))
|
||||||
|
hasFallback := false
|
||||||
|
if msg.ApplicationID == "" &&
|
||||||
|
puppet.bridge.Config.Bridge.PrefixWebhookMessages &&
|
||||||
|
(part.Content.MsgType == event.MsgText || part.Content.MsgType == event.MsgNotice || (part.Content.FileName != "" && part.Content.FileName != part.Content.Body)) {
|
||||||
|
part.Content.EnsureHasHTML()
|
||||||
|
part.Content.Body = fmt.Sprintf("%s: %s", msg.Author.Username, part.Content.Body)
|
||||||
|
part.Content.FormattedBody = fmt.Sprintf("<strong data-mx-profile-fallback>%s: </strong>%s", html.EscapeString(msg.Author.Username), part.Content.FormattedBody)
|
||||||
|
hasFallback = true
|
||||||
|
}
|
||||||
part.Extra["com.beeper.per_message_profile"] = map[string]any{
|
part.Extra["com.beeper.per_message_profile"] = map[string]any{
|
||||||
"id": hex.EncodeToString(profileID[:]),
|
"id": hex.EncodeToString(profileID[:]),
|
||||||
"avatar_url": avatarURL.String(),
|
"avatar_url": avatarURL.String(),
|
||||||
"displayname": msg.Author.Username,
|
"displayname": msg.Author.Username,
|
||||||
|
"has_fallback": hasFallback,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,6 +676,12 @@ func (portal *Portal) convertDiscordMentions(msg *discordgo.Message, syncGhosts
|
|||||||
return &matrixMentions
|
return &matrixMentions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const forwardTemplateHTML = `<blockquote>
|
||||||
|
<p>↷ Forwarded</p>
|
||||||
|
%s
|
||||||
|
<p>%s</p>
|
||||||
|
</blockquote>`
|
||||||
|
|
||||||
func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *appservice.IntentAPI, msg *discordgo.Message) *ConvertedMessage {
|
func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *appservice.IntentAPI, msg *discordgo.Message) *ConvertedMessage {
|
||||||
log := zerolog.Ctx(ctx)
|
log := zerolog.Ctx(ctx)
|
||||||
if msg.Type == discordgo.MessageTypeCall {
|
if msg.Type == discordgo.MessageTypeCall {
|
||||||
@@ -682,6 +703,36 @@ func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *app
|
|||||||
}
|
}
|
||||||
if msg.Content != "" && !isPlainGifMessage(msg) {
|
if msg.Content != "" && !isPlainGifMessage(msg) {
|
||||||
htmlParts = append(htmlParts, portal.renderDiscordMarkdownOnlyHTML(msg.Content, true))
|
htmlParts = append(htmlParts, portal.renderDiscordMarkdownOnlyHTML(msg.Content, true))
|
||||||
|
} else if msg.MessageReference != nil &&
|
||||||
|
msg.MessageReference.Type == discordgo.MessageReferenceTypeForward &&
|
||||||
|
len(msg.MessageSnapshots) > 0 &&
|
||||||
|
msg.MessageSnapshots[0].Message != nil {
|
||||||
|
forwardedHTML := portal.renderDiscordMarkdownOnlyHTMLNoUnwrap(msg.MessageSnapshots[0].Message.Content, true)
|
||||||
|
msgTSText := msg.MessageSnapshots[0].Message.Timestamp.Format("2006-01-02 15:04 MST")
|
||||||
|
origLink := fmt.Sprintf("unknown channel • %s", msgTSText)
|
||||||
|
forwardedFromPortal := portal.bridge.GetExistingPortalByID(database.NewPortalKey(msg.MessageReference.ChannelID, ""))
|
||||||
|
if forwardedFromPortal != nil {
|
||||||
|
origMessage := portal.bridge.DB.Message.GetFirstByDiscordID(forwardedFromPortal.Key, msg.MessageReference.MessageID)
|
||||||
|
if origMessage != nil {
|
||||||
|
origLink = fmt.Sprintf(
|
||||||
|
`<a href="%s">#%s • %s</a>`,
|
||||||
|
forwardedFromPortal.MXID.EventURI(origMessage.MXID, portal.bridge.AS.HomeserverDomain),
|
||||||
|
forwardedFromPortal.PlainName,
|
||||||
|
msgTSText,
|
||||||
|
)
|
||||||
|
} else if forwardedFromPortal.MXID != "" {
|
||||||
|
origLink = fmt.Sprintf(
|
||||||
|
`<a href="%s">#%s</a> • %s`,
|
||||||
|
forwardedFromPortal.MXID.URI(portal.bridge.AS.HomeserverDomain),
|
||||||
|
forwardedFromPortal.PlainName,
|
||||||
|
msgTSText,
|
||||||
|
)
|
||||||
|
} else if forwardedFromPortal.PlainName != "" {
|
||||||
|
origLink = fmt.Sprintf("%s • %s", forwardedFromPortal.PlainName, msgTSText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlParts = append(htmlParts, fmt.Sprintf(forwardTemplateHTML, forwardedHTML, origLink))
|
||||||
}
|
}
|
||||||
previews := make([]*BeeperLinkPreview, 0)
|
previews := make([]*BeeperLinkPreview, 0)
|
||||||
for i, embed := range msg.Embeds {
|
for i, embed := range msg.Embeds {
|
||||||
@@ -724,11 +775,5 @@ func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *app
|
|||||||
"com.beeper.linkpreviews": previews,
|
"com.beeper.linkpreviews": previews,
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.WebhookID != "" && msg.ApplicationID == "" && portal.bridge.Config.Bridge.PrefixWebhookMessages {
|
|
||||||
content.EnsureHasHTML()
|
|
||||||
content.Body = fmt.Sprintf("%s: %s", msg.Author.Username, content.Body)
|
|
||||||
content.FormattedBody = fmt.Sprintf("<strong>%s</strong>: %s", html.EscapeString(msg.Author.Username), content.FormattedBody)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ConvertedMessage{Type: event.EventMessage, Content: &content, Extra: extraContent}
|
return &ConvertedMessage{Type: event.EventMessage, Content: &content, Extra: extraContent}
|
||||||
}
|
}
|
||||||
|
|||||||
21
user.go
21
user.go
@@ -344,6 +344,7 @@ func (user *User) getSpaceRoom(ptr *id.RoomID, name, topic string, parent id.Roo
|
|||||||
user.MXID: 50,
|
user.MXID: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
RoomVersion: "11",
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -549,6 +550,17 @@ func (user *User) Connect() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.HeartbeatSession == nil || user.HeartbeatSession.IsExpired() {
|
||||||
|
user.log.Debug().Msg("Creating new heartbeat session")
|
||||||
|
sess := discordgo.NewHeartbeatSession()
|
||||||
|
user.HeartbeatSession = &sess
|
||||||
|
}
|
||||||
|
user.HeartbeatSession.BumpLastUsed()
|
||||||
|
user.Update()
|
||||||
|
// make discordgo use our session instead of the one it creates automatically
|
||||||
|
session.HeartbeatSession = *user.HeartbeatSession
|
||||||
|
|
||||||
if user.bridge.Config.Bridge.Proxy != "" {
|
if user.bridge.Config.Bridge.Proxy != "" {
|
||||||
u, _ := url.Parse(user.bridge.Config.Bridge.Proxy)
|
u, _ := url.Parse(user.bridge.Config.Bridge.Proxy)
|
||||||
tlsConf := &tls.Config{
|
tlsConf := &tls.Config{
|
||||||
@@ -568,7 +580,10 @@ func (user *User) Connect() error {
|
|||||||
} else {
|
} else {
|
||||||
session.LogLevel = discordgo.LogInformational
|
session.LogLevel = discordgo.LogInformational
|
||||||
}
|
}
|
||||||
userDiscordLog := user.log.With().Str("component", "discordgo").Logger()
|
userDiscordLog := user.log.With().
|
||||||
|
Str("component", "discordgo").
|
||||||
|
Str("heartbeat_session", session.HeartbeatSession.ID.String()).
|
||||||
|
Logger()
|
||||||
session.Logger = func(msgL, caller int, format string, a ...interface{}) {
|
session.Logger = func(msgL, caller int, format string, a ...interface{}) {
|
||||||
userDiscordLog.WithLevel(discordToZeroLevel(msgL)).Caller(caller+1).Msgf(strings.TrimSpace(format), a...) // zerolog-allow-msgf
|
userDiscordLog.WithLevel(discordToZeroLevel(msgL)).Caller(caller+1).Msgf(strings.TrimSpace(format), a...) // zerolog-allow-msgf
|
||||||
}
|
}
|
||||||
@@ -806,6 +821,7 @@ func (user *User) subscribeGuilds(delay time.Duration) {
|
|||||||
func (user *User) resumeHandler(_ *discordgo.Resumed) {
|
func (user *User) resumeHandler(_ *discordgo.Resumed) {
|
||||||
user.log.Debug().Msg("Discord connection resumed")
|
user.log.Debug().Msg("Discord connection resumed")
|
||||||
user.subscribeGuilds(0 * time.Second)
|
user.subscribeGuilds(0 * time.Second)
|
||||||
|
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) addPrivateChannelToSpace(portal *Portal) bool {
|
func (user *User) addPrivateChannelToSpace(portal *Portal) bool {
|
||||||
@@ -1006,7 +1022,6 @@ func (user *User) connectedHandler(_ *discordgo.Connect) {
|
|||||||
user.log.Debug().Msg("Connected to Discord")
|
user.log.Debug().Msg("Connected to Discord")
|
||||||
if user.wasDisconnected {
|
if user.wasDisconnected {
|
||||||
user.wasDisconnected = false
|
user.wasDisconnected = false
|
||||||
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1153,7 +1168,7 @@ func (user *User) channelUpdateHandler(c *discordgo.ChannelUpdate) {
|
|||||||
portal := user.GetPortalByMeta(c.Channel)
|
portal := user.GetPortalByMeta(c.Channel)
|
||||||
if c.GuildID == "" {
|
if c.GuildID == "" {
|
||||||
user.handlePrivateChannel(portal, c.Channel, time.Now(), true, user.IsInSpace(portal.Key.String()))
|
user.handlePrivateChannel(portal, c.Channel, time.Now(), true, user.IsInSpace(portal.Key.String()))
|
||||||
} else {
|
} else if user.channelIsBridgeable(c.Channel) {
|
||||||
portal.UpdateInfo(user, c.Channel)
|
portal.UpdateInfo(user, c.Channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user