Skip to content

Commit

Permalink
v2: delete old bridge and add stub v2 bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 19, 2024
1 parent 0471a16 commit e796813
Show file tree
Hide file tree
Showing 76 changed files with 450 additions and 6,980 deletions.
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.py]
max_line_length = 99

[*.{yaml,yml,py}]
[*.{yaml,yml,sql}]
indent_style = space

[{.gitlab-ci.yml,.pre-commit-config.yaml}]
[{.gitlab-ci.yml,.github/workflows/*.yml}]
indent_size = 2
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Bug report
about: If something is definitely wrong in the bridge (rather than just a setup issue),
file a bug report. Remember to include relevant logs.
labels: bug

---
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contact_links:
- name: Troubleshooting docs & FAQ
url: https://docs.mau.fi/bridges/general/troubleshooting.html
about: Check this first if you're having problems setting up the bridge.
- name: Support room
url: https://matrix.to/#/#twitter:maunium.net
about: For setup issues not answered by the troubleshooting docs, ask in the Matrix room.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: Enhancement request
about: Submit a feature request or other suggestion
labels: enhancement

---
33 changes: 33 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Go

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: ["1.22"]
name: Lint ${{ matrix.go-version == '1.22' && '(latest)' || '(old)' }}

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true

- name: Install libolm
run: sudo apt-get install libolm-dev libolm3

- name: Install dependencies
run: |
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
export PATH="$HOME/go/bin:$PATH"
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
26 changes: 0 additions & 26 deletions .github/workflows/python-lint.yml

This file was deleted.

24 changes: 6 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
/.idea/

/.venv
/env/
pip-selfcheck.json
*.pyc
__pycache__
/build
/dist
/*.egg-info
/.eggs
mautrix-twitter
logs/
*.db*
*.yaml
!example-config.yaml
!.pre-commit-config.yaml
/start

/config.yaml
/registration.yaml
*.log*
*.db
*.pickle
*.bak
5 changes: 4 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
include:
- project: 'mautrix/ci'
file: '/python.yml'
file: '/gov2.yml'

variables:
BINARY_NAME_V2: mautrix-twitter
27 changes: 17 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
exclude_types: [markdown]
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.1.0

- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: black
language_version: python3
files: ^(mautwitdm|mautrix_twitter)/.*\.pyi?$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- id: go-imports-repo
args:
- "-local"
- "go.mau.fi/mautrix-twitter"
- "-w"
- id: go-vet-repo-mod
- id: go-staticcheck-repo-mod
- id: go-mod-tidy

- repo: https://github.com/beeper/pre-commit-go
rev: v0.3.1
hooks:
- id: isort
files: ^(mautwitdm|mautrix_twitter)/.*\.pyi?$
- id: zerolog-ban-msgf
- id: zerolog-use-stringer
39 changes: 0 additions & 39 deletions Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions Dockerfile.v2.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine:3.20

ENV UID=1337 \
GID=1337

RUN apk add --no-cache ffmpeg su-exec ca-certificates bash jq curl yq-go

ARG EXECUTABLE=./mautrix-twitter
COPY $EXECUTABLE /usr/bin/mautrix-twitter
COPY ./docker-run.sh /docker-run.sh
ENV BRIDGEV2=1
VOLUME /data
WORKDIR /data

CMD ["/docker-run.sh"]
12 changes: 12 additions & 0 deletions LICENSE.exceptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The mautrix-twitter developers grant the following special exceptions:

* to Beeper the right to embed the program in the Beeper clients and servers,
and use and distribute the collective work without applying the license to
the whole.
* to Element the right to distribute compiled binaries of the program as a part
of the Element Server Suite and other server bundles without applying the
license.

All exceptions are only valid under the condition that any modifications to
the source code of mautrix-twitter remain publicly available under the terms
of the GNU AGPL version 3 or later.
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

44 changes: 21 additions & 23 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,38 @@

* Matrix → Twitter
* [ ] Message content
* [x] Text
* [ ] Text
* [ ] Formatting
* [ ] Media
* [x] Images
* [x] Videos
* [x] Gifs
* [x] Message reactions
* [ ] Images
* [ ] Videos
* [ ] Gifs
* [ ] Message reactions
* [ ] Typing notifications
* [x] Read receipts
* [ ] Read receipts
* Twitter → Matrix
* [ ] Message content
* [x] Text
* [ ] Text
* [ ] Formatting
* [x] Media
* [x] Images
* [x] Videos
* [x] Gifs
* [x] Message reactions
* [x] Message history
* [x] When creating portal
* [x] Missed messages
* [x] Avatars
* [ ] Media
* [ ] Images
* [ ] Videos
* [ ] Gifs
* [ ] Message reactions
* [ ] Message history
* [ ] When creating portal
* [ ] Missed messages
* [ ] Avatars
* [ ] † Typing notifications
* [ ] † Read receipts
* Misc
* [x] Automatic portal creation
* [x] At startup
* [x] When receiving invite or message
* [x] Provisioning API for logging in
* [ ] Automatic portal creation
* [ ] At startup
* [ ] When receiving invite or message
* [ ] Provisioning API for logging in
* [ ] Private chat creation by inviting Matrix puppet of Twitter user to new room
* [ ] Option to use own Matrix account for messages sent from other Twitter clients
* [x] Automatic login with shared secret
* [ ] Manual login with `login-matrix`
* [x] E2EE in Matrix rooms
* [ ] E2EE in Matrix rooms

† Information not automatically sent from source, i.e. implementation may not be possible
‡ Maybe, i.e. this feature may or may not be implemented at some point
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
MAUTRIX_VERSION=$(cat go.mod | grep 'maunium.net/go/mautrix ' | awk '{ print $2 }' | head -n1)
GO_LDFLAGS="-s -w -X main.Tag=$(git describe --exact-match --tags 2>/dev/null) -X main.Commit=$(git rev-parse HEAD) -X 'main.BuildTime=`date -Iseconds`' -X 'maunium.net/go/mautrix.GoModVersion=$MAUTRIX_VERSION'"
go build -ldflags="$GO_LDFLAGS" ./cmd/mautrix-twitter "$@"
20 changes: 20 additions & 0 deletions cmd/mautrix-twitter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// mautrix-twitter - A Matrix-Slack puppeting bridge.
// Copyright (C) 2024 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package main

func main() {
}
3 changes: 0 additions & 3 deletions dev-requirements.txt

This file was deleted.

28 changes: 12 additions & 16 deletions docker-run.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
#!/bin/sh

# Define functions.
if [[ -z "$GID" ]]; then
GID="$UID"
fi

BINARY_NAME=/usr/bin/mautrix-twitter

function fixperms {
chown -R $UID:$GID /data

# /opt/mautrix-twitter is read-only, so disable file logging if it's pointing there.
if [[ "$(yq e '.logging.handlers.file.filename' /data/config.yaml)" == "./mautrix-twitter.log" ]]; then
yq -I4 e -i 'del(.logging.root.handlers[] | select(. == "file"))' /data/config.yaml
yq -I4 e -i 'del(.logging.handlers.file)' /data/config.yaml
fi
}

cd /opt/mautrix-twitter

if [ ! -f /data/config.yaml ]; then
cp example-config.yaml /data/config.yaml
if [[ ! -f /data/config.yaml ]]; then
$BINARY_NAME -c /data/config.yaml -e
echo "Didn't find a config file."
echo "Copied default config file to /data/config.yaml"
echo "Modify that config file to your liking."
echo "Start the container again after that to generate the registration file."
fixperms
exit
fi

if [ ! -f /data/registration.yaml ]; then
python3 -m mautrix_twitter -g -c /data/config.yaml -r /data/registration.yaml || exit $?
if [[ ! -f /data/registration.yaml ]]; then
$BINARY_NAME -g -c /data/config.yaml -r /data/registration.yaml
echo "Didn't find a registration file."
echo "Generated one for you."
echo "See https://docs.mau.fi/bridges/general/registering-appservices.html on how to use it."
fixperms
exit
fi

cd /data
fixperms
exec su-exec $UID:$GID python3 -m mautrix_twitter -c /data/config.yaml
exec su-exec $UID:$GID $BINARY_NAME
Loading

0 comments on commit e796813

Please sign in to comment.