Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dab1aba6e5 | ||
|
|
792ad54b9c | ||
|
|
9b7b60966f | ||
|
|
104ee2da57 | ||
|
|
41d0ffcf3b | ||
|
|
b87421f0fb | ||
|
|
3c4561113b | ||
|
|
3eb5c44be3 | ||
|
|
a67d6d2af7 | ||
|
|
f4284e7b3f | ||
|
|
07785997bf | ||
|
|
62a1d83508 | ||
|
|
57b7be8cbb | ||
|
|
f5ffbe1311 | ||
|
|
be1128fd50 | ||
|
|
b4249488db | ||
|
|
b446d865d0 | ||
|
|
25d07c9c34 | ||
|
|
200c4fc9d0 | ||
|
|
d39499cdcf | ||
|
|
c449696120 | ||
|
|
914b360720 | ||
|
|
11b91dc299 | ||
|
|
b77eea4586 | ||
|
|
8ebad277f5 | ||
|
|
248664f8b0 | ||
|
|
3247709abb | ||
|
|
00465bb715 | ||
|
|
cf640ac83d | ||
|
|
67c8d9237e | ||
|
|
b2d7077e8d | ||
|
|
d5db336eee | ||
|
|
b153e70f2a | ||
|
|
cc30353075 | ||
|
|
4c62fe8b12 | ||
|
|
8c57b7a69b | ||
|
|
a265d03319 | ||
|
|
1c606e97a6 | ||
|
|
e6108cb25d | ||
|
|
d004aea9cb | ||
|
|
0fd88fedea | ||
|
|
1e9099e989 | ||
|
|
52fa4da8b2 | ||
|
|
4393772ccc | ||
|
|
824dea4745 | ||
|
|
07182efddd | ||
|
|
280e01969a | ||
|
|
084cde0162 | ||
|
|
434f27c8b4 | ||
|
|
75181741da | ||
|
|
e85f50633d |
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,3 +1,34 @@
|
|||||||
|
# v0.6.0 (2023-07-16)
|
||||||
|
|
||||||
|
* Added initial support for backfilling threads.
|
||||||
|
* Exposed `Application` flag to displayname template.
|
||||||
|
* Changed `m.emote` bridging to use italics on Discord.
|
||||||
|
* Updated Docker image to Alpine 3.18.
|
||||||
|
* Added limit to parallel media transfers to avoid high memory usage if lots
|
||||||
|
of messages are received at the same time.
|
||||||
|
* Fixed guilds being unbridged if Discord has server issues and temporarily
|
||||||
|
marks a guild as unavailable.
|
||||||
|
* Fixed using `guilds bridge` command without `--entire` flag.
|
||||||
|
* Fixed panic if lottieconverter isn't installed.
|
||||||
|
* Fixed relay webhook secret being leaked in network error messages.
|
||||||
|
|
||||||
|
# v0.5.0 (2023-06-16)
|
||||||
|
|
||||||
|
* Added support for intentional mentions in Matrix (MSC3952).
|
||||||
|
* Added `GlobalName` variable to displayname templates and updated the default
|
||||||
|
template to prefer it over usernames.
|
||||||
|
* Added `Webhook` variable to displayname templates to allow determining if a
|
||||||
|
ghost user is a webhook.
|
||||||
|
* Added guild profiles and webhook profiles as a custom field in Matrix
|
||||||
|
message events.
|
||||||
|
* Added support for bulk message delete from Discord.
|
||||||
|
* Added support for appservice websockets.
|
||||||
|
* Enabled parsing headers (`#`) in Discord markdown.
|
||||||
|
* Messages that consist of a single image link are now bridged as images to
|
||||||
|
closer match Discord.
|
||||||
|
* Stopped bridging incoming typing notifications from users who are logged into
|
||||||
|
the bridge to prevent echoes.
|
||||||
|
|
||||||
# v0.4.0 (2023-05-16)
|
# v0.4.0 (2023-05-16)
|
||||||
|
|
||||||
* Added bridging of friend nicks into DM room names.
|
* Added bridging of friend nicks into DM room names.
|
||||||
@@ -6,12 +37,17 @@
|
|||||||
* Added conversion of replies to embeds when sending messages via webhook.
|
* Added conversion of replies to embeds when sending messages via webhook.
|
||||||
* Added option to disable caching reuploaded media. This may be necessary when
|
* Added option to disable caching reuploaded media. This may be necessary when
|
||||||
using a media repo that doesn't create a unique mxc URI for each upload.
|
using a media repo that doesn't create a unique mxc URI for each upload.
|
||||||
|
* Added option to disable uploading files directly to the Discord CDN
|
||||||
|
(and send as form parts in the message send request instead).
|
||||||
* Improved formatting of error messages returned by Discord.
|
* Improved formatting of error messages returned by Discord.
|
||||||
* Enabled discordgo info logs by default.
|
* Enabled discordgo info logs by default.
|
||||||
* Fixed limited backfill always stopping after 50 messages
|
* Fixed limited backfill always stopping after 50 messages
|
||||||
(thanks to [@odrling] in [#81]).
|
(thanks to [@odrling] in [#81]).
|
||||||
* Fixed startup sync to sync most recent private channels first.
|
* Fixed startup sync to sync most recent private channels first.
|
||||||
* Fixed syncing group DM participants when they change.
|
* Fixed syncing group DM participants when they change.
|
||||||
|
* Fixed bridging animated emojis in messages.
|
||||||
|
* Stopped handling all message edits from relay webhook to prevent incorrect
|
||||||
|
edits.
|
||||||
* Possibly fixed inviting to portal rooms when multiple Matrix users use the
|
* Possibly fixed inviting to portal rooms when multiple Matrix users use the
|
||||||
bridge.
|
bridge.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.17 AS lottie
|
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.18 AS lottie
|
||||||
|
|
||||||
FROM golang:1-alpine3.17 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,7 +8,7 @@ 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.17
|
FROM alpine:3.18
|
||||||
|
|
||||||
ENV UID=1337 \
|
ENV UID=1337 \
|
||||||
GID=1337
|
GID=1337
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.17 AS lottie
|
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.18 AS lottie
|
||||||
|
|
||||||
FROM alpine:3.17
|
FROM alpine:3.18
|
||||||
|
|
||||||
ENV UID=1337 \
|
ENV UID=1337 \
|
||||||
GID=1337
|
GID=1337
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.17 AS lottie
|
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.18 AS lottie
|
||||||
|
|
||||||
FROM golang:1-alpine3.17 AS builder
|
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 \
|
RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev bash jq yq curl \
|
||||||
zlib libpng giflib libstdc++ libgcc
|
zlib libpng giflib libstdc++ libgcc
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
@@ -28,7 +30,7 @@ import (
|
|||||||
"go.mau.fi/mautrix-discord/database"
|
"go.mau.fi/mautrix-discord/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func downloadDiscordAttachment(url string) ([]byte, error) {
|
func downloadDiscordAttachment(url string, maxSize int64) ([]byte, error) {
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -44,9 +46,24 @@ func downloadDiscordAttachment(url string) ([]byte, error) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode > 300 {
|
if resp.StatusCode > 300 {
|
||||||
data, _ := io.ReadAll(resp.Body)
|
data, _ := io.ReadAll(resp.Body)
|
||||||
return nil, fmt.Errorf("unexpected status %d: %s", resp.StatusCode, data)
|
return nil, fmt.Errorf("unexpected status %d downloading %s: %s", resp.StatusCode, url, data)
|
||||||
|
}
|
||||||
|
if resp.Header.Get("Content-Length") != "" {
|
||||||
|
length, err := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse content length: %w", err)
|
||||||
|
} else if length > maxSize {
|
||||||
|
return nil, fmt.Errorf("attachment too large (%d > %d)", length, maxSize)
|
||||||
|
}
|
||||||
|
return io.ReadAll(resp.Body)
|
||||||
|
} else {
|
||||||
|
var mbe *http.MaxBytesError
|
||||||
|
data, err := io.ReadAll(http.MaxBytesReader(nil, resp.Body, maxSize))
|
||||||
|
if err != nil && errors.As(err, &mbe) {
|
||||||
|
return nil, fmt.Errorf("attachment too large (over %d)", maxSize)
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
}
|
}
|
||||||
return io.ReadAll(resp.Body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadDiscordAttachment(url string, data []byte) error {
|
func uploadDiscordAttachment(url string, data []byte) error {
|
||||||
@@ -99,7 +116,7 @@ func downloadMatrixAttachment(intent *appservice.IntentAPI, content *event.Messa
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *DiscordBridge) uploadMatrixAttachment(intent *appservice.IntentAPI, data []byte, url string, encrypt bool, meta AttachmentMeta) (*database.File, error) {
|
func (br *DiscordBridge) uploadMatrixAttachment(intent *appservice.IntentAPI, data []byte, url string, encrypt bool, meta AttachmentMeta, semaWg *sync.WaitGroup) (*database.File, error) {
|
||||||
dbFile := br.DB.File.New()
|
dbFile := br.DB.File.New()
|
||||||
dbFile.Timestamp = time.Now()
|
dbFile.Timestamp = time.Now()
|
||||||
dbFile.URL = url
|
dbFile.URL = url
|
||||||
@@ -128,17 +145,19 @@ func (br *DiscordBridge) uploadMatrixAttachment(intent *appservice.IntentAPI, da
|
|||||||
ContentType: uploadMime,
|
ContentType: uploadMime,
|
||||||
}
|
}
|
||||||
if br.Config.Homeserver.AsyncMedia {
|
if br.Config.Homeserver.AsyncMedia {
|
||||||
resp, err := intent.UnstableCreateMXC()
|
resp, err := intent.CreateMXC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dbFile.MXC = resp.ContentURI
|
dbFile.MXC = resp.ContentURI
|
||||||
req.UnstableMXC = resp.ContentURI
|
req.MXC = resp.ContentURI
|
||||||
req.UploadURL = resp.UploadURL
|
req.UnstableUploadURL = resp.UnstableUploadURL
|
||||||
|
semaWg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer semaWg.Done()
|
||||||
_, err = intent.UploadMedia(req)
|
_, err = intent.UploadMedia(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
br.Log.Errorfln("Failed to upload %s: %v", req.UnstableMXC, err)
|
br.Log.Errorfln("Failed to upload %s: %v", req.MXC, err)
|
||||||
dbFile.Delete()
|
dbFile.Delete()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -259,8 +278,25 @@ func (br *DiscordBridge) copyAttachmentToMatrix(intent *appservice.IntentAPI, ur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const attachmentSizeVal = 1
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
onceErr = br.parallelAttachmentSemaphore.Acquire(ctx, attachmentSizeVal)
|
||||||
|
cancel()
|
||||||
|
if onceErr != nil {
|
||||||
|
br.ZLog.Warn().Err(onceErr).Msg("Failed to acquire semaphore")
|
||||||
|
onceErr = fmt.Errorf("reuploading timed out")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var semaWg sync.WaitGroup
|
||||||
|
semaWg.Add(1)
|
||||||
|
defer semaWg.Done()
|
||||||
|
go func() {
|
||||||
|
semaWg.Wait()
|
||||||
|
br.parallelAttachmentSemaphore.Release(attachmentSizeVal)
|
||||||
|
}()
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
data, onceErr = downloadDiscordAttachment(url)
|
data, onceErr = downloadDiscordAttachment(url, br.MediaConfig.UploadSize)
|
||||||
if onceErr != nil {
|
if onceErr != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -273,7 +309,7 @@ func (br *DiscordBridge) copyAttachmentToMatrix(intent *appservice.IntentAPI, ur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onceDBFile, onceErr = br.uploadMatrixAttachment(intent, data, url, encrypt, meta)
|
onceDBFile, onceErr = br.uploadMatrixAttachment(intent, data, url, encrypt, meta, &semaWg)
|
||||||
if onceErr != nil {
|
if onceErr != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
40
avatar.go
40
avatar.go
@@ -1,40 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
|
||||||
"maunium.net/go/mautrix/id"
|
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func uploadAvatar(intent *appservice.IntentAPI, url string) (id.ContentURI, error) {
|
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return id.ContentURI{}, fmt.Errorf("failed to prepare request: %w", err)
|
|
||||||
}
|
|
||||||
for key, value := range discordgo.DroidImageHeaders {
|
|
||||||
req.Header.Set(key, value)
|
|
||||||
}
|
|
||||||
getResp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return id.ContentURI{}, fmt.Errorf("failed to download avatar: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := io.ReadAll(getResp.Body)
|
|
||||||
_ = getResp.Body.Close()
|
|
||||||
if err != nil {
|
|
||||||
return id.ContentURI{}, fmt.Errorf("failed to read avatar data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mime := http.DetectContentType(data)
|
|
||||||
resp, err := intent.UploadBytes(data, mime)
|
|
||||||
if err != nil {
|
|
||||||
return id.ContentURI{}, fmt.Errorf("failed to upload avatar to Matrix: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.ContentURI, nil
|
|
||||||
}
|
|
||||||
153
backfill.go
153
backfill.go
@@ -10,15 +10,18 @@ import (
|
|||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"go.mau.fi/mautrix-discord/database"
|
"go.mau.fi/mautrix-discord/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (portal *Portal) forwardBackfillInitial(source *User) {
|
func (portal *Portal) forwardBackfillInitial(source *User, thread *Thread) {
|
||||||
defer portal.forwardBackfillLock.Unlock()
|
log := portal.log
|
||||||
|
defer func() {
|
||||||
|
log.Debug().Msg("Forward backfill finished, unlocking lock")
|
||||||
|
portal.forwardBackfillLock.Unlock()
|
||||||
|
}()
|
||||||
// This should only be called from CreateMatrixRoom which locks forwardBackfillLock before creating the room.
|
// This should only be called from CreateMatrixRoom which locks forwardBackfillLock before creating the room.
|
||||||
if portal.forwardBackfillLock.TryLock() {
|
if portal.forwardBackfillLock.TryLock() {
|
||||||
panic("forwardBackfillInitial() called without locking forwardBackfillLock")
|
panic("forwardBackfillInitial() called without locking forwardBackfillLock")
|
||||||
@@ -27,21 +30,28 @@ func (portal *Portal) forwardBackfillInitial(source *User) {
|
|||||||
limit := portal.bridge.Config.Bridge.Backfill.Limits.Initial.Channel
|
limit := portal.bridge.Config.Bridge.Backfill.Limits.Initial.Channel
|
||||||
if portal.GuildID == "" {
|
if portal.GuildID == "" {
|
||||||
limit = portal.bridge.Config.Bridge.Backfill.Limits.Initial.DM
|
limit = portal.bridge.Config.Bridge.Backfill.Limits.Initial.DM
|
||||||
|
if thread != nil {
|
||||||
|
limit = portal.bridge.Config.Bridge.Backfill.Limits.Initial.Thread
|
||||||
|
thread.initialBackfillAttempted = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if limit == 0 {
|
if limit == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log := portal.log.With().
|
with := log.With().
|
||||||
Str("action", "initial backfill").
|
Str("action", "initial backfill").
|
||||||
Str("room_id", portal.MXID.String()).
|
Str("room_id", portal.MXID.String()).
|
||||||
Int("limit", limit).
|
Int("limit", limit)
|
||||||
Logger()
|
if thread != nil {
|
||||||
|
with = with.Str("thread_id", thread.ID)
|
||||||
|
}
|
||||||
|
log = with.Logger()
|
||||||
|
|
||||||
portal.backfillLimited(log, source, limit, "")
|
portal.backfillLimited(log, source, limit, "", thread)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) ForwardBackfillMissed(source *User, meta *discordgo.Channel) {
|
func (portal *Portal) ForwardBackfillMissed(source *User, serverLastMessageID string, thread *Thread) {
|
||||||
if portal.MXID == "" {
|
if portal.MXID == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -49,50 +59,65 @@ func (portal *Portal) ForwardBackfillMissed(source *User, meta *discordgo.Channe
|
|||||||
limit := portal.bridge.Config.Bridge.Backfill.Limits.Missed.Channel
|
limit := portal.bridge.Config.Bridge.Backfill.Limits.Missed.Channel
|
||||||
if portal.GuildID == "" {
|
if portal.GuildID == "" {
|
||||||
limit = portal.bridge.Config.Bridge.Backfill.Limits.Missed.DM
|
limit = portal.bridge.Config.Bridge.Backfill.Limits.Missed.DM
|
||||||
|
if thread != nil {
|
||||||
|
limit = portal.bridge.Config.Bridge.Backfill.Limits.Missed.Thread
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if limit == 0 {
|
if limit == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log := portal.log.With().
|
with := portal.log.With().
|
||||||
Str("action", "missed event backfill").
|
Str("action", "missed event backfill").
|
||||||
Str("room_id", portal.MXID.String()).
|
Str("room_id", portal.MXID.String()).
|
||||||
Int("limit", limit).
|
Int("limit", limit)
|
||||||
Logger()
|
if thread != nil {
|
||||||
|
with = with.Str("thread_id", thread.ID)
|
||||||
|
}
|
||||||
|
log := with.Logger()
|
||||||
|
|
||||||
portal.forwardBackfillLock.Lock()
|
portal.forwardBackfillLock.Lock()
|
||||||
defer portal.forwardBackfillLock.Unlock()
|
defer portal.forwardBackfillLock.Unlock()
|
||||||
|
|
||||||
lastMessage := portal.bridge.DB.Message.GetLast(portal.Key)
|
var lastMessage *database.Message
|
||||||
if lastMessage == nil || meta.LastMessageID == "" {
|
if thread != nil {
|
||||||
|
lastMessage = portal.bridge.DB.Message.GetLastInThread(portal.Key, thread.ID)
|
||||||
|
} else {
|
||||||
|
lastMessage = portal.bridge.DB.Message.GetLast(portal.Key)
|
||||||
|
}
|
||||||
|
if lastMessage == nil || serverLastMessageID == "" {
|
||||||
log.Debug().Msg("Not backfilling, no last message in database or no last message in metadata")
|
log.Debug().Msg("Not backfilling, no last message in database or no last message in metadata")
|
||||||
return
|
return
|
||||||
} else if !shouldBackfill(lastMessage.DiscordID, meta.LastMessageID) {
|
} else if !shouldBackfill(lastMessage.DiscordID, serverLastMessageID) {
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("last_bridged_message", lastMessage.DiscordID).
|
Str("last_bridged_message", lastMessage.DiscordID).
|
||||||
Str("last_server_message", meta.LastMessageID).
|
Str("last_server_message", serverLastMessageID).
|
||||||
Msg("Not backfilling, last message in database is newer than last message in metadata")
|
Msg("Not backfilling, last message in database is newer than last message in metadata")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("last_bridged_message", lastMessage.DiscordID).
|
Str("last_bridged_message", lastMessage.DiscordID).
|
||||||
Str("last_server_message", meta.LastMessageID).
|
Str("last_server_message", serverLastMessageID).
|
||||||
Msg("Backfilling missed messages")
|
Msg("Backfilling missed messages")
|
||||||
if limit < 0 {
|
if limit < 0 {
|
||||||
portal.backfillUnlimitedMissed(log, source, lastMessage.DiscordID)
|
portal.backfillUnlimitedMissed(log, source, lastMessage.DiscordID, thread)
|
||||||
} else {
|
} else {
|
||||||
portal.backfillLimited(log, source, limit, lastMessage.DiscordID)
|
portal.backfillLimited(log, source, limit, lastMessage.DiscordID, thread)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageFetchChunkSize = 50
|
const messageFetchChunkSize = 50
|
||||||
|
|
||||||
func (portal *Portal) collectBackfillMessages(log zerolog.Logger, source *User, limit int, until string) ([]*discordgo.Message, bool, error) {
|
func (portal *Portal) collectBackfillMessages(log zerolog.Logger, source *User, limit int, until string, thread *Thread) ([]*discordgo.Message, bool, error) {
|
||||||
var messages []*discordgo.Message
|
var messages []*discordgo.Message
|
||||||
var before string
|
var before string
|
||||||
var foundAll bool
|
var foundAll bool
|
||||||
|
protoChannelID := portal.Key.ChannelID
|
||||||
|
if thread != nil {
|
||||||
|
protoChannelID = thread.ID
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
log.Debug().Str("before_id", before).Msg("Fetching messages for backfill")
|
log.Debug().Str("before_id", before).Msg("Fetching messages for backfill")
|
||||||
newMessages, err := source.Session.ChannelMessages(portal.Key.ChannelID, messageFetchChunkSize, before, "", "")
|
newMessages, err := source.Session.ChannelMessages(protoChannelID, messageFetchChunkSize, before, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
@@ -123,8 +148,8 @@ func (portal *Portal) collectBackfillMessages(log zerolog.Logger, source *User,
|
|||||||
return messages, foundAll, nil
|
return messages, foundAll, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) backfillLimited(log zerolog.Logger, source *User, limit int, after string) {
|
func (portal *Portal) backfillLimited(log zerolog.Logger, source *User, limit int, after string, thread *Thread) {
|
||||||
messages, foundAll, err := portal.collectBackfillMessages(log, source, limit, after)
|
messages, foundAll, err := portal.collectBackfillMessages(log, source, limit, after, thread)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("Error collecting messages to forward backfill")
|
log.Err(err).Msg("Error collecting messages to forward backfill")
|
||||||
return
|
return
|
||||||
@@ -134,7 +159,7 @@ func (portal *Portal) backfillLimited(log zerolog.Logger, source *User, limit in
|
|||||||
Bool("found_all", foundAll).
|
Bool("found_all", foundAll).
|
||||||
Msg("Collected messages to backfill")
|
Msg("Collected messages to backfill")
|
||||||
sort.Sort(MessageSlice(messages))
|
sort.Sort(MessageSlice(messages))
|
||||||
if !foundAll {
|
if !foundAll && after != "" {
|
||||||
_, err = portal.sendMatrixMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
|
_, err = portal.sendMatrixMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
|
||||||
MsgType: event.MsgNotice,
|
MsgType: event.MsgNotice,
|
||||||
Body: "Some messages may have been missed here while the bridge was offline.",
|
Body: "Some messages may have been missed here while the bridge was offline.",
|
||||||
@@ -145,13 +170,17 @@ func (portal *Portal) backfillLimited(log zerolog.Logger, source *User, limit in
|
|||||||
log.Debug().Msg("Sent warning about possibly missed messages")
|
log.Debug().Msg("Sent warning about possibly missed messages")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portal.sendBackfillBatch(log, source, messages)
|
portal.sendBackfillBatch(log, source, messages, thread)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) backfillUnlimitedMissed(log zerolog.Logger, source *User, after string) {
|
func (portal *Portal) backfillUnlimitedMissed(log zerolog.Logger, source *User, after string, thread *Thread) {
|
||||||
|
protoChannelID := portal.Key.ChannelID
|
||||||
|
if thread != nil {
|
||||||
|
protoChannelID = thread.ID
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
log.Debug().Str("after_id", after).Msg("Fetching chunk of messages to backfill")
|
log.Debug().Str("after_id", after).Msg("Fetching chunk of messages to backfill")
|
||||||
messages, err := source.Session.ChannelMessages(portal.Key.ChannelID, messageFetchChunkSize, "", after, "")
|
messages, err := source.Session.ChannelMessages(protoChannelID, messageFetchChunkSize, "", after, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("Error fetching chunk of messages to forward backfill")
|
log.Err(err).Msg("Error fetching chunk of messages to forward backfill")
|
||||||
return
|
return
|
||||||
@@ -159,7 +188,7 @@ func (portal *Portal) backfillUnlimitedMissed(log zerolog.Logger, source *User,
|
|||||||
log.Debug().Int("count", len(messages)).Msg("Fetched chunk of messages to backfill")
|
log.Debug().Int("count", len(messages)).Msg("Fetched chunk of messages to backfill")
|
||||||
sort.Sort(MessageSlice(messages))
|
sort.Sort(MessageSlice(messages))
|
||||||
|
|
||||||
portal.sendBackfillBatch(log, source, messages)
|
portal.sendBackfillBatch(log, source, messages, thread)
|
||||||
|
|
||||||
if len(messages) < messageFetchChunkSize {
|
if len(messages) < messageFetchChunkSize {
|
||||||
// Assume that was all the missing messages
|
// Assume that was all the missing messages
|
||||||
@@ -170,28 +199,28 @@ func (portal *Portal) backfillUnlimitedMissed(log zerolog.Logger, source *User,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) sendBackfillBatch(log zerolog.Logger, source *User, messages []*discordgo.Message) {
|
func (portal *Portal) sendBackfillBatch(log zerolog.Logger, source *User, messages []*discordgo.Message, thread *Thread) {
|
||||||
if portal.bridge.Config.Homeserver.Software == bridgeconfig.SoftwareHungry {
|
if portal.bridge.SpecVersions.Supports(mautrix.BeeperFeatureBatchSending) {
|
||||||
log.Debug().Msg("Using hungryserv, sending messages with batch send endpoint")
|
log.Debug().Msg("Using hungryserv, sending messages with batch send endpoint")
|
||||||
portal.forwardBatchSend(log, source, messages)
|
portal.forwardBatchSend(log, source, messages, thread)
|
||||||
} else {
|
} else {
|
||||||
log.Debug().Msg("Not using hungryserv, sending messages one by one")
|
log.Debug().Msg("Not using hungryserv, sending messages one by one")
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
portal.handleDiscordMessageCreate(source, msg, nil)
|
portal.handleDiscordMessageCreate(source, msg, thread)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, messages []*discordgo.Message) {
|
func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, messages []*discordgo.Message, thread *Thread) {
|
||||||
evts, dbMessages := portal.convertMessageBatch(log, source, messages)
|
evts, metas, dbMessages := portal.convertMessageBatch(log, source, messages, thread)
|
||||||
if len(evts) == 0 {
|
if len(evts) == 0 {
|
||||||
log.Warn().Msg("Didn't get any events to backfill")
|
log.Warn().Msg("Didn't get any events to backfill")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info().Int("events", len(evts)).Msg("Converted messages to backfill")
|
log.Info().Int("events", len(evts)).Msg("Converted messages to backfill")
|
||||||
resp, err := portal.MainIntent().BatchSend(portal.MXID, &mautrix.ReqBatchSend{
|
resp, err := portal.MainIntent().BeeperBatchSend(portal.MXID, &mautrix.ReqBeeperBatchSend{
|
||||||
BeeperNewMessages: true,
|
Forward: true,
|
||||||
Events: evts,
|
Events: evts,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("Error sending backfill batch")
|
log.Err(err).Msg("Error sending backfill batch")
|
||||||
@@ -199,25 +228,43 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message
|
|||||||
}
|
}
|
||||||
for i, evtID := range resp.EventIDs {
|
for i, evtID := range resp.EventIDs {
|
||||||
dbMessages[i].MXID = evtID
|
dbMessages[i].MXID = evtID
|
||||||
|
if metas[i] != nil && metas[i].Flags == discordgo.MessageFlagsHasThread {
|
||||||
|
// TODO proper context
|
||||||
|
ctx := log.WithContext(context.Background())
|
||||||
|
portal.bridge.threadFound(ctx, source, &dbMessages[i], metas[i].ID, metas[i].Thread)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
portal.bridge.DB.Message.MassInsert(portal.Key, dbMessages)
|
portal.bridge.DB.Message.MassInsert(portal.Key, dbMessages)
|
||||||
log.Info().Msg("Inserted backfilled batch to database")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, messages []*discordgo.Message) ([]*event.Event, []database.Message) {
|
func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, messages []*discordgo.Message, thread *Thread) ([]*event.Event, []*discordgo.Message, []database.Message) {
|
||||||
|
var discordThreadID string
|
||||||
|
var threadRootEvent, lastThreadEvent id.EventID
|
||||||
|
if thread != nil {
|
||||||
|
discordThreadID = thread.ID
|
||||||
|
threadRootEvent = thread.RootMXID
|
||||||
|
lastThreadEvent = threadRootEvent
|
||||||
|
lastInThread := portal.bridge.DB.Message.GetLastInThread(portal.Key, thread.ID)
|
||||||
|
if lastInThread != nil {
|
||||||
|
lastThreadEvent = lastInThread.MXID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
evts := make([]*event.Event, 0, len(messages))
|
evts := make([]*event.Event, 0, len(messages))
|
||||||
dbMessages := make([]database.Message, 0, len(messages))
|
dbMessages := make([]database.Message, 0, len(messages))
|
||||||
|
metas := make([]*discordgo.Message, 0, len(messages))
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
for _, mention := range msg.Mentions {
|
for _, mention := range msg.Mentions {
|
||||||
puppet := portal.bridge.GetPuppetByID(mention.ID)
|
puppet := portal.bridge.GetPuppetByID(mention.ID)
|
||||||
puppet.UpdateInfo(nil, mention)
|
puppet.UpdateInfo(nil, mention, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
||||||
puppet.UpdateInfo(source, msg.Author)
|
puppet.UpdateInfo(source, msg.Author, msg)
|
||||||
intent := puppet.IntentFor(portal)
|
intent := puppet.IntentFor(portal)
|
||||||
replyTo := portal.getReplyTarget(source, "", msg.MessageReference, msg.Embeds, true)
|
replyTo := portal.getReplyTarget(source, discordThreadID, msg.MessageReference, msg.Embeds, true)
|
||||||
|
mentions := portal.convertDiscordMentions(msg, false)
|
||||||
|
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
log := log.With().
|
log := log.With().
|
||||||
@@ -225,13 +272,24 @@ func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, mess
|
|||||||
Int("message_type", int(msg.Type)).
|
Int("message_type", int(msg.Type)).
|
||||||
Str("author_id", msg.Author.ID).
|
Str("author_id", msg.Author.ID).
|
||||||
Logger()
|
Logger()
|
||||||
parts := portal.convertDiscordMessage(log.WithContext(ctx), intent, msg)
|
parts := portal.convertDiscordMessage(log.WithContext(ctx), puppet, intent, msg)
|
||||||
for i, part := range parts {
|
for i, part := range parts {
|
||||||
|
if (replyTo != nil || threadRootEvent != "") && part.Content.RelatesTo == nil {
|
||||||
|
part.Content.RelatesTo = &event.RelatesTo{}
|
||||||
|
}
|
||||||
|
if threadRootEvent != "" {
|
||||||
|
part.Content.RelatesTo.SetThread(threadRootEvent, lastThreadEvent)
|
||||||
|
}
|
||||||
if replyTo != nil {
|
if replyTo != nil {
|
||||||
part.Content.RelatesTo = &event.RelatesTo{InReplyTo: replyTo}
|
part.Content.RelatesTo.SetReplyTo(replyTo.EventID)
|
||||||
// Only set reply for first event
|
// Only set reply for first event
|
||||||
replyTo = nil
|
replyTo = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
part.Content.Mentions = mentions
|
||||||
|
// Only set mentions for first event, but keep empty object for rest
|
||||||
|
mentions = &event.Mentions{}
|
||||||
|
|
||||||
partName := part.AttachmentID
|
partName := part.AttachmentID
|
||||||
// Always use blank part name for first part so that replies and other things
|
// Always use blank part name for first part so that replies and other things
|
||||||
// can reference it without knowing about attachments.
|
// can reference it without knowing about attachments.
|
||||||
@@ -262,10 +320,17 @@ func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, mess
|
|||||||
SenderID: msg.Author.ID,
|
SenderID: msg.Author.ID,
|
||||||
Timestamp: ts,
|
Timestamp: ts,
|
||||||
AttachmentID: part.AttachmentID,
|
AttachmentID: part.AttachmentID,
|
||||||
|
SenderMXID: intent.UserID,
|
||||||
})
|
})
|
||||||
|
if i == 0 {
|
||||||
|
metas = append(metas, msg)
|
||||||
|
} else {
|
||||||
|
metas = append(metas, nil)
|
||||||
|
}
|
||||||
|
lastThreadEvent = evt.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return evts, dbMessages
|
return evts, metas, dbMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) deterministicEventID(messageID, partName string) id.EventID {
|
func (portal *Portal) deterministicEventID(messageID, partName string) id.EventID {
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ type BridgeConfig struct {
|
|||||||
DeletePortalOnChannelDelete bool `yaml:"delete_portal_on_channel_delete"`
|
DeletePortalOnChannelDelete bool `yaml:"delete_portal_on_channel_delete"`
|
||||||
DeleteGuildOnLeave bool `yaml:"delete_guild_on_leave"`
|
DeleteGuildOnLeave bool `yaml:"delete_guild_on_leave"`
|
||||||
FederateRooms bool `yaml:"federate_rooms"`
|
FederateRooms bool `yaml:"federate_rooms"`
|
||||||
|
PrefixWebhookMessages bool `yaml:"prefix_webhook_messages"`
|
||||||
|
EnableWebhookAvatars bool `yaml:"enable_webhook_avatars"`
|
||||||
UseDiscordCDNUpload bool `yaml:"use_discord_cdn_upload"`
|
UseDiscordCDNUpload bool `yaml:"use_discord_cdn_upload"`
|
||||||
|
|
||||||
CacheMedia string `yaml:"cache_media"`
|
CacheMedia string `yaml:"cache_media"`
|
||||||
@@ -205,6 +207,7 @@ func (mp *MediaPatterns) Avatar(userID, avatarID, ext string) id.ContentURI {
|
|||||||
type BackfillLimitPart struct {
|
type BackfillLimitPart struct {
|
||||||
DM int `yaml:"dm"`
|
DM int `yaml:"dm"`
|
||||||
Channel int `yaml:"channel"`
|
Channel int `yaml:"channel"`
|
||||||
|
Thread int `yaml:"thread"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BridgeConfig) GetResendBridgeInfo() bool {
|
func (bc *BridgeConfig) GetResendBridgeInfo() bool {
|
||||||
@@ -287,9 +290,19 @@ func (bc BridgeConfig) FormatUsername(userID string) string {
|
|||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc BridgeConfig) FormatDisplayname(user *discordgo.User) string {
|
type DisplaynameParams struct {
|
||||||
|
*discordgo.User
|
||||||
|
Webhook bool
|
||||||
|
Application bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc BridgeConfig) FormatDisplayname(user *discordgo.User, webhook, application bool) string {
|
||||||
var buffer strings.Builder
|
var buffer strings.Builder
|
||||||
_ = bc.displaynameTemplate.Execute(&buffer, user)
|
_ = bc.displaynameTemplate.Execute(&buffer, &DisplaynameParams{
|
||||||
|
User: user,
|
||||||
|
Webhook: webhook,
|
||||||
|
Application: application,
|
||||||
|
})
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ func DoUpgrade(helper *up.Helper) {
|
|||||||
helper.Copy(up.Bool, "bridge", "delete_portal_on_channel_delete")
|
helper.Copy(up.Bool, "bridge", "delete_portal_on_channel_delete")
|
||||||
helper.Copy(up.Bool, "bridge", "delete_guild_on_leave")
|
helper.Copy(up.Bool, "bridge", "delete_guild_on_leave")
|
||||||
helper.Copy(up.Bool, "bridge", "federate_rooms")
|
helper.Copy(up.Bool, "bridge", "federate_rooms")
|
||||||
|
helper.Copy(up.Bool, "bridge", "prefix_webhook_messages")
|
||||||
|
helper.Copy(up.Bool, "bridge", "enable_webhook_avatars")
|
||||||
helper.Copy(up.Bool, "bridge", "use_discord_cdn_upload")
|
helper.Copy(up.Bool, "bridge", "use_discord_cdn_upload")
|
||||||
helper.Copy(up.Bool, "bridge", "media_patterns", "enabled")
|
helper.Copy(up.Bool, "bridge", "media_patterns", "enabled")
|
||||||
helper.Copy(up.Str, "bridge", "cache_media")
|
helper.Copy(up.Str, "bridge", "cache_media")
|
||||||
@@ -77,14 +79,17 @@ func DoUpgrade(helper *up.Helper) {
|
|||||||
helper.Copy(up.Bool, "bridge", "backfill", "enabled")
|
helper.Copy(up.Bool, "bridge", "backfill", "enabled")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "dm")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "dm")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "channel")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "channel")
|
||||||
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "thread")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "dm")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "dm")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "channel")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "channel")
|
||||||
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "thread")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "max_guild_members")
|
helper.Copy(up.Int, "bridge", "backfill", "max_guild_members")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
||||||
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", "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", "delete_keys", "delete_outbound_on_ack")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_outbound_on_ack")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "dont_store_outbound")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "dont_store_outbound")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "ratchet_on_decrypt")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "ratchet_on_decrypt")
|
||||||
@@ -92,12 +97,14 @@ func DoUpgrade(helper *up.Helper) {
|
|||||||
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_prev_on_new_session")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_prev_on_new_session")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_on_device_delete")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_on_device_delete")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "periodically_delete_expired")
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "periodically_delete_expired")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_outdated_inbound")
|
||||||
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "receive")
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "receive")
|
||||||
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "send")
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "send")
|
||||||
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "share")
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "share")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "enable_custom")
|
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "enable_custom")
|
||||||
helper.Copy(up.Int, "bridge", "encryption", "rotation", "milliseconds")
|
helper.Copy(up.Int, "bridge", "encryption", "rotation", "milliseconds")
|
||||||
helper.Copy(up.Int, "bridge", "encryption", "rotation", "messages")
|
helper.Copy(up.Int, "bridge", "encryption", "rotation", "messages")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "disable_device_change_key_rotation")
|
||||||
|
|
||||||
helper.Copy(up.Str, "bridge", "provisioning", "prefix")
|
helper.Copy(up.Str, "bridge", "provisioning", "prefix")
|
||||||
if secret, ok := helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
|
if secret, ok := helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ func (fq *FileQuery) Get(url string, encrypted bool) *File {
|
|||||||
return fq.New().Scan(fq.db.QueryRow(query, url, encrypted))
|
return fq.New().Scan(fq.db.QueryRow(query, url, encrypted))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fq *FileQuery) GetByMXC(mxc id.ContentURI) *File {
|
func (fq *FileQuery) GetEmojiByMXC(mxc id.ContentURI) *File {
|
||||||
query := fileSelect + " WHERE mxc=$1"
|
query := fileSelect + " WHERE mxc=$1 AND emoji_name<>'' LIMIT 1"
|
||||||
return fq.New().Scan(fq.db.QueryRow(query, mxc.String()))
|
return fq.New().Scan(fq.db.QueryRow(query, mxc.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type MessageQuery struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
messageSelect = "SELECT dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid FROM message"
|
messageSelect = "SELECT dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid, sender_mxid FROM message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (mq *MessageQuery) New() *Message {
|
func (mq *MessageQuery) New() *Message {
|
||||||
@@ -99,11 +99,11 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|||||||
if len(msgs) == 0 {
|
if len(msgs) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
valueStringFormat := "($%d, $%d, $1, $2, $%d, $%d, $%d, $%d, $%d)"
|
valueStringFormat := "($%d, $%d, $1, $2, $%d, $%d, $%d, $%d, $%d, $%d)"
|
||||||
if mq.db.Dialect == dbutil.SQLite {
|
if mq.db.Dialect == dbutil.SQLite {
|
||||||
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
||||||
}
|
}
|
||||||
params := make([]interface{}, 2+len(msgs)*7)
|
params := make([]interface{}, 2+len(msgs)*8)
|
||||||
placeholders := make([]string, len(msgs))
|
placeholders := make([]string, len(msgs))
|
||||||
params[0] = key.ChannelID
|
params[0] = key.ChannelID
|
||||||
params[1] = key.Receiver
|
params[1] = key.Receiver
|
||||||
@@ -116,7 +116,8 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|||||||
params[baseIndex+4] = msg.editTimestampVal()
|
params[baseIndex+4] = msg.editTimestampVal()
|
||||||
params[baseIndex+5] = msg.ThreadID
|
params[baseIndex+5] = msg.ThreadID
|
||||||
params[baseIndex+6] = msg.MXID
|
params[baseIndex+6] = msg.MXID
|
||||||
placeholders[i] = fmt.Sprintf(valueStringFormat, baseIndex+1, baseIndex+2, baseIndex+3, baseIndex+4, baseIndex+5, baseIndex+6, baseIndex+7)
|
params[baseIndex+7] = msg.SenderMXID.String()
|
||||||
|
placeholders[i] = fmt.Sprintf(valueStringFormat, baseIndex+1, baseIndex+2, baseIndex+3, baseIndex+4, baseIndex+5, baseIndex+6, baseIndex+7, baseIndex+8)
|
||||||
}
|
}
|
||||||
_, err := mq.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
_, err := mq.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -137,7 +138,8 @@ type Message struct {
|
|||||||
EditTimestamp time.Time
|
EditTimestamp time.Time
|
||||||
ThreadID string
|
ThreadID string
|
||||||
|
|
||||||
MXID id.EventID
|
MXID id.EventID
|
||||||
|
SenderMXID id.UserID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) DiscordProtoChannelID() string {
|
func (m *Message) DiscordProtoChannelID() string {
|
||||||
@@ -151,7 +153,7 @@ func (m *Message) DiscordProtoChannelID() string {
|
|||||||
func (m *Message) Scan(row dbutil.Scannable) *Message {
|
func (m *Message) Scan(row dbutil.Scannable) *Message {
|
||||||
var ts, editTS int64
|
var ts, editTS int64
|
||||||
|
|
||||||
err := row.Scan(&m.DiscordID, &m.AttachmentID, &m.Channel.ChannelID, &m.Channel.Receiver, &m.SenderID, &ts, &editTS, &m.ThreadID, &m.MXID)
|
err := row.Scan(&m.DiscordID, &m.AttachmentID, &m.Channel.ChannelID, &m.Channel.Receiver, &m.SenderID, &ts, &editTS, &m.ThreadID, &m.MXID, &m.SenderMXID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, sql.ErrNoRows) {
|
if !errors.Is(err, sql.ErrNoRows) {
|
||||||
m.log.Errorln("Database scan failed:", err)
|
m.log.Errorln("Database scan failed:", err)
|
||||||
@@ -173,12 +175,12 @@ func (m *Message) Scan(row dbutil.Scannable) *Message {
|
|||||||
|
|
||||||
const messageInsertQuery = `
|
const messageInsertQuery = `
|
||||||
INSERT INTO message (
|
INSERT INTO message (
|
||||||
dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid
|
dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid, sender_mxid
|
||||||
)
|
)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||||
`
|
`
|
||||||
|
|
||||||
var messageMassInsertTemplate = strings.Replace(messageInsertQuery, "($1, $2, $3, $4, $5, $6, $7, $8, $9)", "%s", 1)
|
var messageMassInsertTemplate = strings.Replace(messageInsertQuery, "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", "%s", 1)
|
||||||
|
|
||||||
type MessagePart struct {
|
type MessagePart struct {
|
||||||
AttachmentID string
|
AttachmentID string
|
||||||
@@ -196,11 +198,11 @@ func (m *Message) MassInsertParts(msgs []MessagePart) {
|
|||||||
if len(msgs) == 0 {
|
if len(msgs) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
valueStringFormat := "($1, $%d, $2, $3, $4, $5, $6, $7, $%d)"
|
valueStringFormat := "($1, $%d, $2, $3, $4, $5, $6, $7, $%d, $8)"
|
||||||
if m.db.Dialect == dbutil.SQLite {
|
if m.db.Dialect == dbutil.SQLite {
|
||||||
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
||||||
}
|
}
|
||||||
params := make([]interface{}, 7+len(msgs)*2)
|
params := make([]interface{}, 8+len(msgs)*2)
|
||||||
placeholders := make([]string, len(msgs))
|
placeholders := make([]string, len(msgs))
|
||||||
params[0] = m.DiscordID
|
params[0] = m.DiscordID
|
||||||
params[1] = m.Channel.ChannelID
|
params[1] = m.Channel.ChannelID
|
||||||
@@ -209,10 +211,11 @@ func (m *Message) MassInsertParts(msgs []MessagePart) {
|
|||||||
params[4] = m.Timestamp.UnixMilli()
|
params[4] = m.Timestamp.UnixMilli()
|
||||||
params[5] = m.editTimestampVal()
|
params[5] = m.editTimestampVal()
|
||||||
params[6] = m.ThreadID
|
params[6] = m.ThreadID
|
||||||
|
params[7] = m.SenderMXID.String()
|
||||||
for i, msg := range msgs {
|
for i, msg := range msgs {
|
||||||
params[7+i*2] = msg.AttachmentID
|
params[8+i*2] = msg.AttachmentID
|
||||||
params[7+i*2+1] = msg.MXID
|
params[8+i*2+1] = msg.MXID
|
||||||
placeholders[i] = fmt.Sprintf(valueStringFormat, 7+i*2+1, 7+i*2+2)
|
placeholders[i] = fmt.Sprintf(valueStringFormat, 8+i*2+1, 8+i*2+2)
|
||||||
}
|
}
|
||||||
_, err := m.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
_, err := m.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -224,7 +227,7 @@ func (m *Message) MassInsertParts(msgs []MessagePart) {
|
|||||||
func (m *Message) Insert() {
|
func (m *Message) Insert() {
|
||||||
_, err := m.db.Exec(messageInsertQuery,
|
_, err := m.db.Exec(messageInsertQuery,
|
||||||
m.DiscordID, m.AttachmentID, m.Channel.ChannelID, m.Channel.Receiver, m.SenderID,
|
m.DiscordID, m.AttachmentID, m.Channel.ChannelID, m.Channel.Receiver, m.SenderID,
|
||||||
m.Timestamp.UnixMilli(), m.editTimestampVal(), m.ThreadID, m.MXID)
|
m.Timestamp.UnixMilli(), m.editTimestampVal(), m.ThreadID, m.MXID, m.SenderMXID.String())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.log.Warnfln("Failed to insert %s@%s: %v", m.DiscordID, m.Channel, err)
|
m.log.Warnfln("Failed to insert %s@%s: %v", m.DiscordID, m.Channel, err)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
puppetSelect = "SELECT id, name, name_set, avatar, avatar_url, avatar_set," +
|
puppetSelect = "SELECT id, name, name_set, avatar, avatar_url, avatar_set," +
|
||||||
" contact_info_set, username, discriminator, is_bot, custom_mxid, access_token, next_batch" +
|
" contact_info_set, global_name, username, discriminator, is_bot, is_webhook, is_application, custom_mxid, access_token, next_batch" +
|
||||||
" FROM puppet "
|
" FROM puppet "
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -75,9 +75,12 @@ type Puppet struct {
|
|||||||
|
|
||||||
ContactInfoSet bool
|
ContactInfoSet bool
|
||||||
|
|
||||||
|
GlobalName string
|
||||||
Username string
|
Username string
|
||||||
Discriminator string
|
Discriminator string
|
||||||
IsBot bool
|
IsBot bool
|
||||||
|
IsWebhook bool
|
||||||
|
IsApplication bool
|
||||||
|
|
||||||
CustomMXID id.UserID
|
CustomMXID id.UserID
|
||||||
AccessToken string
|
AccessToken string
|
||||||
@@ -89,7 +92,7 @@ func (p *Puppet) Scan(row dbutil.Scannable) *Puppet {
|
|||||||
var customMXID, accessToken, nextBatch sql.NullString
|
var customMXID, accessToken, nextBatch sql.NullString
|
||||||
|
|
||||||
err := row.Scan(&p.ID, &p.Name, &p.NameSet, &p.Avatar, &avatarURL, &p.AvatarSet, &p.ContactInfoSet,
|
err := row.Scan(&p.ID, &p.Name, &p.NameSet, &p.Avatar, &avatarURL, &p.AvatarSet, &p.ContactInfoSet,
|
||||||
&p.Username, &p.Discriminator, &p.IsBot, &customMXID, &accessToken, &nextBatch)
|
&p.GlobalName, &p.Username, &p.Discriminator, &p.IsBot, &p.IsWebhook, &p.IsApplication, &customMXID, &accessToken, &nextBatch)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
@@ -110,11 +113,16 @@ func (p *Puppet) Scan(row dbutil.Scannable) *Puppet {
|
|||||||
|
|
||||||
func (p *Puppet) Insert() {
|
func (p *Puppet) Insert() {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO puppet (id, name, name_set, avatar, avatar_url, avatar_set, contact_info_set, username, discriminator, is_bot, custom_mxid, access_token, next_batch)
|
INSERT INTO puppet (
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
id, name, name_set, avatar, avatar_url, avatar_set, contact_info_set,
|
||||||
|
global_name, username, discriminator, is_bot, is_webhook, is_application,
|
||||||
|
custom_mxid, access_token, next_batch
|
||||||
|
)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
|
||||||
`
|
`
|
||||||
_, err := p.db.Exec(query, p.ID, p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
_, err := p.db.Exec(query, p.ID, p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
||||||
p.Username, p.Discriminator, p.IsBot, strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch))
|
p.GlobalName, p.Username, p.Discriminator, p.IsBot, p.IsWebhook, p.IsApplication,
|
||||||
|
strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.log.Warnfln("Failed to insert %s: %v", p.ID, err)
|
p.log.Warnfln("Failed to insert %s: %v", p.ID, err)
|
||||||
@@ -125,12 +133,17 @@ func (p *Puppet) Insert() {
|
|||||||
func (p *Puppet) Update() {
|
func (p *Puppet) Update() {
|
||||||
query := `
|
query := `
|
||||||
UPDATE puppet SET name=$1, name_set=$2, avatar=$3, avatar_url=$4, avatar_set=$5, contact_info_set=$6,
|
UPDATE puppet SET name=$1, name_set=$2, avatar=$3, avatar_url=$4, avatar_set=$5, contact_info_set=$6,
|
||||||
username=$7, discriminator=$8, is_bot=$9, custom_mxid=$10, access_token=$11, next_batch=$12
|
global_name=$7, username=$8, discriminator=$9, is_bot=$10, is_webhook=$11, is_application=$12,
|
||||||
WHERE id=$13
|
custom_mxid=$13, access_token=$14, next_batch=$15
|
||||||
|
WHERE id=$16
|
||||||
`
|
`
|
||||||
_, err := p.db.Exec(query, p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
_, err := p.db.Exec(
|
||||||
p.Username, p.Discriminator, p.IsBot, strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch),
|
query,
|
||||||
p.ID)
|
p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
||||||
|
p.GlobalName, p.Username, p.Discriminator, p.IsBot, p.IsWebhook, p.IsApplication,
|
||||||
|
strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch),
|
||||||
|
p.ID,
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.log.Warnfln("Failed to update %s: %v", p.ID, err)
|
p.log.Warnfln("Failed to update %s: %v", p.ID, err)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-- v0 -> v19: Latest revision
|
-- v0 -> v23 (compatible with v19+): Latest revision
|
||||||
|
|
||||||
CREATE TABLE guild (
|
CREATE TABLE guild (
|
||||||
dcid TEXT PRIMARY KEY,
|
dcid TEXT PRIMARY KEY,
|
||||||
@@ -71,9 +71,12 @@ CREATE TABLE puppet (
|
|||||||
|
|
||||||
contact_info_set BOOLEAN NOT NULL DEFAULT false,
|
contact_info_set BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
|
||||||
username TEXT NOT NULL DEFAULT '',
|
global_name TEXT NOT NULL DEFAULT '',
|
||||||
discriminator TEXT NOT NULL DEFAULT '',
|
username TEXT NOT NULL DEFAULT '',
|
||||||
is_bot BOOLEAN NOT NULL DEFAULT false,
|
discriminator TEXT NOT NULL DEFAULT '',
|
||||||
|
is_bot BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
is_webhook BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
is_application BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
|
||||||
custom_mxid TEXT,
|
custom_mxid TEXT,
|
||||||
access_token TEXT,
|
access_token TEXT,
|
||||||
@@ -113,7 +116,8 @@ CREATE TABLE message (
|
|||||||
dc_edit_timestamp BIGINT NOT NULL,
|
dc_edit_timestamp BIGINT NOT NULL,
|
||||||
dc_thread_id TEXT NOT NULL,
|
dc_thread_id TEXT NOT NULL,
|
||||||
|
|
||||||
mxid TEXT NOT NULL UNIQUE,
|
mxid TEXT NOT NULL UNIQUE,
|
||||||
|
sender_mxid TEXT NOT NULL DEFAULT '',
|
||||||
|
|
||||||
PRIMARY KEY (dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver),
|
PRIMARY KEY (dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver),
|
||||||
CONSTRAINT message_portal_fkey FOREIGN KEY (dc_chan_id, dc_chan_receiver) REFERENCES portal (dcid, receiver) ON DELETE CASCADE
|
CONSTRAINT message_portal_fkey FOREIGN KEY (dc_chan_id, dc_chan_receiver) REFERENCES portal (dcid, receiver) ON DELETE CASCADE
|
||||||
@@ -157,7 +161,7 @@ CREATE TABLE role (
|
|||||||
CREATE TABLE discord_file (
|
CREATE TABLE discord_file (
|
||||||
url TEXT,
|
url TEXT,
|
||||||
encrypted BOOLEAN,
|
encrypted BOOLEAN,
|
||||||
mxc TEXT NOT NULL UNIQUE,
|
mxc TEXT NOT NULL,
|
||||||
|
|
||||||
id TEXT,
|
id TEXT,
|
||||||
emoji_name TEXT,
|
emoji_name TEXT,
|
||||||
@@ -171,3 +175,5 @@ CREATE TABLE discord_file (
|
|||||||
|
|
||||||
PRIMARY KEY (url, encrypted)
|
PRIMARY KEY (url, encrypted)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE INDEX discord_file_mxc_idx ON discord_file (mxc);
|
||||||
|
|||||||
2
database/upgrades/20-message-sender-mxid.sql
Normal file
2
database/upgrades/20-message-sender-mxid.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- v20 (compatible with v19+): Store message sender Matrix user ID
|
||||||
|
ALTER TABLE message ADD COLUMN sender_mxid TEXT NOT NULL DEFAULT '';
|
||||||
3
database/upgrades/21-more-puppet-info.sql
Normal file
3
database/upgrades/21-more-puppet-info.sql
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
-- v21 (compatible with v19+): Store global displayname and is webhook status for puppets
|
||||||
|
ALTER TABLE puppet ADD COLUMN global_name TEXT NOT NULL DEFAULT '';
|
||||||
|
ALTER TABLE puppet ADD COLUMN is_webhook BOOLEAN NOT NULL DEFAULT false;
|
||||||
26
database/upgrades/22-file-cache-duplicate-mxc.sql
Normal file
26
database/upgrades/22-file-cache-duplicate-mxc.sql
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- v22 (compatible with v19+): Allow non-unique mxc URIs in file cache
|
||||||
|
CREATE TABLE new_discord_file (
|
||||||
|
url TEXT,
|
||||||
|
encrypted BOOLEAN,
|
||||||
|
mxc TEXT NOT NULL,
|
||||||
|
|
||||||
|
id TEXT,
|
||||||
|
emoji_name TEXT,
|
||||||
|
|
||||||
|
size BIGINT NOT NULL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
mime_type TEXT NOT NULL,
|
||||||
|
decryption_info jsonb,
|
||||||
|
timestamp BIGINT NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (url, encrypted)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO new_discord_file (url, encrypted, mxc, id, emoji_name, size, width, height, mime_type, decryption_info, timestamp)
|
||||||
|
SELECT url, encrypted, mxc, id, emoji_name, size, width, height, mime_type, decryption_info, timestamp FROM discord_file;
|
||||||
|
|
||||||
|
DROP TABLE discord_file;
|
||||||
|
ALTER TABLE new_discord_file RENAME TO discord_file;
|
||||||
|
|
||||||
|
CREATE INDEX discord_file_mxc_idx ON discord_file (mxc);
|
||||||
2
database/upgrades/23-puppet-is-application.sql
Normal file
2
database/upgrades/23-puppet-is-application.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- v23 (compatible with v19+): Store is application status for puppets
|
||||||
|
ALTER TABLE puppet ADD COLUMN is_application BOOLEAN NOT NULL DEFAULT false;
|
||||||
@@ -20,6 +20,13 @@ homeserver:
|
|||||||
# Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246?
|
# Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246?
|
||||||
async_media: false
|
async_media: false
|
||||||
|
|
||||||
|
# Should the bridge use a websocket for connecting to the homeserver?
|
||||||
|
# The server side is currently not documented anywhere and is only implemented by mautrix-wsproxy,
|
||||||
|
# mautrix-asmux (deprecated), and hungryserv (proprietary).
|
||||||
|
websocket: false
|
||||||
|
# How often should the websocket be pinged? Pinging will be disabled if this is zero.
|
||||||
|
ping_interval_seconds: 0
|
||||||
|
|
||||||
# Application service host/registration related details.
|
# Application service host/registration related details.
|
||||||
# Changing these values requires regeneration of the registration.
|
# Changing these values requires regeneration of the registration.
|
||||||
appservice:
|
appservice:
|
||||||
@@ -80,11 +87,14 @@ bridge:
|
|||||||
# Displayname template for Discord users. This is also used as the room name in DMs if private_chat_portal_meta is enabled.
|
# Displayname template for Discord users. This is also used as the room name in DMs if private_chat_portal_meta is enabled.
|
||||||
# Available variables:
|
# Available variables:
|
||||||
# .ID - Internal user ID
|
# .ID - Internal user ID
|
||||||
# .Username - User's displayname on Discord
|
# .Username - Legacy display/username on Discord
|
||||||
|
# .GlobalName - New displayname on Discord
|
||||||
# .Discriminator - The 4 numbers after the name on Discord
|
# .Discriminator - The 4 numbers after the name on Discord
|
||||||
# .Bot - Whether the user is a bot
|
# .Bot - Whether the user is a bot
|
||||||
# .System - Whether the user is an official system user
|
# .System - Whether the user is an official system user
|
||||||
displayname_template: '{{.Username}}#{{.Discriminator}}{{if .Bot}} (bot){{end}}'
|
# .Webhook - Whether the user is a webhook and is not an application
|
||||||
|
# .Application - Whether the user is an application
|
||||||
|
displayname_template: '{{or .GlobalName .Username}}{{if .Bot}} (bot){{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.
|
||||||
@@ -145,6 +155,11 @@ bridge:
|
|||||||
# Whether or not created rooms should have federation enabled.
|
# Whether or not created rooms should have federation enabled.
|
||||||
# If false, created portal rooms will never be federated.
|
# If false, created portal rooms will never be federated.
|
||||||
federate_rooms: true
|
federate_rooms: true
|
||||||
|
# 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).
|
||||||
|
prefix_webhook_messages: false
|
||||||
|
# Bridge webhook avatars?
|
||||||
|
enable_webhook_avatars: true
|
||||||
# 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).
|
||||||
@@ -218,6 +233,7 @@ bridge:
|
|||||||
initial:
|
initial:
|
||||||
dm: 0
|
dm: 0
|
||||||
channel: 0
|
channel: 0
|
||||||
|
thread: 0
|
||||||
# Missed message backfill (on startup).
|
# Missed message backfill (on startup).
|
||||||
# 0 means backfill is disabled, -1 means fetch all messages since last bridged message.
|
# 0 means backfill is disabled, -1 means fetch all messages since last bridged message.
|
||||||
# When using unlimited backfill (-1), messages are backfilled as they are fetched.
|
# When using unlimited backfill (-1), messages are backfilled as they are fetched.
|
||||||
@@ -225,6 +241,7 @@ bridge:
|
|||||||
missed:
|
missed:
|
||||||
dm: 0
|
dm: 0
|
||||||
channel: 0
|
channel: 0
|
||||||
|
thread: 0
|
||||||
# Maximum members in a guild to enable backfilling. Set to -1 to disable limit.
|
# Maximum members in a guild to enable backfilling. Set to -1 to disable limit.
|
||||||
# This can be used as a rough heuristic to disable backfilling in channels that are too active.
|
# This can be used as a rough heuristic to disable backfilling in channels that are too active.
|
||||||
# Currently only applies to missed message backfill.
|
# Currently only applies to missed message backfill.
|
||||||
@@ -246,6 +263,8 @@ bridge:
|
|||||||
# 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.
|
||||||
# You must use a client that supports requesting keys from other users to use this feature.
|
# You must use a client that supports requesting keys from other users to use this feature.
|
||||||
allow_key_sharing: false
|
allow_key_sharing: false
|
||||||
|
# Should users mentions be in the event wire content to enable the server to send push notifications?
|
||||||
|
plaintext_mentions: false
|
||||||
# Options for deleting megolm sessions from the bridge.
|
# Options for deleting megolm sessions from the bridge.
|
||||||
delete_keys:
|
delete_keys:
|
||||||
# Beeper-specific: delete outbound sessions when hungryserv confirms
|
# Beeper-specific: delete outbound sessions when hungryserv confirms
|
||||||
@@ -263,6 +282,10 @@ bridge:
|
|||||||
delete_on_device_delete: false
|
delete_on_device_delete: false
|
||||||
# Periodically delete megolm sessions when 2x max_age has passed since receiving the session.
|
# Periodically delete megolm sessions when 2x max_age has passed since receiving the session.
|
||||||
periodically_delete_expired: false
|
periodically_delete_expired: false
|
||||||
|
# Delete inbound megolm sessions that don't have the received_at field used for
|
||||||
|
# automatic ratcheting and expired session deletion. This is meant as a migration
|
||||||
|
# to delete old keys prior to the bridge update.
|
||||||
|
delete_outdated_inbound: false
|
||||||
# What level of device verification should be required from users?
|
# What level of device verification should be required from users?
|
||||||
#
|
#
|
||||||
# Valid levels:
|
# Valid levels:
|
||||||
@@ -298,6 +321,10 @@ bridge:
|
|||||||
# default.
|
# default.
|
||||||
messages: 100
|
messages: 100
|
||||||
|
|
||||||
|
# Disable rotating keys when a user's devices change?
|
||||||
|
# You should not enable this option unless you understand all the implications.
|
||||||
|
disable_device_change_key_rotation: false
|
||||||
|
|
||||||
# Settings for provisioning API
|
# Settings for provisioning API
|
||||||
provisioning:
|
provisioning:
|
||||||
# Prefix for the provisioning API paths.
|
# Prefix for the provisioning API paths.
|
||||||
|
|||||||
12
formatter.go
12
formatter.go
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/yuin/goldmark/extension"
|
"github.com/yuin/goldmark/extension"
|
||||||
"github.com/yuin/goldmark/parser"
|
"github.com/yuin/goldmark/parser"
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/format"
|
"maunium.net/go/mautrix/format"
|
||||||
@@ -58,7 +59,7 @@ func (b *indentableParagraphParser) CanAcceptIndentedLine() bool {
|
|||||||
|
|
||||||
var removeFeaturesExceptLinks = []any{
|
var removeFeaturesExceptLinks = []any{
|
||||||
parser.NewListParser(), parser.NewListItemParser(), parser.NewHTMLBlockParser(), parser.NewRawHTMLParser(),
|
parser.NewListParser(), parser.NewListItemParser(), parser.NewHTMLBlockParser(), parser.NewRawHTMLParser(),
|
||||||
parser.NewSetextHeadingParser(), parser.NewATXHeadingParser(), parser.NewThematicBreakParser(),
|
parser.NewSetextHeadingParser(), parser.NewThematicBreakParser(),
|
||||||
parser.NewCodeBlockParser(),
|
parser.NewCodeBlockParser(),
|
||||||
}
|
}
|
||||||
var removeFeaturesAndLinks = append(removeFeaturesExceptLinks, parser.NewLinkParser())
|
var removeFeaturesAndLinks = append(removeFeaturesExceptLinks, parser.NewLinkParser())
|
||||||
@@ -93,6 +94,7 @@ func (portal *Portal) renderDiscordMarkdownOnlyHTML(text string, allowInlineLink
|
|||||||
|
|
||||||
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"
|
||||||
|
|
||||||
func appendIfNotContains(arr []string, newItem string) []string {
|
func appendIfNotContains(arr []string, newItem string) []string {
|
||||||
for _, item := range arr {
|
for _, item := range arr {
|
||||||
@@ -135,6 +137,10 @@ func (br *DiscordBridge) pillConverter(displayname, mxid, eventID string, ctx fo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if mxid[0] == '@' {
|
} else if mxid[0] == '@' {
|
||||||
|
allowedMentions, _ := ctx.ReturnData[formatterContextInputAllowedMentionsKey].([]id.UserID)
|
||||||
|
if allowedMentions != nil && !slices.Contains(allowedMentions, id.UserID(mxid)) {
|
||||||
|
return displayname
|
||||||
|
}
|
||||||
mentions := ctx.ReturnData[formatterContextAllowedMentionsKey].(*discordgo.MessageAllowedMentions)
|
mentions := ctx.ReturnData[formatterContextAllowedMentionsKey].(*discordgo.MessageAllowedMentions)
|
||||||
parsedID, ok := br.ParsePuppetMXID(id.UserID(mxid))
|
parsedID, ok := br.ParsePuppetMXID(id.UserID(mxid))
|
||||||
if ok {
|
if ok {
|
||||||
@@ -164,6 +170,7 @@ var discordMarkdownEscaper = strings.NewReplacer(
|
|||||||
"`", "\\`",
|
"`", "\\`",
|
||||||
`|`, `\|`,
|
`|`, `\|`,
|
||||||
`<`, `\<`,
|
`<`, `\<`,
|
||||||
|
`#`, `\#`,
|
||||||
)
|
)
|
||||||
|
|
||||||
func escapeDiscordMarkdown(s string) string {
|
func escapeDiscordMarkdown(s string) string {
|
||||||
@@ -219,6 +226,9 @@ func (portal *Portal) parseMatrixHTML(content *event.MessageEventContent) (strin
|
|||||||
ctx := format.NewContext()
|
ctx := format.NewContext()
|
||||||
ctx.ReturnData[formatterContextPortalKey] = portal
|
ctx.ReturnData[formatterContextPortalKey] = portal
|
||||||
ctx.ReturnData[formatterContextAllowedMentionsKey] = allowedMentions
|
ctx.ReturnData[formatterContextAllowedMentionsKey] = allowedMentions
|
||||||
|
if content.Mentions != nil {
|
||||||
|
ctx.ReturnData[formatterContextInputAllowedMentionsKey] = content.Mentions.UserIDs
|
||||||
|
}
|
||||||
return variationselector.FullyQualify(matrixHTMLParser.Parse(content.FormattedBody, ctx)), allowedMentions
|
return variationselector.FullyQualify(matrixHTMLParser.Parse(content.FormattedBody, ctx)), allowedMentions
|
||||||
} else {
|
} else {
|
||||||
return variationselector.FullyQualify(escapeDiscordMarkdown(content.Body)), allowedMentions
|
return variationselector.FullyQualify(escapeDiscordMarkdown(content.Body)), allowedMentions
|
||||||
|
|||||||
17
go.mod
17
go.mod
@@ -9,13 +9,15 @@ require (
|
|||||||
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.16
|
github.com/mattn/go-sqlite3 v1.14.17
|
||||||
github.com/rs/zerolog v1.29.1
|
github.com/rs/zerolog v1.29.1
|
||||||
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.8.2
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/yuin/goldmark v1.5.4
|
github.com/yuin/goldmark v1.5.4
|
||||||
|
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
|
||||||
|
golang.org/x/sync v0.3.0
|
||||||
maunium.net/go/maulogger/v2 v2.4.1
|
maunium.net/go/maulogger/v2 v2.4.1
|
||||||
maunium.net/go/mautrix v0.15.2
|
maunium.net/go/mautrix v0.15.4
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -29,13 +31,12 @@ require (
|
|||||||
github.com/tidwall/pretty v1.2.0 // indirect
|
github.com/tidwall/pretty v1.2.0 // 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.9.0 // indirect
|
golang.org/x/crypto v0.11.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
|
golang.org/x/net v0.12.0 // indirect
|
||||||
golang.org/x/net v0.10.0 // indirect
|
golang.org/x/sys v0.10.0 // indirect
|
||||||
golang.org/x/sys v0.8.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-20230426184739-79aea97f6660
|
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20230620222529-2cb9d9280e37
|
||||||
|
|||||||
41
go.sum
41
go.sum
@@ -1,9 +1,8 @@
|
|||||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
github.com/beeper/discordgo v0.0.0-20230426184739-79aea97f6660 h1:5LFnUY/Aj/0k/UqeEmW2GS4ql1vxmivkrckPxUHf8oc=
|
github.com/beeper/discordgo v0.0.0-20230620222529-2cb9d9280e37 h1:N0c/439VcoHGc+gL1lb3vUjr6vUbXz+vor7SLnBOhJU=
|
||||||
github.com/beeper/discordgo v0.0.0-20230426184739-79aea97f6660/go.mod h1:59+AOzzjmL6onAh62nuLXmn7dJCaC/owDLWbGtjTcFA=
|
github.com/beeper/discordgo v0.0.0-20230620222529-2cb9d9280e37/go.mod h1:59+AOzzjmL6onAh62nuLXmn7dJCaC/owDLWbGtjTcFA=
|
||||||
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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
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.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
@@ -21,8 +20,8 @@ github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZb
|
|||||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
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=
|
||||||
@@ -31,13 +30,8 @@ github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
|
|||||||
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
|
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
||||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
|
||||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
|
||||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
|
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
|
||||||
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
@@ -51,26 +45,27 @@ github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
|
|||||||
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
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.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||||
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4=
|
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
|
||||||
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||||
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
|
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
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=
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
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.15.2 h1:fUiVajeoOR92uJoSShHbCvh7uG6lDY4ZO4Mvt90LbjU=
|
maunium.net/go/mautrix v0.15.4 h1:Ug3n2Mo+9Yb94AjZTWJQSNHmShaksEzZi85EPl3S3P0=
|
||||||
maunium.net/go/mautrix v0.15.2/go.mod h1:h4NwfKqE4YxGTLSgn/gawKzXAb2sF4qx8agL6QEFtGg=
|
maunium.net/go/mautrix v0.15.4/go.mod h1:dBaDmsnOOBM4a+gKcgefXH73pHGXm+MCJzCs1dXFgrw=
|
||||||
|
|||||||
@@ -272,12 +272,15 @@ func (guild *Guild) UpdateAvatar(iconID string) bool {
|
|||||||
guild.Avatar = iconID
|
guild.Avatar = iconID
|
||||||
guild.AvatarURL = id.ContentURI{}
|
guild.AvatarURL = id.ContentURI{}
|
||||||
if guild.Avatar != "" {
|
if guild.Avatar != "" {
|
||||||
var err error
|
// TODO direct media support
|
||||||
guild.AvatarURL, err = uploadAvatar(guild.bridge.Bot, discordgo.EndpointGuildIcon(guild.ID, iconID))
|
copied, err := guild.bridge.copyAttachmentToMatrix(guild.bridge.Bot, discordgo.EndpointGuildIcon(guild.ID, iconID), false, AttachmentMeta{
|
||||||
|
AttachmentID: fmt.Sprintf("guild_avatar/%s/%s", guild.ID, iconID),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guild.log.Warnfln("Failed to reupload guild avatar %s: %v", guild.Avatar, err)
|
guild.log.Warnfln("Failed to reupload guild avatar %s: %v", iconID, err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
guild.AvatarURL = copied.MXC
|
||||||
}
|
}
|
||||||
if guild.MXID != "" {
|
if guild.MXID != "" {
|
||||||
_, err := guild.bridge.Bot.SetRoomAvatar(guild.MXID, guild.AvatarURL)
|
_, err := guild.bridge.Bot.SetRoomAvatar(guild.MXID, guild.AvatarURL)
|
||||||
@@ -295,7 +298,7 @@ func (guild *Guild) cleanup() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
intent := guild.bridge.Bot
|
intent := guild.bridge.Bot
|
||||||
if guild.bridge.SpecVersions.UnstableFeatures["com.beeper.room_yeeting"] {
|
if guild.bridge.SpecVersions.Supports(mautrix.BeeperFeatureRoomYeeting) {
|
||||||
err := intent.BeeperDeleteRoom(guild.MXID)
|
err := intent.BeeperDeleteRoom(guild.MXID)
|
||||||
if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
||||||
guild.log.Errorfln("Failed to delete %s using hungryserv yeet endpoint: %v", guild.MXID, err)
|
guild.log.Errorfln("Failed to delete %s using hungryserv yeet endpoint: %v", guild.MXID, err)
|
||||||
|
|||||||
11
main.go
11
main.go
@@ -20,6 +20,7 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"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/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@@ -73,7 +74,8 @@ type DiscordBridge struct {
|
|||||||
puppetsByCustomMXID map[id.UserID]*Puppet
|
puppetsByCustomMXID map[id.UserID]*Puppet
|
||||||
puppetsLock sync.Mutex
|
puppetsLock sync.Mutex
|
||||||
|
|
||||||
attachmentTransfers *util.SyncMap[attachmentKey, *util.ReturnableOnce[*database.File]]
|
attachmentTransfers *util.SyncMap[attachmentKey, *util.ReturnableOnce[*database.File]]
|
||||||
|
parallelAttachmentSemaphore *semaphore.Weighted
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *DiscordBridge) GetExampleConfig() string {
|
func (br *DiscordBridge) GetExampleConfig() string {
|
||||||
@@ -102,7 +104,7 @@ func (br *DiscordBridge) Start() {
|
|||||||
if br.Config.Bridge.Provisioning.SharedSecret != "disable" {
|
if br.Config.Bridge.Provisioning.SharedSecret != "disable" {
|
||||||
br.provisioning = newProvisioningAPI(br)
|
br.provisioning = newProvisioningAPI(br)
|
||||||
}
|
}
|
||||||
go br.updatePuppetsContactInfo()
|
br.WaitWebsocketConnected()
|
||||||
go br.startUsers()
|
go br.startUsers()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,13 +172,14 @@ func main() {
|
|||||||
puppets: make(map[string]*Puppet),
|
puppets: make(map[string]*Puppet),
|
||||||
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
||||||
|
|
||||||
attachmentTransfers: util.NewSyncMap[attachmentKey, *util.ReturnableOnce[*database.File]](),
|
attachmentTransfers: util.NewSyncMap[attachmentKey, *util.ReturnableOnce[*database.File]](),
|
||||||
|
parallelAttachmentSemaphore: semaphore.NewWeighted(3),
|
||||||
}
|
}
|
||||||
br.Bridge = bridge.Bridge{
|
br.Bridge = bridge.Bridge{
|
||||||
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.4.0",
|
Version: "0.6.0",
|
||||||
ProtocolName: "Discord",
|
ProtocolName: "Discord",
|
||||||
BeeperServiceName: "discordgo",
|
BeeperServiceName: "discordgo",
|
||||||
BeeperNetworkName: "discord",
|
BeeperNetworkName: "discord",
|
||||||
|
|||||||
130
portal.go
130
portal.go
@@ -541,7 +541,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
|
|||||||
portal.Update()
|
portal.Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
go portal.forwardBackfillInitial(user)
|
go portal.forwardBackfillInitial(user, nil)
|
||||||
backfillStarted = true
|
backfillStarted = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -549,13 +549,15 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
|
|||||||
|
|
||||||
func (portal *Portal) handleDiscordMessages(msg portalDiscordMessage) {
|
func (portal *Portal) handleDiscordMessages(msg portalDiscordMessage) {
|
||||||
if portal.MXID == "" {
|
if portal.MXID == "" {
|
||||||
_, ok := msg.msg.(*discordgo.MessageCreate)
|
msgCreate, ok := msg.msg.(*discordgo.MessageCreate)
|
||||||
if !ok {
|
if !ok {
|
||||||
portal.log.Warn().Msg("Can't create Matrix room from non new message event")
|
portal.log.Warn().Msg("Can't create Matrix room from non new message event")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
portal.log.Debug().Msg("Creating Matrix room from incoming message")
|
portal.log.Debug().
|
||||||
|
Str("message_id", msgCreate.ID).
|
||||||
|
Msg("Creating Matrix room from incoming message")
|
||||||
if err := portal.CreateMatrixRoom(msg.user, nil); err != nil {
|
if err := portal.CreateMatrixRoom(msg.user, nil); err != nil {
|
||||||
portal.log.Err(err).Msg("Failed to create portal room")
|
portal.log.Err(err).Msg("Failed to create portal room")
|
||||||
return
|
return
|
||||||
@@ -571,6 +573,8 @@ func (portal *Portal) handleDiscordMessages(msg portalDiscordMessage) {
|
|||||||
portal.handleDiscordMessageUpdate(msg.user, convertedMsg.Message)
|
portal.handleDiscordMessageUpdate(msg.user, convertedMsg.Message)
|
||||||
case *discordgo.MessageDelete:
|
case *discordgo.MessageDelete:
|
||||||
portal.handleDiscordMessageDelete(msg.user, convertedMsg.Message)
|
portal.handleDiscordMessageDelete(msg.user, convertedMsg.Message)
|
||||||
|
case *discordgo.MessageDeleteBulk:
|
||||||
|
portal.handleDiscordMessageDeleteBulk(msg.user, convertedMsg.Messages)
|
||||||
case *discordgo.MessageReactionAdd:
|
case *discordgo.MessageReactionAdd:
|
||||||
portal.handleDiscordReaction(msg.user, convertedMsg.MessageReaction, true, msg.thread, convertedMsg.Member)
|
portal.handleDiscordReaction(msg.user, convertedMsg.MessageReaction, true, msg.thread, convertedMsg.Member)
|
||||||
case *discordgo.MessageReactionRemove:
|
case *discordgo.MessageReactionRemove:
|
||||||
@@ -584,14 +588,18 @@ func (portal *Portal) ensureUserInvited(user *User, ignoreCache bool) bool {
|
|||||||
return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat(), ignoreCache)
|
return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat(), ignoreCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) markMessageHandled(discordID string, authorID string, timestamp time.Time, threadID string, parts []database.MessagePart) {
|
func (portal *Portal) markMessageHandled(discordID string, authorID string, timestamp time.Time, threadID string, senderMXID id.UserID, parts []database.MessagePart) *database.Message {
|
||||||
msg := portal.bridge.DB.Message.New()
|
msg := portal.bridge.DB.Message.New()
|
||||||
msg.Channel = portal.Key
|
msg.Channel = portal.Key
|
||||||
msg.DiscordID = discordID
|
msg.DiscordID = discordID
|
||||||
msg.SenderID = authorID
|
msg.SenderID = authorID
|
||||||
msg.Timestamp = timestamp
|
msg.Timestamp = timestamp
|
||||||
msg.ThreadID = threadID
|
msg.ThreadID = threadID
|
||||||
|
msg.SenderMXID = senderMXID
|
||||||
msg.MassInsertParts(parts)
|
msg.MassInsertParts(parts)
|
||||||
|
msg.MXID = parts[0].MXID
|
||||||
|
msg.AttachmentID = parts[0].AttachmentID
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Message, thread *Thread) {
|
func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Message, thread *Thread) {
|
||||||
@@ -616,15 +624,10 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
log.Debug().Msg("Dropping duplicate message")
|
log.Debug().Msg("Dropping duplicate message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug().Msg("Starting handling of Discord message")
|
|
||||||
|
|
||||||
for _, mention := range msg.Mentions {
|
|
||||||
puppet := portal.bridge.GetPuppetByID(mention.ID)
|
|
||||||
puppet.UpdateInfo(nil, mention)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
handlingStartTime := time.Now()
|
||||||
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
||||||
puppet.UpdateInfo(user, msg.Author)
|
puppet.UpdateInfo(user, msg.Author, msg)
|
||||||
intent := puppet.IntentFor(portal)
|
intent := puppet.IntentFor(portal)
|
||||||
|
|
||||||
var discordThreadID string
|
var discordThreadID string
|
||||||
@@ -639,10 +642,12 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
replyTo := portal.getReplyTarget(user, discordThreadID, msg.MessageReference, msg.Embeds, false)
|
replyTo := portal.getReplyTarget(user, discordThreadID, msg.MessageReference, msg.Embeds, false)
|
||||||
|
mentions := portal.convertDiscordMentions(msg, true)
|
||||||
|
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
parts := portal.convertDiscordMessage(ctx, intent, msg)
|
parts := portal.convertDiscordMessage(ctx, puppet, intent, msg)
|
||||||
dbParts := make([]database.MessagePart, 0, len(parts))
|
dbParts := make([]database.MessagePart, 0, len(parts))
|
||||||
|
eventIDs := zerolog.Dict()
|
||||||
for i, part := range parts {
|
for i, part := range parts {
|
||||||
if (replyTo != nil || threadRootEvent != "") && part.Content.RelatesTo == nil {
|
if (replyTo != nil || threadRootEvent != "") && part.Content.RelatesTo == nil {
|
||||||
part.Content.RelatesTo = &event.RelatesTo{}
|
part.Content.RelatesTo = &event.RelatesTo{}
|
||||||
@@ -658,6 +663,11 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
// Only set reply for first event
|
// Only set reply for first event
|
||||||
replyTo = nil
|
replyTo = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
part.Content.Mentions = mentions
|
||||||
|
// Only set mentions for first event, but keep empty object for rest
|
||||||
|
mentions = &event.Mentions{}
|
||||||
|
|
||||||
resp, err := portal.sendMatrixMessage(intent, part.Type, part.Content, part.Extra, ts.UnixMilli())
|
resp, err := portal.sendMatrixMessage(intent, part.Type, part.Content, part.Extra, ts.UnixMilli())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).
|
log.Err(err).
|
||||||
@@ -668,13 +678,20 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
lastThreadEvent = resp.EventID
|
lastThreadEvent = resp.EventID
|
||||||
dbParts = append(dbParts, database.MessagePart{AttachmentID: part.AttachmentID, MXID: resp.EventID})
|
dbParts = append(dbParts, database.MessagePart{AttachmentID: part.AttachmentID, MXID: resp.EventID})
|
||||||
|
eventIDs.Str(part.AttachmentID, resp.EventID.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.With().Dur("handling_time", time.Since(handlingStartTime)).Logger()
|
||||||
if len(parts) == 0 {
|
if len(parts) == 0 {
|
||||||
log.Warn().Msg("Unhandled message")
|
log.Warn().Msg("Unhandled message")
|
||||||
} else if len(dbParts) == 0 {
|
} else if len(dbParts) == 0 {
|
||||||
log.Warn().Msg("All parts of message failed to send to Matrix")
|
log.Warn().Msg("All parts of message failed to send to Matrix")
|
||||||
} else {
|
} else {
|
||||||
portal.markMessageHandled(msg.ID, msg.Author.ID, ts, discordThreadID, dbParts)
|
log.Debug().Dict("event_ids", eventIDs).Msg("Finished handling Discord message")
|
||||||
|
firstDBMessage := portal.markMessageHandled(msg.ID, msg.Author.ID, ts, discordThreadID, intent.UserID, dbParts)
|
||||||
|
if msg.Flags == discordgo.MessageFlagsHasThread {
|
||||||
|
portal.bridge.threadFound(ctx, user, firstDBMessage, msg.ID, msg.Thread)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,12 +715,8 @@ func (portal *Portal) getReplyTarget(source *User, threadID string, ref *discord
|
|||||||
if ref == nil {
|
if ref == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
isHungry := portal.bridge.Config.Homeserver.Software == bridgeconfig.SoftwareHungry
|
|
||||||
if !isHungry {
|
|
||||||
allowNonExistent = false
|
|
||||||
}
|
|
||||||
// TODO add config option for cross-room replies
|
// TODO add config option for cross-room replies
|
||||||
crossRoomReplies := isHungry
|
crossRoomReplies := portal.bridge.Config.Homeserver.Software == bridgeconfig.SoftwareHungry
|
||||||
|
|
||||||
targetPortal := portal
|
targetPortal := portal
|
||||||
if ref.ChannelID != portal.Key.ChannelID && ref.ChannelID != threadID && crossRoomReplies {
|
if ref.ChannelID != portal.Key.ChannelID && ref.ChannelID != threadID && crossRoomReplies {
|
||||||
@@ -803,11 +816,7 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
|
|
||||||
if msg.Flags == discordgo.MessageFlagsHasThread {
|
if msg.Flags == discordgo.MessageFlagsHasThread {
|
||||||
thread := portal.bridge.GetThreadByID(msg.ID, existing[0])
|
portal.bridge.threadFound(ctx, user, existing[0], msg.ID, msg.Thread)
|
||||||
log.Debug().Msg("Marked message as thread root")
|
|
||||||
if thread.CreationNoticeMXID == "" {
|
|
||||||
portal.sendThreadCreationNotice(ctx, thread)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Author == nil {
|
if msg.Author == nil {
|
||||||
@@ -842,8 +851,10 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
intent := portal.bridge.GetPuppetByID(msg.Author.ID).IntentFor(portal)
|
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
||||||
|
intent := puppet.IntentFor(portal)
|
||||||
|
|
||||||
|
redactions := zerolog.Dict()
|
||||||
attachmentMap := map[string]*database.Message{}
|
attachmentMap := map[string]*database.Message{}
|
||||||
for _, existingPart := range existing {
|
for _, existingPart := range existing {
|
||||||
if existingPart.AttachmentID != "" {
|
if existingPart.AttachmentID != "" {
|
||||||
@@ -862,7 +873,7 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
for _, remainingEmbed := range msg.Embeds {
|
for _, remainingEmbed := range msg.Embeds {
|
||||||
// Other types of embeds are sent inline with the text message part
|
// Other types of embeds are sent inline with the text message part
|
||||||
if getEmbedType(remainingEmbed) != EmbedVideo {
|
if getEmbedType(nil, remainingEmbed) != EmbedVideo {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
embedID := "video_" + remainingEmbed.URL
|
embedID := "video_" + remainingEmbed.URL
|
||||||
@@ -871,13 +882,14 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, deletedAttachment := range attachmentMap {
|
for _, deletedAttachment := range attachmentMap {
|
||||||
_, err := intent.RedactEvent(portal.MXID, deletedAttachment.MXID)
|
resp, err := intent.RedactEvent(portal.MXID, deletedAttachment.MXID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).
|
log.Warn().Err(err).
|
||||||
Str("event_id", deletedAttachment.MXID.String()).
|
Str("event_id", deletedAttachment.MXID.String()).
|
||||||
Msg("Failed to redact attachment")
|
Msg("Failed to redact attachment")
|
||||||
}
|
}
|
||||||
deletedAttachment.Delete()
|
deletedAttachment.Delete()
|
||||||
|
redactions.Str(deletedAttachment.AttachmentID, resp.EventID.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
var converted *ConvertedMessage
|
var converted *ConvertedMessage
|
||||||
@@ -895,7 +907,12 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
Msg("Dropping non-text edit")
|
Msg("Dropping non-text edit")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
puppet.addWebhookMeta(converted, msg)
|
||||||
|
puppet.addMemberMeta(converted, msg)
|
||||||
|
converted.Content.Mentions = portal.convertDiscordMentions(msg, false)
|
||||||
converted.Content.SetEdit(existing[0].MXID)
|
converted.Content.SetEdit(existing[0].MXID)
|
||||||
|
// Never actually mention new users of edits, only include mentions inside m.new_content
|
||||||
|
converted.Content.Mentions = &event.Mentions{}
|
||||||
if converted.Extra != nil {
|
if converted.Extra != nil {
|
||||||
converted.Extra = map[string]any{
|
converted.Extra = map[string]any{
|
||||||
"m.new_content": converted.Extra,
|
"m.new_content": converted.Extra,
|
||||||
@@ -918,17 +935,40 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
if msg.EditedTimestamp != nil {
|
if msg.EditedTimestamp != nil {
|
||||||
existing[0].UpdateEditTimestamp(*msg.EditedTimestamp)
|
existing[0].UpdateEditTimestamp(*msg.EditedTimestamp)
|
||||||
}
|
}
|
||||||
|
log.Debug().
|
||||||
|
Str("event_id", resp.EventID.String()).
|
||||||
|
Dict("redacted_attachments", redactions).
|
||||||
|
Msg("Finished handling Discord edit")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleDiscordMessageDelete(user *User, msg *discordgo.Message) {
|
func (portal *Portal) handleDiscordMessageDelete(user *User, msg *discordgo.Message) {
|
||||||
existing := portal.bridge.DB.Message.GetByDiscordID(portal.Key, msg.ID)
|
lastResp := portal.redactAllParts(portal.MainIntent(), msg.ID)
|
||||||
|
if lastResp != "" {
|
||||||
|
portal.sendDeliveryReceipt(lastResp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) handleDiscordMessageDeleteBulk(user *User, messages []string) {
|
||||||
intent := portal.MainIntent()
|
intent := portal.MainIntent()
|
||||||
var lastResp id.EventID
|
var lastResp id.EventID
|
||||||
|
for _, msgID := range messages {
|
||||||
|
newLastResp := portal.redactAllParts(intent, msgID)
|
||||||
|
if newLastResp != "" {
|
||||||
|
lastResp = newLastResp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lastResp != "" {
|
||||||
|
portal.sendDeliveryReceipt(lastResp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) redactAllParts(intent *appservice.IntentAPI, msgID string) (lastResp id.EventID) {
|
||||||
|
existing := portal.bridge.DB.Message.GetByDiscordID(portal.Key, msgID)
|
||||||
for _, dbMsg := range existing {
|
for _, dbMsg := range existing {
|
||||||
resp, err := intent.RedactEvent(portal.MXID, dbMsg.MXID)
|
resp, err := intent.RedactEvent(portal.MXID, dbMsg.MXID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Err(err).
|
portal.log.Err(err).
|
||||||
Str("message_id", msg.ID).
|
Str("message_id", msgID).
|
||||||
Str("event_id", dbMsg.MXID.String()).
|
Str("event_id", dbMsg.MXID.String()).
|
||||||
Msg("Failed to redact Matrix message")
|
Msg("Failed to redact Matrix message")
|
||||||
} else if resp != nil && resp.EventID != "" {
|
} else if resp != nil && resp.EventID != "" {
|
||||||
@@ -936,9 +976,7 @@ func (portal *Portal) handleDiscordMessageDelete(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
dbMsg.Delete()
|
dbMsg.Delete()
|
||||||
}
|
}
|
||||||
if lastResp != "" {
|
return
|
||||||
portal.sendDeliveryReceipt(lastResp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleDiscordTyping(evt *discordgo.TypingStart) {
|
func (portal *Portal) handleDiscordTyping(evt *discordgo.TypingStart) {
|
||||||
@@ -965,7 +1003,7 @@ func (portal *Portal) handleDiscordTyping(evt *discordgo.TypingStart) {
|
|||||||
|
|
||||||
func (portal *Portal) syncParticipant(source *User, participant *discordgo.User, remove bool) {
|
func (portal *Portal) syncParticipant(source *User, participant *discordgo.User, remove bool) {
|
||||||
puppet := portal.bridge.GetPuppetByID(participant.ID)
|
puppet := portal.bridge.GetPuppetByID(participant.ID)
|
||||||
puppet.UpdateInfo(source, participant)
|
puppet.UpdateInfo(source, participant, nil)
|
||||||
log := portal.log.With().
|
log := portal.log.With().
|
||||||
Str("participant_id", participant.ID).
|
Str("participant_id", participant.ID).
|
||||||
Str("ghost_mxid", puppet.MXID.String()).
|
Str("ghost_mxid", puppet.MXID.String()).
|
||||||
@@ -992,7 +1030,7 @@ func (portal *Portal) syncParticipant(source *User, participant *discordgo.User,
|
|||||||
func (portal *Portal) syncParticipants(source *User, participants []*discordgo.User) {
|
func (portal *Portal) syncParticipants(source *User, participants []*discordgo.User) {
|
||||||
for _, participant := range participants {
|
for _, participant := range participants {
|
||||||
puppet := portal.bridge.GetPuppetByID(participant.ID)
|
puppet := portal.bridge.GetPuppetByID(participant.ID)
|
||||||
puppet.UpdateInfo(source, participant)
|
puppet.UpdateInfo(source, participant, nil)
|
||||||
|
|
||||||
user := portal.bridge.GetUserByID(participant.ID)
|
user := portal.bridge.GetUserByID(participant.ID)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
@@ -1141,6 +1179,9 @@ func (portal *Portal) sendErrorMessage(msgType, message string, confirmed bool)
|
|||||||
if confirmed {
|
if confirmed {
|
||||||
certainty = "was not"
|
certainty = "was not"
|
||||||
}
|
}
|
||||||
|
if portal.RelayWebhookSecret != "" {
|
||||||
|
message = strings.ReplaceAll(message, portal.RelayWebhookSecret, "<redacted>")
|
||||||
|
}
|
||||||
resp, err := portal.sendMatrixMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
|
resp, err := portal.sendMatrixMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
|
||||||
MsgType: event.MsgNotice,
|
MsgType: event.MsgNotice,
|
||||||
Body: fmt.Sprintf("\u26a0 Your %s %s bridged: %v", msgType, certainty, message),
|
Body: fmt.Sprintf("\u26a0 Your %s %s bridged: %v", msgType, certainty, message),
|
||||||
@@ -1436,9 +1477,10 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if threadRoot := content.GetRelatesTo().GetThreadParent(); threadRoot != "" {
|
} else if threadRoot := content.GetRelatesTo().GetThreadParent(); threadRoot != "" {
|
||||||
existingThread := portal.bridge.DB.Thread.GetByMatrixRootMsg(threadRoot)
|
existingThread := portal.bridge.GetThreadByRootMXID(threadRoot)
|
||||||
if existingThread != nil {
|
if existingThread != nil {
|
||||||
threadID = existingThread.ID
|
threadID = existingThread.ID
|
||||||
|
existingThread.initialBackfillAttempted = true
|
||||||
} else {
|
} else {
|
||||||
if isWebhookSend {
|
if isWebhookSend {
|
||||||
// TODO start thread with bot?
|
// TODO start thread with bot?
|
||||||
@@ -1491,6 +1533,9 @@ 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)
|
||||||
|
if content.MsgType == event.MsgEmote {
|
||||||
|
sendReq.Content = fmt.Sprintf("_%s_", sendReq.Content)
|
||||||
|
}
|
||||||
case event.MsgAudio, event.MsgFile, event.MsgImage, event.MsgVideo:
|
case event.MsgAudio, event.MsgFile, event.MsgImage, event.MsgVideo:
|
||||||
data, err := downloadMatrixAttachment(portal.MainIntent(), content)
|
data, err := downloadMatrixAttachment(portal.MainIntent(), content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1585,6 +1630,7 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
|||||||
} else {
|
} else {
|
||||||
dbMsg.SenderID = portal.RelayWebhookID
|
dbMsg.SenderID = portal.RelayWebhookID
|
||||||
}
|
}
|
||||||
|
dbMsg.SenderMXID = sender.MXID
|
||||||
dbMsg.Timestamp, _ = discordgo.SnowflakeTimestamp(msg.ID)
|
dbMsg.Timestamp, _ = discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
dbMsg.ThreadID = threadID
|
dbMsg.ThreadID = threadID
|
||||||
dbMsg.Insert()
|
dbMsg.Insert()
|
||||||
@@ -1672,7 +1718,7 @@ func (portal *Portal) cleanup(puppetsOnly bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
intent := portal.MainIntent()
|
intent := portal.MainIntent()
|
||||||
if portal.bridge.SpecVersions.UnstableFeatures["com.beeper.room_yeeting"] {
|
if portal.bridge.SpecVersions.Supports(mautrix.BeeperFeatureRoomYeeting) {
|
||||||
err := intent.BeeperDeleteRoom(portal.MXID)
|
err := intent.BeeperDeleteRoom(portal.MXID)
|
||||||
if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
||||||
portal.log.Err(err).Msg("Failed to delete room using hungryserv yeet endpoint")
|
portal.log.Err(err).Msg("Failed to delete room using hungryserv yeet endpoint")
|
||||||
@@ -1781,7 +1827,7 @@ func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) {
|
|||||||
emojiID := reaction.RelatesTo.Key
|
emojiID := reaction.RelatesTo.Key
|
||||||
if strings.HasPrefix(emojiID, "mxc://") {
|
if strings.HasPrefix(emojiID, "mxc://") {
|
||||||
uri, _ := id.ParseContentURI(emojiID)
|
uri, _ := id.ParseContentURI(emojiID)
|
||||||
emojiFile := portal.bridge.DB.File.GetByMXC(uri)
|
emojiFile := portal.bridge.DB.File.GetEmojiByMXC(uri)
|
||||||
if emojiFile == nil || emojiFile.ID == "" || emojiFile.EmojiName == "" {
|
if emojiFile == nil || emojiFile.ID == "" || emojiFile.EmojiName == "" {
|
||||||
go portal.sendMessageMetrics(evt, fmt.Errorf("%w %s", errUnknownEmoji, emojiID), "Ignoring")
|
go portal.sendMessageMetrics(evt, fmt.Errorf("%w %s", errUnknownEmoji, emojiID), "Ignoring")
|
||||||
return
|
return
|
||||||
@@ -1820,7 +1866,7 @@ func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) {
|
|||||||
func (portal *Portal) handleDiscordReaction(user *User, reaction *discordgo.MessageReaction, add bool, thread *Thread, member *discordgo.Member) {
|
func (portal *Portal) handleDiscordReaction(user *User, reaction *discordgo.MessageReaction, add bool, thread *Thread, member *discordgo.Member) {
|
||||||
puppet := portal.bridge.GetPuppetByID(reaction.UserID)
|
puppet := portal.bridge.GetPuppetByID(reaction.UserID)
|
||||||
if member != nil {
|
if member != nil {
|
||||||
puppet.UpdateInfo(user, member.User)
|
puppet.UpdateInfo(user, member.User, nil)
|
||||||
}
|
}
|
||||||
intent := puppet.IntentFor(portal)
|
intent := puppet.IntentFor(portal)
|
||||||
|
|
||||||
@@ -2143,13 +2189,15 @@ func (portal *Portal) UpdateGroupDMAvatar(iconID string) bool {
|
|||||||
portal.AvatarSet = false
|
portal.AvatarSet = false
|
||||||
portal.AvatarURL = id.ContentURI{}
|
portal.AvatarURL = id.ContentURI{}
|
||||||
if portal.Avatar != "" {
|
if portal.Avatar != "" {
|
||||||
uri, err := uploadAvatar(portal.MainIntent(), discordgo.EndpointGroupIcon(portal.Key.ChannelID, portal.Avatar))
|
// TODO direct media support
|
||||||
|
copied, err := portal.bridge.copyAttachmentToMatrix(portal.MainIntent(), discordgo.EndpointGroupIcon(portal.Key.ChannelID, portal.Avatar), false, AttachmentMeta{
|
||||||
|
AttachmentID: fmt.Sprintf("private_channel_avatar/%s/%s", portal.Key.ChannelID, iconID),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Err(err).Str("avatar_id", portal.Avatar).Msg("Failed to reupload channel avatar")
|
portal.log.Err(err).Str("avatar_id", iconID).Msg("Failed to reupload channel avatar")
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
portal.AvatarURL = uri
|
|
||||||
}
|
}
|
||||||
|
portal.AvatarURL = copied.MXC
|
||||||
}
|
}
|
||||||
portal.updateRoomAvatar()
|
portal.updateRoomAvatar()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import (
|
|||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
"maunium.net/go/mautrix/appservice"
|
"maunium.net/go/mautrix/appservice"
|
||||||
@@ -80,6 +82,9 @@ func (portal *Portal) convertDiscordFile(ctx context.Context, typeName string, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) cleanupConvertedStickerInfo(content *event.MessageEventContent) {
|
func (portal *Portal) cleanupConvertedStickerInfo(content *event.MessageEventContent) {
|
||||||
|
if content.Info == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if content.Info.Width == 0 && content.Info.Height == 0 {
|
if content.Info.Width == 0 && content.Info.Height == 0 {
|
||||||
content.Info.Width = DiscordStickerSize
|
content.Info.Width = DiscordStickerSize
|
||||||
content.Info.Height = DiscordStickerSize
|
content.Info.Height = DiscordStickerSize
|
||||||
@@ -193,7 +198,13 @@ func (portal *Portal) convertDiscordAttachment(ctx context.Context, intent *apps
|
|||||||
|
|
||||||
func (portal *Portal) convertDiscordVideoEmbed(ctx context.Context, intent *appservice.IntentAPI, embed *discordgo.MessageEmbed) *ConvertedMessage {
|
func (portal *Portal) convertDiscordVideoEmbed(ctx context.Context, intent *appservice.IntentAPI, embed *discordgo.MessageEmbed) *ConvertedMessage {
|
||||||
attachmentID := fmt.Sprintf("video_%s", embed.URL)
|
attachmentID := fmt.Sprintf("video_%s", embed.URL)
|
||||||
dbFile, err := portal.bridge.copyAttachmentToMatrix(intent, embed.Video.ProxyURL, portal.Encrypted, NoMeta)
|
var proxyURL string
|
||||||
|
if embed.Video != nil {
|
||||||
|
proxyURL = embed.Video.ProxyURL
|
||||||
|
} else {
|
||||||
|
proxyURL = embed.Thumbnail.ProxyURL
|
||||||
|
}
|
||||||
|
dbFile, err := portal.bridge.copyAttachmentToMatrix(intent, proxyURL, portal.Encrypted, NoMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(ctx).Err(err).Msg("Failed to copy video embed to Matrix")
|
zerolog.Ctx(ctx).Err(err).Msg("Failed to copy video embed to Matrix")
|
||||||
return &ConvertedMessage{
|
return &ConvertedMessage{
|
||||||
@@ -204,16 +215,21 @@ func (portal *Portal) convertDiscordVideoEmbed(ctx context.Context, intent *apps
|
|||||||
}
|
}
|
||||||
|
|
||||||
content := &event.MessageEventContent{
|
content := &event.MessageEventContent{
|
||||||
MsgType: event.MsgVideo,
|
Body: embed.URL,
|
||||||
Body: embed.URL,
|
|
||||||
Info: &event.FileInfo{
|
Info: &event.FileInfo{
|
||||||
Width: embed.Video.Width,
|
|
||||||
Height: embed.Video.Height,
|
|
||||||
MimeType: dbFile.MimeType,
|
MimeType: dbFile.MimeType,
|
||||||
|
Size: dbFile.Size,
|
||||||
Size: dbFile.Size,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
if embed.Video != nil {
|
||||||
|
content.MsgType = event.MsgVideo
|
||||||
|
content.Info.Width = embed.Video.Width
|
||||||
|
content.Info.Height = embed.Video.Height
|
||||||
|
} else {
|
||||||
|
content.MsgType = event.MsgImage
|
||||||
|
content.Info.Width = embed.Thumbnail.Width
|
||||||
|
content.Info.Height = embed.Thumbnail.Height
|
||||||
|
}
|
||||||
if content.Info.Width == 0 && content.Info.Height == 0 {
|
if content.Info.Width == 0 && content.Info.Height == 0 {
|
||||||
content.Info.Width = dbFile.Width
|
content.Info.Width = dbFile.Width
|
||||||
content.Info.Height = dbFile.Height
|
content.Info.Height = dbFile.Height
|
||||||
@@ -227,7 +243,7 @@ func (portal *Portal) convertDiscordVideoEmbed(ctx context.Context, intent *apps
|
|||||||
content.URL = dbFile.MXC.CUString()
|
content.URL = dbFile.MXC.CUString()
|
||||||
}
|
}
|
||||||
extra := map[string]any{}
|
extra := map[string]any{}
|
||||||
if embed.Type == discordgo.EmbedTypeGifv {
|
if content.MsgType == event.MsgVideo && embed.Type == discordgo.EmbedTypeGifv {
|
||||||
extra["info"] = map[string]any{
|
extra["info"] = map[string]any{
|
||||||
"fi.mau.discord.gifv": true,
|
"fi.mau.discord.gifv": true,
|
||||||
"fi.mau.loop": true,
|
"fi.mau.loop": true,
|
||||||
@@ -244,7 +260,7 @@ func (portal *Portal) convertDiscordVideoEmbed(ctx context.Context, intent *apps
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) convertDiscordMessage(ctx context.Context, intent *appservice.IntentAPI, msg *discordgo.Message) []*ConvertedMessage {
|
func (portal *Portal) convertDiscordMessage(ctx context.Context, puppet *Puppet, intent *appservice.IntentAPI, msg *discordgo.Message) []*ConvertedMessage {
|
||||||
predictedLength := len(msg.Attachments) + len(msg.StickerItems)
|
predictedLength := len(msg.Attachments) + len(msg.StickerItems)
|
||||||
if msg.Content != "" {
|
if msg.Content != "" {
|
||||||
predictedLength++
|
predictedLength++
|
||||||
@@ -277,7 +293,7 @@ func (portal *Portal) convertDiscordMessage(ctx context.Context, intent *appserv
|
|||||||
}
|
}
|
||||||
for i, embed := range msg.Embeds {
|
for i, embed := range msg.Embeds {
|
||||||
// Ignore non-video embeds, they're handled in convertDiscordTextMessage
|
// Ignore non-video embeds, they're handled in convertDiscordTextMessage
|
||||||
if getEmbedType(embed) != EmbedVideo {
|
if getEmbedType(msg, embed) != EmbedVideo {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Discord deduplicates embeds by URL. It makes things easier for us too.
|
// Discord deduplicates embeds by URL. It makes things easier for us too.
|
||||||
@@ -295,9 +311,92 @@ func (portal *Portal) convertDiscordMessage(ctx context.Context, intent *appserv
|
|||||||
parts = append(parts, part)
|
parts = append(parts, part)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(parts) == 0 && msg.Thread != nil {
|
||||||
|
parts = append(parts, &ConvertedMessage{Type: event.EventMessage, Content: &event.MessageEventContent{
|
||||||
|
MsgType: event.MsgText,
|
||||||
|
Body: fmt.Sprintf("Created a thread: %s", msg.Thread.Name),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
for _, part := range parts {
|
||||||
|
puppet.addWebhookMeta(part, msg)
|
||||||
|
puppet.addMemberMeta(part, msg)
|
||||||
|
}
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (puppet *Puppet) addMemberMeta(part *ConvertedMessage, msg *discordgo.Message) {
|
||||||
|
if msg.Member == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if part.Extra == nil {
|
||||||
|
part.Extra = make(map[string]any)
|
||||||
|
}
|
||||||
|
var avatarURL id.ContentURI
|
||||||
|
var discordAvatarURL string
|
||||||
|
if msg.Member.Avatar != "" {
|
||||||
|
var err error
|
||||||
|
avatarURL, discordAvatarURL, err = puppet.bridge.reuploadUserAvatar(puppet.DefaultIntent(), msg.GuildID, msg.Author.ID, msg.Author.Avatar)
|
||||||
|
if err != nil {
|
||||||
|
puppet.log.Warn().Err(err).
|
||||||
|
Str("avatar_id", msg.Author.Avatar).
|
||||||
|
Msg("Failed to reupload guild user avatar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
part.Extra["fi.mau.discord.guild_member_metadata"] = map[string]any{
|
||||||
|
"nick": msg.Member.Nick,
|
||||||
|
"avatar_id": msg.Member.Avatar,
|
||||||
|
"avatar_url": discordAvatarURL,
|
||||||
|
"avatar_mxc": avatarURL.String(),
|
||||||
|
}
|
||||||
|
if msg.Member.Nick != "" || !avatarURL.IsEmpty() {
|
||||||
|
perMessageProfile := map[string]any{
|
||||||
|
"is_multiple_users": false,
|
||||||
|
|
||||||
|
"displayname": msg.Member.Nick,
|
||||||
|
"avatar_url": avatarURL.String(),
|
||||||
|
}
|
||||||
|
if msg.Member.Nick == "" {
|
||||||
|
perMessageProfile["displayname"] = puppet.Name
|
||||||
|
}
|
||||||
|
if avatarURL.IsEmpty() {
|
||||||
|
perMessageProfile["avatar_url"] = puppet.AvatarURL.String()
|
||||||
|
}
|
||||||
|
part.Extra["com.beeper.per_message_profile"] = perMessageProfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (puppet *Puppet) addWebhookMeta(part *ConvertedMessage, msg *discordgo.Message) {
|
||||||
|
if msg.WebhookID == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if part.Extra == nil {
|
||||||
|
part.Extra = make(map[string]any)
|
||||||
|
}
|
||||||
|
var avatarURL id.ContentURI
|
||||||
|
if msg.Author.Avatar != "" {
|
||||||
|
var err error
|
||||||
|
avatarURL, _, err = puppet.bridge.reuploadUserAvatar(puppet.DefaultIntent(), "", msg.Author.ID, msg.Author.Avatar)
|
||||||
|
if err != nil {
|
||||||
|
puppet.log.Warn().Err(err).
|
||||||
|
Str("avatar_id", msg.Author.Avatar).
|
||||||
|
Msg("Failed to reupload webhook avatar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
part.Extra["fi.mau.discord.webhook_metadata"] = map[string]any{
|
||||||
|
"id": msg.WebhookID,
|
||||||
|
"name": msg.Author.Username,
|
||||||
|
"avatar_id": msg.Author.Avatar,
|
||||||
|
"avatar_url": msg.Author.AvatarURL(""),
|
||||||
|
"avatar_mxc": avatarURL.String(),
|
||||||
|
}
|
||||||
|
part.Extra["com.beeper.per_message_profile"] = map[string]any{
|
||||||
|
"is_multiple_users": true,
|
||||||
|
|
||||||
|
"avatar_url": avatarURL.String(),
|
||||||
|
"displayname": msg.Author.Username,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
embedHTMLWrapper = `<blockquote class="discord-embed">%s</blockquote>`
|
embedHTMLWrapper = `<blockquote class="discord-embed">%s</blockquote>`
|
||||||
embedHTMLWrapperColor = `<blockquote class="discord-embed" background-color="#%06X">%s</blockquote>`
|
embedHTMLWrapperColor = `<blockquote class="discord-embed" background-color="#%06X">%s</blockquote>`
|
||||||
@@ -496,7 +595,7 @@ func isActuallyLinkPreview(embed *discordgo.MessageEmbed) bool {
|
|||||||
return embed.Video != nil && embed.Video.ProxyURL == ""
|
return embed.Video != nil && embed.Video.ProxyURL == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEmbedType(embed *discordgo.MessageEmbed) BridgeEmbedType {
|
func getEmbedType(msg *discordgo.Message, embed *discordgo.MessageEmbed) BridgeEmbedType {
|
||||||
switch embed.Type {
|
switch embed.Type {
|
||||||
case discordgo.EmbedTypeLink, discordgo.EmbedTypeArticle:
|
case discordgo.EmbedTypeLink, discordgo.EmbedTypeArticle:
|
||||||
return EmbedLinkPreview
|
return EmbedLinkPreview
|
||||||
@@ -507,7 +606,14 @@ func getEmbedType(embed *discordgo.MessageEmbed) BridgeEmbedType {
|
|||||||
return EmbedVideo
|
return EmbedVideo
|
||||||
case discordgo.EmbedTypeGifv:
|
case discordgo.EmbedTypeGifv:
|
||||||
return EmbedVideo
|
return EmbedVideo
|
||||||
case discordgo.EmbedTypeRich, discordgo.EmbedTypeImage:
|
case discordgo.EmbedTypeImage:
|
||||||
|
if msg != nil && isPlainGifMessage(msg) {
|
||||||
|
return EmbedVideo
|
||||||
|
} else if embed.Image == nil && embed.Thumbnail != nil {
|
||||||
|
return EmbedLinkPreview
|
||||||
|
}
|
||||||
|
return EmbedRich
|
||||||
|
case discordgo.EmbedTypeRich:
|
||||||
return EmbedRich
|
return EmbedRich
|
||||||
default:
|
default:
|
||||||
return EmbedUnknown
|
return EmbedUnknown
|
||||||
@@ -515,7 +621,31 @@ func getEmbedType(embed *discordgo.MessageEmbed) BridgeEmbedType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isPlainGifMessage(msg *discordgo.Message) bool {
|
func isPlainGifMessage(msg *discordgo.Message) bool {
|
||||||
return len(msg.Embeds) == 1 && msg.Embeds[0].Video != nil && msg.Embeds[0].URL == msg.Content && msg.Embeds[0].Type == discordgo.EmbedTypeGifv
|
return len(msg.Embeds) == 1 && msg.Embeds[0].URL == msg.Content &&
|
||||||
|
((msg.Embeds[0].Type == discordgo.EmbedTypeGifv && msg.Embeds[0].Video != nil) ||
|
||||||
|
(msg.Embeds[0].Type == discordgo.EmbedTypeImage && msg.Embeds[0].Image == nil && msg.Embeds[0].Thumbnail != nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) convertDiscordMentions(msg *discordgo.Message, syncGhosts bool) *event.Mentions {
|
||||||
|
var matrixMentions event.Mentions
|
||||||
|
for _, mention := range msg.Mentions {
|
||||||
|
puppet := portal.bridge.GetPuppetByID(mention.ID)
|
||||||
|
if syncGhosts {
|
||||||
|
puppet.UpdateInfo(nil, mention, nil)
|
||||||
|
}
|
||||||
|
user := portal.bridge.GetUserByID(mention.ID)
|
||||||
|
if user != nil {
|
||||||
|
matrixMentions.UserIDs = append(matrixMentions.UserIDs, user.MXID)
|
||||||
|
} else {
|
||||||
|
matrixMentions.UserIDs = append(matrixMentions.UserIDs, puppet.MXID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slices.Sort(matrixMentions.UserIDs)
|
||||||
|
matrixMentions.UserIDs = slices.Compact(matrixMentions.UserIDs)
|
||||||
|
if msg.MentionEveryone {
|
||||||
|
matrixMentions.Room = true
|
||||||
|
}
|
||||||
|
return &matrixMentions
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -534,7 +664,7 @@ func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *app
|
|||||||
var htmlParts []string
|
var htmlParts []string
|
||||||
if msg.Interaction != nil {
|
if msg.Interaction != nil {
|
||||||
puppet := portal.bridge.GetPuppetByID(msg.Interaction.User.ID)
|
puppet := portal.bridge.GetPuppetByID(msg.Interaction.User.ID)
|
||||||
puppet.UpdateInfo(nil, msg.Interaction.User)
|
puppet.UpdateInfo(nil, msg.Interaction.User, nil)
|
||||||
htmlParts = append(htmlParts, fmt.Sprintf(msgInteractionTemplateHTML, puppet.MXID, puppet.Name, msg.Interaction.Name))
|
htmlParts = append(htmlParts, fmt.Sprintf(msgInteractionTemplateHTML, puppet.MXID, puppet.Name, msg.Interaction.Name))
|
||||||
}
|
}
|
||||||
if msg.Content != "" && !isPlainGifMessage(msg) {
|
if msg.Content != "" && !isPlainGifMessage(msg) {
|
||||||
@@ -548,7 +678,7 @@ func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *app
|
|||||||
with := log.With().
|
with := log.With().
|
||||||
Str("embed_type", string(embed.Type)).
|
Str("embed_type", string(embed.Type)).
|
||||||
Int("embed_index", i)
|
Int("embed_index", i)
|
||||||
switch getEmbedType(embed) {
|
switch getEmbedType(msg, embed) {
|
||||||
case EmbedRich:
|
case EmbedRich:
|
||||||
log := with.Str("computed_embed_type", "rich").Logger()
|
log := with.Str("computed_embed_type", "rich").Logger()
|
||||||
htmlParts = append(htmlParts, portal.convertDiscordRichEmbed(log.WithContext(ctx), intent, embed, msg.ID, i))
|
htmlParts = append(htmlParts, portal.convertDiscordRichEmbed(log.WithContext(ctx), intent, embed, msg.ID, i))
|
||||||
@@ -581,5 +711,11 @@ 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}
|
||||||
}
|
}
|
||||||
|
|||||||
114
puppet.go
114
puppet.go
@@ -9,9 +9,9 @@ import (
|
|||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
|
"maunium.net/go/mautrix"
|
||||||
"maunium.net/go/mautrix/appservice"
|
"maunium.net/go/mautrix/appservice"
|
||||||
"maunium.net/go/mautrix/bridge"
|
"maunium.net/go/mautrix/bridge"
|
||||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"go.mau.fi/mautrix-discord/database"
|
"go.mau.fi/mautrix-discord/database"
|
||||||
@@ -158,18 +158,6 @@ func (br *DiscordBridge) FormatPuppetMXID(did string) id.UserID {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *DiscordBridge) updatePuppetsContactInfo() {
|
|
||||||
if br.Config.Homeserver.Software != bridgeconfig.SoftwareHungry {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, puppet := range br.GetAllPuppets() {
|
|
||||||
if !puppet.ContactInfoSet && puppet.NameSet {
|
|
||||||
puppet.ResendContactInfo()
|
|
||||||
puppet.Update()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (puppet *Puppet) GetDisplayname() string {
|
func (puppet *Puppet) GetDisplayname() string {
|
||||||
return puppet.Name
|
return puppet.Name
|
||||||
}
|
}
|
||||||
@@ -207,7 +195,7 @@ func (puppet *Puppet) updatePortalMeta(meta func(portal *Portal)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) UpdateName(info *discordgo.User) bool {
|
func (puppet *Puppet) UpdateName(info *discordgo.User) bool {
|
||||||
newName := puppet.bridge.Config.Bridge.FormatDisplayname(info)
|
newName := puppet.bridge.Config.Bridge.FormatDisplayname(info, puppet.IsWebhook, puppet.IsApplication)
|
||||||
if puppet.Name == newName && puppet.NameSet {
|
if puppet.Name == newName && puppet.NameSet {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -228,30 +216,56 @@ func (puppet *Puppet) UpdateName(info *discordgo.User) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (br *DiscordBridge) reuploadUserAvatar(intent *appservice.IntentAPI, guildID, userID, avatarID string) (id.ContentURI, string, error) {
|
||||||
|
var downloadURL, ext string
|
||||||
|
if guildID == "" {
|
||||||
|
downloadURL = discordgo.EndpointUserAvatar(userID, avatarID)
|
||||||
|
ext = "png"
|
||||||
|
if strings.HasPrefix(avatarID, "a_") {
|
||||||
|
downloadURL = discordgo.EndpointUserAvatarAnimated(userID, avatarID)
|
||||||
|
ext = "gif"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
downloadURL = discordgo.EndpointGuildMemberAvatar(guildID, userID, avatarID)
|
||||||
|
ext = "png"
|
||||||
|
if strings.HasPrefix(avatarID, "a_") {
|
||||||
|
downloadURL = discordgo.EndpointGuildMemberAvatarAnimated(guildID, userID, avatarID)
|
||||||
|
ext = "gif"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if guildID == "" {
|
||||||
|
url := br.Config.Bridge.MediaPatterns.Avatar(userID, avatarID, ext)
|
||||||
|
if !url.IsEmpty() {
|
||||||
|
return url, downloadURL, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
copied, err := br.copyAttachmentToMatrix(intent, downloadURL, false, AttachmentMeta{
|
||||||
|
AttachmentID: fmt.Sprintf("avatar/%s/%s/%s", guildID, userID, avatarID),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return id.ContentURI{}, downloadURL, err
|
||||||
|
}
|
||||||
|
return copied.MXC, downloadURL, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) UpdateAvatar(info *discordgo.User) bool {
|
func (puppet *Puppet) UpdateAvatar(info *discordgo.User) bool {
|
||||||
if puppet.Avatar == info.Avatar && puppet.AvatarSet {
|
avatarID := info.Avatar
|
||||||
|
if puppet.IsWebhook && !puppet.bridge.Config.Bridge.EnableWebhookAvatars {
|
||||||
|
avatarID = ""
|
||||||
|
}
|
||||||
|
if puppet.Avatar == avatarID && puppet.AvatarSet {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
avatarChanged := info.Avatar != puppet.Avatar
|
avatarChanged := avatarID != puppet.Avatar
|
||||||
puppet.Avatar = info.Avatar
|
puppet.Avatar = avatarID
|
||||||
puppet.AvatarSet = false
|
puppet.AvatarSet = false
|
||||||
puppet.AvatarURL = id.ContentURI{}
|
puppet.AvatarURL = id.ContentURI{}
|
||||||
|
|
||||||
if puppet.Avatar != "" && (puppet.AvatarURL.IsEmpty() || avatarChanged) {
|
if puppet.Avatar != "" && (puppet.AvatarURL.IsEmpty() || avatarChanged) {
|
||||||
downloadURL := discordgo.EndpointUserAvatar(info.ID, info.Avatar)
|
url, _, err := puppet.bridge.reuploadUserAvatar(puppet.DefaultIntent(), "", info.ID, puppet.Avatar)
|
||||||
ext := "png"
|
if err != nil {
|
||||||
if strings.HasPrefix(info.Avatar, "a_") {
|
puppet.log.Warn().Err(err).Str("avatar_id", puppet.Avatar).Msg("Failed to reupload user avatar")
|
||||||
downloadURL = discordgo.EndpointUserAvatarAnimated(info.ID, info.Avatar)
|
return true
|
||||||
ext = "gif"
|
|
||||||
}
|
|
||||||
url := puppet.bridge.Config.Bridge.MediaPatterns.Avatar(info.ID, info.Avatar, ext)
|
|
||||||
if url.IsEmpty() {
|
|
||||||
var err error
|
|
||||||
url, err = uploadAvatar(puppet.DefaultIntent(), downloadURL)
|
|
||||||
if err != nil {
|
|
||||||
puppet.log.Warn().Err(err).Str("avatar_id", puppet.Avatar).Msg("Failed to reupload user avatar")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
puppet.AvatarURL = url
|
puppet.AvatarURL = url
|
||||||
}
|
}
|
||||||
@@ -271,7 +285,7 @@ func (puppet *Puppet) UpdateAvatar(info *discordgo.User) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) UpdateInfo(source *User, info *discordgo.User) {
|
func (puppet *Puppet) UpdateInfo(source *User, info *discordgo.User, message *discordgo.Message) {
|
||||||
puppet.syncLock.Lock()
|
puppet.syncLock.Lock()
|
||||||
defer puppet.syncLock.Unlock()
|
defer puppet.syncLock.Unlock()
|
||||||
|
|
||||||
@@ -294,6 +308,25 @@ func (puppet *Puppet) UpdateInfo(source *User, info *discordgo.User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changed := false
|
changed := false
|
||||||
|
if message != nil {
|
||||||
|
if message.WebhookID != "" && message.ApplicationID == "" && !puppet.IsWebhook {
|
||||||
|
puppet.log.Debug().
|
||||||
|
Str("message_id", message.ID).
|
||||||
|
Str("webhook_id", message.WebhookID).
|
||||||
|
Msg("Found webhook ID in message, marking ghost as a webhook")
|
||||||
|
puppet.IsWebhook = true
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
if message.ApplicationID != "" && !puppet.IsApplication {
|
||||||
|
puppet.log.Debug().
|
||||||
|
Str("message_id", message.ID).
|
||||||
|
Str("application_id", message.ApplicationID).
|
||||||
|
Msg("Found application ID in message, marking ghost as an application")
|
||||||
|
puppet.IsApplication = true
|
||||||
|
puppet.IsWebhook = false
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
changed = puppet.UpdateContactInfo(info) || changed
|
changed = puppet.UpdateContactInfo(info) || changed
|
||||||
changed = puppet.UpdateName(info) || changed
|
changed = puppet.UpdateName(info) || changed
|
||||||
changed = puppet.UpdateAvatar(info) || changed
|
changed = puppet.UpdateAvatar(info) || changed
|
||||||
@@ -308,6 +341,10 @@ func (puppet *Puppet) UpdateContactInfo(info *discordgo.User) bool {
|
|||||||
puppet.Username = info.Username
|
puppet.Username = info.Username
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
if puppet.GlobalName != info.GlobalName {
|
||||||
|
puppet.GlobalName = info.GlobalName
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
if puppet.Discriminator != info.Discriminator {
|
if puppet.Discriminator != info.Discriminator {
|
||||||
puppet.Discriminator = info.Discriminator
|
puppet.Discriminator = info.Discriminator
|
||||||
changed = true
|
changed = true
|
||||||
@@ -316,7 +353,7 @@ func (puppet *Puppet) UpdateContactInfo(info *discordgo.User) bool {
|
|||||||
puppet.IsBot = info.Bot
|
puppet.IsBot = info.Bot
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
if changed {
|
if (changed && !puppet.IsWebhook) || !puppet.ContactInfoSet {
|
||||||
puppet.ContactInfoSet = false
|
puppet.ContactInfoSet = false
|
||||||
puppet.ResendContactInfo()
|
puppet.ResendContactInfo()
|
||||||
return true
|
return true
|
||||||
@@ -325,18 +362,25 @@ func (puppet *Puppet) UpdateContactInfo(info *discordgo.User) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) ResendContactInfo() {
|
func (puppet *Puppet) ResendContactInfo() {
|
||||||
if puppet.bridge.Config.Homeserver.Software != bridgeconfig.SoftwareHungry || puppet.ContactInfoSet {
|
if !puppet.bridge.SpecVersions.Supports(mautrix.BeeperFeatureArbitraryProfileMeta) || puppet.ContactInfoSet {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
discordUsername := puppet.Username
|
||||||
|
if puppet.Discriminator != "0" {
|
||||||
|
discordUsername += "#" + puppet.Discriminator
|
||||||
|
}
|
||||||
contactInfo := map[string]any{
|
contactInfo := map[string]any{
|
||||||
"com.beeper.bridge.identifiers": []string{
|
"com.beeper.bridge.identifiers": []string{
|
||||||
fmt.Sprintf("discord:%s#%s", puppet.Username, puppet.Discriminator),
|
fmt.Sprintf("discord:%s", discordUsername),
|
||||||
},
|
},
|
||||||
"com.beeper.bridge.remote_id": puppet.ID,
|
"com.beeper.bridge.remote_id": puppet.ID,
|
||||||
"com.beeper.bridge.service": puppet.bridge.BeeperServiceName,
|
"com.beeper.bridge.service": puppet.bridge.BeeperServiceName,
|
||||||
"com.beeper.bridge.network": puppet.bridge.BeeperNetworkName,
|
"com.beeper.bridge.network": puppet.bridge.BeeperNetworkName,
|
||||||
"com.beeper.bridge.is_network_bot": puppet.IsBot,
|
"com.beeper.bridge.is_network_bot": puppet.IsBot,
|
||||||
}
|
}
|
||||||
|
if puppet.IsWebhook {
|
||||||
|
contactInfo["com.beeper.bridge.identifiers"] = []string{}
|
||||||
|
}
|
||||||
err := puppet.DefaultIntent().BeeperUpdateProfile(contactInfo)
|
err := puppet.DefaultIntent().BeeperUpdateProfile(contactInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
puppet.log.Warn().Err(err).Msg("Failed to store custom contact info in profile")
|
puppet.log.Warn().Err(err).Msg("Failed to store custom contact info in profile")
|
||||||
|
|||||||
61
thread.go
61
thread.go
@@ -1,10 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"go.mau.fi/mautrix-discord/database"
|
"go.mau.fi/mautrix-discord/database"
|
||||||
@@ -14,7 +17,8 @@ type Thread struct {
|
|||||||
*database.Thread
|
*database.Thread
|
||||||
Parent *Portal
|
Parent *Portal
|
||||||
|
|
||||||
creationNoticeLock sync.Mutex
|
creationNoticeLock sync.Mutex
|
||||||
|
initialBackfillAttempted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *DiscordBridge) GetThreadByID(id string, root *database.Message) *Thread {
|
func (br *DiscordBridge) GetThreadByID(id string, root *database.Message) *Thread {
|
||||||
@@ -74,12 +78,63 @@ func (br *DiscordBridge) loadThread(dbThread *database.Thread, id string, root *
|
|||||||
return thread
|
return thread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (br *DiscordBridge) threadFound(ctx context.Context, source *User, rootMessage *database.Message, id string, metadata *discordgo.Channel) {
|
||||||
|
thread := br.GetThreadByID(id, rootMessage)
|
||||||
|
log := zerolog.Ctx(ctx)
|
||||||
|
log.Debug().Msg("Marked message as thread root")
|
||||||
|
if thread.CreationNoticeMXID == "" {
|
||||||
|
thread.Parent.sendThreadCreationNotice(ctx, thread)
|
||||||
|
}
|
||||||
|
// TODO member_ids_preview is probably not guaranteed to contain the source user
|
||||||
|
if source != nil && metadata != nil && slices.Contains(metadata.MemberIDsPreview, source.DiscordID) && !source.IsInPortal(thread.ID) {
|
||||||
|
source.MarkInPortal(database.UserPortal{
|
||||||
|
DiscordID: thread.ID,
|
||||||
|
Type: database.UserPortalTypeThread,
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
})
|
||||||
|
if metadata.MessageCount > 0 {
|
||||||
|
go thread.maybeInitialBackfill(source)
|
||||||
|
} else {
|
||||||
|
thread.initialBackfillAttempted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (thread *Thread) maybeInitialBackfill(source *User) {
|
||||||
|
if thread.initialBackfillAttempted || thread.Parent.bridge.Config.Bridge.Backfill.Limits.Initial.Thread == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
thread.Parent.forwardBackfillLock.Lock()
|
||||||
|
if thread.Parent.bridge.DB.Message.GetLastInThread(thread.Parent.Key, thread.ID) != nil {
|
||||||
|
thread.Parent.forwardBackfillLock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
thread.Parent.forwardBackfillInitial(source, thread)
|
||||||
|
}
|
||||||
|
|
||||||
func (thread *Thread) Join(user *User) {
|
func (thread *Thread) Join(user *User) {
|
||||||
if user.IsInPortal(thread.ID) {
|
if user.IsInPortal(thread.ID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log := user.log.With().Str("thread_id", thread.ID).Str("channel_id", thread.ParentID).Logger()
|
log := user.log.With().Str("thread_id", thread.ID).Str("channel_id", thread.ParentID).Logger()
|
||||||
log.Debug().Msg("Joining thread")
|
log.Debug().Msg("Joining thread")
|
||||||
|
|
||||||
|
var doBackfill, backfillStarted bool
|
||||||
|
if !thread.initialBackfillAttempted && thread.Parent.bridge.Config.Bridge.Backfill.Limits.Initial.Thread > 0 {
|
||||||
|
thread.Parent.forwardBackfillLock.Lock()
|
||||||
|
lastMessage := thread.Parent.bridge.DB.Message.GetLastInThread(thread.Parent.Key, thread.ID)
|
||||||
|
if lastMessage != nil {
|
||||||
|
thread.Parent.forwardBackfillLock.Unlock()
|
||||||
|
} else {
|
||||||
|
doBackfill = true
|
||||||
|
defer func() {
|
||||||
|
if !backfillStarted {
|
||||||
|
thread.Parent.forwardBackfillLock.Unlock()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if user.Session.IsUser {
|
if user.Session.IsUser {
|
||||||
err = user.Session.ThreadJoinWithLocation(thread.ID, discordgo.ThreadJoinLocationContextMenu)
|
err = user.Session.ThreadJoinWithLocation(thread.ID, discordgo.ThreadJoinLocationContextMenu)
|
||||||
@@ -94,5 +149,9 @@ func (thread *Thread) Join(user *User) {
|
|||||||
Type: database.UserPortalTypeThread,
|
Type: database.UserPortalTypeThread,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
})
|
})
|
||||||
|
if doBackfill {
|
||||||
|
go thread.Parent.forwardBackfillInitial(user, thread)
|
||||||
|
backfillStarted = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
67
user.go
67
user.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -73,6 +74,9 @@ func (user *User) GetRemoteID() string {
|
|||||||
|
|
||||||
func (user *User) GetRemoteName() string {
|
func (user *User) GetRemoteName() string {
|
||||||
if user.Session != nil && user.Session.State != nil && user.Session.State.User != nil {
|
if user.Session != nil && user.Session.State != nil && user.Session.State.User != nil {
|
||||||
|
if user.Session.State.User.Discriminator == "0" {
|
||||||
|
return fmt.Sprintf("@%s", user.Session.State.User.Username)
|
||||||
|
}
|
||||||
return fmt.Sprintf("%s#%s", user.Session.State.User.Username, user.Session.State.User.Discriminator)
|
return fmt.Sprintf("%s#%s", user.Session.State.User.Username, user.Session.State.User.Discriminator)
|
||||||
}
|
}
|
||||||
return user.DiscordID
|
return user.DiscordID
|
||||||
@@ -186,6 +190,12 @@ func (br *DiscordBridge) GetUserByID(id string) *User {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (br *DiscordBridge) GetCachedUserByID(id string) *User {
|
||||||
|
br.usersLock.Lock()
|
||||||
|
defer br.usersLock.Unlock()
|
||||||
|
return br.usersByID[id]
|
||||||
|
}
|
||||||
|
|
||||||
func (br *DiscordBridge) NewUser(dbUser *database.User) *User {
|
func (br *DiscordBridge) NewUser(dbUser *database.User) *User {
|
||||||
user := &User{
|
user := &User{
|
||||||
User: dbUser,
|
User: dbUser,
|
||||||
@@ -630,6 +640,8 @@ func (user *User) eventHandler(rawEvt any) {
|
|||||||
user.pushPortalMessage(evt, "message create", evt.ChannelID, evt.GuildID)
|
user.pushPortalMessage(evt, "message create", evt.ChannelID, evt.GuildID)
|
||||||
case *discordgo.MessageDelete:
|
case *discordgo.MessageDelete:
|
||||||
user.pushPortalMessage(evt, "message delete", evt.ChannelID, evt.GuildID)
|
user.pushPortalMessage(evt, "message delete", evt.ChannelID, evt.GuildID)
|
||||||
|
case *discordgo.MessageDeleteBulk:
|
||||||
|
user.pushPortalMessage(evt, "bulk message delete", evt.ChannelID, evt.GuildID)
|
||||||
case *discordgo.MessageUpdate:
|
case *discordgo.MessageUpdate:
|
||||||
user.pushPortalMessage(evt, "message update", evt.ChannelID, evt.GuildID)
|
user.pushPortalMessage(evt, "message update", evt.ChannelID, evt.GuildID)
|
||||||
case *discordgo.MessageReactionAdd:
|
case *discordgo.MessageReactionAdd:
|
||||||
@@ -642,6 +654,8 @@ func (user *User) eventHandler(rawEvt any) {
|
|||||||
user.typingStartHandler(evt)
|
user.typingStartHandler(evt)
|
||||||
case *discordgo.InteractionSuccess:
|
case *discordgo.InteractionSuccess:
|
||||||
user.interactionSuccessHandler(evt)
|
user.interactionSuccessHandler(evt)
|
||||||
|
case *discordgo.ThreadListSync:
|
||||||
|
user.threadListSyncHandler(evt)
|
||||||
case *discordgo.Event:
|
case *discordgo.Event:
|
||||||
// Ignore
|
// Ignore
|
||||||
default:
|
default:
|
||||||
@@ -856,7 +870,7 @@ func (user *User) handlePrivateChannel(portal *Portal, meta *discordgo.Channel,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
portal.UpdateInfo(user, meta)
|
portal.UpdateInfo(user, meta)
|
||||||
portal.ForwardBackfillMissed(user, meta)
|
portal.ForwardBackfillMissed(user, meta.LastMessageID, nil)
|
||||||
}
|
}
|
||||||
user.MarkInPortal(database.UserPortal{
|
user.MarkInPortal(database.UserPortal{
|
||||||
DiscordID: portal.Key.ChannelID,
|
DiscordID: portal.Key.ChannelID,
|
||||||
@@ -958,7 +972,7 @@ func (user *User) handleGuild(meta *discordgo.Guild, timestamp time.Time, isInSp
|
|||||||
} else {
|
} else {
|
||||||
portal.UpdateInfo(user, ch)
|
portal.UpdateInfo(user, ch)
|
||||||
if user.bridge.Config.Bridge.Backfill.MaxGuildMembers < 0 || meta.MemberCount < user.bridge.Config.Bridge.Backfill.MaxGuildMembers {
|
if user.bridge.Config.Bridge.Backfill.MaxGuildMembers < 0 || meta.MemberCount < user.bridge.Config.Bridge.Backfill.MaxGuildMembers {
|
||||||
portal.ForwardBackfillMissed(user, ch)
|
portal.ForwardBackfillMissed(user, ch.LastMessageID, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1010,6 +1024,10 @@ func (user *User) guildCreateHandler(g *discordgo.GuildCreate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) guildDeleteHandler(g *discordgo.GuildDelete) {
|
func (user *User) guildDeleteHandler(g *discordgo.GuildDelete) {
|
||||||
|
if g.Unavailable {
|
||||||
|
user.log.Info().Str("guild_id", g.ID).Msg("Ignoring guild delete event with unavailable flag")
|
||||||
|
return
|
||||||
|
}
|
||||||
user.log.Info().Str("guild_id", g.ID).Msg("Got guild delete event")
|
user.log.Info().Str("guild_id", g.ID).Msg("Got guild delete event")
|
||||||
user.MarkNotInPortal(g.ID)
|
user.MarkNotInPortal(g.ID)
|
||||||
guild := user.bridge.GetGuildByID(g.ID, false)
|
guild := user.bridge.GetGuildByID(g.ID, false)
|
||||||
@@ -1030,6 +1048,30 @@ func (user *User) guildUpdateHandler(g *discordgo.GuildUpdate) {
|
|||||||
user.handleGuild(g.Guild, time.Now(), user.IsInSpace(g.ID))
|
user.handleGuild(g.Guild, time.Now(), user.IsInSpace(g.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) threadListSyncHandler(t *discordgo.ThreadListSync) {
|
||||||
|
for _, meta := range t.Threads {
|
||||||
|
log := user.log.With().
|
||||||
|
Str("action", "thread list sync").
|
||||||
|
Str("guild_id", t.GuildID).
|
||||||
|
Str("parent_id", meta.ParentID).
|
||||||
|
Str("thread_id", meta.ID).
|
||||||
|
Logger()
|
||||||
|
ctx := log.WithContext(context.Background())
|
||||||
|
thread := user.bridge.GetThreadByID(meta.ID, nil)
|
||||||
|
if thread == nil {
|
||||||
|
msg := user.bridge.DB.Message.GetByDiscordID(database.NewPortalKey(meta.ParentID, ""), meta.ID)
|
||||||
|
if len(msg) == 0 {
|
||||||
|
log.Debug().Msg("Found unknown thread in thread list sync and don't have message")
|
||||||
|
} else {
|
||||||
|
log.Debug().Msg("Found unknown thread in thread list sync for existing message, creating thread")
|
||||||
|
user.bridge.threadFound(ctx, user, msg[0], meta.ID, meta)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
thread.Parent.ForwardBackfillMissed(user, meta.LastMessageID, thread)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (user *User) channelCreateHandler(c *discordgo.ChannelCreate) {
|
func (user *User) channelCreateHandler(c *discordgo.ChannelCreate) {
|
||||||
if user.getGuildBridgingMode(c.GuildID) < database.GuildBridgeEverything {
|
if user.getGuildBridgingMode(c.GuildID) < database.GuildBridgeEverything {
|
||||||
user.log.Debug().
|
user.log.Debug().
|
||||||
@@ -1161,11 +1203,21 @@ func (user *User) pushPortalMessage(msg interface{}, typeName, channelID, guildI
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
portal.discordMessages <- portalDiscordMessage{
|
wrappedMsg := portalDiscordMessage{
|
||||||
msg: msg,
|
msg: msg,
|
||||||
user: user,
|
user: user,
|
||||||
thread: thread,
|
thread: thread,
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
case portal.discordMessages <- wrappedMsg:
|
||||||
|
default:
|
||||||
|
user.log.Warn().
|
||||||
|
Str("discord_event", typeName).
|
||||||
|
Str("guild_id", guildID).
|
||||||
|
Str("channel_id", channelID).
|
||||||
|
Msg("Portal message buffer is full")
|
||||||
|
portal.discordMessages <- wrappedMsg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomReadReceipt struct {
|
type CustomReadReceipt struct {
|
||||||
@@ -1226,10 +1278,17 @@ func (user *User) messageAckHandler(m *discordgo.MessageAck) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) typingStartHandler(t *discordgo.TypingStart) {
|
func (user *User) typingStartHandler(t *discordgo.TypingStart) {
|
||||||
|
if t.UserID == user.DiscordID {
|
||||||
|
return
|
||||||
|
}
|
||||||
portal := user.GetExistingPortalByID(t.ChannelID)
|
portal := user.GetExistingPortalByID(t.ChannelID)
|
||||||
if portal == nil || portal.MXID == "" {
|
if portal == nil || portal.MXID == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
targetUser := user.bridge.GetCachedUserByID(t.UserID)
|
||||||
|
if targetUser != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
portal.handleDiscordTyping(t)
|
portal.handleDiscordTyping(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1394,6 +1453,8 @@ func (user *User) bridgeGuild(guildID string, everything bool) error {
|
|||||||
}
|
}
|
||||||
if everything {
|
if everything {
|
||||||
guild.BridgingMode = database.GuildBridgeEverything
|
guild.BridgingMode = database.GuildBridgeEverything
|
||||||
|
} else {
|
||||||
|
guild.BridgingMode = database.GuildBridgeCreateOnMessage
|
||||||
}
|
}
|
||||||
guild.Update()
|
guild.Update()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user