add mautrix-discord
This commit is contained in:
parent
a5cc88b548
commit
0d0f788a5c
10 changed files with 65 additions and 201 deletions
69
.drone.yml
69
.drone.yml
|
@ -9,66 +9,10 @@ steps:
|
|||
commands:
|
||||
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
|
||||
- nix flake update
|
||||
- name: Update minecraft
|
||||
image: nixery.dev/shell/curl/jq
|
||||
commands:
|
||||
- (cd minecraft && bash ./update.sh)
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Update akkoma
|
||||
- name: Run update script
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- (cd akkoma && ./update.sh)
|
||||
environment:
|
||||
USER: nobody
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Update matrix-media-repo
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- mkdir -p /etc/nix
|
||||
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
|
||||
- (cd matrix/matrix-media-repo && ./update.sh)
|
||||
environment:
|
||||
USER: nobody
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Update mautrix-whatsapp
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- mkdir -p /etc/nix
|
||||
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
|
||||
- (cd matrix/mautrix-whatsapp && ./update.sh)
|
||||
- name: Update mautrix-discord
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- mkdir -p /etc/nix
|
||||
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
|
||||
- (cd matrix/mautrix-discord && ./update.sh)
|
||||
environment:
|
||||
USER: nobody
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Update art
|
||||
image: nixery.dev/shell/nix-prefetch-git/jq/gnugrep
|
||||
commands:
|
||||
- (cd art && bash ./update.sh)
|
||||
environment:
|
||||
USER: nobody
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Update pypi
|
||||
image: nixery.dev/shell/curl/jq/gnused
|
||||
commands:
|
||||
- (cd python && bash ./update.sh)
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Update miifox
|
||||
image: nixery.dev/shell/nix-prefetch-git/jq/gnugrep
|
||||
commands:
|
||||
- (cd web && bash ./update.sh)
|
||||
environment:
|
||||
USER: nobody
|
||||
- yes | nix-shell ./scripts/update.nix
|
||||
depends_on:
|
||||
- Update flake
|
||||
- name: Format nix
|
||||
|
@ -76,14 +20,7 @@ steps:
|
|||
commands:
|
||||
- alejandra .
|
||||
depends_on:
|
||||
- Update minecraft
|
||||
- Update akkoma
|
||||
- Update matrix-media-repo
|
||||
- Update mautrix-whatsapp
|
||||
- Update mautrix-discord
|
||||
- Update art
|
||||
- Update pypi
|
||||
- Update miifox
|
||||
- Run update script
|
||||
- name: Push git
|
||||
image: nixery.dev/shell/gitfull/git-lfs/shadow
|
||||
commands:
|
||||
|
|
|
@ -33,9 +33,9 @@ in
|
|||
}
|
||||
];
|
||||
};
|
||||
passthru.updateScript = writeScript "update-matrix-media-repo" ''
|
||||
${../../scripts/update-git.sh} "https://github.com/drone-runners/drone-runner-docker" ci/drone-runner-docker/source.json
|
||||
SRC_PATH=$(nix-build -E '(import ./. {}).${pname}.src')
|
||||
${../../scripts/update-go.sh} ./ci/drone-runner-docker ci/drone-runner-docker/goVendor.hash
|
||||
'';
|
||||
passthru.updateScript = writeScript "update-matrix-media-repo" ''
|
||||
${../../scripts/update-git.sh} "https://github.com/drone-runners/drone-runner-docker" ci/drone-runner-docker/source.json
|
||||
SRC_PATH=$(nix-build -E '(import ./. {}).${pname}.src')
|
||||
${../../scripts/update-go.sh} ./ci/drone-runner-docker ci/drone-runner-docker/goVendor.hash
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -31,4 +31,5 @@
|
|||
kreative-square = pkgs.callPackage ./fonts/kreative/kreative-square.nix {};
|
||||
nasin-nanpa = pkgs.callPackage ./fonts/nasin-nanpa {};
|
||||
matrix-media-repo = pkgs.callPackage ./matrix/matrix-media-repo {};
|
||||
mautrix-discord = pkgs.callPackage ./matrix/mautrix-discord {};
|
||||
}
|
||||
|
|
|
@ -1,18 +1,34 @@
|
|||
{
|
||||
pkgs,
|
||||
inputs,
|
||||
...
|
||||
} @ args: let
|
||||
inherit ((pkgs.callPackage "${inputs.gomod2nix}/builder" {})) buildGoApplication;
|
||||
in {
|
||||
mautrix-discord = buildGoApplication rec {
|
||||
buildGoModule,
|
||||
olm,
|
||||
fetchFromGitHub,
|
||||
lib,
|
||||
writeScript,
|
||||
}: let
|
||||
source = builtins.fromJSON (builtins.readFile ./source.json);
|
||||
in
|
||||
buildGoModule rec {
|
||||
pname = "mautrix-discord";
|
||||
version = inputs.mautrix-discord.lastModifiedDate;
|
||||
src = pkgs.callPackage ./source.nix {};
|
||||
version = source.date;
|
||||
src = fetchFromGitHub {
|
||||
owner = "mautrix";
|
||||
repo = "discord";
|
||||
inherit (source) rev sha256;
|
||||
};
|
||||
patches = [./sticker.patch];
|
||||
vendorSha256 = builtins.readFile ./vendor.sha256;
|
||||
buildInputs = [
|
||||
olm
|
||||
];
|
||||
proxyVendor = true;
|
||||
modules = ./gomod2nix.toml;
|
||||
CGO_ENABLED = "1";
|
||||
buildInputs = [pkgs.olm];
|
||||
};
|
||||
}
|
||||
meta = {
|
||||
description = "Discord-Matrix double-puppeting bridge";
|
||||
license = lib.licenses.agpl3;
|
||||
};
|
||||
passthru.updateScript = writeScript "update-matrix-media-repo" ''
|
||||
${../../scripts/update-git.sh} "https://github.com/mautrix/discord" matrix/mautrix-discord/source.json
|
||||
SRC_PATH=$(nix-build -E '(import ./. {}).${pname}.src')
|
||||
${../../scripts/update-go.sh} ./matrix/mautrix-discord matrix/mautrix-discord/vendor.sha256
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
schema = 3
|
||||
|
||||
[mod]
|
||||
[mod."github.com/bwmarrin/discordgo"]
|
||||
version = "v0.0.0-20220913114117-bbf4447874d5"
|
||||
hash = "sha256-No877Jxf/g52IYlCubu3CAbZ1fFd1Jrnmep4eFH44Ow="
|
||||
replaced = "github.com/beeper/discordgo"
|
||||
[mod."github.com/davecgh/go-spew"]
|
||||
version = "v1.1.1"
|
||||
hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI="
|
||||
[mod."github.com/gorilla/mux"]
|
||||
version = "v1.8.0"
|
||||
hash = "sha256-s905hpzMH9bOLue09E2JmzPXfIS4HhAlgT7g13HCwKE="
|
||||
[mod."github.com/gorilla/websocket"]
|
||||
version = "v1.5.0"
|
||||
hash = "sha256-EYVgkSEMo4HaVrsWKqnsYRp8SSS8gNf7t+Elva02Ofc="
|
||||
[mod."github.com/lib/pq"]
|
||||
version = "v1.10.6"
|
||||
hash = "sha256-8EhFwY/9YH5L/fd6l2beOnC3VvpegRAmCCsnDVJBqBM="
|
||||
[mod."github.com/mattn/go-colorable"]
|
||||
version = "v0.1.12"
|
||||
hash = "sha256-Y1vCt0ShrCz4wSmwsppCfeLPLKrWusc2zM2lUFwDMyI="
|
||||
[mod."github.com/mattn/go-isatty"]
|
||||
version = "v0.0.14"
|
||||
hash = "sha256-e8zn5eCVh/B1HOP1PGXeXH0bGkIV0vKYP9KLwZni5as="
|
||||
[mod."github.com/mattn/go-sqlite3"]
|
||||
version = "v1.14.15"
|
||||
hash = "sha256-fSrs2sdBKFTAiffBHNnAkN8kDTqiXgm4HNqzJAOF1RM="
|
||||
[mod."github.com/pmezard/go-difflib"]
|
||||
version = "v1.0.0"
|
||||
hash = "sha256-/FtmHnaGjdvEIKAJtrUfEhV7EVo5A/eYrtdnUkuxLDA="
|
||||
[mod."github.com/rs/zerolog"]
|
||||
version = "v1.27.0"
|
||||
hash = "sha256-BxQtP2TROeSSpj9l1irocuSfxn55UL4ugzB/og7r8eE="
|
||||
[mod."github.com/skip2/go-qrcode"]
|
||||
version = "v0.0.0-20200617195104-da1b6568686e"
|
||||
hash = "sha256-ST9t4/b7WFXUb8wra4ZYVDNZJGrEykw8dkWhLrxp8F0="
|
||||
[mod."github.com/stretchr/testify"]
|
||||
version = "v1.8.0"
|
||||
hash = "sha256-LDxBAebK+A06y4vbH7cd1sVBOameIY81Xm8/9OPZh7o="
|
||||
[mod."github.com/tidwall/gjson"]
|
||||
version = "v1.14.3"
|
||||
hash = "sha256-CjsKkesYwKl6hwHXB/+mvkuzW2ihKecUyvUFHUtylcw="
|
||||
[mod."github.com/tidwall/match"]
|
||||
version = "v1.1.1"
|
||||
hash = "sha256-M2klhPId3Q3T3VGkSbOkYl/2nLHnsG+yMbXkPkyrRdg="
|
||||
[mod."github.com/tidwall/pretty"]
|
||||
version = "v1.2.0"
|
||||
hash = "sha256-esRQGsn2Ee/CiySlwyuOICSLdqUkH4P7u8qXszos8Yc="
|
||||
[mod."github.com/tidwall/sjson"]
|
||||
version = "v1.2.5"
|
||||
hash = "sha256-OYGNolkmL7E1Qs2qrQ3IVpQp5gkcHNU/AB/z2O+Myps="
|
||||
[mod."github.com/yuin/goldmark"]
|
||||
version = "v1.4.13"
|
||||
hash = "sha256-GVwFKZY6moIS6I0ZGuio/WtDif+lkZRfqWS6b4AAJyI="
|
||||
[mod."golang.org/x/crypto"]
|
||||
version = "v0.0.0-20220817201139-bc19a97f63c8"
|
||||
hash = "sha256-LvSArox3yRkhJLOik9DLTSBp4ldI+OHjiWWilg2t4Hs="
|
||||
[mod."golang.org/x/net"]
|
||||
version = "v0.0.0-20220812174116-3211cb980234"
|
||||
hash = "sha256-v/Qep/W6lw6IurR+R2V0AN/MlQUROLnEaWeeuwY8sg8="
|
||||
[mod."golang.org/x/sys"]
|
||||
version = "v0.0.0-20220728004956-3c1f35247d10"
|
||||
hash = "sha256-obSKM1aiGEyYNauzaL0msReglT2XL726gL89ywjFLE8="
|
||||
[mod."gopkg.in/yaml.v3"]
|
||||
version = "v3.0.1"
|
||||
hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="
|
||||
[mod."maunium.net/go/mauflag"]
|
||||
version = "v1.0.0"
|
||||
hash = "sha256-fYc/WwqE0ev0dvnu5qGmHJsYiSTuWeOTiAVzmQIKWyY="
|
||||
[mod."maunium.net/go/maulogger/v2"]
|
||||
version = "v2.3.2"
|
||||
hash = "sha256-FlrO1bogPrIzzVzDtIovYyr+1mNk0YaO5hEVv5zovM8="
|
||||
[mod."maunium.net/go/mautrix"]
|
||||
version = "v0.12.2-0.20220919211529-34e3589a5d5e"
|
||||
hash = "sha256-5pwxh15xZ13ih5YP17MnSI5pOkn8VPDdY1G4Z9u2vMw="
|
11
matrix/mautrix-discord/source.json
Normal file
11
matrix/mautrix-discord/source.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"url": "https://github.com/mautrix/discord",
|
||||
"rev": "6be531685f308f081675034904d89c9e920be996",
|
||||
"date": "2022-09-20T00:18:06+03:00",
|
||||
"path": "/nix/store/mypn7mac96gbirbys1vg75v2b5cz99an-discord",
|
||||
"sha256": "13nlz7l619fh7yy2g487ghjw4cvypjrvqb5w9va3r3asimgy7wlg",
|
||||
"fetchLFS": false,
|
||||
"fetchSubmodules": false,
|
||||
"deepClone": false,
|
||||
"leaveDotGit": false
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{fetchgit}:
|
||||
fetchgit {
|
||||
url = "https://github.com/mautrix/discord";
|
||||
rev = "6be531685f308f081675034904d89c9e920be996";
|
||||
sha256 = "0faz3ikvwb02n5vdvwkqn77pmbjpis0cfl30h5kfi893vr05rsrs";
|
||||
leaveDotGit = true;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
diff --git a/portal.go b/portal.go
|
||||
index d93ad17..e5cd370 100644
|
||||
index d93ad17..198a12c 100644
|
||||
--- a/portal.go
|
||||
+++ b/portal.go
|
||||
@@ -874,7 +874,7 @@ func (portal *Portal) sendMatrixMessage(intent *appservice.IntentAPI, eventType
|
||||
|
@ -11,7 +11,7 @@ index d93ad17..e5cd370 100644
|
|||
portal.handleMatrixMessage(msg.user, msg.evt)
|
||||
case event.EventRedaction:
|
||||
portal.handleMatrixRedaction(msg.user, msg.evt)
|
||||
@@ -1138,7 +1138,7 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
||||
@@ -1138,13 +1138,20 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
|
||||
}
|
||||
}
|
||||
sendReq.Content = portal.parseMatrixHTML(sender, content)
|
||||
|
@ -20,3 +20,16 @@ index d93ad17..e5cd370 100644
|
|||
data, err := portal.downloadMatrixAttachment(content)
|
||||
if err != nil {
|
||||
go portal.sendMessageMetrics(evt, err, "Error downloading media in")
|
||||
return
|
||||
}
|
||||
|
||||
+ // extract file suffix from mime type
|
||||
+ mimeParts := strings.Split(content.Info.MimeType, "/")
|
||||
+
|
||||
+ if content.MsgType == "" && !strings.HasSuffix(content.Body, "." + mimeParts[1]) {
|
||||
+ content.Body += mimeParts[1]
|
||||
+ }
|
||||
+
|
||||
sendReq.Files = []*discordgo.File{{
|
||||
Name: content.Body,
|
||||
ContentType: content.Info.MimeType,
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p nix-prefetch-git jq
|
||||
set -e
|
||||
|
||||
WORK_DIR=$(mktemp -d)
|
||||
URL=https://github.com/mautrix/discord
|
||||
REVISION=$(jq -r '.nodes."mautrix-discord".locked.rev' ../../flake.lock)
|
||||
TARGET_DIR="$PWD"
|
||||
|
||||
function cleanup {
|
||||
grep "fatal" $WORK_DIR/nix-prefetch-git.out >/dev/stderr || true
|
||||
rm -rf "$WORK_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "Fetching source code $REVISION from $URL"
|
||||
JSON=$(nix-prefetch-git --url "$URL" --rev "$REVISION" --leave-dotGit 2> $WORK_DIR/nix-prefetch-git.out)
|
||||
SHA=$(echo $JSON | jq -r .sha256)
|
||||
SOURCE_DIR=$(grep '^path is' $WORK_DIR/nix-prefetch-git.out | sed 's/^path is //')
|
||||
|
||||
cat > source.nix << EOF
|
||||
{fetchgit}:
|
||||
fetchgit {
|
||||
url = "$URL";
|
||||
rev = "$REVISION";
|
||||
sha256 = "$SHA";
|
||||
leaveDotGit = true;
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Creating gomod2nix.toml"
|
||||
nix run github:tweag/gomod2nix -- --dir $SOURCE_DIR --outdir $TARGET_DIR
|
1
matrix/mautrix-discord/vendor.sha256
Normal file
1
matrix/mautrix-discord/vendor.sha256
Normal file
|
@ -0,0 +1 @@
|
|||
sha256-Ao9sc4M7J/jsIjDYn7vK58mnetn8RDqfChIV0ln8wyU=
|
Reference in a new issue