Compare commits
37 Commits
build-test
...
master
Author | SHA1 | Date | |
---|---|---|---|
f6e32ec435 | |||
0a96c8646a | |||
93d02cf028 | |||
d4e7152dde | |||
5e71ad974c | |||
8797e96b22 | |||
b067459739 | |||
f32d3f1668 | |||
1cb9710188 | |||
5c231cbaba | |||
9fdf405504 | |||
d9fc3014b4 | |||
22a9faa3ca | |||
2074d45d9d | |||
86c6bab1eb | |||
d6f94287d4 | |||
3db8e1da05 | |||
9f65ad172c | |||
84a017281f | |||
48e426dd67 | |||
|
47656ca0bb | ||
|
e702662919 | ||
|
95bd2f6548 | ||
|
88615a43e1 | ||
|
d979478a01 | ||
|
5b3be968d2 | ||
|
853fad9576 | ||
|
4ac86fee98 | ||
|
715107f5a2 | ||
|
e843faf9b4 | ||
|
4d37d06c58 | ||
|
07d2cae5b2 | ||
|
f2df6e517b | ||
|
de84a5094e | ||
|
d81f929900 | ||
|
79c32afe84 | ||
|
3eb7ce4fa6 |
34
.drone.yaml
Normal file
34
.drone.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: Build and Publish
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username:
|
||||
from_secret: docker_user
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: gitea.watsonlabs.net/watsonb8/groupme
|
||||
registry: gitea.watsonlabs.net
|
||||
dockerfile: Dockerfile
|
||||
auto_tag: true
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
- name: Notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
host: 10.44.1.13
|
||||
username: srvGitea
|
||||
password:
|
||||
from_secret: smtp_password
|
||||
from: drone@watsonlabs.net
|
||||
skip_verify: true
|
||||
when:
|
||||
status:
|
||||
- failure
|
@ -10,6 +10,8 @@ insert_final_newline = true
|
||||
|
||||
[*.{yaml,yml}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[.gitlab-ci.yml]
|
||||
indent_size = 2
|
||||
[*.sql]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
34
.gitea/workflows/ci.yaml
Normal file
34
.gitea/workflows/ci.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
name: Build and Publish Docker Image
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_and_publish:
|
||||
name: Build and Publish Docker
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Log in to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.watsonlabs.net/watsonb8/groupme
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: gitea.watsonlabs.net/watsonb8/groupme
|
||||
|
||||
- name: Build and push Docker image
|
||||
id: push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
105
.github/workflows/deploy.yml
vendored
Normal file
105
.github/workflows/deploy.yml
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
name: Build, Test and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
env:
|
||||
GO_VERSION: 1.19
|
||||
BEEPER_BRIDGE_TYPE: groupme
|
||||
CI_REGISTRY_IMAGE: "${{ secrets.CI_REGISTRY }}/groupme"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go ${{ env.GO_VERSION }}
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get install libolm-dev libolm3
|
||||
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.0
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get install libolm-dev libolm3
|
||||
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
go test -v -json ./... -cover | gotestfmt
|
||||
|
||||
build-docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ secrets.CI_REGISTRY }}
|
||||
username: ${{ secrets.CI_REGISTRY_USER }}
|
||||
password: ${{ secrets.CI_REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Docker Build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
cache-from: ${{ env.CI_REGISTRY_IMAGE }}:latest
|
||||
pull: true
|
||||
file: Dockerfile
|
||||
tags: ${{ env.CI_REGISTRY_IMAGE }}:${{ github.sha }}
|
||||
push: true
|
||||
build-args: |
|
||||
COMMIT_HASH=${{ github.sha }}
|
||||
|
||||
deploy-docker:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- lint
|
||||
- test
|
||||
- build-docker
|
||||
if: github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- name: Login to registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ secrets.CI_REGISTRY }}
|
||||
username: ${{ secrets.CI_REGISTRY_USER }}
|
||||
password: ${{ secrets.CI_REGISTRY_PASSWORD }}
|
||||
|
||||
- uses: beeper/docker-retag-push-latest@main
|
||||
with:
|
||||
image: ${{ env.CI_REGISTRY_IMAGE }}
|
||||
|
||||
- name: Run bridge CD tool
|
||||
uses: beeper/bridge-cd-tool@main
|
||||
env:
|
||||
CI_REGISTRY: "${{ secrets.CI_REGISTRY }}"
|
||||
BEEPER_DEV_ADMIN_API_URL: "${{ secrets.BEEPER_DEV_ADMIN_API_URL }}"
|
||||
BEEPER_STAGING_ADMIN_API_URL: "${{ secrets.BEEPER_STAGING_ADMIN_API_URL }}"
|
||||
BEEPER_PROD_ADMIN_API_URL: "${{ secrets.BEEPER_PROD_ADMIN_API_URL }}"
|
||||
BEEPER_DEV_ADMIN_NIGHTLY_PASS: "${{ secrets.BEEPER_DEV_ADMIN_NIGHTLY_PASS }}"
|
||||
BEEPER_STAGING_ADMIN_NIGHTLY_PASS: "${{ secrets.BEEPER_STAGING_ADMIN_NIGHTLY_PASS }}"
|
||||
BEEPER_PROD_ADMIN_NIGHTLY_PASS: "${{ secrets.BEEPER_PROD_ADMIN_NIGHTLY_PASS }}"
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,7 +1,5 @@
|
||||
.idea
|
||||
|
||||
*.yaml
|
||||
!example-config.yaml
|
||||
logs/*
|
||||
|
||||
*.session
|
||||
*.json
|
||||
@ -11,4 +9,7 @@
|
||||
/matrix-groupme-go
|
||||
.profile
|
||||
|
||||
groupme
|
||||
groupme
|
||||
config.yaml
|
||||
!.pre-commit-config.yaml
|
||||
!example-config.yaml
|
||||
|
@ -1,57 +0,0 @@
|
||||
stages:
|
||||
- build
|
||||
- build docker
|
||||
# - manifest
|
||||
|
||||
.build: &build
|
||||
stage: build
|
||||
cache:
|
||||
paths:
|
||||
- .cache
|
||||
before_script:
|
||||
- mkdir -p .cache
|
||||
- export GOPATH="$CI_PROJECT_DIR/.cache"
|
||||
- export GOCACHE="$CI_PROJECT_DIR/.cache/build"
|
||||
- export GO_LDFLAGS="-linkmode external -extldflags -static -X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'"
|
||||
- git clone https://github.com/karmanyaahm/groupme.git ./groupme
|
||||
script:
|
||||
- go build -ldflags "$GO_LDFLAGS" -o go-groupme
|
||||
artifacts:
|
||||
paths:
|
||||
- go-groupme
|
||||
- example-config.yaml
|
||||
|
||||
.build-docker: &build-docker
|
||||
image: docker:stable
|
||||
stage: build docker
|
||||
before_script:
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
script:
|
||||
- docker pull $CI_REGISTRY_IMAGE:latest || true
|
||||
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH . --file Dockerfile.ci
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH
|
||||
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH
|
||||
|
||||
build amd64:
|
||||
<<: *build
|
||||
image: dock.mau.dev/tulir/gomuks-build-docker:linux-amd64
|
||||
|
||||
build docker amd64:
|
||||
<<: *build-docker
|
||||
tags:
|
||||
- docker
|
||||
services:
|
||||
- docker:dind
|
||||
dependencies:
|
||||
- build amd64
|
||||
needs:
|
||||
- build amd64
|
||||
variables:
|
||||
DOCKER_ARCH: amd64
|
||||
after_script:
|
||||
- |
|
||||
if [ "$CI_COMMIT_BRANCH" = "master" ]; then
|
||||
apk add --update curl
|
||||
rm -rf /var/cache/apk/*
|
||||
curl "$NOVA_ADMIN_API_URL" -H "Content-Type: application/json" -d '{"password":"'"$NOVA_ADMIN_NIGHTLY_PASS"'","bridge":"'$NOVA_BRIDGE_TYPE'","image":"'$CI_REGISTRY_IMAGE':'$CI_COMMIT_SHA'-amd64"}'
|
||||
fi
|
20
.pre-commit-config.yaml
Normal file
20
.pre-commit-config.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.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/tekwizely/pre-commit-golang
|
||||
rev: v1.0.0-rc.1
|
||||
hooks:
|
||||
- id: go-imports-repo
|
||||
args:
|
||||
- "-local"
|
||||
- "github.com/beeper/groupme"
|
||||
- "-w"
|
||||
- id: go-vet-repo-mod
|
||||
# - id: go-staticcheck-repo-mod
|
16
.run/go build github.com_beeper_groupme.run.xml
Normal file
16
.run/go build github.com_beeper_groupme.run.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="go build github.com/beeper/groupme" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
|
||||
<module name="groupme" />
|
||||
<working_directory value="$PROJECT_DIR$" />
|
||||
<envs>
|
||||
<env name="CPATH" value="/opt/homebrew/include" />
|
||||
<env name="LIBRARY_PATH" value="/opt/homebrew/lib" />
|
||||
<env name="PATH" value="/opt/homebrew/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin" />
|
||||
</envs>
|
||||
<kind value="PACKAGE" />
|
||||
<package value="github.com/beeper/groupme" />
|
||||
<directory value="$PROJECT_DIR$" />
|
||||
<filePath value="$PROJECT_DIR$" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
@ -1,4 +1,4 @@
|
||||
FROM golang:1-alpine3.14 AS builder
|
||||
FROM golang:1.19-alpine3.16 AS builder
|
||||
|
||||
RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev
|
||||
|
||||
@ -6,7 +6,7 @@ COPY . /build
|
||||
WORKDIR /build
|
||||
RUN go build -o /usr/bin/go-groupme
|
||||
|
||||
FROM alpine:3.14
|
||||
FROM alpine:3.16
|
||||
|
||||
ENV UID=1337 \
|
||||
GID=1337
|
||||
|
@ -1,14 +0,0 @@
|
||||
FROM alpine:3.14
|
||||
|
||||
ENV UID=1337 \
|
||||
GID=1337
|
||||
|
||||
RUN apk add --no-cache ffmpeg su-exec ca-certificates bash jq curl yq
|
||||
|
||||
ARG EXECUTABLE=./go-groupme
|
||||
COPY $EXECUTABLE /usr/bin/go-groupme
|
||||
COPY ./example-config.yaml /opt/go-groupme/example-config.yaml
|
||||
COPY ./docker-run.sh /docker-run.sh
|
||||
VOLUME /data
|
||||
|
||||
CMD ["/docker-run.sh"]
|
@ -1,9 +1,11 @@
|
||||
# Matrix GroupMe Go Bridge
|
||||
A Matrix-GroupMe puppeting bridge
|
||||
|
||||
### [Wiki](https://github.com/karmanyaahm/matrix-groupme-go/wiki)
|
||||
|
||||
### [Features & Roadmap](https://github.com/karmanyaahm/matrix-groupme-go/blob/master/ROADMAP.md)
|
||||
[Features & Roadmap](./ROADMAP.md)
|
||||
|
||||
## Discussion
|
||||
Matrix room: [#groupme-go-bridge:malhotra.cc](https://matrix.to/#/#groupme-go-bridge:malhotra.cc)
|
||||
|
||||
## Credits
|
||||
|
||||
Forked from https://github.com/karmanyaahm/matrix-groupme-go which was archived.
|
||||
|
10
ROADMAP.md
10
ROADMAP.md
@ -69,10 +69,10 @@
|
||||
* [x] At startup
|
||||
* [x] When receiving invite
|
||||
* [x] When receiving message
|
||||
* [ ] Private chat creation by inviting Matrix puppet of WhatsApp user to new room
|
||||
* [ ] Option to use own Matrix account for messages sent from WhatsApp mobile/other web clients
|
||||
* [ ] Private chat creation by inviting Matrix puppet of GroupMe user to new room
|
||||
* [ ] Option to use own Matrix account for messages sent from GroupMe mobile/other web clients
|
||||
* [ ] Shared group chat portals
|
||||
|
||||
<sup>[1]</sup> Basic feature works. Improvements are TODO.
|
||||
<sup>[2]</sup> May already work
|
||||
<sup>[3]</sup> May not be possible
|
||||
<sup>[1]</sup> Basic feature works. Improvements are TODO.
|
||||
<sup>[2]</sup> May already work
|
||||
<sup>[3]</sup> May not be possible
|
||||
|
17
bridgestate.go
Normal file
17
bridgestate.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (user *User) GetRemoteID() string {
|
||||
if user == nil || !user.GMID.Valid() {
|
||||
return ""
|
||||
}
|
||||
return user.GMID.String()
|
||||
}
|
||||
|
||||
func (user *User) GetRemoteName() string {
|
||||
if user == nil || !user.GMID.Valid() {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("+%s", user.GMID.String())
|
||||
}
|
990
commands.go
990
commands.go
File diff suppressed because it is too large
Load Diff
132
community.go
132
community.go
@ -1,132 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
)
|
||||
|
||||
func (user *User) inviteToCommunity() {
|
||||
url := user.bridge.Bot.BuildURL("groups", user.CommunityID, "admin", "users", "invite", user.MXID)
|
||||
reqBody := map[string]interface{}{}
|
||||
_, err := user.bridge.Bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to invite user to personal filtering community %s: %v", user.CommunityID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) updateCommunityProfile() {
|
||||
url := user.bridge.Bot.BuildURL("groups", user.CommunityID, "profile")
|
||||
profileReq := struct {
|
||||
Name string `json:"name"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
ShortDescription string `json:"short_description"`
|
||||
}{"WhatsApp", user.bridge.Config.AppService.Bot.Avatar, "Your WhatsApp bridged chats"}
|
||||
_, err := user.bridge.Bot.MakeRequest(http.MethodPost, url, &profileReq, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to update metadata of %s: %v", user.CommunityID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) createCommunity() {
|
||||
if user.IsRelaybot || !user.bridge.Config.Bridge.EnableCommunities() {
|
||||
return
|
||||
}
|
||||
|
||||
localpart, server, _ := user.MXID.Parse()
|
||||
community := user.bridge.Config.Bridge.FormatCommunity(localpart, server)
|
||||
user.log.Debugln("Creating personal filtering community", community)
|
||||
bot := user.bridge.Bot
|
||||
req := struct {
|
||||
Localpart string `json:"localpart"`
|
||||
}{community}
|
||||
resp := struct {
|
||||
GroupID string `json:"group_id"`
|
||||
}{}
|
||||
_, err := bot.MakeRequest(http.MethodPost, bot.BuildURL("create_group"), &req, &resp)
|
||||
if err != nil {
|
||||
if httpErr, ok := err.(mautrix.HTTPError); ok {
|
||||
if httpErr.RespError.Err != "Group already exists" {
|
||||
user.log.Warnln("Server responded with error creating personal filtering community:", err)
|
||||
return
|
||||
} else {
|
||||
user.log.Debugln("Personal filtering community", resp.GroupID, "already existed")
|
||||
user.CommunityID = fmt.Sprintf("+%s:%s", req.Localpart, user.bridge.Config.Homeserver.Domain)
|
||||
}
|
||||
} else {
|
||||
user.log.Warnln("Unknown error creating personal filtering community:", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
user.log.Infoln("Created personal filtering community %s", resp.GroupID)
|
||||
user.CommunityID = resp.GroupID
|
||||
user.inviteToCommunity()
|
||||
user.updateCommunityProfile()
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) addPuppetToCommunity(puppet *Puppet) bool {
|
||||
if user.IsRelaybot || len(user.CommunityID) == 0 {
|
||||
return false
|
||||
}
|
||||
bot := user.bridge.Bot
|
||||
url := bot.BuildURL("groups", user.CommunityID, "admin", "users", "invite", puppet.MXID)
|
||||
blankReqBody := map[string]interface{}{}
|
||||
_, err := bot.MakeRequest(http.MethodPut, url, &blankReqBody, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to invite %s to %s: %v", puppet.MXID, user.CommunityID, err)
|
||||
return false
|
||||
}
|
||||
reqBody := map[string]map[string]string{
|
||||
"m.visibility": {
|
||||
"type": "private",
|
||||
},
|
||||
}
|
||||
url = bot.BuildURLWithQuery(mautrix.URLPath{"groups", user.CommunityID, "self", "accept_invite"}, map[string]string{
|
||||
"user_id": puppet.MXID.String(),
|
||||
})
|
||||
_, err = bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to join %s as %s: %v", user.CommunityID, puppet.MXID, err)
|
||||
return false
|
||||
}
|
||||
user.log.Debugln("Added", puppet.MXID, "to", user.CommunityID)
|
||||
return true
|
||||
}
|
||||
|
||||
func (user *User) addPortalToCommunity(portal *Portal) bool {
|
||||
if user.IsRelaybot || len(user.CommunityID) == 0 || len(portal.MXID) == 0 {
|
||||
return false
|
||||
}
|
||||
bot := user.bridge.Bot
|
||||
url := bot.BuildURL("groups", user.CommunityID, "admin", "rooms", portal.MXID)
|
||||
reqBody := map[string]map[string]string{
|
||||
"m.visibility": {
|
||||
"type": "private",
|
||||
},
|
||||
}
|
||||
_, err := bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to add %s to %s: %v", portal.MXID, user.CommunityID, err)
|
||||
return false
|
||||
}
|
||||
user.log.Debugln("Added", portal.MXID, "to", user.CommunityID)
|
||||
return true
|
||||
}
|
351
config/bridge.go
351
config/bridge.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,112 +17,138 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
)
|
||||
|
||||
type DeferredConfig struct {
|
||||
StartDaysAgo int `yaml:"start_days_ago"`
|
||||
MaxBatchEvents int `yaml:"max_batch_events"`
|
||||
BatchDelay int `yaml:"batch_delay"`
|
||||
}
|
||||
|
||||
type BridgeConfig struct {
|
||||
UsernameTemplate string `yaml:"username_template"`
|
||||
DisplaynameTemplate string `yaml:"displayname_template"`
|
||||
CommunityTemplate string `yaml:"community_template"`
|
||||
|
||||
ConnectionTimeout int `yaml:"connection_timeout"`
|
||||
FetchMessageOnTimeout bool `yaml:"fetch_message_on_timeout"`
|
||||
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
||||
LoginQRRegenCount int `yaml:"login_qr_regen_count"`
|
||||
MaxConnectionAttempts int `yaml:"max_connection_attempts"`
|
||||
ConnectionRetryDelay int `yaml:"connection_retry_delay"`
|
||||
ReportConnectionRetry bool `yaml:"report_connection_retry"`
|
||||
ChatListWait int `yaml:"chat_list_wait"`
|
||||
PortalSyncWait int `yaml:"portal_sync_wait"`
|
||||
UserMessageBuffer int `yaml:"user_message_buffer"`
|
||||
PortalMessageBuffer int `yaml:"portal_message_buffer"`
|
||||
PersonalFilteringSpaces bool `yaml:"personal_filtering_spaces"`
|
||||
|
||||
CallNotices struct {
|
||||
Start bool `yaml:"start"`
|
||||
End bool `yaml:"end"`
|
||||
} `yaml:"call_notices"`
|
||||
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
||||
MessageStatusEvents bool `yaml:"message_status_events"`
|
||||
MessageErrorNotices bool `yaml:"message_error_notices"`
|
||||
PortalMessageBuffer int `yaml:"portal_message_buffer"`
|
||||
|
||||
InitialChatSync int `yaml:"initial_chat_sync_count"`
|
||||
InitialHistoryFill int `yaml:"initial_history_fill_count"`
|
||||
HistoryDisableNotifs bool `yaml:"initial_history_disable_notifications"`
|
||||
RecoverChatSync int `yaml:"recovery_chat_sync_count"`
|
||||
RecoverHistory bool `yaml:"recovery_history_backfill"`
|
||||
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
|
||||
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
|
||||
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
||||
SyncManualMarkedUnread bool `yaml:"sync_manual_marked_unread"`
|
||||
DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
|
||||
|
||||
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
|
||||
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
||||
DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
|
||||
DefaultBridgePresence bool `yaml:"default_bridge_presence"`
|
||||
LoginSharedSecret string `yaml:"login_shared_secret"`
|
||||
HistorySync struct {
|
||||
CreatePortals bool `yaml:"create_portals"`
|
||||
Backfill bool `yaml:"backfill"`
|
||||
|
||||
InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"`
|
||||
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
|
||||
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
|
||||
DoublePuppetBackfill bool `yaml:"double_puppet_backfill"`
|
||||
RequestFullSync bool `yaml:"request_full_sync"`
|
||||
MaxInitialConversations int `yaml:"max_initial_conversations"`
|
||||
UnreadHoursThreshold int `yaml:"unread_hours_threshold"`
|
||||
|
||||
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
|
||||
Immediate struct {
|
||||
WorkerCount int `yaml:"worker_count"`
|
||||
MaxEvents int `yaml:"max_events"`
|
||||
} `yaml:"immediate"`
|
||||
|
||||
AllowUserInvite bool `yaml:"allow_user_invite"`
|
||||
Deferred []DeferredConfig `yaml:"deferred"`
|
||||
} `yaml:"history_sync"`
|
||||
|
||||
DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"`
|
||||
DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"`
|
||||
LoginSharedSecretMap map[string]string `yaml:"login_shared_secret_map"`
|
||||
|
||||
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
|
||||
|
||||
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
|
||||
FederateRooms bool `yaml:"federate_rooms"`
|
||||
AllowUserInvite bool `yaml:"allow_user_invite"`
|
||||
|
||||
MessageHandlingTimeout struct {
|
||||
ErrorAfterStr string `yaml:"error_after"`
|
||||
DeadlineStr string `yaml:"deadline"`
|
||||
|
||||
ErrorAfter time.Duration `yaml:"-"`
|
||||
Deadline time.Duration `yaml:"-"`
|
||||
} `yaml:"message_handling_timeout"`
|
||||
|
||||
CommandPrefix string `yaml:"command_prefix"`
|
||||
|
||||
Encryption struct {
|
||||
Allow bool `yaml:"allow"`
|
||||
Default bool `yaml:"default"`
|
||||
ManagementRoomText bridgeconfig.ManagementRoomTexts `yaml:"management_room_text"`
|
||||
|
||||
KeySharing struct {
|
||||
Allow bool `yaml:"allow"`
|
||||
RequireCrossSigning bool `yaml:"require_cross_signing"`
|
||||
RequireVerification bool `yaml:"require_verification"`
|
||||
} `yaml:"key_sharing"`
|
||||
} `yaml:"encryption"`
|
||||
Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`
|
||||
|
||||
Permissions PermissionConfig `yaml:"permissions"`
|
||||
Provisioning struct {
|
||||
Prefix string `yaml:"prefix"`
|
||||
SharedSecret string `yaml:"shared_secret"`
|
||||
} `yaml:"provisioning"`
|
||||
|
||||
Relaybot RelaybotConfig `yaml:"relaybot"`
|
||||
Permissions bridgeconfig.PermissionConfig `yaml:"permissions"`
|
||||
|
||||
usernameTemplate *template.Template `yaml:"-"`
|
||||
displaynameTemplate *template.Template `yaml:"-"`
|
||||
communityTemplate *template.Template `yaml:"-"`
|
||||
ParsedUsernameTemplate *template.Template `yaml:"-"`
|
||||
displaynameTemplate *template.Template `yaml:"-"`
|
||||
}
|
||||
|
||||
func (bc *BridgeConfig) setDefaults() {
|
||||
bc.ConnectionTimeout = 20
|
||||
bc.FetchMessageOnTimeout = false
|
||||
bc.DeliveryReceipts = false
|
||||
bc.LoginQRRegenCount = 2
|
||||
bc.MaxConnectionAttempts = 3
|
||||
bc.ConnectionRetryDelay = -1
|
||||
bc.ReportConnectionRetry = true
|
||||
bc.ChatListWait = 30
|
||||
bc.PortalSyncWait = 600
|
||||
bc.UserMessageBuffer = 1024
|
||||
bc.PortalMessageBuffer = 128
|
||||
func (bc BridgeConfig) GetDoublePuppetConfig() bridgeconfig.DoublePuppetConfig {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
bc.CallNotices.Start = true
|
||||
bc.CallNotices.End = true
|
||||
func (bc BridgeConfig) GetEncryptionConfig() bridgeconfig.EncryptionConfig {
|
||||
return bc.Encryption
|
||||
}
|
||||
|
||||
bc.InitialChatSync = 10
|
||||
bc.InitialHistoryFill = 20
|
||||
bc.RecoverChatSync = -1
|
||||
bc.RecoverHistory = true
|
||||
bc.SyncChatMaxAge = 259200
|
||||
func (bc BridgeConfig) EnableMessageStatusEvents() bool {
|
||||
return bc.MessageStatusEvents
|
||||
}
|
||||
|
||||
bc.SyncWithCustomPuppets = true
|
||||
bc.DefaultBridgePresence = true
|
||||
bc.DefaultBridgeReceipts = true
|
||||
bc.LoginSharedSecret = ""
|
||||
func (bc BridgeConfig) EnableMessageErrorNotices() bool {
|
||||
return bc.MessageErrorNotices
|
||||
}
|
||||
|
||||
bc.InviteOwnPuppetForBackfilling = true
|
||||
bc.PrivateChatPortalMeta = false
|
||||
func (bc BridgeConfig) GetCommandPrefix() string {
|
||||
return bc.CommandPrefix
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) GetManagementRoomTexts() bridgeconfig.ManagementRoomTexts {
|
||||
return bc.ManagementRoomText
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) GetResendBridgeInfo() bool {
|
||||
return bc.ResendBridgeInfo
|
||||
}
|
||||
|
||||
func boolToInt(val bool) int {
|
||||
if val {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) Validate() error {
|
||||
_, hasWildcard := bc.Permissions["*"]
|
||||
_, hasExampleDomain := bc.Permissions["example.com"]
|
||||
_, hasExampleUser := bc.Permissions["@admin:example.com"]
|
||||
exampleLen := boolToInt(hasWildcard) + boolToInt(hasExampleUser) + boolToInt(hasExampleDomain)
|
||||
if len(bc.Permissions) <= exampleLen {
|
||||
return errors.New("bridge.permissions not configured")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type umBridgeConfig BridgeConfig
|
||||
@ -133,9 +159,11 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
bc.usernameTemplate, err = template.New("username").Parse(bc.UsernameTemplate)
|
||||
bc.ParsedUsernameTemplate, err = template.New("username").Parse(bc.UsernameTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !strings.Contains(bc.FormatUsername("1234567890"), "1234567890") {
|
||||
return fmt.Errorf("username template is missing user ID placeholder")
|
||||
}
|
||||
|
||||
bc.displaynameTemplate, err = template.New("displayname").Parse(bc.DisplaynameTemplate)
|
||||
@ -143,8 +171,14 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(bc.CommunityTemplate) > 0 {
|
||||
bc.communityTemplate, err = template.New("community").Parse(bc.CommunityTemplate)
|
||||
if bc.MessageHandlingTimeout.ErrorAfterStr != "" {
|
||||
bc.MessageHandlingTimeout.ErrorAfter, err = time.ParseDuration(bc.MessageHandlingTimeout.ErrorAfterStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if bc.MessageHandlingTimeout.DeadlineStr != "" {
|
||||
bc.MessageHandlingTimeout.Deadline, err = time.ParseDuration(bc.MessageHandlingTimeout.DeadlineStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -157,144 +191,27 @@ type UsernameTemplateArgs struct {
|
||||
UserID id.UserID
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8) {
|
||||
var buf bytes.Buffer
|
||||
if index := strings.IndexRune(contact.ID.String(), '@'); index > 0 {
|
||||
contact.ID = groupme.ID("+" + contact.UserID.String()[:index])
|
||||
}
|
||||
bc.displaynameTemplate.Execute(&buf, contact)
|
||||
var quality int8
|
||||
switch {
|
||||
case len(contact.Nickname) > 0:
|
||||
quality = 3
|
||||
//TODO what
|
||||
case len(contact.UserID) > 0:
|
||||
quality = 1
|
||||
default:
|
||||
quality = 0
|
||||
}
|
||||
return buf.String(), quality
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) FormatUsername(userID types.GroupMeID) string {
|
||||
var buf bytes.Buffer
|
||||
bc.usernameTemplate.Execute(&buf, userID)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type CommunityTemplateArgs struct {
|
||||
Localpart string
|
||||
Server string
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) EnableCommunities() bool {
|
||||
return bc.communityTemplate != nil
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) FormatCommunity(localpart, server string) string {
|
||||
var buf bytes.Buffer
|
||||
bc.communityTemplate.Execute(&buf, CommunityTemplateArgs{localpart, server})
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type PermissionConfig map[string]PermissionLevel
|
||||
|
||||
type PermissionLevel int
|
||||
|
||||
const (
|
||||
PermissionLevelDefault PermissionLevel = 0
|
||||
PermissionLevelRelaybot PermissionLevel = 5
|
||||
PermissionLevelUser PermissionLevel = 10
|
||||
PermissionLevelAdmin PermissionLevel = 100
|
||||
)
|
||||
|
||||
func (pc *PermissionConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
rawPC := make(map[string]string)
|
||||
err := unmarshal(&rawPC)
|
||||
func (bc BridgeConfig) FormatDisplayname(gmid groupme.ID, member groupme.Member) string {
|
||||
var buf strings.Builder
|
||||
err := bc.displaynameTemplate.Execute(&buf, map[string]string{
|
||||
"Name": member.Nickname,
|
||||
"GMID": gmid.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if *pc == nil {
|
||||
*pc = make(map[string]PermissionLevel)
|
||||
}
|
||||
for key, value := range rawPC {
|
||||
switch strings.ToLower(value) {
|
||||
case "relaybot":
|
||||
(*pc)[key] = PermissionLevelRelaybot
|
||||
case "user":
|
||||
(*pc)[key] = PermissionLevelUser
|
||||
case "admin":
|
||||
(*pc)[key] = PermissionLevelAdmin
|
||||
default:
|
||||
val, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
(*pc)[key] = PermissionLevelDefault
|
||||
} else {
|
||||
(*pc)[key] = PermissionLevel(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
|
||||
if *pc == nil {
|
||||
return nil, nil
|
||||
}
|
||||
rawPC := make(map[string]string)
|
||||
for key, value := range *pc {
|
||||
switch value {
|
||||
case PermissionLevelRelaybot:
|
||||
rawPC[key] = "relaybot"
|
||||
case PermissionLevelUser:
|
||||
rawPC[key] = "user"
|
||||
case PermissionLevelAdmin:
|
||||
rawPC[key] = "admin"
|
||||
default:
|
||||
rawPC[key] = strconv.Itoa(int(value))
|
||||
}
|
||||
}
|
||||
return rawPC, nil
|
||||
}
|
||||
|
||||
func (pc PermissionConfig) IsRelaybotWhitelisted(userID id.UserID) bool {
|
||||
return pc.GetPermissionLevel(userID) >= PermissionLevelRelaybot
|
||||
}
|
||||
|
||||
func (pc PermissionConfig) IsWhitelisted(userID id.UserID) bool {
|
||||
return pc.GetPermissionLevel(userID) >= PermissionLevelUser
|
||||
}
|
||||
|
||||
func (pc PermissionConfig) IsAdmin(userID id.UserID) bool {
|
||||
return pc.GetPermissionLevel(userID) >= PermissionLevelAdmin
|
||||
}
|
||||
|
||||
func (pc PermissionConfig) GetPermissionLevel(userID id.UserID) PermissionLevel {
|
||||
permissions, ok := pc[string(userID)]
|
||||
if ok {
|
||||
return permissions
|
||||
}
|
||||
|
||||
_, homeserver, _ := userID.Parse()
|
||||
permissions, ok = pc[homeserver]
|
||||
if len(homeserver) > 0 && ok {
|
||||
return permissions
|
||||
}
|
||||
|
||||
permissions, ok = pc["*"]
|
||||
if ok {
|
||||
return permissions
|
||||
}
|
||||
|
||||
return PermissionLevelDefault
|
||||
func (bc BridgeConfig) FormatUsername(username string) string {
|
||||
var buf strings.Builder
|
||||
_ = bc.ParsedUsernameTemplate.Execute(&buf, username)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type RelaybotConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
ManagementRoom id.RoomID `yaml:"management"`
|
||||
InviteUsers []id.UserID `yaml:"invites"`
|
||||
|
||||
Enabled bool `yaml:"enabled"`
|
||||
AdminOnly bool `yaml:"admin_only"`
|
||||
MessageFormats map[event.MessageType]string `yaml:"message_formats"`
|
||||
messageTemplates *template.Template `yaml:"-"`
|
||||
}
|
||||
@ -319,8 +236,8 @@ func (rc *RelaybotConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
|
||||
}
|
||||
|
||||
type Sender struct {
|
||||
UserID id.UserID
|
||||
*event.MemberEventContent
|
||||
UserID string
|
||||
event.MemberEventContent
|
||||
}
|
||||
|
||||
type formatData struct {
|
||||
@ -329,11 +246,15 @@ type formatData struct {
|
||||
Content *event.MessageEventContent
|
||||
}
|
||||
|
||||
func (rc *RelaybotConfig) FormatMessage(content *event.MessageEventContent, sender id.UserID, member *event.MemberEventContent) (string, error) {
|
||||
func (rc *RelaybotConfig) FormatMessage(content *event.MessageEventContent, sender id.UserID, member event.MemberEventContent) (string, error) {
|
||||
if len(member.Displayname) == 0 {
|
||||
member.Displayname = sender.String()
|
||||
}
|
||||
member.Displayname = template.HTMLEscapeString(member.Displayname)
|
||||
var output strings.Builder
|
||||
err := rc.messageTemplates.ExecuteTemplate(&output, string(content.MsgType), formatData{
|
||||
Sender: Sender{
|
||||
UserID: sender,
|
||||
UserID: template.HTMLEscapeString(sender.String()),
|
||||
MemberEventContent: member,
|
||||
},
|
||||
Content: content,
|
||||
|
102
config/config.go
102
config/config.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,101 +17,45 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Homeserver struct {
|
||||
Address string `yaml:"address"`
|
||||
Domain string `yaml:"domain"`
|
||||
Asmux bool `yaml:"asmux"`
|
||||
} `yaml:"homeserver"`
|
||||
*bridgeconfig.BaseConfig `yaml:",inline"`
|
||||
|
||||
AppService struct {
|
||||
Address string `yaml:"address"`
|
||||
Hostname string `yaml:"hostname"`
|
||||
Port uint16 `yaml:"port"`
|
||||
|
||||
Database struct {
|
||||
Type string `yaml:"type"`
|
||||
URI string `yaml:"uri"`
|
||||
|
||||
MaxOpenConns int `yaml:"max_open_conns"`
|
||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
||||
} `yaml:"database"`
|
||||
|
||||
StateStore string `yaml:"state_store_path,omitempty"`
|
||||
|
||||
Provisioning struct {
|
||||
Prefix string `yaml:"prefix"`
|
||||
SharedSecret string `yaml:"shared_secret"`
|
||||
} `yaml:"provisioning"`
|
||||
|
||||
ID string `yaml:"id"`
|
||||
Bot struct {
|
||||
Username string `yaml:"username"`
|
||||
Displayname string `yaml:"displayname"`
|
||||
Avatar string `yaml:"avatar"`
|
||||
} `yaml:"bot"`
|
||||
|
||||
ASToken string `yaml:"as_token"`
|
||||
HSToken string `yaml:"hs_token"`
|
||||
} `yaml:"appservice"`
|
||||
SegmentKey string `yaml:"segment_key"`
|
||||
SegmentUserID string `yaml:"segment_user_id"`
|
||||
|
||||
Metrics struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Listen string `yaml:"listen"`
|
||||
} `yaml:"metrics"`
|
||||
|
||||
// TODO need these?
|
||||
GroupMe struct {
|
||||
OSName string `yaml:"os_name"`
|
||||
BrowserName string `yaml:"browser_name"`
|
||||
OSName string `yaml:"os_name"`
|
||||
BrowserName string `yaml:"browser_name"`
|
||||
ConnectionTimeout int `yaml:"connection_timeout"`
|
||||
} `yaml:"groupme"`
|
||||
|
||||
Bridge BridgeConfig `yaml:"bridge"`
|
||||
|
||||
Logging appservice.LogConfig `yaml:"logging"`
|
||||
}
|
||||
|
||||
func (config *Config) setDefaults() {
|
||||
config.AppService.Database.MaxOpenConns = 20
|
||||
config.AppService.Database.MaxIdleConns = 2
|
||||
config.GroupMe.OSName = "Go GroupMe bridge"
|
||||
config.GroupMe.BrowserName = "mx-gm"
|
||||
config.Bridge.setDefaults()
|
||||
func (config *Config) CanAutoDoublePuppet(userID id.UserID) bool {
|
||||
_, homeserver, _ := userID.Parse()
|
||||
_, hasSecret := config.Bridge.LoginSharedSecretMap[homeserver]
|
||||
return hasSecret
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func (config *Config) CanDoublePuppetBackfill(userID id.UserID) bool {
|
||||
if !config.Bridge.HistorySync.DoublePuppetBackfill {
|
||||
return false
|
||||
}
|
||||
|
||||
var config = &Config{}
|
||||
config.setDefaults()
|
||||
err = yaml.Unmarshal(data, config)
|
||||
return config, err
|
||||
}
|
||||
|
||||
func (config *Config) Save(path string) error {
|
||||
data, err := yaml.Marshal(config)
|
||||
if err != nil {
|
||||
return err
|
||||
_, homeserver, _ := userID.Parse()
|
||||
// Batch sending can only use local users, so don't allow double puppets on other servers.
|
||||
if homeserver != config.Homeserver.Domain && config.Homeserver.Software != bridgeconfig.SoftwareHungry {
|
||||
return false
|
||||
}
|
||||
return ioutil.WriteFile(path, data, 0600)
|
||||
}
|
||||
|
||||
func (config *Config) MakeAppService() (*appservice.AppService, error) {
|
||||
as := appservice.Create()
|
||||
as.HomeserverDomain = config.Homeserver.Domain
|
||||
as.HomeserverURL = config.Homeserver.Address
|
||||
as.Host.Hostname = config.AppService.Hostname
|
||||
as.Host.Port = config.AppService.Port
|
||||
var err error
|
||||
as.Registration, err = config.GetRegistration()
|
||||
return as, err
|
||||
return true
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
)
|
||||
|
||||
func (config *Config) NewRegistration() (*appservice.Registration, error) {
|
||||
registration := appservice.CreateRegistration()
|
||||
|
||||
err := config.copyToRegistration(registration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config.AppService.ASToken = registration.AppToken
|
||||
config.AppService.HSToken = registration.ServerToken
|
||||
|
||||
// Workaround for https://github.com/matrix-org/synapse/pull/5758
|
||||
registration.SenderLocalpart = appservice.RandomString(32)
|
||||
botRegex := regexp.MustCompile(fmt.Sprintf("^@%s:%s$", config.AppService.Bot.Username, config.Homeserver.Domain))
|
||||
registration.Namespaces.RegisterUserIDs(botRegex, true)
|
||||
|
||||
return registration, nil
|
||||
}
|
||||
|
||||
func (config *Config) GetRegistration() (*appservice.Registration, error) {
|
||||
registration := appservice.CreateRegistration()
|
||||
|
||||
err := config.copyToRegistration(registration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
registration.AppToken = config.AppService.ASToken
|
||||
registration.ServerToken = config.AppService.HSToken
|
||||
return registration, nil
|
||||
}
|
||||
|
||||
func (config *Config) copyToRegistration(registration *appservice.Registration) error {
|
||||
registration.ID = config.AppService.ID
|
||||
registration.URL = config.AppService.Address
|
||||
falseVal := false
|
||||
registration.RateLimited = &falseVal
|
||||
registration.SenderLocalpart = config.AppService.Bot.Username
|
||||
|
||||
userIDRegex, err := regexp.Compile(fmt.Sprintf("^@%s:%s$",
|
||||
config.Bridge.FormatUsername("[0-9]+"),
|
||||
config.Homeserver.Domain))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
registration.Namespaces.RegisterUserIDs(userIDRegex, true)
|
||||
return nil
|
||||
}
|
131
config/upgrade.go
Normal file
131
config/upgrade.go
Normal file
@ -0,0 +1,131 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"go.mau.fi/util/random"
|
||||
"strings"
|
||||
|
||||
up "go.mau.fi/util/configupgrade"
|
||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||
)
|
||||
|
||||
func DoUpgrade(helper *up.Helper) {
|
||||
bridgeconfig.Upgrader.DoUpgrade(helper)
|
||||
|
||||
helper.Copy(up.Str|up.Null, "segment_key")
|
||||
|
||||
helper.Copy(up.Bool, "metrics", "enabled")
|
||||
helper.Copy(up.Str, "metrics", "listen")
|
||||
|
||||
helper.Copy(up.Int, "groupme", "connection_timeout")
|
||||
helper.Copy(up.Bool, "groupme", "fetch_message_on_timeout")
|
||||
|
||||
helper.Copy(up.Str, "bridge", "username_template")
|
||||
helper.Copy(up.Str, "bridge", "displayname_template")
|
||||
helper.Copy(up.Bool, "bridge", "personal_filtering_spaces")
|
||||
helper.Copy(up.Bool, "bridge", "delivery_receipts")
|
||||
helper.Copy(up.Bool, "bridge", "message_status_events")
|
||||
helper.Copy(up.Bool, "bridge", "message_error_notices")
|
||||
|
||||
helper.Copy(up.Int, "bridge", "portal_message_buffer")
|
||||
helper.Copy(up.Bool, "bridge", "call_start_notices")
|
||||
helper.Copy(up.Bool, "bridge", "identity_change_notices")
|
||||
helper.Copy(up.Bool, "bridge", "user_avatar_sync")
|
||||
helper.Copy(up.Bool, "bridge", "bridge_matrix_leave")
|
||||
helper.Copy(up.Bool, "bridge", "sync_with_custom_puppets")
|
||||
helper.Copy(up.Bool, "bridge", "sync_direct_chat_list")
|
||||
helper.Copy(up.Bool, "bridge", "default_bridge_receipts")
|
||||
helper.Copy(up.Bool, "bridge", "default_bridge_presence")
|
||||
helper.Copy(up.Bool, "bridge", "send_presence_on_typing")
|
||||
helper.Copy(up.Bool, "bridge", "force_active_delivery_receipts")
|
||||
helper.Copy(up.Map, "bridge", "double_puppet_server_map")
|
||||
helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery")
|
||||
if legacySecret, ok := helper.Get(up.Str, "bridge", "login_shared_secret"); ok && len(legacySecret) > 0 {
|
||||
baseNode := helper.GetBaseNode("bridge", "login_shared_secret_map")
|
||||
baseNode.Map[helper.GetBase("homeserver", "domain")] = up.StringNode(legacySecret)
|
||||
baseNode.UpdateContent()
|
||||
} else {
|
||||
helper.Copy(up.Map, "bridge", "login_shared_secret_map")
|
||||
}
|
||||
helper.Copy(up.Bool, "bridge", "private_chat_portal_meta")
|
||||
helper.Copy(up.Bool, "bridge", "parallel_member_sync")
|
||||
helper.Copy(up.Bool, "bridge", "bridge_notices")
|
||||
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
|
||||
helper.Copy(up.Bool, "bridge", "mute_bridging")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "archive_tag")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "pinned_tag")
|
||||
helper.Copy(up.Bool, "bridge", "tag_only_on_create")
|
||||
helper.Copy(up.Bool, "bridge", "enable_status_broadcast")
|
||||
helper.Copy(up.Bool, "bridge", "disable_status_broadcast_send")
|
||||
helper.Copy(up.Bool, "bridge", "mute_status_broadcast")
|
||||
helper.Copy(up.Bool, "bridge", "allow_user_invite")
|
||||
helper.Copy(up.Str, "bridge", "command_prefix")
|
||||
helper.Copy(up.Bool, "bridge", "federate_rooms")
|
||||
helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups")
|
||||
helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
|
||||
helper.Copy(up.Bool, "bridge", "crash_on_stream_replaced")
|
||||
helper.Copy(up.Bool, "bridge", "url_previews")
|
||||
helper.Copy(up.Bool, "bridge", "caption_in_message")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "deadline")
|
||||
|
||||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome")
|
||||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_connected")
|
||||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_unconnected")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "management_room_text", "additional_help")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "appservice")
|
||||
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", "share")
|
||||
|
||||
legacyKeyShareAllow, ok := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "allow")
|
||||
if ok {
|
||||
helper.Set(up.Bool, legacyKeyShareAllow, "bridge", "encryption", "allow_key_sharing")
|
||||
legacyKeyShareRequireCS, legacyOK1 := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "require_cross_signing")
|
||||
legacyKeyShareRequireVerification, legacyOK2 := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "require_verification")
|
||||
if legacyOK1 && legacyOK2 && legacyKeyShareRequireVerification == "false" && legacyKeyShareRequireCS == "false" {
|
||||
helper.Set(up.Str, "unverified", "bridge", "encryption", "verification_levels", "share")
|
||||
}
|
||||
} else {
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "allow_key_sharing")
|
||||
}
|
||||
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "enable_custom")
|
||||
helper.Copy(up.Int, "bridge", "encryption", "rotation", "milliseconds")
|
||||
helper.Copy(up.Int, "bridge", "encryption", "rotation", "messages")
|
||||
if prefix, ok := helper.Get(up.Str, "appservice", "provisioning", "prefix"); ok {
|
||||
helper.Set(up.Str, strings.TrimSuffix(prefix, "/v1"), "bridge", "provisioning", "prefix")
|
||||
} else {
|
||||
helper.Copy(up.Str, "bridge", "provisioning", "prefix")
|
||||
}
|
||||
if secret, ok := helper.Get(up.Str, "appservice", "provisioning", "shared_secret"); ok && secret != "generate" {
|
||||
helper.Set(up.Str, secret, "bridge", "provisioning", "shared_secret")
|
||||
} else if secret, ok = helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
|
||||
sharedSecret := random.String(64)
|
||||
helper.Set(up.Str, sharedSecret, "bridge", "provisioning", "shared_secret")
|
||||
} else {
|
||||
helper.Copy(up.Str, "bridge", "provisioning", "shared_secret")
|
||||
}
|
||||
helper.Copy(up.Map, "bridge", "permissions")
|
||||
}
|
||||
|
||||
var SpacedBlocks = [][]string{
|
||||
{"homeserver", "software"},
|
||||
{"appservice"},
|
||||
{"appservice", "hostname"},
|
||||
{"appservice", "database"},
|
||||
{"appservice", "id"},
|
||||
{"appservice", "as_token"},
|
||||
{"segment_key"},
|
||||
{"metrics"},
|
||||
{"groupme"},
|
||||
{"bridge"},
|
||||
{"bridge", "command_prefix"},
|
||||
{"bridge", "management_room_text"},
|
||||
{"bridge", "encryption"},
|
||||
{"bridge", "provisioning"},
|
||||
{"bridge", "permissions"},
|
||||
{"logging"},
|
||||
}
|
334
crypto.go
334
crypto.go
@ -1,334 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 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/>.
|
||||
|
||||
// +build cgo,!nocrypto
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database"
|
||||
)
|
||||
|
||||
var NoSessionFound = crypto.NoSessionFound
|
||||
|
||||
var levelTrace = maulogger.Level{
|
||||
Name: "Trace",
|
||||
Severity: -10,
|
||||
Color: -1,
|
||||
}
|
||||
|
||||
type CryptoHelper struct {
|
||||
bridge *Bridge
|
||||
client *mautrix.Client
|
||||
mach *crypto.OlmMachine
|
||||
store *database.SQLCryptoStore
|
||||
log maulogger.Logger
|
||||
baseLog maulogger.Logger
|
||||
}
|
||||
|
||||
func NewCryptoHelper(bridge *Bridge) Crypto {
|
||||
if !bridge.Config.Bridge.Encryption.Allow {
|
||||
bridge.Log.Debugln("Bridge built with end-to-bridge encryption, but disabled in config")
|
||||
return nil
|
||||
}
|
||||
baseLog := bridge.Log.Sub("Crypto")
|
||||
return &CryptoHelper{
|
||||
bridge: bridge,
|
||||
log: baseLog.Sub("Helper"),
|
||||
baseLog: baseLog,
|
||||
}
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) Init() error {
|
||||
helper.log.Debugln("Initializing end-to-bridge encryption...")
|
||||
|
||||
helper.store = database.NewSQLCryptoStore(helper.bridge.DB, helper.bridge.AS.BotMXID(),
|
||||
fmt.Sprintf("@%s:%s", helper.bridge.Config.Bridge.FormatUsername("%"), helper.bridge.AS.HomeserverDomain))
|
||||
|
||||
var err error
|
||||
helper.client, err = helper.loginBot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
helper.log.Debugln("Logged in as bridge bot with device ID", helper.client.DeviceID)
|
||||
logger := &cryptoLogger{helper.baseLog}
|
||||
stateStore := &cryptoStateStore{helper.bridge}
|
||||
helper.mach = crypto.NewOlmMachine(helper.client, logger, helper.store, stateStore)
|
||||
helper.mach.AllowKeyShare = helper.allowKeyShare
|
||||
|
||||
helper.client.Syncer = &cryptoSyncer{helper.mach}
|
||||
helper.client.Store = &cryptoClientStore{helper.store}
|
||||
|
||||
return helper.mach.Load()
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) allowKeyShare(device *crypto.DeviceIdentity, info event.RequestedKeyInfo) *crypto.KeyShareRejection {
|
||||
cfg := helper.bridge.Config.Bridge.Encryption.KeySharing
|
||||
if !cfg.Allow {
|
||||
return &crypto.KeyShareRejectNoResponse
|
||||
} else if device.Trust == crypto.TrustStateBlacklisted {
|
||||
return &crypto.KeyShareRejectBlacklisted
|
||||
} else if device.Trust == crypto.TrustStateVerified || !cfg.RequireVerification {
|
||||
portal := helper.bridge.GetPortalByMXID(info.RoomID)
|
||||
if portal == nil {
|
||||
helper.log.Debugfln("Rejecting key request for %s from %s/%s: room is not a portal", info.SessionID, device.UserID, device.DeviceID)
|
||||
return &crypto.KeyShareRejection{Code: event.RoomKeyWithheldUnavailable, Reason: "Requested room is not a portal room"}
|
||||
}
|
||||
user := helper.bridge.GetUserByMXID(device.UserID)
|
||||
if !user.Admin && !user.IsInPortal(portal.Key) {
|
||||
helper.log.Debugfln("Rejecting key request for %s from %s/%s: user is not in portal", info.SessionID, device.UserID, device.DeviceID)
|
||||
return &crypto.KeyShareRejection{Code: event.RoomKeyWithheldUnauthorized, Reason: "You're not in that portal"}
|
||||
}
|
||||
helper.log.Debugfln("Accepting key request for %s from %s/%s", info.SessionID, device.UserID, device.DeviceID)
|
||||
return nil
|
||||
} else {
|
||||
return &crypto.KeyShareRejectUnverified
|
||||
}
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) loginBot() (*mautrix.Client, error) {
|
||||
deviceID := helper.store.FindDeviceID()
|
||||
if len(deviceID) > 0 {
|
||||
helper.log.Debugln("Found existing device ID for bot in database:", deviceID)
|
||||
}
|
||||
client, err := mautrix.NewClient(helper.bridge.AS.HomeserverURL, "", "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize client: %w", err)
|
||||
}
|
||||
client.Logger = helper.baseLog.Sub("Bot")
|
||||
client.Client = helper.bridge.AS.HTTPClient
|
||||
client.DefaultHTTPRetries = helper.bridge.AS.DefaultHTTPRetries
|
||||
flows, err := client.GetLoginFlows()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get supported login flows: %w", err)
|
||||
}
|
||||
if !flows.HasFlow(mautrix.AuthTypeHalfyAppservice) {
|
||||
return nil, fmt.Errorf("homeserver does not support appservice login")
|
||||
}
|
||||
// if !flows.HasFlow(mautrix.AuthTypeAppservice) {
|
||||
// // TODO after synapse 1.22, turn this into an error
|
||||
// helper.log.Warnln("Encryption enabled in config, but homeserver does not advertise appservice login")
|
||||
// //return nil, fmt.Errorf("homeserver does not support appservice login")
|
||||
// }
|
||||
|
||||
// We set the API token to the AS token here to authenticate the appservice login
|
||||
// It'll get overridden after the login
|
||||
client.AccessToken = helper.bridge.AS.Registration.AppToken
|
||||
resp, err := client.Login(&mautrix.ReqLogin{
|
||||
Type: mautrix.AuthTypeHalfyAppservice,
|
||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())},
|
||||
DeviceID: deviceID,
|
||||
InitialDeviceDisplayName: "GroupMe Bridge",
|
||||
StoreCredentials: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to log in as bridge bot: %w", err)
|
||||
}
|
||||
helper.store.DeviceID = resp.DeviceID
|
||||
return client, nil
|
||||
|
||||
// client.AccessToken = helper.bridge.AS.Registration.AppToken
|
||||
// resp, err := client.Login(&mautrix.ReqLogin{
|
||||
// Type: mautrix.AuthTypeAppservice,
|
||||
// Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())},
|
||||
// DeviceID: deviceID,
|
||||
// InitialDeviceDisplayName: "GroupMe Bridge",
|
||||
// StoreCredentials: true,
|
||||
// })
|
||||
// if err != nil {
|
||||
// return nil, fmt.Errorf("failed to log in as bridge bot: %w", err)
|
||||
// }
|
||||
// if len(deviceID) == 0 {
|
||||
// helper.store.DeviceID = resp.DeviceID
|
||||
// }
|
||||
// return client, nil
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) Start() {
|
||||
helper.log.Debugln("Starting syncer for receiving to-device messages")
|
||||
err := helper.client.Sync()
|
||||
if err != nil {
|
||||
helper.log.Errorln("Fatal error syncing:", err)
|
||||
} else {
|
||||
helper.log.Infoln("Bridge bot to-device syncer stopped without error")
|
||||
}
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) Stop() {
|
||||
helper.log.Debugln("CryptoHelper.Stop() called, stopping bridge bot sync")
|
||||
helper.client.StopSync()
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) Decrypt(evt *event.Event) (*event.Event, error) {
|
||||
return helper.mach.DecryptMegolmEvent(evt)
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) Encrypt(roomID id.RoomID, evtType event.Type, content event.Content) (*event.EncryptedEventContent, error) {
|
||||
encrypted, err := helper.mach.EncryptMegolmEvent(roomID, evtType, &content)
|
||||
if err != nil {
|
||||
if err != crypto.SessionExpired && err != crypto.SessionNotShared && err != crypto.NoGroupSession {
|
||||
return nil, err
|
||||
}
|
||||
helper.log.Debugfln("Got %v while encrypting event for %s, sharing group session and trying again...", err, roomID)
|
||||
users, err := helper.store.GetRoomMembers(roomID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get room member list: %w", err)
|
||||
}
|
||||
err = helper.mach.ShareGroupSession(roomID, users)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to share group session: %w", err)
|
||||
}
|
||||
encrypted, err = helper.mach.EncryptMegolmEvent(roomID, evtType, &content)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encrypt event after re-sharing group session: %w", err)
|
||||
}
|
||||
}
|
||||
return encrypted, nil
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) WaitForSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, timeout time.Duration) bool {
|
||||
return helper.mach.WaitForSession(roomID, senderKey, sessionID, timeout)
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) ResetSession(roomID id.RoomID) {
|
||||
err := helper.mach.CryptoStore.RemoveOutboundGroupSession(roomID)
|
||||
if err != nil {
|
||||
helper.log.Debugfln("Error manually removing outbound group session in %s: %v", roomID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) HandleMemberEvent(evt *event.Event) {
|
||||
helper.mach.HandleMemberEvent(evt)
|
||||
}
|
||||
|
||||
type cryptoSyncer struct {
|
||||
*crypto.OlmMachine
|
||||
}
|
||||
|
||||
func (syncer *cryptoSyncer) ProcessResponse(resp *mautrix.RespSync, since string) error {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
syncer.Log.Error("Processing sync response (%s) panicked: %v\n%s", since, err, debug.Stack())
|
||||
}
|
||||
done <- struct{}{}
|
||||
}()
|
||||
syncer.Log.Trace("Starting sync response handling (%s)", since)
|
||||
syncer.ProcessSyncResponse(resp, since)
|
||||
syncer.Log.Trace("Successfully handled sync response (%s)", since)
|
||||
}()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(30 * time.Second):
|
||||
syncer.Log.Warn("Handling sync response (%s) is taking unusually long", since)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (syncer *cryptoSyncer) OnFailedSync(_ *mautrix.RespSync, err error) (time.Duration, error) {
|
||||
syncer.Log.Error("Error /syncing, waiting 10 seconds: %v", err)
|
||||
return 10 * time.Second, nil
|
||||
}
|
||||
|
||||
func (syncer *cryptoSyncer) GetFilterJSON(_ id.UserID) *mautrix.Filter {
|
||||
everything := []event.Type{{Type: "*"}}
|
||||
return &mautrix.Filter{
|
||||
Presence: mautrix.FilterPart{NotTypes: everything},
|
||||
AccountData: mautrix.FilterPart{NotTypes: everything},
|
||||
Room: mautrix.RoomFilter{
|
||||
IncludeLeave: false,
|
||||
Ephemeral: mautrix.FilterPart{NotTypes: everything},
|
||||
AccountData: mautrix.FilterPart{NotTypes: everything},
|
||||
State: mautrix.FilterPart{NotTypes: everything},
|
||||
Timeline: mautrix.FilterPart{NotTypes: everything},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type cryptoLogger struct {
|
||||
int maulogger.Logger
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Error(message string, args ...interface{}) {
|
||||
c.int.Errorfln(message, args...)
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Warn(message string, args ...interface{}) {
|
||||
c.int.Warnfln(message, args...)
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Debug(message string, args ...interface{}) {
|
||||
c.int.Debugfln(message, args...)
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Trace(message string, args ...interface{}) {
|
||||
c.int.Logfln(levelTrace, message, args...)
|
||||
}
|
||||
|
||||
type cryptoClientStore struct {
|
||||
int *database.SQLCryptoStore
|
||||
}
|
||||
|
||||
func (c cryptoClientStore) SaveFilterID(_ id.UserID, _ string) {}
|
||||
func (c cryptoClientStore) LoadFilterID(_ id.UserID) string { return "" }
|
||||
func (c cryptoClientStore) SaveRoom(_ *mautrix.Room) {}
|
||||
func (c cryptoClientStore) LoadRoom(_ id.RoomID) *mautrix.Room { return nil }
|
||||
|
||||
func (c cryptoClientStore) SaveNextBatch(_ id.UserID, nextBatchToken string) {
|
||||
c.int.PutNextBatch(nextBatchToken)
|
||||
}
|
||||
|
||||
func (c cryptoClientStore) LoadNextBatch(_ id.UserID) string {
|
||||
return c.int.GetNextBatch()
|
||||
}
|
||||
|
||||
var _ mautrix.Storer = (*cryptoClientStore)(nil)
|
||||
|
||||
type cryptoStateStore struct {
|
||||
bridge *Bridge
|
||||
}
|
||||
|
||||
var _ crypto.StateStore = (*cryptoStateStore)(nil)
|
||||
|
||||
func (c *cryptoStateStore) IsEncrypted(id id.RoomID) bool {
|
||||
portal := c.bridge.GetPortalByMXID(id)
|
||||
if portal != nil {
|
||||
return portal.Encrypted
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *cryptoStateStore) FindSharedRooms(id id.UserID) []id.RoomID {
|
||||
return c.bridge.StateStore.FindSharedRooms(id)
|
||||
}
|
||||
|
||||
func (c *cryptoStateStore) GetEncryptionEvent(id.RoomID) *event.EncryptionEventContent {
|
||||
// TODO implement
|
||||
return nil
|
||||
}
|
176
custompuppet.go
176
custompuppet.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
@ -42,7 +43,7 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
||||
puppet.CustomMXID = mxid
|
||||
puppet.AccessToken = accessToken
|
||||
|
||||
err := puppet.StartCustomMXID()
|
||||
err := puppet.StartCustomMXID(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -53,7 +54,6 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
||||
if len(puppet.CustomMXID) > 0 {
|
||||
puppet.bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||
}
|
||||
puppet.EnablePresence = puppet.bridge.Config.Bridge.DefaultBridgePresence
|
||||
puppet.EnableReceipts = puppet.bridge.Config.Bridge.DefaultBridgeReceipts
|
||||
puppet.bridge.AS.StateStore.MarkRegistered(puppet.CustomMXID)
|
||||
puppet.Update()
|
||||
@ -62,31 +62,65 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
||||
}
|
||||
|
||||
func (puppet *Puppet) loginWithSharedSecret(mxid id.UserID) (string, error) {
|
||||
_, homeserver, _ := mxid.Parse()
|
||||
puppet.log.Debugfln("Logging into %s with shared secret", mxid)
|
||||
mac := hmac.New(sha512.New, []byte(puppet.bridge.Config.Bridge.LoginSharedSecret))
|
||||
mac.Write([]byte(mxid))
|
||||
resp, err := puppet.bridge.AS.BotClient().Login(&mautrix.ReqLogin{
|
||||
Type: mautrix.AuthTypePassword,
|
||||
loginSecret := puppet.bridge.Config.Bridge.LoginSharedSecretMap[homeserver]
|
||||
client, err := puppet.bridge.newDoublePuppetClient(mxid, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create mautrix client to log in: %v", err)
|
||||
}
|
||||
req := mautrix.ReqLogin{
|
||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(mxid)},
|
||||
Password: hex.EncodeToString(mac.Sum(nil)),
|
||||
DeviceID: "WhatsApp Bridge",
|
||||
InitialDeviceDisplayName: "WhatsApp Bridge",
|
||||
})
|
||||
DeviceID: "GroupMe Bridge",
|
||||
InitialDeviceDisplayName: "GroupMe Bridge",
|
||||
}
|
||||
if loginSecret == "appservice" {
|
||||
client.AccessToken = puppet.bridge.AS.Registration.AppToken
|
||||
req.Type = mautrix.AuthTypeAppservice
|
||||
} else {
|
||||
mac := hmac.New(sha512.New, []byte(loginSecret))
|
||||
mac.Write([]byte(mxid))
|
||||
req.Password = hex.EncodeToString(mac.Sum(nil))
|
||||
req.Type = mautrix.AuthTypePassword
|
||||
}
|
||||
resp, err := client.Login(&req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resp.AccessToken, nil
|
||||
}
|
||||
|
||||
func (br *GMBridge) newDoublePuppetClient(mxid id.UserID, accessToken string) (*mautrix.Client, error) {
|
||||
_, homeserver, err := mxid.Parse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
homeserverURL, found := br.Config.Bridge.DoublePuppetServerMap[homeserver]
|
||||
if !found {
|
||||
if homeserver == br.AS.HomeserverDomain {
|
||||
homeserverURL = ""
|
||||
} else if br.Config.Bridge.DoublePuppetAllowDiscovery {
|
||||
resp, err := mautrix.DiscoverClientAPI(homeserver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find homeserver URL for %s: %v", homeserver, err)
|
||||
}
|
||||
homeserverURL = resp.Homeserver.BaseURL
|
||||
br.Log.Debugfln("Discovered URL %s for %s to enable double puppeting for %s", homeserverURL, homeserver, mxid)
|
||||
} else {
|
||||
return nil, fmt.Errorf("double puppeting from %s is not allowed", homeserver)
|
||||
}
|
||||
}
|
||||
return br.AS.NewExternalMautrixClient(mxid, accessToken, homeserverURL)
|
||||
}
|
||||
|
||||
func (puppet *Puppet) newCustomIntent() (*appservice.IntentAPI, error) {
|
||||
if len(puppet.CustomMXID) == 0 {
|
||||
return nil, ErrNoCustomMXID
|
||||
}
|
||||
client, err := mautrix.NewClient(puppet.bridge.AS.HomeserverURL, puppet.CustomMXID, puppet.AccessToken)
|
||||
client, err := puppet.bridge.newDoublePuppetClient(puppet.CustomMXID, puppet.AccessToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.Logger = puppet.bridge.AS.Log.Sub(string(puppet.CustomMXID))
|
||||
client.Syncer = puppet
|
||||
client.Store = puppet
|
||||
|
||||
@ -102,11 +136,10 @@ func (puppet *Puppet) clearCustomMXID() {
|
||||
puppet.CustomMXID = ""
|
||||
puppet.AccessToken = ""
|
||||
puppet.customIntent = nil
|
||||
puppet.customTypingIn = nil
|
||||
puppet.customUser = nil
|
||||
}
|
||||
|
||||
func (puppet *Puppet) StartCustomMXID() error {
|
||||
func (puppet *Puppet) StartCustomMXID(reloginOnFail bool) error {
|
||||
if len(puppet.CustomMXID) == 0 {
|
||||
puppet.clearCustomMXID()
|
||||
return nil
|
||||
@ -118,15 +151,16 @@ func (puppet *Puppet) StartCustomMXID() error {
|
||||
}
|
||||
resp, err := intent.Whoami()
|
||||
if err != nil {
|
||||
puppet.clearCustomMXID()
|
||||
return err
|
||||
}
|
||||
if resp.UserID != puppet.CustomMXID {
|
||||
if !reloginOnFail || (errors.Is(err, mautrix.MUnknownToken) && !puppet.tryRelogin(err, "initializing double puppeting")) {
|
||||
puppet.clearCustomMXID()
|
||||
return err
|
||||
}
|
||||
intent.AccessToken = puppet.AccessToken
|
||||
} else if resp.UserID != puppet.CustomMXID {
|
||||
puppet.clearCustomMXID()
|
||||
return ErrMismatchingMXID
|
||||
}
|
||||
puppet.customIntent = intent
|
||||
puppet.customTypingIn = make(map[id.RoomID]bool)
|
||||
puppet.customUser = puppet.bridge.GetUserByMXID(puppet.CustomMXID)
|
||||
puppet.startSyncing()
|
||||
return nil
|
||||
@ -154,16 +188,13 @@ func (puppet *Puppet) stopSyncing() {
|
||||
}
|
||||
|
||||
func (puppet *Puppet) ProcessResponse(resp *mautrix.RespSync, _ string) error {
|
||||
if !puppet.customUser.IsConnected() {
|
||||
puppet.log.Debugln("Skipping sync processing: custom user not connected to whatsapp")
|
||||
if !puppet.customUser.IsLoggedIn() {
|
||||
puppet.log.Debugln("Skipping sync processing: custom user not connected to GroupMe")
|
||||
return nil
|
||||
}
|
||||
for roomID, events := range resp.Rooms.Join {
|
||||
portal := puppet.bridge.GetPortalByMXID(roomID)
|
||||
if portal == nil {
|
||||
continue
|
||||
}
|
||||
for _, evt := range events.Ephemeral.Events {
|
||||
evt.RoomID = roomID
|
||||
err := evt.Content.ParseRaw(evt.Type)
|
||||
if err != nil {
|
||||
continue
|
||||
@ -171,85 +202,40 @@ func (puppet *Puppet) ProcessResponse(resp *mautrix.RespSync, _ string) error {
|
||||
switch evt.Type {
|
||||
case event.EphemeralEventReceipt:
|
||||
if puppet.EnableReceipts {
|
||||
go puppet.handleReceiptEvent(portal, evt)
|
||||
go puppet.bridge.MatrixHandler.HandleReceipt(evt)
|
||||
}
|
||||
case event.EphemeralEventTyping:
|
||||
go puppet.handleTypingEvent(portal, evt)
|
||||
go puppet.bridge.MatrixHandler.HandleTyping(evt)
|
||||
}
|
||||
}
|
||||
}
|
||||
if puppet.EnablePresence {
|
||||
for _, evt := range resp.Presence.Events {
|
||||
if evt.Sender != puppet.CustomMXID {
|
||||
continue
|
||||
}
|
||||
err := evt.Content.ParseRaw(evt.Type)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
go puppet.handlePresenceEvent(evt)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (puppet *Puppet) handlePresenceEvent(event *event.Event) {
|
||||
// presence := whatsapp.PresenceAvailable
|
||||
// if event.Content.Raw["presence"].(string) != "online" {
|
||||
// presence = whatsapp.PresenceUnavailable
|
||||
// puppet.customUser.log.Debugln("Marking offline")
|
||||
// } else {
|
||||
// puppet.customUser.log.Debugln("Marking online")
|
||||
// }
|
||||
// _, err := puppet.customUser.Conn.Presence("", presence)
|
||||
// if err != nil {
|
||||
// puppet.customUser.log.Warnln("Failed to set presence:", err)
|
||||
// }
|
||||
}
|
||||
|
||||
func (puppet *Puppet) handleReceiptEvent(portal *Portal, event *event.Event) {
|
||||
// for eventID, receipts := range *event.Content.AsReceipt() {
|
||||
// if _, ok := receipts.Read[puppet.CustomMXID]; !ok {
|
||||
// continue
|
||||
// }
|
||||
// message := puppet.bridge.DB.Message.GetByMXID(eventID)
|
||||
// if message == nil {
|
||||
// continue
|
||||
// }
|
||||
// puppet.customUser.log.Debugfln("Marking %s/%s in %s/%s as read", message.JID, message.MXID, portal.Key.JID, portal.MXID)
|
||||
// _, err := puppet.customUser.Conn.Read(portal.Key.JID, message.JID)
|
||||
// if err != nil {
|
||||
// puppet.customUser.log.Warnln("Error marking read:", err)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
func (puppet *Puppet) handleTypingEvent(portal *Portal, evt *event.Event) {
|
||||
// isTyping := false
|
||||
// for _, userID := range evt.Content.AsTyping().UserIDs {
|
||||
// if userID == puppet.CustomMXID {
|
||||
// isTyping = true
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if puppet.customTypingIn[evt.RoomID] != isTyping {
|
||||
// puppet.customTypingIn[evt.RoomID] = isTyping
|
||||
// presence := whatsapp.PresenceComposing
|
||||
// if !isTyping {
|
||||
// puppet.customUser.log.Debugfln("Marking not typing in %s/%s", portal.Key.JID, portal.MXID)
|
||||
// presence = whatsapp.PresencePaused
|
||||
// } else {
|
||||
// puppet.customUser.log.Debugfln("Marking typing in %s/%s", portal.Key.JID, portal.MXID)
|
||||
// }
|
||||
// _, err := puppet.customUser.Conn.Presence(portal.Key.JID, presence)
|
||||
// if err != nil {
|
||||
// puppet.customUser.log.Warnln("Error setting typing:", err)
|
||||
// }
|
||||
// }
|
||||
func (puppet *Puppet) tryRelogin(cause error, action string) bool {
|
||||
if !puppet.bridge.Config.CanAutoDoublePuppet(puppet.CustomMXID) {
|
||||
return false
|
||||
}
|
||||
puppet.log.Debugfln("Trying to relogin after '%v' while %s", cause, action)
|
||||
accessToken, err := puppet.loginWithSharedSecret(puppet.CustomMXID)
|
||||
if err != nil {
|
||||
puppet.log.Errorfln("Failed to relogin after '%v' while %s: %v", cause, action, err)
|
||||
return false
|
||||
}
|
||||
puppet.log.Infofln("Successfully relogined after '%v' while %s", cause, action)
|
||||
puppet.AccessToken = accessToken
|
||||
return true
|
||||
}
|
||||
|
||||
func (puppet *Puppet) OnFailedSync(_ *mautrix.RespSync, err error) (time.Duration, error) {
|
||||
puppet.log.Warnln("Sync error:", err)
|
||||
puppet.log.Warnln("SyncGroup error:", err)
|
||||
if errors.Is(err, mautrix.MUnknownToken) {
|
||||
if !puppet.tryRelogin(err, "syncing") {
|
||||
return 0, err
|
||||
}
|
||||
puppet.customIntent.AccessToken = puppet.AccessToken
|
||||
return 0, nil
|
||||
}
|
||||
return 10 * time.Second, nil
|
||||
}
|
||||
|
||||
|
@ -1,106 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 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/>.
|
||||
|
||||
// +build cgo,!nocrypto
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type SQLCryptoStore struct {
|
||||
*crypto.SQLCryptoStore
|
||||
UserID id.UserID
|
||||
GhostIDFormat string
|
||||
}
|
||||
|
||||
var _ crypto.Store = (*SQLCryptoStore)(nil)
|
||||
|
||||
func NewSQLCryptoStore(db *Database, userID id.UserID, ghostIDFormat string) *SQLCryptoStore {
|
||||
raw, _ := db.DB.DB()
|
||||
return &SQLCryptoStore{
|
||||
SQLCryptoStore: crypto.NewSQLCryptoStore(raw, db.dialect, "", "",
|
||||
[]byte("github.com/karmanyaahm/matrix-groupme-go"),
|
||||
&cryptoLogger{db.log.Sub("CryptoStore")}),
|
||||
UserID: userID,
|
||||
GhostIDFormat: ghostIDFormat,
|
||||
}
|
||||
}
|
||||
|
||||
func (store *SQLCryptoStore) FindDeviceID() (deviceID id.DeviceID) {
|
||||
err := store.DB.QueryRow("SELECT device_id FROM crypto_account WHERE account_id=$1", store.AccountID).Scan(&deviceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
store.Log.Warn("Failed to scan device ID: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (store *SQLCryptoStore) GetRoomMembers(roomID id.RoomID) (members []id.UserID, err error) {
|
||||
var rows *sql.Rows
|
||||
rows, err = store.DB.Query(`
|
||||
SELECT user_id FROM mx_user_profile
|
||||
WHERE room_id=$1
|
||||
AND (membership='join' OR membership='invite')
|
||||
AND user_id<>$2
|
||||
AND user_id NOT LIKE $3
|
||||
`, roomID, store.UserID, store.GhostIDFormat)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for rows.Next() {
|
||||
var userID id.UserID
|
||||
err := rows.Scan(&userID)
|
||||
if err != nil {
|
||||
store.Log.Warn("Failed to scan member in %s: %v", roomID, err)
|
||||
} else {
|
||||
members = append(members, userID)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TODO merge this with the one in the parent package
|
||||
type cryptoLogger struct {
|
||||
int log.Logger
|
||||
}
|
||||
|
||||
var levelTrace = log.Level{
|
||||
Name: "Trace",
|
||||
Severity: -10,
|
||||
Color: -1,
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Error(message string, args ...interface{}) {
|
||||
c.int.Errorfln(message, args...)
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Warn(message string, args ...interface{}) {
|
||||
c.int.Warnfln(message, args...)
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Debug(message string, args ...interface{}) {
|
||||
c.int.Debugfln(message, args...)
|
||||
}
|
||||
|
||||
func (c *cryptoLogger) Trace(message string, args ...interface{}) {
|
||||
c.int.Logfln(levelTrace, message, args...)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,26 +17,21 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"errors"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"net"
|
||||
|
||||
"github.com/lib/pq"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/maulogger/v2"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database/upgrades"
|
||||
"github.com/beeper/groupme/database/upgrades"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
*gorm.DB
|
||||
log log.Logger
|
||||
dialect string
|
||||
*dbutil.Database
|
||||
|
||||
User *UserQuery
|
||||
Portal *PortalQuery
|
||||
@ -45,92 +40,42 @@ type Database struct {
|
||||
Reaction *ReactionQuery
|
||||
}
|
||||
|
||||
func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
|
||||
|
||||
var conn gorm.Dialector
|
||||
|
||||
if dbType == "sqlite3" {
|
||||
//_, _ = conn.Exec("PRAGMA foreign_keys = ON")
|
||||
log.Fatalln("no sqlite for now only postgresql")
|
||||
os.Exit(1)
|
||||
conn = sqlite.Open(uri)
|
||||
} else {
|
||||
conn = postgres.Open(uri)
|
||||
}
|
||||
|
||||
gdb, err := gorm.Open(conn, &gorm.Config{
|
||||
// Logger: logger.Default.LogMode(logger.Info),
|
||||
// Logger: baseLog,
|
||||
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
NamingStrategy: schema.NamingStrategy{
|
||||
NameReplacer: strings.NewReplacer("JID", "Jid", "MXID", "Mxid"),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
db := &Database{
|
||||
DB: gdb,
|
||||
log: baseLog.Sub("Database"),
|
||||
dialect: dbType,
|
||||
}
|
||||
func New(baseDB *dbutil.Database, log maulogger.Logger) *Database {
|
||||
db := &Database{Database: baseDB}
|
||||
db.UpgradeTable = upgrades.Table
|
||||
db.User = &UserQuery{
|
||||
db: db,
|
||||
log: db.log.Sub("User"),
|
||||
log: log.Sub("User"),
|
||||
}
|
||||
db.Portal = &PortalQuery{
|
||||
db: db,
|
||||
log: db.log.Sub("Portal"),
|
||||
log: log.Sub("Portal"),
|
||||
}
|
||||
db.Puppet = &PuppetQuery{
|
||||
db: db,
|
||||
log: db.log.Sub("Puppet"),
|
||||
log: log.Sub("Puppet"),
|
||||
}
|
||||
db.Message = &MessageQuery{
|
||||
db: db,
|
||||
log: db.log.Sub("Message"),
|
||||
log: log.Sub("Message"),
|
||||
}
|
||||
db.Reaction = &ReactionQuery{
|
||||
db: db,
|
||||
log: db.log.Sub("Reaction"),
|
||||
log: log.Sub("Reaction"),
|
||||
}
|
||||
|
||||
return db, nil
|
||||
return db
|
||||
}
|
||||
|
||||
func (db *Database) Init() error {
|
||||
println("actual upgrade")
|
||||
err := db.AutoMigrate(&Portal{}, &Puppet{})
|
||||
if err != nil {
|
||||
return err
|
||||
func isRetryableError(err error) bool {
|
||||
if pqError := (&pq.Error{}); errors.As(err, &pqError) {
|
||||
switch pqError.Code.Class() {
|
||||
case "08", // Connection Exception
|
||||
"53", // Insufficient Resources (e.g. too many connections)
|
||||
"57": // Operator Intervention (e.g. server restart)
|
||||
return true
|
||||
}
|
||||
} else if netError := (&net.OpError{}); errors.As(err, &netError) {
|
||||
return true
|
||||
}
|
||||
err = db.AutoMigrate(&Message{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.AutoMigrate(&Reaction{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.AutoMigrate(&mxRegistered{}, &MxUserProfile{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.AutoMigrate(&User{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(&UserPortal{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return upgrades.Run(db.log.Sub("Upgrade"), db.dialect, db.DB)
|
||||
}
|
||||
|
||||
type Scannable interface {
|
||||
Scan(...interface{}) error
|
||||
return false
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,11 +17,16 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"time"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/groupmeExt"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
)
|
||||
|
||||
type MessageQuery struct {
|
||||
@ -36,101 +41,125 @@ func (mq *MessageQuery) New() *Message {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
getAllMessagesSelect = `
|
||||
SELECT chat_gmid, chat_receiver, gmid, mxid, sender, timestamp, sent
|
||||
FROM message
|
||||
`
|
||||
getAllMessagesQuery = getAllMessagesSelect + `
|
||||
WHERE chat_gmid=$1 AND chat_receiver=$2
|
||||
`
|
||||
getByGMIDQuery = getAllMessagesQuery + "AND gmid=$3"
|
||||
getByMXIDQuery = getAllMessagesSelect + "WHERE mxid=$1"
|
||||
getLastMessageInChatQuery = getAllMessagesQuery + `
|
||||
AND timestamp<=$3 AND sent=true
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 1
|
||||
`
|
||||
getFirstMessageInChatQuery = getAllMessagesQuery + `
|
||||
AND sent=true
|
||||
ORDER BY timestamp ASC
|
||||
LIMIT 1
|
||||
`
|
||||
getMessagesBetweenQuery = getAllMessagesQuery + `
|
||||
AND timestamp>$3 AND timestamp<=$4 AND sent=true
|
||||
ORDER BY timestamp ASC
|
||||
`
|
||||
)
|
||||
|
||||
func (mq *MessageQuery) GetAll(chat PortalKey) (messages []*Message) {
|
||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ?", chat.JID, chat.Receiver).Find(&messages)
|
||||
if ans.Error != nil || len(messages) == 0 {
|
||||
rows, err := mq.db.Query(getAllMessagesQuery, chat.GMID, chat.Receiver)
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
for rows.Next() {
|
||||
messages = append(messages, mq.New().Scan(rows))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetByJID(chat PortalKey, jid types.WhatsAppMessageID) *Message {
|
||||
var message Message
|
||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ? AND jid = ?", chat.JID, chat.Receiver, jid).Limit(1).Find(&message)
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
return nil
|
||||
}
|
||||
return &message
|
||||
func (mq *MessageQuery) GetByGMID(chat PortalKey, gmid groupme.ID) *Message {
|
||||
return mq.maybeScan(mq.db.QueryRow(getByGMIDQuery, chat.GMID, chat.Receiver, gmid))
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message {
|
||||
var message Message
|
||||
ans := mq.db.Where("mxid = ?", mxid).Limit(1).Find(&message)
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
return nil
|
||||
}
|
||||
return &message
|
||||
return mq.maybeScan(mq.db.QueryRow(getByMXIDQuery, mxid))
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
|
||||
var message Message
|
||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ?", chat.JID, chat.Receiver).Order("timestamp desc").Limit(1).Find(&message)
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
return mq.GetLastInChatBefore(chat, time.Now().Add(60*time.Second))
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetLastInChatBefore(chat PortalKey, maxTimestamp time.Time) *Message {
|
||||
return mq.maybeScan(mq.db.QueryRow(getLastMessageInChatQuery, chat.GMID, chat.Receiver, maxTimestamp.Unix()))
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetFirstInChat(chat PortalKey) *Message {
|
||||
return mq.maybeScan(mq.db.QueryRow(getFirstMessageInChatQuery, chat.GMID, chat.Receiver))
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetMessagesBetween(chat PortalKey, minTimestamp, maxTimestamp time.Time) (messages []*Message) {
|
||||
rows, err := mq.db.Query(getMessagesBetweenQuery, chat.GMID, chat.Receiver, minTimestamp.Unix(), maxTimestamp.Unix())
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
return &message
|
||||
for rows.Next() {
|
||||
messages = append(messages, mq.New().Scan(rows))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) maybeScan(row *sql.Row) *Message {
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
return mq.New().Scan(row)
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
Chat PortalKey `gorm:"embedded;embeddedPrefix:chat_"`
|
||||
JID types.GroupMeID `gorm:"primaryKey;unique;notNull"`
|
||||
MXID id.EventID `gorm:"primaryKey;unique;notNull"`
|
||||
Sender types.GroupMeID `gorm:"notNull"`
|
||||
Timestamp uint64 `gorm:"notNull;default:0"`
|
||||
Content *groupmeExt.Message `gorm:"type:TEXT;notNull"`
|
||||
Chat PortalKey
|
||||
GMID groupme.ID
|
||||
MXID id.EventID
|
||||
Sender groupme.ID
|
||||
Timestamp time.Time
|
||||
Sent bool
|
||||
|
||||
Portal Portal `gorm:"foreignKey:chat_jid,chat_receiver;references:jid,receiver;constraint:onDelete:CASCADE;"`
|
||||
Portal Portal
|
||||
}
|
||||
|
||||
// func (msg *Message) Scan(row Scannable) *Message {
|
||||
// var content []byte
|
||||
// err := row.Scan(&msg.Chat.JID, &msg.Chat.Receiver, &msg.JID, &msg.MXID, &msg.Sender, &msg.Timestamp, &content)
|
||||
// if err != nil {
|
||||
// if err != sql.ErrNoRows {
|
||||
// msg.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// msg.decodeBinaryContent(content)
|
||||
|
||||
// return msg
|
||||
// }
|
||||
|
||||
// func (msg *Message) decodeBinaryContent(content []byte) {
|
||||
// msg.Content = &waProto.Message{}
|
||||
// reader := bytes.NewReader(content)
|
||||
// dec := json.NewDecoder(reader)
|
||||
// err := dec.Decode(msg.Content)
|
||||
// if err != nil {
|
||||
// msg.log.Warnln("Failed to decode message content:", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func (msg *Message) encodeBinaryContent() []byte {
|
||||
// var buf bytes.Buffer
|
||||
// enc := json.NewEncoder(&buf)
|
||||
// err := enc.Encode(msg.Content)
|
||||
// if err != nil {
|
||||
// msg.log.Warnln("Failed to encode message content:", err)
|
||||
// }
|
||||
// return buf.Bytes()
|
||||
// }
|
||||
func (msg *Message) Scan(row dbutil.Scannable) *Message {
|
||||
var ts int64
|
||||
err := row.Scan(&msg.Chat.GMID, &msg.Chat.Receiver, &msg.GMID, &msg.MXID, &msg.Sender, &ts, &msg.Sent)
|
||||
if err != nil {
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
msg.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if ts != 0 {
|
||||
msg.Timestamp = time.Unix(ts, 0)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (msg *Message) Insert() {
|
||||
ans := msg.db.Create(&msg)
|
||||
if ans.Error != nil {
|
||||
msg.log.Warnfln("Failed to insert %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
||||
query := fmt.Sprintf(`
|
||||
INSERT INTO message (chat_gmid, chat_receiver, gmid, mxid, sender, timestamp, sent)
|
||||
VALUES ('%s', '%s', '%s', '%s', '%s', '%d', '%t')
|
||||
`, msg.Chat.GMID, msg.Chat.Receiver, msg.GMID, msg.MXID, msg.Sender, msg.Timestamp.Unix(), msg.Sent)
|
||||
_, err := msg.db.Exec(query)
|
||||
|
||||
if err != nil {
|
||||
msg.log.Warnfln("Failed to insert %s: %v", msg.MXID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (msg *Message) Delete() {
|
||||
ans := msg.db.Delete(&msg)
|
||||
if ans.Error != nil {
|
||||
msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
||||
}
|
||||
}
|
||||
//func (msg *Message) Delete() {
|
||||
// ans := msg.db.Delete(&msg)
|
||||
// if ans.Error != nil {
|
||||
// msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
||||
// }
|
||||
//}
|
||||
|
@ -1,157 +0,0 @@
|
||||
package database
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "math"
|
||||
// "strings"
|
||||
// )
|
||||
|
||||
// // func countRows(db *Database, table string) (int, error) {
|
||||
// // countRow := db.QueryRow(fmt.Sprintf("SELECT COUNT(*) FROM %s", table))
|
||||
// // var count int
|
||||
// // err := countRow.Scan(&count)
|
||||
// // return count, err
|
||||
// // }
|
||||
|
||||
// const VariableCountLimit = 512
|
||||
|
||||
// func migrateTable(old *Database, new *Database, table string, columns ...string) error {
|
||||
// columnNames := strings.Join(columns, ",")
|
||||
// fmt.Printf("Migrating %s: ", table)
|
||||
// rowCount, err := countRows(old, table)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// fmt.Print("found ", rowCount, " rows of data, ")
|
||||
// rows, err := old.Query(fmt.Sprintf("SELECT %s FROM \"%s\"", columnNames, table))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// serverColNames, err := rows.Columns()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// colCount := len(serverColNames)
|
||||
// valueStringFormat := strings.Repeat("$%d, ", colCount)
|
||||
// valueStringFormat = fmt.Sprintf("(%s)", valueStringFormat[:len(valueStringFormat)-2])
|
||||
// cols := make([]interface{}, colCount)
|
||||
// colPtrs := make([]interface{}, colCount)
|
||||
// for i := 0; i < colCount; i++ {
|
||||
// colPtrs[i] = &cols[i]
|
||||
// }
|
||||
// batchSize := VariableCountLimit / colCount
|
||||
// values := make([]interface{}, batchSize*colCount)
|
||||
// valueStrings := make([]string, batchSize)
|
||||
// var inserted int64
|
||||
// batchCount := int(math.Ceil(float64(rowCount) / float64(batchSize)))
|
||||
// tx, err := new.Begin()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// fmt.Printf("migrating in %d batches: ", batchCount)
|
||||
// for rowCount > 0 {
|
||||
// var i int
|
||||
// for ; rows.Next() && i < batchSize; i++ {
|
||||
// colPtrs := make([]interface{}, colCount)
|
||||
// valueStringArgs := make([]interface{}, colCount)
|
||||
// for j := 0; j < colCount; j++ {
|
||||
// pos := i*colCount + j
|
||||
// colPtrs[j] = &values[pos]
|
||||
// valueStringArgs[j] = pos + 1
|
||||
// }
|
||||
// valueStrings[i] = fmt.Sprintf(valueStringFormat, valueStringArgs...)
|
||||
// err = rows.Scan(colPtrs...)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// }
|
||||
// slicedValues := values
|
||||
// slicedValueStrings := valueStrings
|
||||
// if i < len(valueStrings) {
|
||||
// slicedValueStrings = slicedValueStrings[:i]
|
||||
// slicedValues = slicedValues[:i*colCount]
|
||||
// }
|
||||
// if len(slicedValues) == 0 {
|
||||
// break
|
||||
// }
|
||||
// res, err := tx.Exec(fmt.Sprintf("INSERT INTO \"%s\" (%s) VALUES %s", table, columnNames, strings.Join(slicedValueStrings, ",")), slicedValues...)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// count, _ := res.RowsAffected()
|
||||
// inserted += count
|
||||
// rowCount -= batchSize
|
||||
// fmt.Print("#")
|
||||
// }
|
||||
// err = tx.Commit()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// fmt.Println(" -- done with", inserted, "rows inserted")
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func Migrate(old *Database, new *Database) {
|
||||
print("skipping migration because test")
|
||||
}
|
||||
// err := migrateTable(old, new, "portal", "jid", "receiver", "mxid", "name", "topic", "avatar", "avatar_url", "encrypted")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "user", "mxid", "jid", "management_room", "client_id", "client_token", "server_token", "enc_key", "mac_key", "last_connection")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "puppet", "jid", "avatar", "displayname", "name_quality", "custom_mxid", "access_token", "next_batch", "avatar_url", "enable_presence", "enable_receipts")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "user_portal", "user_jid", "portal_jid", "portal_receiver", "in_community")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "message", "chat_jid", "chat_receiver", "jid", "mxid", "sender", "content", "timestamp")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "mx_registrations", "user_id")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "mx_user_profile", "room_id", "user_id", "membership")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "mx_room_state", "room_id", "power_levels")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_account", "account_id", "device_id", "shared", "sync_token", "account")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_message_index", "sender_key", "session_id", `"index"`, "event_id", "timestamp")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_tracked_user", "user_id")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_device", "user_id", "device_id", "identity_key", "signing_key", "trust", "deleted", "name")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_olm_session", "account_id", "session_id", "sender_key", "session", "created_at", "last_used")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_megolm_inbound_session", "account_id", "session_id", "sender_key", "signing_key", "room_id", "session", "forwarding_chains")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = migrateTable(old, new, "crypto_megolm_outbound_session", "account_id", "room_id", "session_id", "session", "shared", "max_messages", "message_count", "max_age", "created_at", "last_used")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// }
|
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,31 +17,33 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
)
|
||||
|
||||
// JID is the puppet or the group
|
||||
// GMID is the puppet or the group
|
||||
// Receiver is the "Other Person" in a DM or the group itself in a group
|
||||
type PortalKey struct {
|
||||
JID types.GroupMeID `gorm:"primaryKey"`
|
||||
Receiver types.GroupMeID `gorm:"primaryKey"`
|
||||
GMID groupme.ID
|
||||
Receiver groupme.ID
|
||||
}
|
||||
|
||||
func ParsePortalKey(inp types.GroupMeID) *PortalKey {
|
||||
func ParsePortalKey(inp string) *PortalKey {
|
||||
parts := strings.Split(inp, "+")
|
||||
|
||||
if len(parts) == 1 {
|
||||
if i, err := strconv.Atoi(inp); i == 0 || err != nil {
|
||||
return nil
|
||||
}
|
||||
return &PortalKey{inp, inp}
|
||||
return &PortalKey{groupme.ID(inp), groupme.ID(inp)}
|
||||
} else if len(parts) == 2 {
|
||||
if i, err := strconv.Atoi(parts[0]); i == 0 || err != nil {
|
||||
return nil
|
||||
@ -51,38 +53,38 @@ func ParsePortalKey(inp types.GroupMeID) *PortalKey {
|
||||
}
|
||||
|
||||
return &PortalKey{
|
||||
JID: parts[1],
|
||||
Receiver: parts[0],
|
||||
GMID: groupme.ID(parts[1]),
|
||||
Receiver: groupme.ID(parts[0]),
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func GroupPortalKey(jid types.GroupMeID) PortalKey {
|
||||
func GroupPortalKey(gmid groupme.ID) PortalKey {
|
||||
return PortalKey{
|
||||
JID: jid,
|
||||
Receiver: jid,
|
||||
GMID: gmid,
|
||||
Receiver: gmid,
|
||||
}
|
||||
}
|
||||
|
||||
func NewPortalKey(jid, receiver types.GroupMeID) PortalKey {
|
||||
func NewPortalKey(gmid, receiver groupme.ID) PortalKey {
|
||||
return PortalKey{
|
||||
JID: jid,
|
||||
GMID: gmid,
|
||||
Receiver: receiver,
|
||||
}
|
||||
}
|
||||
|
||||
func (key PortalKey) String() string {
|
||||
if key.Receiver == key.JID {
|
||||
return key.JID
|
||||
if key.Receiver == key.GMID {
|
||||
return key.GMID.String()
|
||||
}
|
||||
return key.JID + "+" + key.Receiver
|
||||
return key.GMID.String() + "+" + key.Receiver.String()
|
||||
}
|
||||
|
||||
func (key PortalKey) IsPrivate() bool {
|
||||
//also see FindPrivateChats
|
||||
return key.JID != key.Receiver
|
||||
return key.GMID != key.Receiver
|
||||
}
|
||||
|
||||
type PortalQuery struct {
|
||||
@ -97,83 +99,86 @@ func (pq *PortalQuery) New() *Portal {
|
||||
}
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetAll() []*Portal {
|
||||
return pq.getAll(pq.db.DB)
|
||||
const (
|
||||
portalColumns = "gmid, receiver, mxid, name, name_set, topic, topic_set, avatar, avatar_url, avatar_set, encrypted"
|
||||
getAllPortalsQuery = "SELECT " + portalColumns + " FROM portal"
|
||||
getPortalByGMIDQuery = getAllPortalsQuery + " WHERE gmid=$1 AND receiver=$2"
|
||||
getPortalByMXIDQuery = getAllPortalsQuery + " WHERE mxid=$1"
|
||||
getAllPortalsByGMID = getAllPortalsQuery + " WHERE gmid=$1"
|
||||
getAllPrivateChats = getAllPortalsQuery + " WHERE receiver=$1 AND receiver <> gmid"
|
||||
)
|
||||
|
||||
func (pq *PortalQuery) GetAll() []*Portal {
|
||||
return pq.getAll(getAllPortalsQuery)
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetByJID(key PortalKey) *Portal {
|
||||
return pq.get(pq.db.DB.Where("jid = ? AND receiver = ?", key.JID, key.Receiver))
|
||||
|
||||
func (pq *PortalQuery) GetByGMID(key PortalKey) *Portal {
|
||||
return pq.get(getPortalByGMIDQuery, key.GMID, key.Receiver)
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetByMXID(mxid id.RoomID) *Portal {
|
||||
return pq.get(pq.db.DB.Where("mxid = ?", mxid))
|
||||
return pq.get(getPortalByMXIDQuery, mxid)
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetAllByJID(jid types.GroupMeID) []*Portal {
|
||||
return pq.getAll(pq.db.DB.Where("jid = ?", jid))
|
||||
|
||||
func (pq *PortalQuery) GetAllByGMID(gmid groupme.ID) []*Portal {
|
||||
return pq.getAll(getAllPortalsByGMID, gmid)
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) FindPrivateChats(receiver types.GroupMeID) []*Portal {
|
||||
//also see IsPrivate
|
||||
return pq.getAll(pq.db.DB.Where("receiver = ? AND receiver <> jid", receiver))
|
||||
|
||||
func (pq *PortalQuery) FindPrivateChats(receiver groupme.ID) []*Portal {
|
||||
return pq.getAll(getAllPrivateChats, receiver)
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) getAll(db *gorm.DB) (portals []*Portal) {
|
||||
ans := db.Find(&portals)
|
||||
if ans.Error != nil || len(portals) == 0 {
|
||||
func (pq *PortalQuery) getAll(query string, args ...any) (portals []*Portal) {
|
||||
rows, err := pq.db.Query(query, args...)
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
for _, i := range portals {
|
||||
i.db = pq.db
|
||||
i.log = pq.log
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
portals = append(portals, pq.New().Scan(rows))
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) get(db *gorm.DB) *Portal {
|
||||
var portal Portal
|
||||
ans := db.Limit(1).Find(&portal)
|
||||
if ans.Error != nil || db.RowsAffected == 0 {
|
||||
func (pq *PortalQuery) get(query string, args ...interface{}) *Portal {
|
||||
row := pq.db.QueryRow(query, args...)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
portal.db = pq.db
|
||||
portal.log = pq.log
|
||||
|
||||
return &portal
|
||||
return pq.New().Scan(row)
|
||||
}
|
||||
|
||||
type Portal struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
Key PortalKey `gorm:"primaryKey;embedded"`
|
||||
Key PortalKey
|
||||
MXID id.RoomID
|
||||
|
||||
Name string
|
||||
NameSet bool
|
||||
Topic string
|
||||
TopicSet bool
|
||||
Avatar string
|
||||
AvatarURL types.ContentURI
|
||||
Encrypted bool `gorm:"notNull;default:false"`
|
||||
AvatarURL id.ContentURI
|
||||
AvatarSet bool
|
||||
Encrypted bool
|
||||
}
|
||||
|
||||
// func (portal *Portal) Scan(row Scannable) *Portal {
|
||||
// var mxid, avatarURL sql.NullString
|
||||
// err := row.Scan(&portal.Key.JID, &portal.Key.Receiver, &mxid, &portal.Name, &portal.Topic, &portal.Avatar, &avatarURL, &portal.Encrypted)
|
||||
// if err != nil {
|
||||
// if err != sql.ErrNoRows {
|
||||
// portal.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// portal.MXID = id.RoomID(mxid.String)
|
||||
// portal.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
// return portal
|
||||
// }
|
||||
func (portal *Portal) Scan(row dbutil.Scannable) *Portal {
|
||||
var mxid, avatarURL sql.NullString
|
||||
|
||||
err := row.Scan(&portal.Key.GMID, &portal.Key.Receiver, &mxid, &portal.Name, &portal.NameSet, &portal.Topic, &portal.TopicSet, &portal.Avatar, &avatarURL, &portal.AvatarSet, &portal.Encrypted)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
portal.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
portal.MXID = id.RoomID(mxid.String)
|
||||
portal.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
return portal
|
||||
}
|
||||
|
||||
func (portal *Portal) mxidPtr() *id.RoomID {
|
||||
if len(portal.MXID) > 0 {
|
||||
@ -183,50 +188,40 @@ func (portal *Portal) mxidPtr() *id.RoomID {
|
||||
}
|
||||
|
||||
func (portal *Portal) Insert() {
|
||||
|
||||
ans := portal.db.Create(&portal)
|
||||
print("beware of types")
|
||||
if ans.Error != nil {
|
||||
portal.log.Warnfln("Failed to insert %s: %v", portal.Key, ans.Error)
|
||||
_, err := portal.db.Exec(fmt.Sprintf(`
|
||||
INSERT INTO portal (%s)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
`, portalColumns),
|
||||
portal.Key.GMID, portal.Key.Receiver, portal.mxidPtr(), portal.Name, portal.NameSet, portal.Topic, portal.TopicSet, portal.Avatar, portal.AvatarURL.String(), portal.AvatarSet, portal.Encrypted)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to insert %s: %v", portal.Key, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) Update() {
|
||||
ans := portal.db.Where("jid = ? AND receiver = ?", portal.Key.JID, portal.Key.Receiver).Save(&portal)
|
||||
print("check .model vs not")
|
||||
|
||||
if ans.Error != nil {
|
||||
portal.log.Warnfln("Failed to update %s: %v", portal.Key, ans.Error)
|
||||
func (portal *Portal) Update(txn dbutil.Transaction) {
|
||||
query := `
|
||||
UPDATE portal
|
||||
SET mxid=$1, name=$2, name_set=$3, topic=$4, topic_set=$5, avatar=$6, avatar_url=$7, avatar_set=$8, encrypted=$9
|
||||
WHERE gmid=$10 AND receiver=$11
|
||||
`
|
||||
args := []interface{}{
|
||||
portal.mxidPtr(), portal.Name, portal.NameSet, portal.Topic, portal.TopicSet, portal.Avatar, portal.AvatarURL.String(),
|
||||
portal.AvatarSet, portal.Encrypted, portal.Key.GMID, portal.Key.Receiver,
|
||||
}
|
||||
var err error
|
||||
if txn != nil {
|
||||
_, err = txn.Exec(query, args...)
|
||||
} else {
|
||||
_, err = portal.db.Exec(query, args...)
|
||||
}
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to update %s: %v", portal.Key, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) Delete() {
|
||||
ans := portal.db.Where("jid = ? AND receiver = ?", portal.Key.JID, portal.Key.Receiver).Delete(&portal)
|
||||
if ans.Error != nil {
|
||||
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) GetUserIDs() []id.UserID {
|
||||
//TODO: gorm this
|
||||
rows, err := portal.db.Raw(`SELECT "users".mxid FROM "users", user_portals
|
||||
WHERE "users".jid=user_portals.user_jid
|
||||
AND user_portals.portal_jid = ?
|
||||
AND user_portals.portal_receiver = ?`,
|
||||
portal.Key.JID, portal.Key.Receiver).Rows()
|
||||
_, err := portal.db.Exec("DELETE FROM portal WHERE gmid=$1 AND receiver=$2", portal.Key.GMID, portal.Key.Receiver)
|
||||
if err != nil {
|
||||
portal.log.Debugln("Failed to get portal user ids:", err)
|
||||
return nil
|
||||
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, err)
|
||||
}
|
||||
var userIDs []id.UserID
|
||||
for rows.Next() {
|
||||
var userID id.UserID
|
||||
err = rows.Scan(&userID)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to scan row:", err)
|
||||
continue
|
||||
}
|
||||
userIDs = append(userIDs, userID)
|
||||
}
|
||||
return userIDs
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,11 +17,14 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"go.mau.fi/util/dbutil"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
)
|
||||
|
||||
type PuppetQuery struct {
|
||||
@ -34,120 +37,126 @@ func (pq *PuppetQuery) New() *Puppet {
|
||||
db: pq.db,
|
||||
log: pq.log,
|
||||
|
||||
EnablePresence: true,
|
||||
EnableReceipts: true,
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
puppetColumns = "gmid, displayname, name_set, avatar, avatar_url, avatar_set, custom_mxid, access_token, next_batch, enable_receipts"
|
||||
getAllPuppetsQuery = "SELECT " + puppetColumns + " FROM puppet"
|
||||
getPuppetQuery = getAllPuppetsQuery + " WHERE gmid=$1"
|
||||
getPuppetByCustomMXIDQuery = getAllPuppetsQuery + " WHERE custom_mxid=$1"
|
||||
getAllPuppetsWithCustomMXIDQuery = getAllPuppetsQuery + " WHERE custom_mxid<>''"
|
||||
)
|
||||
|
||||
func (pq *PuppetQuery) GetAll() (puppets []*Puppet) {
|
||||
ans := pq.db.Find(&puppets)
|
||||
if ans.Error != nil || len(puppets) == 0 {
|
||||
rows, err := pq.db.Query(getAllPuppetsQuery)
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
for _, puppet := range puppets {
|
||||
pq.initializePuppet(puppet)
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
puppets = append(puppets, pq.New().Scan(rows))
|
||||
}
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// puppets = append(puppets, pq.New().Scan(rows))
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) Get(jid types.GroupMeID) *Puppet {
|
||||
puppet := Puppet{}
|
||||
ans := pq.db.Where("jid = ?", jid).Limit(1).Find(&puppet)
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
func (pq *PuppetQuery) Get(gmid groupme.ID) *Puppet {
|
||||
row := pq.db.QueryRow(getPuppetQuery, gmid)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
pq.initializePuppet(&puppet)
|
||||
return &puppet
|
||||
return pq.New().Scan(row)
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) GetByCustomMXID(mxid id.UserID) *Puppet {
|
||||
puppet := Puppet{}
|
||||
ans := pq.db.Where("custom_mxid = ?", mxid).Limit(1).Find(&puppet)
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
row := pq.db.QueryRow(getPuppetByCustomMXIDQuery, mxid)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
pq.initializePuppet(&puppet)
|
||||
return &puppet
|
||||
return pq.New().Scan(row)
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) GetAllWithCustomMXID() (puppets []*Puppet) {
|
||||
|
||||
ans := pq.db.Find(&puppets, "custom_mxid <> ''")
|
||||
if ans.Error != nil || len(puppets) != 0 {
|
||||
rows, err := pq.db.Query(getAllPuppetsWithCustomMXIDQuery)
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
for _, puppet := range puppets {
|
||||
pq.initializePuppet(puppet)
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
puppets = append(puppets, pq.New().Scan(rows))
|
||||
}
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// puppets = append(puppets, pq.New().Scan(rows))
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) initializePuppet(p *Puppet) {
|
||||
p.db = pq.db
|
||||
p.log = pq.log
|
||||
}
|
||||
|
||||
//Puppet is comment
|
||||
// Puppet is comment
|
||||
type Puppet struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
JID types.GroupMeID `gorm:"primaryKey"`
|
||||
//Avatar string
|
||||
//AvatarURL types.ContentURI
|
||||
//Displayname string
|
||||
//NameQuality int8
|
||||
GMID groupme.ID
|
||||
|
||||
CustomMXID id.UserID `gorm:"column:custom_mxid;"`
|
||||
Displayname string
|
||||
NameSet bool
|
||||
|
||||
Avatar string
|
||||
AvatarURL id.ContentURI
|
||||
AvatarSet bool
|
||||
|
||||
CustomMXID id.UserID
|
||||
AccessToken string
|
||||
NextBatch string
|
||||
EnablePresence bool `gorm:"notNull;default:true"`
|
||||
EnableReceipts bool `gorm:"notNull;default:true"`
|
||||
EnableReceipts bool
|
||||
}
|
||||
|
||||
// func (puppet *Puppet) Scan(row Scannable) *Puppet {
|
||||
// var displayname, avatar, avatarURL, customMXID, accessToken, nextBatch sql.NullString
|
||||
// var quality sql.NullInt64
|
||||
// var enablePresence, enableReceipts sql.NullBool
|
||||
// err := row.Scan(&puppet.JID, &avatar, &avatarURL, &displayname, &quality, &customMXID, &accessToken, &nextBatch, &enablePresence, &enableReceipts)
|
||||
// if err != nil {
|
||||
// if err != sql.ErrNoRows {
|
||||
// puppet.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// puppet.Displayname = displayname.String
|
||||
// puppet.Avatar = avatar.String
|
||||
// puppet.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
// puppet.NameQuality = int8(quality.Int64)
|
||||
// puppet.CustomMXID = id.UserID(customMXID.String)
|
||||
// puppet.AccessToken = accessToken.String
|
||||
// puppet.NextBatch = nextBatch.String
|
||||
// puppet.EnablePresence = enablePresence.Bool
|
||||
// puppet.EnableReceipts = enableReceipts.Bool
|
||||
// return puppet
|
||||
// }
|
||||
func (puppet *Puppet) Scan(row dbutil.Scannable) *Puppet {
|
||||
var displayname, avatar, avatarURL, customMXID, accessToken, nextBatch sql.NullString
|
||||
var enableReceipts, nameSet, avatarSet sql.NullBool
|
||||
var gmid string
|
||||
err := row.Scan(&gmid, &displayname, &nameSet, &avatar, &avatarURL, &avatarSet, &customMXID, &accessToken, &nextBatch, &enableReceipts)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
puppet.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
puppet.GMID = groupme.ID(gmid)
|
||||
puppet.Displayname = displayname.String
|
||||
puppet.NameSet = nameSet.Bool
|
||||
puppet.Avatar = avatar.String
|
||||
puppet.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
puppet.AvatarSet = avatarSet.Bool
|
||||
puppet.CustomMXID = id.UserID(customMXID.String)
|
||||
puppet.AccessToken = accessToken.String
|
||||
puppet.NextBatch = nextBatch.String
|
||||
puppet.EnableReceipts = enableReceipts.Bool
|
||||
return puppet
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Insert() {
|
||||
// _, err := puppet.db.Exec("INSERT INTO puppet (jid, avatar, avatar_url, displayname, name_quality, custom_mxid, access_token, next_batch, enable_presence, enable_receipts) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
// puppet.JID, puppet.Avatar, puppet.AvatarURL.String(), puppet.Displayname, puppet.NameQuality, puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnablePresence, puppet.EnableReceipts)
|
||||
ans := puppet.db.Create(&puppet)
|
||||
if ans.Error != nil {
|
||||
puppet.log.Warnfln("Failed to insert %s: %v", puppet.JID, ans.Error)
|
||||
_, err := puppet.db.Exec(`
|
||||
INSERT INTO puppet (gmid, avatar, avatar_url, avatar_set, displayname, name_set,
|
||||
custom_mxid, access_token, next_batch, enable_receipts)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
`, puppet.GMID, puppet.Avatar, puppet.AvatarURL.String(), puppet.AvatarSet, puppet.Displayname,
|
||||
puppet.NameSet, puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch,
|
||||
puppet.EnableReceipts,
|
||||
)
|
||||
if err != nil {
|
||||
puppet.log.Warnfln("Failed to insert %s: %v", puppet.GMID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Update() {
|
||||
ans := puppet.db.Where("jid = ?", puppet.JID).Updates(&puppet)
|
||||
if ans.Error != nil {
|
||||
puppet.log.Warnfln("Failed to update %s->%s: %v", puppet.JID, ans.Error)
|
||||
_, err := puppet.db.Exec(`
|
||||
UPDATE puppet
|
||||
SET displayname=$1, name_set=$2, avatar=$3, avatar_url=$4, avatar_set=$5, custom_mxid=$6,
|
||||
access_token=$7, next_batch=$8, enable_receipts=$9
|
||||
WHERE GMID=$10
|
||||
`, puppet.Displayname, puppet.NameSet, puppet.Avatar, puppet.AvatarURL.String(), puppet.AvatarSet,
|
||||
puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnableReceipts,
|
||||
puppet.GMID)
|
||||
if err != nil {
|
||||
puppet.log.Warnfln("Failed to update %s: %v", puppet.GMID, err)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"go.mau.fi/util/dbutil"
|
||||
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
@ -18,56 +22,81 @@ func (mq *ReactionQuery) New() *Reaction {
|
||||
}
|
||||
}
|
||||
|
||||
func (mq *ReactionQuery) GetByJID(jid types.GroupMeID) (reactions []*Reaction) {
|
||||
ans := mq.db.Model(&Reaction{}).
|
||||
Preload("Puppet"). // TODO: Do this in seperate function?
|
||||
Where("message_jid = ?", jid).
|
||||
Limit(1).Find(&reactions)
|
||||
const (
|
||||
getReactionByTargetGMIDQuery = `
|
||||
SELECT chat_gmid, chat_receiver, target_gmid, sender, mxid, gmid
|
||||
FROM reaction
|
||||
WHERE chat_gmid=$1 AND chat_receiver=$2 AND target_gmid=$3 AND sender=$4
|
||||
`
|
||||
getReactionByMXIDQuery = `
|
||||
SELECT chat_gmid, chat_receiver, target_gmid, sender, mxid, gmid FROM reaction
|
||||
WHERE mxid=$1
|
||||
`
|
||||
upsertReactionQuery = `
|
||||
INSERT INTO reaction (chat_gmid, chat_receiver, target_gmid, sender, mxid, gmid)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (chat_gmid, chat_receiver, target_gmid, sender)
|
||||
DO UPDATE SET mxid=excluded.mxid, gmid=excluded.gmid
|
||||
`
|
||||
deleteReactionQuery = `
|
||||
DELETE FROM reaction WHERE chat_gmid=$1 AND chat_receiver=$2 AND target_gmid=$3 AND sender=$4 AND mxid=$5
|
||||
`
|
||||
)
|
||||
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, reaction := range reactions {
|
||||
reaction.db = mq.db
|
||||
reaction.log = mq.log
|
||||
}
|
||||
|
||||
return
|
||||
func (rq *ReactionQuery) GetByTargetGMID(chat PortalKey, gmid groupme.ID, sender groupme.ID) *Reaction {
|
||||
return rq.maybeScan(rq.db.QueryRow(getReactionByTargetGMIDQuery, chat.GMID, chat.Receiver, gmid, sender))
|
||||
}
|
||||
|
||||
// ans := mq.db.Model(&Reaction{}).
|
||||
// Joins("INNER JOIN users on users.mxid = reactions.user_mxid").
|
||||
// Where("reactions.message_jid = ? AND users.jid = ?", jid, uid).
|
||||
// Limit(1).Find(&reactions)
|
||||
func (rq *ReactionQuery) GetByMXID(mxid id.EventID) *Reaction {
|
||||
return rq.maybeScan(rq.db.QueryRow(getReactionByMXIDQuery, mxid))
|
||||
}
|
||||
|
||||
func (rq *ReactionQuery) maybeScan(row *sql.Row) *Reaction {
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
return rq.New().Scan(row)
|
||||
}
|
||||
|
||||
type Reaction struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
MXID id.EventID `gorm:"primaryKey"`
|
||||
|
||||
//Message
|
||||
MessageJID types.GroupMeID `gorm:"notNull"`
|
||||
MessageMXID id.EventID `gorm:"notNull"`
|
||||
|
||||
Message Message `gorm:"foreignKey:MessageMXID,MessageJID;references:MXID,JID;"`
|
||||
|
||||
//User
|
||||
PuppetJID types.GroupMeID `gorm:"notNull"`
|
||||
Puppet Puppet `gorm:"foreignKey:PuppetJID;references:jid;"`
|
||||
Chat PortalKey
|
||||
TargetGMID groupme.ID
|
||||
Sender groupme.ID
|
||||
MXID id.EventID
|
||||
GMID groupme.ID
|
||||
}
|
||||
|
||||
func (reaction *Reaction) Insert() {
|
||||
ans := reaction.db.Create(&reaction)
|
||||
if ans.Error != nil {
|
||||
reaction.log.Warnfln("Failed to insert %s@%s: %v", reaction.MXID, reaction.MessageJID, ans.Error)
|
||||
func (reaction *Reaction) Scan(row dbutil.Scannable) *Reaction {
|
||||
err := row.Scan(&reaction.Chat.GMID, &reaction.Chat.Receiver, &reaction.TargetGMID, &reaction.Sender, &reaction.MXID, &reaction.GMID)
|
||||
if err != nil {
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
reaction.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return reaction
|
||||
}
|
||||
|
||||
func (reaction *Reaction) Upsert(txn dbutil.Execable) {
|
||||
if txn == nil {
|
||||
txn = reaction.db
|
||||
}
|
||||
_, err := txn.Exec(upsertReactionQuery, reaction.Chat.GMID, reaction.Chat.Receiver, reaction.TargetGMID, reaction.Sender, reaction.MXID, reaction.GMID)
|
||||
if err != nil {
|
||||
reaction.log.Warnfln("Failed to upsert reaction to %s@%s by %s: %v", reaction.Chat, reaction.TargetGMID, reaction.Sender, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (reaction *Reaction) GetTarget() *Message {
|
||||
return reaction.db.Message.GetByGMID(reaction.Chat, reaction.TargetGMID)
|
||||
}
|
||||
|
||||
func (reaction *Reaction) Delete() {
|
||||
ans := reaction.db.Delete(&reaction)
|
||||
if ans.Error != nil {
|
||||
reaction.log.Warnfln("Failed to insert %s@%s: %v", reaction.MXID, reaction.MessageJID, ans.Error)
|
||||
_, err := reaction.db.Exec(deleteReactionQuery, reaction.Chat.GMID, reaction.Chat.Receiver, reaction.TargetGMID, reaction.Sender, reaction.MXID)
|
||||
if err != nil {
|
||||
reaction.log.Warnfln("Failed to delete reaction %s: %v", reaction.MXID, err)
|
||||
}
|
||||
}
|
||||
|
@ -1,368 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 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 database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type SQLStateStore struct {
|
||||
*appservice.TypingStateStore
|
||||
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
Typing map[id.RoomID]map[id.UserID]int64
|
||||
typingLock sync.RWMutex
|
||||
}
|
||||
|
||||
type mxRegistered struct {
|
||||
UserID string `gorm:"primaryKey"`
|
||||
}
|
||||
|
||||
var _ appservice.StateStore = (*SQLStateStore)(nil)
|
||||
|
||||
func NewSQLStateStore(db *Database) *SQLStateStore {
|
||||
return &SQLStateStore{
|
||||
TypingStateStore: appservice.NewTypingStateStore(),
|
||||
db: db,
|
||||
log: db.log.Sub("StateStore"),
|
||||
}
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) IsRegistered(userID id.UserID) bool {
|
||||
v := mxRegistered{UserID: userID.String()}
|
||||
var count int64
|
||||
ans := store.db.Model(&mxRegistered{}).Where(&v).Count(&count)
|
||||
|
||||
if errors.Is(ans.Error, gorm.ErrRecordNotFound) {
|
||||
return false
|
||||
}
|
||||
if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to scan registration existence for %s: %v", userID, ans.Error)
|
||||
}
|
||||
return count >= 1
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) MarkRegistered(userID id.UserID) {
|
||||
|
||||
ans := store.db.Create(mxRegistered{userID.String()})
|
||||
|
||||
if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to mark %s as registered: %v", userID, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
type MxUserProfile struct {
|
||||
RoomID string `gorm:"primaryKey"`
|
||||
UserID string `gorm:"primaryKey"`
|
||||
Membership string `gorm:"notNull"`
|
||||
|
||||
DisplayName string
|
||||
AvatarURL string
|
||||
Avatar string
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetRoomMembers(roomID id.RoomID) map[id.UserID]*event.MemberEventContent {
|
||||
members := make(map[id.UserID]*event.MemberEventContent)
|
||||
var users []MxUserProfile
|
||||
ans := store.db.Where("room_id = ?", roomID.String()).Find(&users)
|
||||
if ans.Error != nil {
|
||||
return members
|
||||
}
|
||||
|
||||
var userID id.UserID
|
||||
var member event.MemberEventContent
|
||||
for _, user := range users {
|
||||
// if err != nil {
|
||||
// store.log.Warnfln("Failed to scan member in %s: %v", roomID, err)
|
||||
// continue
|
||||
// }
|
||||
userID = id.UserID(user.UserID)
|
||||
member = event.MemberEventContent{
|
||||
Membership: event.Membership(user.Membership),
|
||||
Displayname: user.DisplayName,
|
||||
AvatarURL: id.ContentURIString(user.AvatarURL),
|
||||
}
|
||||
|
||||
members[userID] = &member
|
||||
}
|
||||
return members
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetMembership(roomID id.RoomID, userID id.UserID) event.Membership {
|
||||
var user MxUserProfile
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
|
||||
membership := event.MembershipLeave
|
||||
if ans.Error != nil && ans.Error != gorm.ErrRecordNotFound {
|
||||
store.log.Warnfln("Failed to scan membership of %s in %s: %v", userID, roomID, ans.Error)
|
||||
}
|
||||
membership = event.Membership(user.Membership)
|
||||
|
||||
return membership
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetMember(roomID id.RoomID, userID id.UserID) *event.MemberEventContent {
|
||||
member, ok := store.TryGetMember(roomID, userID)
|
||||
if !ok {
|
||||
member.Membership = event.MembershipLeave
|
||||
}
|
||||
return member
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) TryGetMember(roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, bool) {
|
||||
var user MxUserProfile
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
|
||||
|
||||
if ans.Error != nil && ans.Error != gorm.ErrRecordNotFound {
|
||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, ans.Error)
|
||||
}
|
||||
eventMember := event.MemberEventContent{
|
||||
Membership: event.Membership(user.Membership),
|
||||
Displayname: user.DisplayName,
|
||||
AvatarURL: id.ContentURIString(user.AvatarURL),
|
||||
}
|
||||
|
||||
return &eventMember, ans.Error != nil
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) TryGetMemberRaw(roomID id.RoomID, userID id.UserID) (user MxUserProfile, err bool) {
|
||||
user.RoomID = roomID.String()
|
||||
user.UserID = userID.String()
|
||||
|
||||
ans := store.db.Limit(1).Find(&user)
|
||||
|
||||
if ans.Error == gorm.ErrRecordNotFound {
|
||||
err = true
|
||||
return
|
||||
} else if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, ans.Error)
|
||||
err = true
|
||||
return
|
||||
}
|
||||
|
||||
return user, false
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) SetMemberRaw(member *MxUserProfile) {
|
||||
ans := store.db.Clauses(clause.OnConflict{
|
||||
UpdateAll: true,
|
||||
}).Create(member)
|
||||
|
||||
if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", member.UserID, member.RoomID, member, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) FindSharedRooms(userID id.UserID) (rooms []id.RoomID) {
|
||||
|
||||
rows, err := store.db.Table("mx_user_profile").Select("room_id").
|
||||
Joins("LEFT JOIN portal ON portal.mxid=mx_user_profile.room_id").
|
||||
Where("user_id = ? AND portal.encrypted=true", userID).Rows()
|
||||
defer rows.Close()
|
||||
|
||||
if err != nil {
|
||||
store.log.Warnfln("Failed to query shared rooms with %s: %v", userID, err)
|
||||
return
|
||||
}
|
||||
print("running maybe maybe code f937060306")
|
||||
for rows.Next() {
|
||||
var roomID id.RoomID
|
||||
err := rows.Scan(&roomID)
|
||||
if err != nil {
|
||||
store.log.Warnfln("Failed to scan room ID: %v", err)
|
||||
} else {
|
||||
rooms = append(rooms, roomID)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) IsInRoom(roomID id.RoomID, userID id.UserID) bool {
|
||||
return store.IsMembership(roomID, userID, "join")
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) IsInvited(roomID id.RoomID, userID id.UserID) bool {
|
||||
return store.IsMembership(roomID, userID, "join", "invite")
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) IsMembership(roomID id.RoomID, userID id.UserID, allowedMemberships ...event.Membership) bool {
|
||||
membership := store.GetMembership(roomID, userID)
|
||||
for _, allowedMembership := range allowedMemberships {
|
||||
if allowedMembership == membership {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) SetMembership(roomID id.RoomID, userID id.UserID, membership event.Membership) {
|
||||
var err error
|
||||
user := MxUserProfile{
|
||||
RoomID: roomID.String(),
|
||||
UserID: userID.String(),
|
||||
Membership: string(membership),
|
||||
}
|
||||
print("weird thing 2 502650285")
|
||||
|
||||
ans := store.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "room_id"}, {Name: "user_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"membership"}),
|
||||
}).Create(&user)
|
||||
|
||||
if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", userID, roomID, membership, err)
|
||||
}
|
||||
}
|
||||
func (store *SQLStateStore) SetMember(roomID id.RoomID, userID id.UserID, member *event.MemberEventContent) {
|
||||
|
||||
user := MxUserProfile{
|
||||
RoomID: roomID.String(),
|
||||
UserID: userID.String(),
|
||||
Membership: string(member.Membership),
|
||||
DisplayName: member.Displayname,
|
||||
// AvatarURL: string(member.AvatarURL),//try ignoring
|
||||
}
|
||||
ans := store.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "room_id"}, {Name: "user_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"membership", "display_name"}),
|
||||
}).Create(&user)
|
||||
|
||||
if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", userID, roomID, member, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) SetPowerLevels(roomID id.RoomID, levels *event.PowerLevelsEventContent) {
|
||||
// levelsBytes, err := json.Marshal(levels)
|
||||
// if err != nil {
|
||||
// store.log.Errorfln("Failed to marshal power levels of %s: %v", roomID, err)
|
||||
// return
|
||||
// }
|
||||
// if store.db.dialect == "postgres" {
|
||||
// _, err = store.db.Exec(`INSERT INTO mx_room_state (room_id, power_levels) VALUES ($1, $2)
|
||||
// ON CONFLICT (room_id) DO UPDATE SET power_levels=$2`, roomID, levelsBytes)
|
||||
// } else if store.db.dialect == "sqlite3" {
|
||||
// _, err = store.db.Exec("INSERT OR REPLACE INTO mx_room_state (room_id, power_levels) VALUES ($1, $2)", roomID, levelsBytes)
|
||||
// } else {
|
||||
// err = fmt.Errorf("unsupported dialect %s", store.db.dialect)
|
||||
// }
|
||||
// if err != nil {
|
||||
// store.log.Warnfln("Failed to store power levels of %s: %v", roomID, err)
|
||||
// }
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetPowerLevels(roomID id.RoomID) (levels *event.PowerLevelsEventContent) {
|
||||
// row := store.db.QueryRow("SELECT power_levels FROM mx_room_state WHERE room_id=$1", roomID)
|
||||
// if row == nil {
|
||||
// return
|
||||
// }
|
||||
// var data []byte
|
||||
// err := row.Scan(&data)
|
||||
// if err != nil {
|
||||
// store.log.Errorln("Failed to scan power levels of %s: %v", roomID, err)
|
||||
// return
|
||||
// }
|
||||
// levels = &event.PowerLevelsEventContent{}
|
||||
// err = json.Unmarshal(data, levels)
|
||||
// if err != nil {
|
||||
// store.log.Errorln("Failed to parse power levels of %s: %v", roomID, err)
|
||||
// return nil
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetPowerLevel(roomID id.RoomID, userID id.UserID) int {
|
||||
// if store.db.dialect == "postgres" {
|
||||
// row := store.db.QueryRow(`SELECT
|
||||
// COALESCE((power_levels->'users'->$2)::int, (power_levels->'users_default')::int, 0)
|
||||
// FROM mx_room_state WHERE room_id=$1`, roomID, userID)
|
||||
// if row == nil {
|
||||
// // Power levels not in db
|
||||
// return 0
|
||||
// }
|
||||
// var powerLevel int
|
||||
// err := row.Scan(&powerLevel)
|
||||
// if err != nil {
|
||||
// store.log.Errorln("Failed to scan power level of %s in %s: %v", userID, roomID, err)
|
||||
// }
|
||||
// return powerLevel
|
||||
// }
|
||||
return store.GetPowerLevels(roomID).GetUserLevel(userID)
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetPowerLevelRequirement(roomID id.RoomID, eventType event.Type) int {
|
||||
// if store.db.dialect == "postgres" {
|
||||
// defaultType := "events_default"
|
||||
// defaultValue := 0
|
||||
// if eventType.IsState() {
|
||||
// defaultType = "state_default"
|
||||
// defaultValue = 50
|
||||
// }
|
||||
// row := store.db.QueryRow(`SELECT
|
||||
// COALESCE((power_levels->'events'->$2)::int, (power_levels->'$3')::int, $4)
|
||||
// FROM mx_room_state WHERE room_id=$1`, roomID, eventType.Type, defaultType, defaultValue)
|
||||
// if row == nil {
|
||||
// // Power levels not in db
|
||||
// return defaultValue
|
||||
// }
|
||||
// var powerLevel int
|
||||
// err := row.Scan(&powerLevel)
|
||||
// if err != nil {
|
||||
// store.log.Errorln("Failed to scan power level for %s in %s: %v", eventType, roomID, err)
|
||||
// }
|
||||
// return powerLevel
|
||||
// }
|
||||
return store.GetPowerLevels(roomID).GetEventLevel(eventType)
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) HasPowerLevel(roomID id.RoomID, userID id.UserID, eventType event.Type) bool {
|
||||
// if store.db.dialect == "postgres" {
|
||||
// defaultType := "events_default"
|
||||
// defaultValue := 0
|
||||
// if eventType.IsState() {
|
||||
// defaultType = "state_default"
|
||||
// defaultValue = 50
|
||||
// }
|
||||
// row := store.db.QueryRow(`SELECT
|
||||
// COALESCE((power_levels->'users'->$2)::int, (power_levels->'users_default')::int, 0)
|
||||
// >=
|
||||
// COALESCE((power_levels->'events'->$3)::int, (power_levels->'$4')::int, $5)
|
||||
// FROM mx_room_state WHERE room_id=$1`, roomID, userID, eventType.Type, defaultType, defaultValue)
|
||||
// if row == nil {
|
||||
// // Power levels not in db
|
||||
// return defaultValue == 0
|
||||
// }
|
||||
// var hasPower bool
|
||||
// err := row.Scan(&hasPower)
|
||||
// if err != nil {
|
||||
// store.log.Errorln("Failed to scan power level for %s in %s: %v", eventType, roomID, err)
|
||||
// }
|
||||
// return hasPower
|
||||
// }
|
||||
// return store.GetPowerLevel(roomID, userID) >= store.GetPowerLevelRequirement(roomID, eventType)
|
||||
return false
|
||||
}
|
83
database/upgrades/00-latest-revision.sql
Normal file
83
database/upgrades/00-latest-revision.sql
Normal file
@ -0,0 +1,83 @@
|
||||
-- v0 -> v1: Latest revision
|
||||
|
||||
CREATE TABLE "user" (
|
||||
mxid TEXT PRIMARY KEY,
|
||||
gmid TEXT UNIQUE,
|
||||
|
||||
auth_token TEXT,
|
||||
|
||||
management_room TEXT,
|
||||
space_room TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE portal (
|
||||
gmid TEXT,
|
||||
receiver TEXT,
|
||||
mxid TEXT UNIQUE,
|
||||
|
||||
name TEXT NOT NULL,
|
||||
name_set BOOLEAN NOT NULL DEFAULT false,
|
||||
topic TEXT NOT NULL,
|
||||
topic_set BOOLEAN NOT NULL DEFAULT false,
|
||||
avatar TEXT NOT NULL,
|
||||
avatar_url TEXT,
|
||||
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
||||
encrypted BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
PRIMARY KEY (gmid, receiver)
|
||||
);
|
||||
|
||||
CREATE TABLE puppet (
|
||||
gmid TEXT PRIMARY KEY,
|
||||
displayname TEXT,
|
||||
name_set BOOLEAN NOT NULL DEFAULT false,
|
||||
avatar TEXT,
|
||||
avatar_url TEXT,
|
||||
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
custom_mxid TEXT,
|
||||
access_token TEXT,
|
||||
next_batch TEXT,
|
||||
|
||||
enable_presence BOOLEAN NOT NULL DEFAULT true,
|
||||
enable_receipts BOOLEAN NOT NULL DEFAULT true
|
||||
);
|
||||
|
||||
CREATE TABLE message (
|
||||
chat_gmid TEXT,
|
||||
chat_receiver TEXT,
|
||||
gmid TEXT,
|
||||
mxid TEXT UNIQUE,
|
||||
sender TEXT,
|
||||
timestamp BIGINT,
|
||||
sent BOOLEAN,
|
||||
|
||||
PRIMARY KEY (chat_gmid, chat_receiver, gmid),
|
||||
FOREIGN KEY (chat_gmid, chat_receiver) REFERENCES portal(gmid, receiver) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE reaction (
|
||||
chat_gmid TEXT,
|
||||
chat_receiver TEXT,
|
||||
target_gmid TEXT,
|
||||
sender TEXT,
|
||||
|
||||
mxid TEXT NOT NULL,
|
||||
gmid TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY (chat_gmid, chat_receiver, target_gmid, sender),
|
||||
FOREIGN KEY (chat_gmid, chat_receiver, target_gmid) REFERENCES message(chat_gmid, chat_receiver, gmid)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE user_portal (
|
||||
user_mxid TEXT,
|
||||
portal_gmid TEXT,
|
||||
portal_receiver TEXT,
|
||||
in_space BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
PRIMARY KEY (user_mxid, portal_gmid, portal_receiver),
|
||||
|
||||
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
FOREIGN KEY (portal_gmid, portal_receiver) REFERENCES portal(gmid, receiver) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
@ -1,180 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[0] = upgrade{"Initial schema", func(tx *gorm.DB, ctx context) error {
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS portal (
|
||||
jid VARCHAR(255),
|
||||
receiver VARCHAR(255),
|
||||
mxid VARCHAR(255) UNIQUE,
|
||||
|
||||
name VARCHAR(255) NOT NULL,
|
||||
topic VARCHAR(512) NOT NULL,
|
||||
avatar VARCHAR(255) NOT NULL,
|
||||
avatar_url VARCHAR(255),
|
||||
encrypted BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
PRIMARY KEY (jid, receiver)
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS puppet (
|
||||
jid VARCHAR(255) PRIMARY KEY,
|
||||
avatar VARCHAR(255),
|
||||
displayname VARCHAR(255),
|
||||
name_quality SMALLINT,
|
||||
custom_mxid VARCHAR(255),
|
||||
access_token VARCHAR(1023),
|
||||
next_batch VARCHAR(255),
|
||||
avatar_url VARCHAR(255),
|
||||
enable_presence BOOLEAN NOT NULL DEFAULT true,
|
||||
enable_receipts BOOLEAN NOT NULL DEFAULT true
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS "user" (
|
||||
mxid VARCHAR(255) PRIMARY KEY,
|
||||
jid VARCHAR(255) UNIQUE,
|
||||
|
||||
management_room VARCHAR(255),
|
||||
|
||||
client_id VARCHAR(255),
|
||||
client_token VARCHAR(255),
|
||||
server_token VARCHAR(255),
|
||||
enc_key bytea,
|
||||
mac_key bytea,
|
||||
last_connection BIGINT NOT NULL DEFAULT 0
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS "user_portal" (
|
||||
user_jid VARCHAR(255),
|
||||
portal_jid VARCHAR(255),
|
||||
portal_receiver VARCHAR(255),
|
||||
in_community BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
|
||||
PRIMARY KEY (user_jid, portal_jid, portal_receiver),
|
||||
|
||||
FOREIGN KEY (user_jid) REFERENCES "user"(jid) ON DELETE CASCADE,
|
||||
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS message (
|
||||
chat_jid VARCHAR(255),
|
||||
chat_receiver VARCHAR(255),
|
||||
jid VARCHAR(255),
|
||||
mxid VARCHAR(255) NOT NULL UNIQUE,
|
||||
sender VARCHAR(255) NOT NULL,
|
||||
content bytea NOT NULL,
|
||||
timestamp BIGINT NOT NULL DEFAULT 0,
|
||||
|
||||
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS mx_registrations (
|
||||
user_id VARCHAR(255) PRIMARY KEY
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS mx_room_state (
|
||||
room_id VARCHAR(255) PRIMARY KEY,
|
||||
power_levels TEXT
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS mx_user_profile (
|
||||
room_id VARCHAR(255),
|
||||
user_id VARCHAR(255),
|
||||
membership VARCHAR(15) NOT NULL,
|
||||
PRIMARY KEY (room_id, user_id),
|
||||
displayname TEXT,
|
||||
avatar_url VARCHAR(255)
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_olm_session (
|
||||
session_id CHAR(43) NOT NULL,
|
||||
sender_key CHAR(43) NOT NULL,
|
||||
session bytea NOT NULL,
|
||||
created_at timestamp NOT NULL,
|
||||
last_used timestamp NOT NULL,
|
||||
account_id TEXT NOT NULL,
|
||||
PRIMARY KEY (account_id, session_id)
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_megolm_inbound_session (
|
||||
session_id CHAR(43) NOT NULL,
|
||||
sender_key CHAR(43) NOT NULL,
|
||||
signing_key CHAR(43) NOT NULL,
|
||||
room_id VARCHAR(255) NOT NULL,
|
||||
session bytea NOT NULL,
|
||||
forwarding_chains bytea NOT NULL,
|
||||
account_id TEXT NOT NULL,
|
||||
withheld_code TEXT,
|
||||
withheld_reason TEXT,
|
||||
PRIMARY KEY (account_id, session_id)
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_device (
|
||||
user_id VARCHAR(255),
|
||||
device_id VARCHAR(255),
|
||||
identity_key CHAR(43) NOT NULL,
|
||||
signing_key CHAR(43) NOT NULL,
|
||||
trust SMALLINT NOT NULL,
|
||||
deleted BOOLEAN NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
|
||||
PRIMARY KEY (user_id, device_id)
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_tracked_user (
|
||||
user_id VARCHAR(255) PRIMARY KEY
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_message_index (
|
||||
sender_key CHAR(43),
|
||||
session_id CHAR(43),
|
||||
"index" INTEGER,
|
||||
event_id VARCHAR(255) NOT NULL,
|
||||
timestamp BIGINT NOT NULL,
|
||||
|
||||
PRIMARY KEY (sender_key, session_id, "index")
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_account (
|
||||
device_id VARCHAR(255) PRIMARY KEY,
|
||||
shared BOOLEAN NOT NULL,
|
||||
sync_token TEXT NOT NULL,
|
||||
account bytea NOT NULL,
|
||||
account_id TEXT NOT NULL
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_megolm_outbound_session (
|
||||
room_id VARCHAR(255) PRIMARY KEY,
|
||||
session_id CHAR(43) NOT NULL UNIQUE,
|
||||
session bytea NOT NULL,
|
||||
shared BOOLEAN NOT NULL,
|
||||
max_messages INTEGER NOT NULL,
|
||||
message_count INTEGER NOT NULL,
|
||||
max_age BIGINT NOT NULL,
|
||||
created_at timestamp NOT NULL,
|
||||
last_used timestamp NOT NULL
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_cross_signing_keys (
|
||||
user_id TEXT NOT NULL,
|
||||
usage TEXT NOT NULL,
|
||||
key CHAR(43) NOT NULL,
|
||||
PRIMARY KEY (user_id, usage)
|
||||
)`)
|
||||
|
||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_cross_signing_signatures (
|
||||
signed_user_id TEXT NOT NULL,
|
||||
signed_key TEXT NOT NULL,
|
||||
signer_user_id TEXT NOT NULL,
|
||||
signer_key TEXT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
PRIMARY KEY (signed_user_id, signed_key, signer_user_id, signer_key)
|
||||
)`)
|
||||
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,123 +1,32 @@
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 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 upgrades
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"embed"
|
||||
|
||||
"gorm.io/gorm"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"go.mau.fi/util/dbutil"
|
||||
)
|
||||
|
||||
type Dialect int
|
||||
var Table dbutil.UpgradeTable
|
||||
|
||||
const (
|
||||
Postgres Dialect = iota
|
||||
SQLite
|
||||
)
|
||||
//go:embed *.sql
|
||||
var rawUpgrades embed.FS
|
||||
|
||||
func (dialect Dialect) String() string {
|
||||
switch dialect {
|
||||
case Postgres:
|
||||
return "postgres"
|
||||
case SQLite:
|
||||
return "sqlite3"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type upgradeFunc func(*gorm.DB, context) error
|
||||
|
||||
type context struct {
|
||||
dialect Dialect
|
||||
db *gorm.DB
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
type upgrade struct {
|
||||
message string
|
||||
fn upgradeFunc
|
||||
}
|
||||
|
||||
type version struct {
|
||||
gorm.Model
|
||||
V int
|
||||
}
|
||||
|
||||
const NumberOfUpgrades = 1
|
||||
|
||||
var upgrades [NumberOfUpgrades]upgrade
|
||||
|
||||
var UnsupportedDatabaseVersion = fmt.Errorf("unsupported database version")
|
||||
|
||||
func GetVersion(db *gorm.DB) (int, error) {
|
||||
var ver = version{V: 0}
|
||||
result := db.FirstOrCreate(&ver, &ver)
|
||||
if result.Error != nil {
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) ||
|
||||
errors.Is(result.Error, gorm.ErrInvalidField) {
|
||||
db.Create(&ver)
|
||||
print("create version")
|
||||
|
||||
} else {
|
||||
return 0, result.Error
|
||||
}
|
||||
}
|
||||
return int(ver.V), nil
|
||||
}
|
||||
|
||||
func SetVersion(tx *gorm.DB, newVersion int) error {
|
||||
err := tx.Where("v IS NOT NULL").Delete(&version{})
|
||||
if err.Error != nil {
|
||||
return err.Error
|
||||
}
|
||||
|
||||
val := version{V: newVersion}
|
||||
tx = tx.Create(&val)
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
func Run(log log.Logger, dialectName string, db *gorm.DB) error {
|
||||
var dialect Dialect
|
||||
switch strings.ToLower(dialectName) {
|
||||
case "postgres":
|
||||
dialect = Postgres
|
||||
case "sqlite3":
|
||||
dialect = SQLite
|
||||
default:
|
||||
return fmt.Errorf("unknown dialect %s", dialectName)
|
||||
}
|
||||
|
||||
db.AutoMigrate(&version{})
|
||||
version, err := GetVersion(db)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if version > NumberOfUpgrades {
|
||||
return UnsupportedDatabaseVersion
|
||||
}
|
||||
|
||||
log.Infofln("Database currently on v%d, latest: v%d", version, NumberOfUpgrades)
|
||||
for i, upgrade := range upgrades[version:] {
|
||||
log.Infofln("Upgrading database to v%d: %s", version+i+1, upgrade.message)
|
||||
err = db.Transaction(func(tx *gorm.DB) error {
|
||||
err = upgrade.fn(tx, context{dialect, db, log})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = SetVersion(tx, version+i+1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
func init() {
|
||||
Table.RegisterFS(rawUpgrades)
|
||||
}
|
||||
|
245
database/user.go
245
database/user.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,12 +17,15 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
@ -32,218 +35,114 @@ type UserQuery struct {
|
||||
}
|
||||
|
||||
func (uq *UserQuery) New() *User {
|
||||
return &User{
|
||||
db: uq.db,
|
||||
log: uq.log,
|
||||
}
|
||||
return &User{db: uq.db, log: uq.log}
|
||||
}
|
||||
|
||||
const (
|
||||
userColumns = "gmid, mxid, auth_token, management_room, space_room"
|
||||
getAllUsersQuery = "SELECT " + userColumns + ` FROM "user"`
|
||||
getUserByMXIDQuery = getAllUsersQuery + ` WHERE mxid=$1`
|
||||
getUserByGMIDQuery = getAllUsersQuery + ` WHERE gmid=$1`
|
||||
insertUserQuery = `INSERT INTO "user" (` + userColumns + `) VALUES ($1, $2, $3, $4, $5)`
|
||||
updateUserQurey = `
|
||||
UPDATE "user"
|
||||
SET gmid=$1, auth_token=$2, management_room=$3, space_room=$4
|
||||
WHERE mxid=$5
|
||||
`
|
||||
)
|
||||
|
||||
func (uq *UserQuery) GetAll() (users []*User) {
|
||||
ans := uq.db.Find(&users)
|
||||
if ans.Error != nil || len(users) == 0 {
|
||||
rows, err := uq.db.Query(getAllUsersQuery)
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
for _, i := range users {
|
||||
i.db = uq.db
|
||||
i.log = uq.log
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
users = append(users, uq.New().Scan(rows))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
|
||||
var user User
|
||||
ans := uq.db.Where("mxid = ?", userID).Take(&user)
|
||||
user.db = uq.db
|
||||
user.log = uq.log
|
||||
if ans.Error != nil {
|
||||
row := uq.db.QueryRow(getUserByMXIDQuery, userID)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
return &user
|
||||
return uq.New().Scan(row)
|
||||
}
|
||||
|
||||
func (uq *UserQuery) GetByJID(userID types.GroupMeID) *User {
|
||||
var user User
|
||||
ans := uq.db.Where("jid = ?", userID).Limit(1).Find(&user)
|
||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
||||
func (uq *UserQuery) GetByGMID(gmid groupme.ID) *User {
|
||||
row := uq.db.QueryRow(getUserByGMIDQuery, gmid)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
user.db = uq.db
|
||||
user.log = uq.log
|
||||
|
||||
return &user
|
||||
return uq.New().Scan(row)
|
||||
}
|
||||
|
||||
type User struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
MXID id.UserID `gorm:"primaryKey"`
|
||||
JID types.GroupMeID `gorm:"unique"`
|
||||
Token types.AuthToken
|
||||
|
||||
MXID id.UserID
|
||||
GMID groupme.ID
|
||||
ManagementRoom id.RoomID
|
||||
LastConnection uint64 `gorm:"notNull;default:0"`
|
||||
SpaceRoom id.RoomID
|
||||
|
||||
Token string
|
||||
|
||||
lastReadCache map[PortalKey]time.Time
|
||||
lastReadCacheLock sync.Mutex
|
||||
inSpaceCache map[PortalKey]bool
|
||||
inSpaceCacheLock sync.Mutex
|
||||
}
|
||||
|
||||
//func (user *User) Scan(row Scannable) *User {
|
||||
// var jid, clientID, clientToken, serverToken sql.NullString
|
||||
// var encKey, macKey []byte
|
||||
// err := row.Scan(&user.MXID, &jid, &user.ManagementRoom, &user.LastConnection, &clientID, &clientToken, &serverToken, &encKey, &macKey)
|
||||
// if err != nil {
|
||||
// if err != sql.ErrNoRows {
|
||||
// user.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// if len(jid.String) > 0 && len(clientID.String) > 0 {
|
||||
// user.JID = jid.String + whatsappExt.NewUserSuffix
|
||||
// // user.Session = &whatsapp.Session{
|
||||
// // ClientId: clientID.String,
|
||||
// // ClientToken: clientToken.String,
|
||||
// // ServerToken: serverToken.String,
|
||||
// // EncKey: encKey,
|
||||
// // MacKey: macKey,
|
||||
// // Wid: jid.String + whatsappExt.OldUserSuffix,
|
||||
// // }
|
||||
// } // else {
|
||||
// // user.Session = nil
|
||||
// // }
|
||||
// return user
|
||||
//}
|
||||
func (user *User) Scan(row dbutil.Scannable) *User {
|
||||
var gmid, authToken sql.NullString
|
||||
err := row.Scan(&gmid, &user.MXID, &authToken, &user.ManagementRoom, &user.SpaceRoom)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
user.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(gmid.String) > 0 {
|
||||
user.GMID = groupme.ID(gmid.String)
|
||||
}
|
||||
user.Token = authToken.String
|
||||
return user
|
||||
}
|
||||
|
||||
func stripSuffix(jid types.GroupMeID) string {
|
||||
if len(jid) == 0 {
|
||||
return jid
|
||||
func stripSuffix(gmid groupme.ID) string {
|
||||
if len(gmid) == 0 {
|
||||
return gmid.String()
|
||||
}
|
||||
|
||||
index := strings.IndexRune(jid, '@')
|
||||
index := strings.IndexRune(gmid.String(), '@')
|
||||
if index < 0 {
|
||||
return jid
|
||||
return gmid.String()
|
||||
}
|
||||
|
||||
return jid[:index]
|
||||
return gmid.String()[:index]
|
||||
}
|
||||
|
||||
func (user *User) jidPtr() *string {
|
||||
if len(user.JID) > 0 {
|
||||
str := stripSuffix(user.JID)
|
||||
func (user *User) gmidPtr() *string {
|
||||
if len(user.GMID) > 0 {
|
||||
str := stripSuffix(user.GMID)
|
||||
return &str
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//func (user *User) sessionUnptr() (sess whatsapp.Session) {
|
||||
// // if user.Session != nil {
|
||||
// // sess = *user.Session
|
||||
// // }
|
||||
// return
|
||||
//}
|
||||
|
||||
func (user *User) Insert() {
|
||||
ans := user.db.Create(&user)
|
||||
if ans.Error != nil {
|
||||
user.log.Warnfln("Failed to insert %s: %v", user.MXID, ans.Error)
|
||||
_, err := user.db.Exec(insertUserQuery, user.gmidPtr(), user.MXID, user.Token, user.ManagementRoom, user.SpaceRoom)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to insert %s: %v", user.MXID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) UpdateLastConnection() {
|
||||
user.LastConnection = uint64(time.Now().Unix())
|
||||
user.Update()
|
||||
}
|
||||
|
||||
func (user *User) Update() {
|
||||
ans := user.db.Save(&user)
|
||||
if ans.Error != nil {
|
||||
user.log.Warnfln("Failed to update user: %v", ans.Error)
|
||||
_, err := user.db.Exec(updateUserQurey, user.gmidPtr(), user.Token, user.ManagementRoom, user.SpaceRoom, user.MXID)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to update %s: %v", user.MXID, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type PortalKeyWithMeta struct {
|
||||
PortalKey
|
||||
InCommunity bool
|
||||
}
|
||||
|
||||
type UserPortal struct {
|
||||
UserJID types.GroupMeID `gorm:"primaryKey;"`
|
||||
|
||||
PortalJID types.GroupMeID `gorm:"primaryKey;"`
|
||||
PortalReceiver types.GroupMeID `gorm:"primaryKey;"`
|
||||
|
||||
InCommunity bool `gorm:"notNull;default:false;"`
|
||||
|
||||
User User `gorm:"foreignKey:UserJID;references:jid;constraint:OnDelete:CASCADE;"`
|
||||
Portal Portal `gorm:"foreignKey:PortalJID,PortalReceiver;references:JID,Receiver;constraint:OnDelete:CASCADE;"`
|
||||
}
|
||||
|
||||
func (user *User) SetPortalKeys(newKeys []PortalKeyWithMeta) error {
|
||||
tx := user.db.Begin()
|
||||
ans := tx.Where("user_jid = ?", *user.jidPtr()).Delete(UserPortal{})
|
||||
|
||||
if ans.Error != nil {
|
||||
_ = tx.Rollback()
|
||||
return ans.Error
|
||||
}
|
||||
|
||||
for _, key := range newKeys {
|
||||
ans = tx.Create(&UserPortal{
|
||||
UserJID: *user.jidPtr(),
|
||||
PortalJID: key.JID,
|
||||
PortalReceiver: key.Receiver,
|
||||
InCommunity: key.InCommunity,
|
||||
})
|
||||
if ans.Error != nil {
|
||||
_ = tx.Rollback()
|
||||
return ans.Error
|
||||
}
|
||||
}
|
||||
|
||||
println("portalkey transaction complete")
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func (user *User) IsInPortal(key PortalKey) bool {
|
||||
var count int64
|
||||
user.db.Find(&UserPortal{
|
||||
UserJID: *user.jidPtr(),
|
||||
PortalJID: key.JID,
|
||||
PortalReceiver: key.Receiver,
|
||||
}).Count(&count) //TODO: efficient
|
||||
return count > 0
|
||||
}
|
||||
|
||||
func (user *User) GetPortalKeys() []PortalKey {
|
||||
var up []UserPortal
|
||||
ans := user.db.Where("user_jid = ?", *user.jidPtr()).Find(&up)
|
||||
if ans.Error != nil {
|
||||
user.log.Warnln("Failed to get user portal keys:", ans.Error)
|
||||
return nil
|
||||
}
|
||||
var keys []PortalKey
|
||||
for _, i := range up {
|
||||
key := PortalKey{
|
||||
JID: i.PortalJID,
|
||||
Receiver: i.PortalReceiver,
|
||||
}
|
||||
keys = append(keys, key)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func (user *User) GetInCommunityMap() map[PortalKey]bool {
|
||||
var up []UserPortal
|
||||
ans := user.db.Where("user_jid = ?", *user.jidPtr()).Find(&up)
|
||||
if ans.Error != nil {
|
||||
user.log.Warnln("Failed to get user portal keys:", ans.Error)
|
||||
return nil
|
||||
}
|
||||
keys := make(map[PortalKey]bool)
|
||||
for _, i := range up {
|
||||
key := PortalKey{
|
||||
JID: i.PortalJID,
|
||||
Receiver: i.PortalReceiver,
|
||||
}
|
||||
keys[key] = i.InCommunity
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
69
database/userportal.go
Normal file
69
database/userportal.go
Normal file
@ -0,0 +1,69 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func (user *User) IsInSpace(portal PortalKey) bool {
|
||||
user.inSpaceCacheLock.Lock()
|
||||
defer user.inSpaceCacheLock.Unlock()
|
||||
if cached, ok := user.inSpaceCache[portal]; ok {
|
||||
return cached
|
||||
}
|
||||
var inSpace bool
|
||||
err := user.db.QueryRow("SELECT in_space FROM user_portal WHERE user_mxid=$1 AND portal_gmid=$2 AND portal_receiver=$3", user.MXID, portal.GMID, portal.Receiver).Scan(&inSpace)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
user.log.Warnfln("Failed to scan in space status from user portal table: %v", err)
|
||||
}
|
||||
user.inSpaceCache[portal] = inSpace
|
||||
return inSpace
|
||||
}
|
||||
|
||||
func (user *User) MarkInSpace(portal PortalKey) {
|
||||
user.inSpaceCacheLock.Lock()
|
||||
defer user.inSpaceCacheLock.Unlock()
|
||||
_, err := user.db.Exec(`
|
||||
INSERT INTO user_portal (user_mxid, portal_gmid, portal_receiver, in_space) VALUES ($1, $2, $3, true)
|
||||
ON CONFLICT (user_mxid, portal_gmid, portal_receiver) DO UPDATE SET in_space=true
|
||||
`, user.MXID, portal.GMID, portal.Receiver)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to update in space status: %v", err)
|
||||
} else {
|
||||
user.inSpaceCache[portal] = true
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) SetPortalKeys(newKeys []PortalKey) error {
|
||||
tx, err := user.db.Begin()
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil
|
||||
}
|
||||
ans, err := tx.Query("DELETE FROM user_portal WHERE user_mxid = $1", user.MXID)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
err = ans.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, key := range newKeys {
|
||||
ans, err = tx.Query("INSERT INTO user_portal (user_mxid, portal_gmid, portal_receiver, in_space) VALUES ($1, $2, $3, $4)",
|
||||
user.MXID, key.GMID, key.Receiver, true)
|
||||
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
err = ans.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
println("portalkey transaction complete")
|
||||
return tx.Commit()
|
||||
}
|
11
docker-compose.yaml
Normal file
11
docker-compose.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_DB: groupme
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
@ -5,35 +5,45 @@ homeserver:
|
||||
# The domain of the homeserver (for MXIDs, etc).
|
||||
domain: example.com
|
||||
|
||||
# What software is the homeserver running?
|
||||
# Standard Matrix homeservers like Synapse, Dendrite and Conduit should just use "standard" here.
|
||||
software: standard
|
||||
# The URL to push real-time bridge status to.
|
||||
# If set, the bridge will make POST requests to this URL whenever a user's GroupMe connection state changes.
|
||||
# The bridge will use the appservice as_token to authorize requests.
|
||||
status_endpoint: null
|
||||
# Endpoint for reporting per-message status.
|
||||
message_send_checkpoint_endpoint: null
|
||||
# Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246?
|
||||
async_media: false
|
||||
|
||||
# Application service host/registration related details.
|
||||
# Changing these values requires regeneration of the registration.
|
||||
appservice:
|
||||
# The address that the homeserver can use to connect to this appservice.
|
||||
address: http://localhost:29318
|
||||
address: http://localhost:29328
|
||||
|
||||
# The hostname and port where this appservice should listen.
|
||||
hostname: 0.0.0.0
|
||||
port: 29318
|
||||
port: 29328
|
||||
|
||||
# Database config.
|
||||
database:
|
||||
# The database type. only "postgres" is supported for now. sqlite is TODO
|
||||
# The database type. "sqlite3-fk-wal" and "postgres" are supported.
|
||||
type: postgres
|
||||
# The database URI.
|
||||
# SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string
|
||||
# SQLite: A raw file path is supported, but `file:<path>?_txlock=immediate` is recommended.
|
||||
# https://github.com/mattn/go-sqlite3#connection-string
|
||||
# Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable
|
||||
# To connect via Unix socket, use something like postgres:///dbname?host=/var/run/postgresql
|
||||
uri: postgres://user:password@host/database?sslmode=disable
|
||||
# Maximum number of connections. Mostly relevant for Postgres.
|
||||
max_open_conns: 20
|
||||
max_idle_conns: 2
|
||||
|
||||
# NOT TESTED YET
|
||||
# Settings for provisioning API
|
||||
provisioning:
|
||||
# Prefix for the provisioning API paths.
|
||||
prefix: /_matrix/provision/v1
|
||||
# Shared secret for authentication. If set to "disable", the provisioning API will be disabled.
|
||||
shared_secret: disable
|
||||
# Maximum connection idle time and lifetime before they're closed. Disabled if null.
|
||||
# Parsed with https://pkg.go.dev/time#ParseDuration
|
||||
max_conn_idle_time: null
|
||||
max_conn_lifetime: null
|
||||
|
||||
# The unique ID of this appservice.
|
||||
id: groupme
|
||||
@ -44,12 +54,19 @@ appservice:
|
||||
# Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty
|
||||
# to leave display name/avatar as-is.
|
||||
displayname: GroupMe bridge bot
|
||||
avatar: mxc://malhotra.cc/YTWNAdhgJhYOPsKIxyfFZsrA
|
||||
avatar: mxc://nevarro.space/eoAJPcSuTEvffoNycrXjvsmj
|
||||
|
||||
# Whether or not to receive ephemeral events via appservice transactions.
|
||||
# Requires MSC2409 support (i.e. Synapse 1.22+).
|
||||
ephemeral_events: true
|
||||
|
||||
# Authentication tokens for AS <-> HS communication. Autogenerated; do not modify.
|
||||
as_token: "This value is generated when generating the registration"
|
||||
hs_token: "This value is generated when generating the registration"
|
||||
|
||||
# Segment API key to track some events, like provisioning API login and encryption errors.
|
||||
segment_key: null
|
||||
|
||||
# Metrics not yet tested!
|
||||
metrics:
|
||||
# Whether or not to enable prometheus metrics
|
||||
@ -57,36 +74,34 @@ metrics:
|
||||
# IP and port where the metrics listener should be. The path is always /metrics
|
||||
listen: 127.0.0.1:8001
|
||||
|
||||
# GroupMe configuration
|
||||
groupme:
|
||||
# GroupMe connection timeout in seconds.
|
||||
connection_timeout: 20
|
||||
# If GroupMe doesn't respond within connection_timeout, should the bridge
|
||||
# try to fetch the message to see if it was actually bridged? Use this if
|
||||
# you have problems with sends timing out but actually succeeding.
|
||||
fetch_message_on_timeout: false
|
||||
|
||||
# Bridge config
|
||||
bridge:
|
||||
# Localpart template of MXIDs for WhatsApp users.
|
||||
# {{.}} is replaced with the phone number of the WhatsApp user.
|
||||
# Localpart template of MXIDs for GroupMe users.
|
||||
# {{.}} is replaced with the phone number of the GroupMe user.
|
||||
username_template: groupme_{{.}}
|
||||
# Displayname template for GroupMe users.
|
||||
# {{call .UserID.String}} - the number GroupMe assigns to the user
|
||||
# {{.Nickname}} - the nickname in that room
|
||||
# {{.ImageURL}} - User's avatar URL is available but irrelevant here
|
||||
displayname_template: "{{if .Nickname}}{{.Nickname}}{{else}}{{call .UserID.String}}{{end}} (GM)"
|
||||
# Localpart template for per-user room grouping community IDs.
|
||||
# On startup, the bridge will try to create these communities, add all of the specific user's
|
||||
# portals to the community, and invite the Matrix user to it.
|
||||
# (Note that, by default, non-admins might not have your homeserver's permission to create
|
||||
# communities.)
|
||||
# {{.Localpart}} is the MXID localpart and {{.Server}} is the MXID server part of the user.
|
||||
# whatsapp_{{.Localpart}}={{.Server}} is a good value that should work for any user.
|
||||
# communities are NOT YET TESTED in the GroupMe bridge
|
||||
community_template: null
|
||||
|
||||
# GroupMe connection timeout in seconds.
|
||||
connection_timeout: 20
|
||||
# If groupme doesn't respond within connection_timeout, should the bridge try to fetch the message
|
||||
# to see if it was actually bridged? Use this if you have problems with sends timing out but actually
|
||||
# succeeding.
|
||||
fetch_message_on_timeout: false
|
||||
# Whether or not the bridge should send a read receipt from the bridge bot when a message has been
|
||||
# sent to WhatsApp. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will
|
||||
# trigger a read receipt too.
|
||||
displayname_template: "{{if .Name}}{{.Name}}{{else}}{{.GMID}}{{end}} (GM)"
|
||||
# Should the bridge create a space for each logged-in user and add bridged rooms to it?
|
||||
# Users who logged in before turning this on should run `!wa sync space` to create and fill the space for the first time.
|
||||
personal_filtering_spaces: false
|
||||
# Should the bridge send a read receipt from the bridge bot when a message has been sent to GroupMe?
|
||||
delivery_receipts: false
|
||||
# Whether the bridge should send the message status as a custom com.beeper.message_send_status event.
|
||||
message_status_events: false
|
||||
# Whether the bridge should send error notices via m.notice events when a message fails to bridge.
|
||||
message_error_notices: true
|
||||
|
||||
# Maximum number of times to retry connecting on connection error.
|
||||
max_connection_attempts: 3
|
||||
@ -142,13 +157,16 @@ bridge:
|
||||
default_bridge_receipts: true
|
||||
default_bridge_presence: true
|
||||
# Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth
|
||||
|
||||
login_shared_secret_map:
|
||||
example.com: null
|
||||
#
|
||||
# If set, custom puppets will be enabled automatically for local users
|
||||
# instead of users having to find an access token and run `login-matrix`
|
||||
# manually.
|
||||
login_shared_secret: null
|
||||
|
||||
# Whether or not to invite own WhatsApp user's Matrix puppet into private
|
||||
# Whether or not to invite own GroupMe user's Matrix puppet into private
|
||||
# chat portals when backfilling if needed.
|
||||
# This always uses the default puppet instead of custom puppets due to
|
||||
# rate limits and timestamp massaging.
|
||||
@ -162,47 +180,91 @@ bridge:
|
||||
# except if the config file is not writable.
|
||||
resend_bridge_info: false
|
||||
|
||||
# Whether or not thumbnails from WhatsApp should be sent.
|
||||
# Whether or not thumbnails from GroupMe should be sent.
|
||||
# They're disabled by default due to very low resolution.
|
||||
whatsapp_thumbnail: false
|
||||
groupme_thumbnail: false
|
||||
|
||||
# Allow invite permission for user. User can invite any bots to room with whatsapp
|
||||
# Allow invite permission for user. User can invite any bots to room with GroupMe
|
||||
# users (private chat and groups)
|
||||
allow_user_invite: false
|
||||
|
||||
# The prefix for commands. Only required in non-management rooms.
|
||||
command_prefix: "!gm"
|
||||
|
||||
# NOT TESTED in GroupMe
|
||||
# End-to-bridge encryption support options. This requires login_shared_secret to be configured
|
||||
# in order to get a device for the bridge bot.
|
||||
# Messages sent upon joining a management room.
|
||||
# Markdown is supported. The defaults are listed below.
|
||||
management_room_text:
|
||||
# Sent when joining a room.
|
||||
welcome: "Hello, I'm a GroupMe bridge bot."
|
||||
# Sent when joining a management room and the user is already logged in.
|
||||
welcome_connected: "Use `help` for help."
|
||||
# Sent when joining a management room and the user is not logged in.
|
||||
welcome_unconnected: "Use `help` for help or `login` to log in."
|
||||
# Optional extra text sent when joining a management room.
|
||||
additional_help: ""
|
||||
|
||||
# End-to-bridge encryption support options.
|
||||
#
|
||||
# Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal
|
||||
# application service.
|
||||
# See https://docs.mau.fi/bridges/general/end-to-bridge-encryption.html for more info.
|
||||
encryption:
|
||||
# Allow encryption, work in group chat rooms with e2ee enabled
|
||||
allow: false
|
||||
# Default to encryption, force-enable encryption in all portals the bridge creates
|
||||
# This will cause the bridge bot to be in private chats for the encryption to work properly.
|
||||
# It is recommended to also set private_chat_portal_meta to true when using this.
|
||||
default: false
|
||||
# Options for automatic key sharing.
|
||||
key_sharing:
|
||||
# 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.
|
||||
allow: false
|
||||
# Require the requesting device to have a valid cross-signing signature?
|
||||
# This doesn't require that the bridge has verified the device, only that the user has verified it.
|
||||
# Not yet implemented.
|
||||
require_cross_signing: false
|
||||
# Require devices to be verified by the bridge?
|
||||
# Verification by the bridge is not yet implemented.
|
||||
require_verification: true
|
||||
# Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data.
|
||||
appservice: false
|
||||
# Require encryption, drop any unencrypted messages.
|
||||
require: false
|
||||
# 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.
|
||||
allow_key_sharing: false
|
||||
# What level of device verification should be required from users?
|
||||
#
|
||||
# Valid levels:
|
||||
# unverified - Send keys to all device in the room.
|
||||
# cross-signed-untrusted - Require valid cross-signing, but trust all cross-signing keys.
|
||||
# cross-signed-tofu - Require valid cross-signing, trust cross-signing keys on first use (and reject changes).
|
||||
# cross-signed-verified - Require valid cross-signing, plus a valid user signature from the bridge bot.
|
||||
# Note that creating user signatures from the bridge bot is not currently possible.
|
||||
# verified - Require manual per-device verification
|
||||
# (currently only possible by modifying the `trust` column in the `crypto_device` database table).
|
||||
verification_levels:
|
||||
# Minimum level for which the bridge should send keys to when bridging messages from GroupMe to Matrix.
|
||||
receive: unverified
|
||||
# Minimum level that the bridge should accept for incoming Matrix messages.
|
||||
send: unverified
|
||||
# Minimum level that the bridge should require for accepting key requests.
|
||||
share: cross-signed-tofu
|
||||
# Options for Megolm room key rotation. These options allow you to
|
||||
# configure the m.room.encryption event content. See:
|
||||
# https://spec.matrix.org/v1.3/client-server-api/#mroomencryption for
|
||||
# more information about that event.
|
||||
rotation:
|
||||
# Enable custom Megolm room key rotation settings. Note that these
|
||||
# settings will only apply to rooms created after this option is
|
||||
# set.
|
||||
enable_custom: false
|
||||
# The maximum number of milliseconds a session should be used
|
||||
# before changing it. The Matrix spec recommends 604800000 (a week)
|
||||
# as the default.
|
||||
milliseconds: 604800000
|
||||
# The maximum number of messages that should be sent with a given a
|
||||
# session before changing it. The Matrix spec recommends 100 as the
|
||||
# default.
|
||||
messages: 100
|
||||
|
||||
# Settings for provisioning API
|
||||
provisioning:
|
||||
# Prefix for the provisioning API paths.
|
||||
prefix: /_matrix/provision/v1
|
||||
# Shared secret for authentication. If set to "disable", the provisioning API will be disabled.
|
||||
shared_secret: disable
|
||||
|
||||
# Permissions for using the bridge.
|
||||
# Permitted values:
|
||||
# relaybot - Talk through the relaybot (if enabled), no access otherwise
|
||||
# user - Access to use the bridge to chat with a WhatsApp account.
|
||||
# user - Access to use the bridge to chat with a GroupMe account.
|
||||
# admin - User level and some additional administration tools
|
||||
# Permitted keys:
|
||||
# * - All Matrix users
|
||||
@ -213,39 +275,15 @@ bridge:
|
||||
"example.com": user
|
||||
"@admin:example.com": admin
|
||||
|
||||
# GroupMe not tested
|
||||
relaybot:
|
||||
# Whether or not relaybot support is enabled.
|
||||
enabled: false
|
||||
# The management room for the bot. This is where all status notifications are posted and
|
||||
# in this room, you can use `!wa <command>` instead of `!wa relaybot <command>`. Omitting
|
||||
# the command prefix completely like in user management rooms is not possible.
|
||||
management: "!foo:example.com"
|
||||
# List of users to invite to all created rooms that include the relaybot.
|
||||
invites: []
|
||||
# The formats to use when sending messages to WhatsApp via the relaybot.
|
||||
message_formats:
|
||||
m.text: "<b>{{ .Sender.Displayname }}</b>: {{ .Message }}"
|
||||
m.notice: "<b>{{ .Sender.Displayname }}</b>: {{ .Message }}"
|
||||
m.emote: "* <b>{{ .Sender.Displayname }}</b> {{ .Message }}"
|
||||
m.file: "<b>{{ .Sender.Displayname }}</b> sent a file"
|
||||
m.image: "<b>{{ .Sender.Displayname }}</b> sent an image"
|
||||
m.audio: "<b>{{ .Sender.Displayname }}</b> sent an audio file"
|
||||
m.video: "<b>{{ .Sender.Displayname }}</b> sent a video"
|
||||
m.location: "<b>{{ .Sender.Displayname }}</b> sent a location"
|
||||
|
||||
# Logging config.
|
||||
# Logging config. See https://github.com/tulir/zeroconfig for details.
|
||||
logging:
|
||||
# The directory for log files. Will be created if not found.
|
||||
directory: ./logs
|
||||
# Available variables: .Date for the file date and .Index for different log files on the same day.
|
||||
file_name_format: "{{.Date}}-{{.Index}}.log"
|
||||
# Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants
|
||||
file_date_format: 2006-01-02
|
||||
# Log file permissions.
|
||||
file_mode: 0600
|
||||
# Timestamp format for log entries in the Go time format.
|
||||
timestamp_format: Jan _2, 2006 15:04:05
|
||||
# Minimum severity for log messages.
|
||||
# Options: debug, info, warn, error, fatal
|
||||
print_level: debug
|
||||
min_level: debug
|
||||
writers:
|
||||
- type: stdout
|
||||
format: pretty-colored
|
||||
- type: file
|
||||
format: json
|
||||
filename: ./logs/mautrix-groupme.log
|
||||
max_size: 100
|
||||
max_backups: 10
|
||||
compress: true
|
||||
|
137
formatting.go
137
formatting.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -18,128 +18,33 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"go.mau.fi/util/variationselector"
|
||||
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/format"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
)
|
||||
|
||||
var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)")
|
||||
var boldRegex = regexp.MustCompile("([\\s>_~]|^)\\*(.+?)\\*([^a-zA-Z\\d]|$)")
|
||||
var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)")
|
||||
var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```")
|
||||
const formatterContextAllowedMentionsKey = "com.beeper.groupme.allowed_mentions"
|
||||
|
||||
const mentionedJIDsContextKey = "net.maunium.groupme.mentioned_jids"
|
||||
func (br *GMBridge) pillConverter(displayname, mxid, eventID string, ctx format.Context) string {
|
||||
// GroupMe only supports user mentions.
|
||||
if len(mxid) == 0 || mxid[0] != '@' {
|
||||
return displayname
|
||||
}
|
||||
|
||||
type Formatter struct {
|
||||
bridge *Bridge
|
||||
|
||||
matrixHTMLParser *format.HTMLParser
|
||||
|
||||
waReplString map[*regexp.Regexp]string
|
||||
waReplFunc map[*regexp.Regexp]func(string) string
|
||||
waReplFuncText map[*regexp.Regexp]func(string) string
|
||||
return fmt.Sprintf("@%s", displayname)
|
||||
}
|
||||
|
||||
func NewFormatter(bridge *Bridge) *Formatter {
|
||||
formatter := &Formatter{
|
||||
bridge: bridge,
|
||||
matrixHTMLParser: &format.HTMLParser{
|
||||
TabsToSpaces: 4,
|
||||
Newline: "\n",
|
||||
|
||||
PillConverter: func(displayname, mxid, eventID string, ctx format.Context) string {
|
||||
if mxid[0] == '@' {
|
||||
puppet := bridge.GetPuppetByMXID(id.UserID(mxid))
|
||||
if puppet != nil {
|
||||
jids, ok := ctx[mentionedJIDsContextKey].([]types.GroupMeID)
|
||||
if !ok {
|
||||
ctx[mentionedJIDsContextKey] = []types.GroupMeID{puppet.JID}
|
||||
} else {
|
||||
ctx[mentionedJIDsContextKey] = append(jids, puppet.JID)
|
||||
}
|
||||
return "@" + puppet.PhoneNumber()
|
||||
}
|
||||
}
|
||||
return mxid
|
||||
},
|
||||
BoldConverter: func(text string, _ format.Context) string {
|
||||
return fmt.Sprintf("*%s*", text)
|
||||
},
|
||||
ItalicConverter: func(text string, _ format.Context) string {
|
||||
return fmt.Sprintf("_%s_", text)
|
||||
},
|
||||
StrikethroughConverter: func(text string, _ format.Context) string {
|
||||
return fmt.Sprintf("~%s~", text)
|
||||
},
|
||||
MonospaceConverter: func(text string, _ format.Context) string {
|
||||
return fmt.Sprintf("```%s```", text)
|
||||
},
|
||||
MonospaceBlockConverter: func(text, language string, _ format.Context) string {
|
||||
return fmt.Sprintf("```%s```", text)
|
||||
},
|
||||
},
|
||||
waReplString: map[*regexp.Regexp]string{
|
||||
italicRegex: "$1<em>$2</em>$3",
|
||||
boldRegex: "$1<strong>$2</strong>$3",
|
||||
strikethroughRegex: "$1<del>$2</del>$3",
|
||||
},
|
||||
}
|
||||
formatter.waReplFunc = map[*regexp.Regexp]func(string) string{
|
||||
codeBlockRegex: func(str string) string {
|
||||
str = str[3 : len(str)-3]
|
||||
if strings.ContainsRune(str, '\n') {
|
||||
return fmt.Sprintf("<pre><code>%s</code></pre>", str)
|
||||
}
|
||||
return fmt.Sprintf("<code>%s</code>", str)
|
||||
},
|
||||
}
|
||||
formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{
|
||||
}
|
||||
return formatter
|
||||
var matrixHTMLParser = &format.HTMLParser{
|
||||
TabsToSpaces: 4,
|
||||
Newline: "\n",
|
||||
HorizontalLine: "\n---\n",
|
||||
}
|
||||
|
||||
//func (formatter *Formatter) getMatrixInfoByJID(jid types.GroupMeID) (mxid id.UserID, displayname string) {
|
||||
// if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
||||
// mxid = user.MXID
|
||||
// displayname = string(user.MXID)
|
||||
// } else if puppet := formatter.bridge.GetPuppetByJID(jid); puppet != nil {
|
||||
// mxid = puppet.MXID
|
||||
// displayname = puppet.Displayname
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
|
||||
//func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, mentionedJIDs []types.GroupMeID) {
|
||||
// output := html.EscapeString(content.Body)
|
||||
// for regex, replacement := range formatter.waReplString {
|
||||
// output = regex.ReplaceAllString(output, replacement)
|
||||
// }
|
||||
// for regex, replacer := range formatter.waReplFunc {
|
||||
// output = regex.ReplaceAllStringFunc(output, replacer)
|
||||
// }
|
||||
// for _, jid := range mentionedJIDs {
|
||||
// mxid, displayname := formatter.getMatrixInfoByJID(jid)
|
||||
// number := "@" + strings.Replace(jid, whatsappExt.NewUserSuffix, "", 1)
|
||||
// output = strings.Replace(output, number, fmt.Sprintf(`<a href="https://matrix.to/#/%s">%s</a>`, mxid, displayname), -1)
|
||||
// content.Body = strings.Replace(content.Body, number, displayname, -1)
|
||||
// }
|
||||
// if output != content.Body {
|
||||
// output = strings.Replace(output, "\n", "<br/>", -1)
|
||||
// content.FormattedBody = output
|
||||
// content.Format = event.FormatHTML
|
||||
// for regex, replacer := range formatter.waReplFuncText {
|
||||
// content.Body = regex.ReplaceAllStringFunc(content.Body, replacer)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
func (formatter *Formatter) ParseMatrix(html string) (string, []types.GroupMeID) {
|
||||
ctx := make(format.Context)
|
||||
result := formatter.matrixHTMLParser.Parse(html, ctx)
|
||||
mentionedJIDs, _ := ctx[mentionedJIDsContextKey].([]types.GroupMeID)
|
||||
return result, mentionedJIDs
|
||||
func (portal *Portal) parseMatrixHTML(content *event.MessageEventContent) string {
|
||||
if content.Format == event.FormatHTML && len(content.FormattedBody) > 0 {
|
||||
return variationselector.FullyQualify(matrixHTMLParser.Parse(content.FormattedBody, format.NewContext()))
|
||||
} else {
|
||||
return variationselector.FullyQualify(content.Body)
|
||||
}
|
||||
}
|
||||
|
67
go.mod
67
go.mod
@ -1,28 +1,49 @@
|
||||
module github.com/karmanyaahm/matrix-groupme-go
|
||||
module github.com/beeper/groupme
|
||||
|
||||
go 1.15
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/Rhymen/go-whatsapp v0.1.1
|
||||
github.com/gabriel-vasile/mimetype v1.1.2
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
|
||||
github.com/karmanyaahm/groupme v0.0.0
|
||||
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14
|
||||
github.com/lib/pq v1.9.0
|
||||
github.com/mattn/go-sqlite3 v1.14.6
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
github.com/prometheus/procfs v0.6.0 // indirect
|
||||
golang.org/x/text v0.3.5 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.25.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
gorm.io/driver/postgres v1.0.8
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
gorm.io/gorm v1.20.12
|
||||
maunium.net/go/mauflag v1.0.0
|
||||
maunium.net/go/maulogger/v2 v2.2.4
|
||||
maunium.net/go/mautrix v0.9.24
|
||||
github.com/gabriel-vasile/mimetype v0.3.23
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
github.com/prometheus/client_golang v1.11.1
|
||||
maunium.net/go/maulogger/v2 v2.4.1
|
||||
maunium.net/go/mautrix v0.16.1-0.20230821105106-ac5c2c22102c
|
||||
)
|
||||
|
||||
replace github.com/karmanyaahm/groupme => ./groupme
|
||||
require go.mau.fi/util v0.0.0-20230805171708-199bf3eec776
|
||||
|
||||
require (
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.5 // indirect
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.7 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.1 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/google/go-cmp v0.5.8 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.26.0 // indirect
|
||||
github.com/prometheus/procfs v0.6.0 // indirect
|
||||
github.com/rs/zerolog v1.30.0 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
github.com/tidwall/gjson v1.16.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/tidwall/sjson v1.2.5 // indirect
|
||||
github.com/yuin/goldmark v1.5.5 // indirect
|
||||
go.mau.fi/zeroconfig v0.1.2 // indirect
|
||||
golang.org/x/crypto v0.12.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect
|
||||
golang.org/x/net v0.14.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
google.golang.org/protobuf v1.26.0-rc.1 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
maunium.net/go/mauflag v1.0.0 // indirect
|
||||
)
|
||||
|
607
go.sum
607
go.sum
@ -1,108 +1,81 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/Rhymen/go-whatsapp v0.0.0/go.mod h1:rdQr95g2C1xcOfM7QGOhza58HeI3I+tZ/bbluv7VazA=
|
||||
github.com/Rhymen/go-whatsapp v0.1.1 h1:OK+bCugQcr2YjyYKeDzULqCtM50TPUFM6LvQtszKfcw=
|
||||
github.com/Rhymen/go-whatsapp v0.1.1/go.mod h1:o7jjkvKnigfu432dMbQ/w4PH0Yp5u4Y6ysCNjUlcYCk=
|
||||
github.com/Rhymen/go-whatsapp/examples/echo v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:zgCiQtBtZ4P4gFWvwl9aashsdwOcbb/EHOGRmSzM8ME=
|
||||
github.com/Rhymen/go-whatsapp/examples/restoreSession v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:5sCUSpG616ZoSJhlt9iBNI/KXBqrVLcNUJqg7J9+8pU=
|
||||
github.com/Rhymen/go-whatsapp/examples/sendImage v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:RdiyhanVEGXTam+mZ3k6Y3VDCCvXYCwReOoxGozqhHw=
|
||||
github.com/Rhymen/go-whatsapp/examples/sendTextMessages v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:suwzklatySS3Q0+NCxCDh5hYfgXdQUWU1DNcxwAxStM=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.0-20230919020138-8f0db7048755 h1:FEhNSjSNvZ+nVg5Z3ds6X8ys3qjM+mmyLTSqKhCUHuQ=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.0-20230919020138-8f0db7048755/go.mod h1:gv8CWMq6dFJQhH30u8bO3u4k2irKlclZktLNYDebQ/0=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.0-20230919151904-5ca9ade6f946 h1:loc70tiaFs1U4sqn+lKMSBlo5OfvVfClYnWjfGLXaSg=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.0-20230919151904-5ca9ade6f946/go.mod h1:gv8CWMq6dFJQhH30u8bO3u4k2irKlclZktLNYDebQ/0=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.2 h1:tqbgr1vRZ6Wq4W81xBg+FTOywSv3EJpK263SAVXXTco=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.2/go.mod h1:gv8CWMq6dFJQhH30u8bO3u4k2irKlclZktLNYDebQ/0=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.3 h1:YpaZBIee8Ix6uGm1UoEtBix1dEU1TURChAsJGJ3pVRo=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.3/go.mod h1:gv8CWMq6dFJQhH30u8bO3u4k2irKlclZktLNYDebQ/0=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.4 h1:SLvwip1DQy13QngVsEgoLtN7T6bS+X6348p6PQhUF2A=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.4/go.mod h1:gv8CWMq6dFJQhH30u8bO3u4k2irKlclZktLNYDebQ/0=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.5 h1:9+UHzUuEcLuZ5Gx5S/NTBxYshUhsiQ5M3vzUF8RAKxw=
|
||||
gitea.watsonlabs.net/watsonb8/fayec v0.0.5/go.mod h1:gv8CWMq6dFJQhH30u8bO3u4k2irKlclZktLNYDebQ/0=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.2.1-0.20230919023741-5727a20506fa h1:dFNaDeztJzo26t7URiOvaWNUDxve80tAAEHTKpi5JEk=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.2.1-0.20230919023741-5727a20506fa/go.mod h1:QRCibl6Tpr/uBtXD46qXqEkxqR5tQa5vdw+0j7hn+Mw=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.0 h1:Uz5TIIF9tFf0LYEbCJqP8axufdBfsVorAYOaal2NmPw=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.0/go.mod h1:vddDne/D5rrUUQkiIXveB7R3rONGEy4wtAIpGL+yFXA=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.1 h1:2HE8pyjczDZ74rhUE2fLvubiknR9Aj+izTcCewiTdik=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.1/go.mod h1:7pn2rsi3Axc15rW24idJfBjuXAFxvjLRmMK/0Ex0dKM=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.2 h1:QJLwAqYoIxhTtZIzMsjZGiLcml6NCS91DLvnmt/N7bM=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.2/go.mod h1:htgKMGvk2QieyYT69DWnTLABFc/6ttMlIRIr6zPXNfo=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.3 h1:sBmF/10Zk0iyKs1nakHfOeB9BUoSyemCpDUEux+BpMk=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.3/go.mod h1:htgKMGvk2QieyYT69DWnTLABFc/6ttMlIRIr6zPXNfo=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.4 h1:RnvQlgcBIyTSnrG7E311Zuy/A3avSuBYUb8lDN9sw5Q=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.4/go.mod h1:htgKMGvk2QieyYT69DWnTLABFc/6ttMlIRIr6zPXNfo=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.5 h1:J8r/xl8mcQ5mkR/3+gWxu0WdD4CecX42iqB+GLRhNt4=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.5/go.mod h1:3tsM98NYRgbrGrHokW/FYSoETCIaZVhfV+UGcDymQGg=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.6 h1:eITXFX7JHleKD7e2BAUjdX9eDxlxHeMGDRSA/wQa9xI=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.6/go.mod h1:3tsM98NYRgbrGrHokW/FYSoETCIaZVhfV+UGcDymQGg=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.7 h1:/rPp/sNfPqVomm950dL5ANooTTJ501ehvV3y/tC307g=
|
||||
gitea.watsonlabs.net/watsonb8/groupme-lib v0.3.7/go.mod h1:opuYpFdMeeGB87rS0KBkawDb74Hiaw24Lg+EOT6SlKY=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||
github.com/autogrowsystems/wray v0.0.0-20160519030252-f36984f6648c/go.mod h1:druJ8QMeBCUmwJ7ZSFowx77dWxEWF3SYlQlsqZaLZQg=
|
||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
||||
github.com/beeper/groupme-lib v0.2.0 h1:d/RSHPso6qjG80cH4nFEBeGnoEo7LJfKdvM+nCBLkqk=
|
||||
github.com/beeper/groupme-lib v0.2.0/go.mod h1:i+bzB18n8RntitrMbr65boSHU0HfjDcbEUEIPPAV+QU=
|
||||
github.com/beeper/groupme-lib v0.2.1-0.20221021205945-8f23e04eea71 h1:QfLfltOhTgjFQAY1P8dkDx1NhXPmo21vxmlgnh4NiEc=
|
||||
github.com/beeper/groupme-lib v0.2.1-0.20221021205945-8f23e04eea71/go.mod h1:8AdyorS5ZuqSarqY/HD+p6sYf+gMr8+pm33U687568g=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
|
||||
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
||||
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
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/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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
||||
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/densestvoid/groupme v0.2.0/go.mod h1:i+bzB18n8RntitrMbr65boSHU0HfjDcbEUEIPPAV+QU=
|
||||
github.com/gabriel-vasile/mimetype v0.3.23 h1:4qH4dGPSe+MBFBkWDag41c+5YFasJjyP4KwI+t6Ukz8=
|
||||
github.com/gabriel-vasile/mimetype v0.3.23/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
|
||||
github.com/gabriel-vasile/mimetype v1.1.2 h1:gaPnPcNor5aZSVCJVSGipcpbgMWiAAj9z182ocSGbHU=
|
||||
github.com/gabriel-vasile/mimetype v1.1.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
|
||||
github.com/go-kit/log v0.1.0 h1:DGJh0Sm43HbOeYDNnVZFl8BvcYVvjD5bqYJvp0REbwQ=
|
||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
@ -110,507 +83,217 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
|
||||
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
||||
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
|
||||
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
||||
github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
|
||||
github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
|
||||
github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
|
||||
github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5lahk=
|
||||
github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
|
||||
github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
|
||||
github.com/jackc/pgconn v1.8.0 h1:FmjZ0rOyXTr1wfWs45i4a9vjnjWUAGpMuQLD9OSs+lw=
|
||||
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
||||
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
||||
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye4717ITLaNwV9mWbJx0dLCpcRzdA=
|
||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
|
||||
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
||||
github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.0.7 h1:6Pwi1b3QdY65cuv6SyVO0FgPd5J3Bl7wf/nQQjinHMA=
|
||||
github.com/jackc/pgproto3/v2 v2.0.7/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
|
||||
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
|
||||
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
|
||||
github.com/jackc/pgtype v1.2.0/go.mod h1:5m2OfMh1wTK7x+Fk952IDmI4nw3nPrvtQdM0ZT4WpC0=
|
||||
github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkALtxZMCH411K+tKzNpwzCKU+AnPzBKZ+I+Po=
|
||||
github.com/jackc/pgtype v1.3.1-0.20200606141011-f6355165a91c/go.mod h1:cvk9Bgu/VzJ9/lxTO5R5sf80p0DiucVtN7ZxvaC4GmQ=
|
||||
github.com/jackc/pgtype v1.6.2 h1:b3pDeuhbbzBYcg5kwNmNDun4pFUD/0AAr1kLXZLeNt8=
|
||||
github.com/jackc/pgtype v1.6.2/go.mod h1:JCULISAZBFGrHaOXIIFiyfzW5VY0GRitRr8NeJsrdig=
|
||||
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
|
||||
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
||||
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
||||
github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXgo+kA=
|
||||
github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
|
||||
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
|
||||
github.com/jackc/pgx/v4 v4.10.1 h1:/6Q3ye4myIj6AaplUm+eRcz4OhK9HAvFf4ePsG40LJY=
|
||||
github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA=
|
||||
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
|
||||
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
|
||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14 h1:NrATjZKvkY+ojL8FXTWa3fQ+wihFrAxLNE6T+wOkIcY=
|
||||
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14/go.mod h1:ysD86MIEevmAkdfdg5s6Qt3I07RN6fvMAyna7jCGG2o=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8=
|
||||
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
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/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
||||
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
|
||||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
|
||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
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/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
github.com/prometheus/client_golang v1.9.0 h1:Rrch9mh17XcxvEu9D9DEpb4isxjGBtcevQjKvxPRQIU=
|
||||
github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU=
|
||||
github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs9yskGu1v4s=
|
||||
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
|
||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
||||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
|
||||
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||
github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzzhMQ=
|
||||
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc h1:jUIKcSPO9MoMJBbEoyE/RJoE8vz7Mb8AjvifMMwSyvY=
|
||||
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
|
||||
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
|
||||
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
|
||||
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg=
|
||||
github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
github.com/yuin/goldmark v1.5.5 h1:IJznPe8wOzfIKETmMkd06F8nXkmlhaHqFRM9l1hAGsU=
|
||||
github.com/yuin/goldmark v1.5.5/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mau.fi/util v0.0.0-20230805171708-199bf3eec776 h1:VrxDCO/gLFHLQywGUsJzertrvt2mUEMrZPf4hEL/s18=
|
||||
go.mau.fi/util v0.0.0-20230805171708-199bf3eec776/go.mod h1:AxuJUMCxpzgJ5eV9JbPWKRH8aAJJidxetNdUj7qcb84=
|
||||
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
|
||||
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad h1:g0bG7Z4uG+OgH2QDODnjp6ggkk1bJDsINcuWmJN1iJU=
|
||||
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
|
||||
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d h1:1aflnvSoWWLI2k/dMUAl5lvU1YO4Mb4hz0gh+1rjcxU=
|
||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/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.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
|
||||
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
|
||||
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
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/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/postgres v1.0.8 h1:PAgM+PaHOSAeroTjHkCHCBIHHoBIf9RgPWGo8dF2DA8=
|
||||
gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
|
||||
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
||||
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
gorm.io/gorm v1.20.12 h1:ebZ5KrSHzet+sqOCVdH9mTjW91L298nX3v5lVxAzSUY=
|
||||
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
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/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/maulogger/v2 v2.2.4 h1:oV2GDeM4fx1uRysdpDC0FcrPg+thFicSd9XzPcYMbVY=
|
||||
maunium.net/go/maulogger/v2 v2.2.4/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
||||
maunium.net/go/mautrix v0.9.24 h1:NEwWLHcJ/hPF0TBppdezfbVaxwWY9E9f2KDkG4Q6GC0=
|
||||
maunium.net/go/mautrix v0.9.24/go.mod h1:7IzKfWvpQtN+W2Lzxc0rLvIxFM3ryKX6Ys3S/ZoWbg8=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||
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/mautrix v0.15.0 h1:gkK9HXc1SSPwY7qOAqchzj2xxYqiOYeee8lr28A2g/o=
|
||||
maunium.net/go/mautrix v0.15.0/go.mod h1:1v8QVDd7q/eJ+eg4sgeOSEafBAFhkt4ab2i97M3IkNQ=
|
||||
maunium.net/go/mautrix v0.16.0 h1:iUqCzJE2yqBC1ddAK6eAn159My8rLb4X8g4SFtQh2Dk=
|
||||
maunium.net/go/mautrix v0.16.0/go.mod h1:XAjE9pTSGcr6vXaiNgQGiip7tddJ8FQV1a29u2QdBG4=
|
||||
maunium.net/go/mautrix v0.16.1-0.20230821105106-ac5c2c22102c h1:oRIaFbS4ds9biwJVguT+9Zu7n5zDbKQeuGklXHQxvCU=
|
||||
maunium.net/go/mautrix v0.16.1-0.20230821105106-ac5c2c22102c/go.mod h1:XAjE9pTSGcr6vXaiNgQGiip7tddJ8FQV1a29u2QdBG4=
|
||||
|
@ -1,58 +0,0 @@
|
||||
package groupmeExt
|
||||
|
||||
import (
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
"github.com/karmanyaahm/wray"
|
||||
)
|
||||
|
||||
type fayeLogger struct {
|
||||
log.Logger
|
||||
}
|
||||
|
||||
func (f fayeLogger) Debugf(i string, a ...interface{}) {
|
||||
f.Logger.Debugfln(i, a...)
|
||||
}
|
||||
func (f fayeLogger) Errorf(i string, a ...interface{}) {
|
||||
f.Logger.Errorfln(i, a...)
|
||||
}
|
||||
func (f fayeLogger) Warnf(i string, a ...interface{}) {
|
||||
f.Logger.Warnfln(i, a...)
|
||||
}
|
||||
func (f fayeLogger) Infof(i string, a ...interface{}) {
|
||||
f.Logger.Infofln(i, a...)
|
||||
}
|
||||
|
||||
type FayeClient struct {
|
||||
*wray.FayeClient
|
||||
}
|
||||
|
||||
func (fc FayeClient) WaitSubscribe(channel string, msgChannel chan groupme.PushMessage) {
|
||||
c_new := make(chan wray.Message)
|
||||
fc.FayeClient.WaitSubscribe(channel, c_new)
|
||||
//converting between types because channels don't support interfaces well
|
||||
go func() {
|
||||
for i := range c_new {
|
||||
msgChannel <- i
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//for authentication, specific implementation will vary based on faye library
|
||||
type AuthExt struct{}
|
||||
|
||||
func (a *AuthExt) In(wray.Message) {}
|
||||
func (a *AuthExt) Out(m wray.Message) {
|
||||
groupme.OutMsgProc(m)
|
||||
}
|
||||
|
||||
func NewFayeClient(logger log.Logger) *FayeClient {
|
||||
|
||||
fc := &FayeClient{wray.NewFayeClient(groupme.PushServer)}
|
||||
fc.SetLogger(fayeLogger{logger.Sub("FayeClient")})
|
||||
fc.AddExtension(&AuthExt{})
|
||||
//fc.AddExtension(fc.FayeClient)
|
||||
|
||||
return fc
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
package groupmeExt
|
||||
package groupmeext
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@ -12,35 +11,35 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient creates a new GroupMe API Client
|
||||
func NewClient(authToken string) *Client {
|
||||
func NewClient() *Client {
|
||||
n := Client{
|
||||
Client: groupme.NewClient(authToken),
|
||||
Client: groupme.NewClient(),
|
||||
}
|
||||
return &n
|
||||
}
|
||||
func (c Client) IndexAllGroups() ([]*groupme.Group, error) {
|
||||
func (c Client) IndexAllGroups(authToken string) ([]*groupme.Group, error) {
|
||||
return c.IndexGroups(context.TODO(), &groupme.GroupsQuery{
|
||||
// Omit: "memberships",
|
||||
PerPage: 100, //TODO: Configurable and add multipage support
|
||||
})
|
||||
}, authToken)
|
||||
}
|
||||
|
||||
func (c Client) IndexAllRelations() ([]*groupme.User, error) {
|
||||
return c.IndexRelations(context.TODO())
|
||||
func (c Client) IndexAllRelations(authToken string) ([]*groupme.User, error) {
|
||||
return c.IndexRelations(context.TODO(), authToken)
|
||||
}
|
||||
|
||||
func (c Client) IndexAllChats() ([]*groupme.Chat, error) {
|
||||
func (c Client) IndexAllChats(authToken string) ([]*groupme.Chat, error) {
|
||||
return c.IndexChats(context.TODO(), &groupme.IndexChatsQuery{
|
||||
PerPage: 100, //TODO?
|
||||
})
|
||||
}, authToken)
|
||||
}
|
||||
|
||||
func (c Client) LoadMessagesAfter(groupID, lastMessageID string, lastMessageFromMe bool, private bool) ([]*groupme.Message, error) {
|
||||
func (c Client) LoadMessagesAfter(groupID groupme.ID, lastMessageID string, lastMessageFromMe bool, private bool, authToken string) ([]*groupme.Message, error) {
|
||||
if private {
|
||||
ans, e := c.IndexDirectMessages(context.TODO(), groupID, &groupme.IndexDirectMessagesQuery{
|
||||
ans, e := c.IndexDirectMessages(context.TODO(), groupID.String(), &groupme.IndexDirectMessagesQuery{
|
||||
SinceID: groupme.ID(lastMessageID),
|
||||
//Limit: num,
|
||||
})
|
||||
}, authToken)
|
||||
//fmt.Println(groupID, lastMessageID, num, i.Count, e)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@ -51,11 +50,11 @@ func (c Client) LoadMessagesAfter(groupID, lastMessageID string, lastMessageFrom
|
||||
}
|
||||
return ans.Messages, nil
|
||||
} else {
|
||||
i, e := c.IndexMessages(context.TODO(), groupme.ID(groupID), &groupme.IndexMessagesQuery{
|
||||
i, e := c.IndexMessages(context.TODO(), groupID, &groupme.IndexMessagesQuery{
|
||||
AfterID: groupme.ID(lastMessageID),
|
||||
//20 for consistency with dms
|
||||
Limit: 20,
|
||||
})
|
||||
}, authToken)
|
||||
//fmt.Println(groupID, lastMessageID, num, i.Count, e)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@ -64,12 +63,12 @@ func (c Client) LoadMessagesAfter(groupID, lastMessageID string, lastMessageFrom
|
||||
}
|
||||
}
|
||||
|
||||
func (c Client) LoadMessagesBefore(groupID, lastMessageID string, private bool) ([]*groupme.Message, error) {
|
||||
func (c Client) LoadMessagesBefore(groupID, lastMessageID string, private bool, authToken string) ([]*groupme.Message, error) {
|
||||
if private {
|
||||
i, e := c.IndexDirectMessages(context.TODO(), groupID, &groupme.IndexDirectMessagesQuery{
|
||||
BeforeID: groupme.ID(lastMessageID),
|
||||
//Limit: num,
|
||||
})
|
||||
}, authToken)
|
||||
//fmt.Println(groupID, lastMessageID, num, i.Count, e)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@ -81,7 +80,7 @@ func (c Client) LoadMessagesBefore(groupID, lastMessageID string, private bool)
|
||||
BeforeID: groupme.ID(lastMessageID),
|
||||
//20 for consistency with dms
|
||||
Limit: 20,
|
||||
})
|
||||
}, authToken)
|
||||
//fmt.Println(groupID, lastMessageID, num, i.Count, e)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@ -90,11 +89,10 @@ func (c Client) LoadMessagesBefore(groupID, lastMessageID string, private bool)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) RemoveFromGroup(uid, groupID types.GroupMeID) error {
|
||||
|
||||
group, err := c.ShowGroup(context.TODO(), groupme.ID(groupID))
|
||||
func (c *Client) RemoveFromGroup(uid, groupID groupme.ID, authToken string) error {
|
||||
group, err := c.ShowGroup(context.TODO(), groupID, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.RemoveMember(context.TODO(), groupme.ID(groupID), group.GetMemberByUserID(groupme.ID(uid)).ID)
|
||||
return c.RemoveMember(context.TODO(), groupID, group.GetMemberByUserID(uid).ID, authToken)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package groupmeExt
|
||||
package groupmeext
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -9,8 +9,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
)
|
||||
|
||||
type Message struct{ groupme.Message }
|
||||
@ -36,7 +35,7 @@ func (m *Message) Value() (driver.Value, error) {
|
||||
return e, nil
|
||||
}
|
||||
|
||||
//DownloadImage helper function to download image from groupme;
|
||||
// DownloadImage helper function to download image from groupme;
|
||||
// append .large/.preview/.avatar to get various sizes
|
||||
func DownloadImage(URL string) (bytes *[]byte, mime string, err error) {
|
||||
//TODO check its actually groupme?
|
||||
@ -59,7 +58,7 @@ func DownloadImage(URL string) (bytes *[]byte, mime string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func DownloadFile(RoomJID types.GroupMeID, FileID string, token string) (contents []byte, fname, mime string) {
|
||||
func DownloadFile(RoomJID groupme.ID, FileID string, token string) (contents []byte, fname, mime string) {
|
||||
client := &http.Client{}
|
||||
b, _ := json.Marshal(struct {
|
||||
FileIDS []string `json:"file_ids"`
|
||||
@ -70,7 +69,11 @@ func DownloadFile(RoomJID types.GroupMeID, FileID string, token string) (content
|
||||
req, _ := http.NewRequest("POST", fmt.Sprintf("https://file.groupme.com/v1/%s/fileData", RoomJID), bytes.NewReader(b))
|
||||
req.Header.Add("X-Access-Token", token)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
resp, _ := client.Do(req)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
// TODO: FIX
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
data := []ImgData{}
|
||||
@ -83,7 +86,11 @@ func DownloadFile(RoomJID types.GroupMeID, FileID string, token string) (content
|
||||
req, _ = http.NewRequest("POST", fmt.Sprintf("https://file.groupme.com/v1/%s/files/%s", RoomJID, FileID), nil)
|
||||
req.URL.Query().Add("token", token)
|
||||
req.Header.Add("X-Access-Token", token)
|
||||
resp, _ = client.Do(req)
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
// TODO: FIX
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bytes, _ := ioutil.ReadAll(resp.Body)
|
@ -1,4 +1,4 @@
|
||||
package groupmeExt
|
||||
package groupmeext
|
||||
|
||||
const (
|
||||
OldUserSuffix = "@c.groupme.com"
|
828
main.go
828
main.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,357 +17,126 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
"github.com/beeper/groupme/groupmeext"
|
||||
"go.mau.fi/util/configupgrade"
|
||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"regexp"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
flag "maunium.net/go/mauflag"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/bridge"
|
||||
"maunium.net/go/mautrix/bridge/commands"
|
||||
"maunium.net/go/mautrix/bridge/status"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/config"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database/upgrades"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"github.com/beeper/groupme/config"
|
||||
"github.com/beeper/groupme/database"
|
||||
)
|
||||
|
||||
// Information to find out exactly which commit the bridge was built from.
|
||||
// These are filled at build time with the -X linker flag.
|
||||
var (
|
||||
// These are static
|
||||
Name = "go-groupme"
|
||||
URL = "https://github.com/tulir/mautrix-whatsapp"
|
||||
// This is changed when making a release
|
||||
Version = "0.1.5"
|
||||
// This is filled by init()
|
||||
WAVersion = ""
|
||||
// These are filled at build time with the -X linker flag
|
||||
Tag = "unknown"
|
||||
Commit = "unknown"
|
||||
BuildTime = "unknown"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if len(Tag) > 0 && Tag[0] == 'v' {
|
||||
Tag = Tag[1:]
|
||||
}
|
||||
if Tag != Version && !strings.HasSuffix(Version, "+dev") {
|
||||
Version += "+dev"
|
||||
}
|
||||
WAVersion = strings.FieldsFunc(Version, func(r rune) bool { return r == '-' || r == '+' })[0]
|
||||
}
|
||||
//go:embed example-config.yaml
|
||||
var ExampleConfig string
|
||||
|
||||
var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String()
|
||||
const unstableFeatureBatchSending = "org.matrix.msc2716"
|
||||
|
||||
//var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String()
|
||||
var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String()
|
||||
var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool()
|
||||
var version = flag.MakeFull("v", "version", "View bridge version and quit.", "false").Bool()
|
||||
var ignoreUnsupportedDatabase = flag.Make().LongKey("ignore-unsupported-database").Usage("Run even if database is too new").Default("false").Bool()
|
||||
var migrateFrom = flag.Make().LongKey("migrate-db").Usage("Source database type and URI to migrate from.").Bool()
|
||||
var wantHelp, _ = flag.MakeHelpFlag()
|
||||
|
||||
func (bridge *Bridge) GenerateRegistration() {
|
||||
reg, err := bridge.Config.NewRegistration()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to generate registration:", err)
|
||||
os.Exit(20)
|
||||
}
|
||||
|
||||
err = reg.Save(*registrationPath)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to save registration:", err)
|
||||
os.Exit(21)
|
||||
}
|
||||
|
||||
err = bridge.Config.Save(*configPath)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to save config:", err)
|
||||
os.Exit(22)
|
||||
}
|
||||
fmt.Println("Registration generated. Add the path to the registration to your Synapse config, restart it, then start the bridge.")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) MigrateDatabase() {
|
||||
oldDB, err := database.New(flag.Arg(0), flag.Arg(1), bridge.Log)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to open old database:", err)
|
||||
os.Exit(30)
|
||||
}
|
||||
err = oldDB.Init()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to upgrade old database:", err)
|
||||
os.Exit(31)
|
||||
}
|
||||
|
||||
newDB, err := database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI, bridge.Log)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to open new database:", err)
|
||||
os.Exit(32)
|
||||
}
|
||||
err = newDB.Init()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to upgrade new database:", err)
|
||||
os.Exit(33)
|
||||
}
|
||||
|
||||
database.Migrate(oldDB, newDB)
|
||||
}
|
||||
|
||||
type Bridge struct {
|
||||
AS *appservice.AppService
|
||||
EventProcessor *appservice.EventProcessor
|
||||
MatrixHandler *MatrixHandler
|
||||
Config *config.Config
|
||||
DB *database.Database
|
||||
Log log.Logger
|
||||
StateStore *database.SQLStateStore
|
||||
Provisioning *ProvisioningAPI
|
||||
Bot *appservice.IntentAPI
|
||||
Formatter *Formatter
|
||||
Relaybot *User
|
||||
Crypto Crypto
|
||||
Metrics *MetricsHandler
|
||||
type GMBridge struct {
|
||||
bridge.Bridge
|
||||
Config *config.Config
|
||||
DB *database.Database
|
||||
Provisioning *ProvisioningAPI
|
||||
Metrics *MetricsHandler
|
||||
|
||||
usersByMXID map[id.UserID]*User
|
||||
usersByJID map[types.GroupMeID]*User
|
||||
usersByGMID map[groupme.ID]*User
|
||||
usersLock sync.Mutex
|
||||
spaceRooms map[id.RoomID]*User
|
||||
spaceRoomsLock sync.Mutex
|
||||
managementRooms map[id.RoomID]*User
|
||||
managementRoomsLock sync.Mutex
|
||||
portalsByMXID map[id.RoomID]*Portal
|
||||
portalsByJID map[database.PortalKey]*Portal
|
||||
portalsByGMID map[database.PortalKey]*Portal
|
||||
portalsLock sync.Mutex
|
||||
puppets map[types.GroupMeID]*Puppet
|
||||
puppets map[groupme.ID]*Puppet
|
||||
puppetsByCustomMXID map[id.UserID]*Puppet
|
||||
puppetsLock sync.Mutex
|
||||
}
|
||||
|
||||
type Crypto interface {
|
||||
HandleMemberEvent(*event.Event)
|
||||
Decrypt(*event.Event) (*event.Event, error)
|
||||
Encrypt(id.RoomID, event.Type, event.Content) (*event.EncryptedEventContent, error)
|
||||
WaitForSession(id.RoomID, id.SenderKey, id.SessionID, time.Duration) bool
|
||||
ResetSession(id.RoomID)
|
||||
Init() error
|
||||
Start()
|
||||
Stop()
|
||||
}
|
||||
var (
|
||||
TypeMSC3381PollStart = event.Type{Class: event.MessageEventType, Type: "org.matrix.msc3381.poll.start"}
|
||||
TypeMSC3381PollResponse = event.Type{Class: event.MessageEventType, Type: "org.matrix.msc3381.poll.response"}
|
||||
TypeMSC3381V2PollResponse = event.Type{Class: event.MessageEventType, Type: "org.matrix.msc3381.v2.poll.response"}
|
||||
)
|
||||
|
||||
func NewBridge() *Bridge {
|
||||
bridge := &Bridge{
|
||||
usersByMXID: make(map[id.UserID]*User),
|
||||
usersByJID: make(map[types.GroupMeID]*User),
|
||||
managementRooms: make(map[id.RoomID]*User),
|
||||
portalsByMXID: make(map[id.RoomID]*Portal),
|
||||
portalsByJID: make(map[database.PortalKey]*Portal),
|
||||
puppets: make(map[types.GroupMeID]*Puppet),
|
||||
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
||||
}
|
||||
func (br *GMBridge) Init() {
|
||||
br.CommandProcessor = commands.NewProcessor(&br.Bridge)
|
||||
br.RegisterCommands()
|
||||
|
||||
var err error
|
||||
bridge.Config, err = config.Load(*configPath)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to load config:", err)
|
||||
os.Exit(10)
|
||||
}
|
||||
return bridge
|
||||
}
|
||||
matrixHTMLParser.PillConverter = br.pillConverter
|
||||
|
||||
func (bridge *Bridge) ensureConnection() {
|
||||
for {
|
||||
resp, err := bridge.Bot.Whoami()
|
||||
if err != nil {
|
||||
if httpErr, ok := err.(mautrix.HTTPError); ok && httpErr.RespError != nil && httpErr.RespError.ErrCode == "M_UNKNOWN_ACCESS_TOKEN" {
|
||||
bridge.Log.Fatalln("Access token invalid. Is the registration installed in your homeserver correctly?")
|
||||
os.Exit(16)
|
||||
}
|
||||
bridge.Log.Errorfln("Failed to connect to homeserver: %v. Retrying in 10 seconds...", err)
|
||||
time.Sleep(10 * time.Second)
|
||||
} else if resp.UserID != bridge.Bot.UserID {
|
||||
bridge.Log.Fatalln("Unexpected user ID in whoami call: got %s, expected %s", resp.UserID, bridge.Bot.UserID)
|
||||
os.Exit(17)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bridge *Bridge) Init() {
|
||||
var err error
|
||||
|
||||
bridge.AS, err = bridge.Config.MakeAppService()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to initialize AppService:", err)
|
||||
os.Exit(11)
|
||||
}
|
||||
_, _ = bridge.AS.Init()
|
||||
bridge.Bot = bridge.AS.BotIntent()
|
||||
|
||||
bridge.Log = log.Create()
|
||||
bridge.Config.Logging.Configure(bridge.Log)
|
||||
log.DefaultLogger = bridge.Log.(*log.BasicLogger)
|
||||
if len(bridge.Config.Logging.FileNameFormat) > 0 {
|
||||
err = log.OpenFile()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to open log file:", err)
|
||||
os.Exit(12)
|
||||
}
|
||||
}
|
||||
bridge.AS.Log = log.Sub("Matrix")
|
||||
|
||||
bridge.Log.Debugln("Initializing database connection")
|
||||
print("test1")
|
||||
|
||||
bridge.DB, err = database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI, bridge.Log)
|
||||
|
||||
if err != nil {
|
||||
bridge.Log.Fatalln("Failed to initialize database connection:", err)
|
||||
os.Exit(14)
|
||||
}
|
||||
|
||||
if len(bridge.Config.AppService.StateStore) > 0 && bridge.Config.AppService.StateStore != "./mx-state.json" {
|
||||
version, err := upgrades.GetVersion(bridge.DB.DB)
|
||||
if version < 0 && err == nil {
|
||||
bridge.Log.Fatalln("Non-standard state store path. Please move the state store to ./mx-state.json " +
|
||||
"and update the config. The state store will be migrated into the db on the next launch.")
|
||||
os.Exit(18)
|
||||
Segment.log = br.Log.Sub("Segment")
|
||||
Segment.key = br.Config.SegmentKey
|
||||
Segment.userID = br.Config.SegmentUserID
|
||||
if Segment.IsEnabled() {
|
||||
Segment.log.Infoln("Segment metrics are enabled")
|
||||
if Segment.userID != "" {
|
||||
Segment.log.Infoln("Overriding Segment user_id with %v", Segment.userID)
|
||||
}
|
||||
}
|
||||
|
||||
bridge.Log.Debugln("Initializing state store")
|
||||
bridge.StateStore = database.NewSQLStateStore(bridge.DB)
|
||||
bridge.AS.StateStore = bridge.StateStore
|
||||
br.DB = database.New(br.Bridge.DB, br.Log.Sub("Database"))
|
||||
|
||||
// bridge.DB.SetMaxOpenConns(bridge.Config.AppService.Database.MaxOpenConns)
|
||||
// bridge.DB.SetMaxIdleConns(bridge.Config.AppService.Database.MaxIdleConns)
|
||||
|
||||
ss := bridge.Config.AppService.Provisioning.SharedSecret
|
||||
ss := br.Config.Bridge.Provisioning.SharedSecret
|
||||
if len(ss) > 0 && ss != "disable" {
|
||||
bridge.Provisioning = &ProvisioningAPI{bridge: bridge}
|
||||
br.Provisioning = &ProvisioningAPI{bridge: br}
|
||||
}
|
||||
|
||||
bridge.Log.Debugln("Initializing Matrix event processor")
|
||||
bridge.EventProcessor = appservice.NewEventProcessor(bridge.AS)
|
||||
bridge.Log.Debugln("Initializing Matrix event handler")
|
||||
bridge.MatrixHandler = NewMatrixHandler(bridge)
|
||||
bridge.Formatter = NewFormatter(bridge)
|
||||
bridge.Crypto = NewCryptoHelper(bridge)
|
||||
bridge.Metrics = NewMetricsHandler(bridge.Config.Metrics.Listen, bridge.Log.Sub("Metrics"), bridge.DB)
|
||||
br.Metrics = NewMetricsHandler(br.Config.Metrics.Listen, br.Log.Sub("Metrics"), br.DB)
|
||||
br.MatrixHandler.TrackEventDuration = br.Metrics.TrackMatrixEvent
|
||||
}
|
||||
|
||||
func (bridge *Bridge) Start() {
|
||||
bridge.Log.Debugln("Running database upgrades")
|
||||
err := bridge.DB.Init()
|
||||
if err != nil && (err != upgrades.UnsupportedDatabaseVersion || !*ignoreUnsupportedDatabase) {
|
||||
bridge.Log.Fatalln("Failed to initialize database:", err)
|
||||
os.Exit(15)
|
||||
func (br *GMBridge) Start() {
|
||||
if br.Provisioning != nil {
|
||||
br.Log.Debugln("Initializing provisioning API")
|
||||
br.Provisioning.Init()
|
||||
}
|
||||
bridge.Log.Debugln("Checking connection to homeserver")
|
||||
bridge.ensureConnection()
|
||||
if bridge.Crypto != nil {
|
||||
err := bridge.Crypto.Init()
|
||||
if err != nil {
|
||||
bridge.Log.Fatalln("Error initializing end-to-bridge encryption:", err)
|
||||
os.Exit(19)
|
||||
go br.StartUsers()
|
||||
if br.Config.Metrics.Enabled {
|
||||
go br.Metrics.Start()
|
||||
}
|
||||
}
|
||||
|
||||
func (br *GMBridge) StartUsers() {
|
||||
br.Log.Debugln("Starting users")
|
||||
foundAnySessions := false
|
||||
gmc := groupmeext.NewClient()
|
||||
conn := groupme.NewPushSubscription(context.Background())
|
||||
conn.Connect(context.Background())
|
||||
for _, user := range br.GetAllUsers() {
|
||||
if user.GMID.Valid() {
|
||||
foundAnySessions = true
|
||||
}
|
||||
go user.Connect(gmc, &conn)
|
||||
}
|
||||
if bridge.Provisioning != nil {
|
||||
bridge.Log.Debugln("Initializing provisioning API")
|
||||
bridge.Provisioning.Init()
|
||||
if !foundAnySessions {
|
||||
br.SendGlobalBridgeState(status.BridgeState{StateEvent: status.StateUnconfigured}.Fill(nil))
|
||||
}
|
||||
bridge.LoadRelaybot()
|
||||
bridge.Log.Debugln("Starting application service HTTP server")
|
||||
go bridge.AS.Start()
|
||||
bridge.Log.Debugln("Starting event processor")
|
||||
go bridge.EventProcessor.Start()
|
||||
go bridge.UpdateBotProfile()
|
||||
if bridge.Crypto != nil {
|
||||
go bridge.Crypto.Start()
|
||||
}
|
||||
go bridge.StartUsers()
|
||||
if bridge.Config.Metrics.Enabled {
|
||||
go bridge.Metrics.Start()
|
||||
}
|
||||
|
||||
if bridge.Config.Bridge.ResendBridgeInfo {
|
||||
go bridge.ResendBridgeInfo()
|
||||
}
|
||||
}
|
||||
|
||||
func (bridge *Bridge) ResendBridgeInfo() {
|
||||
bridge.Config.Bridge.ResendBridgeInfo = false
|
||||
err := bridge.Config.Save(*configPath)
|
||||
if err != nil {
|
||||
bridge.Log.Errorln("Failed to save config after setting resend_bridge_info to false:", err)
|
||||
}
|
||||
bridge.Log.Infoln("Re-sending bridge info state event to all portals")
|
||||
for _, portal := range bridge.GetAllPortals() {
|
||||
portal.UpdateBridgeInfo()
|
||||
}
|
||||
bridge.Log.Infoln("Finished re-sending bridge info state events")
|
||||
}
|
||||
|
||||
func (bridge *Bridge) LoadRelaybot() {
|
||||
if !bridge.Config.Bridge.Relaybot.Enabled {
|
||||
return
|
||||
}
|
||||
bridge.Relaybot = bridge.GetUserByMXID("relaybot")
|
||||
if bridge.Relaybot.HasSession() {
|
||||
bridge.Log.Debugln("Relaybot is enabled")
|
||||
} else {
|
||||
bridge.Log.Debugln("Relaybot is enabled, but not logged in")
|
||||
}
|
||||
bridge.Relaybot.ManagementRoom = bridge.Config.Bridge.Relaybot.ManagementRoom
|
||||
bridge.Relaybot.IsRelaybot = true
|
||||
bridge.Relaybot.Connect()
|
||||
}
|
||||
|
||||
func (bridge *Bridge) UpdateBotProfile() {
|
||||
bridge.Log.Debugln("Updating bot profile")
|
||||
botConfig := bridge.Config.AppService.Bot
|
||||
|
||||
var err error
|
||||
var mxc id.ContentURI
|
||||
if botConfig.Avatar == "remove" {
|
||||
err = bridge.Bot.SetAvatarURL(mxc)
|
||||
} else if len(botConfig.Avatar) > 0 {
|
||||
mxc, err = id.ParseContentURI(botConfig.Avatar)
|
||||
if err == nil {
|
||||
err = bridge.Bot.SetAvatarURL(mxc)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
bridge.Log.Warnln("Failed to update bot avatar:", err)
|
||||
}
|
||||
|
||||
if botConfig.Displayname == "remove" {
|
||||
err = bridge.Bot.SetDisplayName("")
|
||||
} else if len(botConfig.Avatar) > 0 {
|
||||
err = bridge.Bot.SetDisplayName(botConfig.Displayname)
|
||||
}
|
||||
if err != nil {
|
||||
bridge.Log.Warnln("Failed to update bot displayname:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (bridge *Bridge) StartUsers() {
|
||||
bridge.Log.Debugln("Starting users")
|
||||
for _, user := range bridge.GetAllUsers() {
|
||||
go user.Connect()
|
||||
}
|
||||
bridge.Log.Debugln("Starting custom puppets")
|
||||
for _, loopuppet := range bridge.GetAllPuppetsWithCustomMXID() {
|
||||
br.Log.Debugln("Starting custom puppets")
|
||||
for _, loopuppet := range br.GetAllPuppetsWithCustomMXID() {
|
||||
go func(puppet *Puppet) {
|
||||
puppet.log.Debugln("Starting custom puppet", puppet.CustomMXID)
|
||||
err := puppet.StartCustomMXID()
|
||||
err := puppet.StartCustomMXID(true)
|
||||
if err != nil {
|
||||
puppet.log.Errorln("Failed to start custom puppet:", err)
|
||||
}
|
||||
@ -375,89 +144,398 @@ func (bridge *Bridge) StartUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
func (bridge *Bridge) Stop() {
|
||||
if bridge.Crypto != nil {
|
||||
bridge.Crypto.Stop()
|
||||
}
|
||||
bridge.AS.Stop()
|
||||
bridge.Metrics.Stop()
|
||||
bridge.EventProcessor.Stop()
|
||||
for _, user := range bridge.usersByJID {
|
||||
if user.Conn == nil {
|
||||
func (br *GMBridge) Stop() {
|
||||
br.Metrics.Stop()
|
||||
// TODO anything needed to disconnect the users?
|
||||
for _, user := range br.usersByGMID {
|
||||
if user.Client == nil {
|
||||
continue
|
||||
}
|
||||
bridge.Log.Debugln("Disconnecting", user.MXID)
|
||||
//sess, err :=
|
||||
//user.Conn.Stop(context.TODO())
|
||||
// if err != nil {
|
||||
// bridge.Log.Errorfln("Error while disconnecting %s: %v", user.MXID, err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
br.Log.Debugln("Disconnecting", user.MXID)
|
||||
}
|
||||
}
|
||||
|
||||
var cpuprofile = flag.MakeFull("", "cpuprofile", "write cpu profile to `file`", "").String()
|
||||
func (br *GMBridge) GetExampleConfig() string {
|
||||
return ExampleConfig
|
||||
}
|
||||
|
||||
func (bridge *Bridge) Main() {
|
||||
|
||||
if *generateRegistration {
|
||||
bridge.GenerateRegistration()
|
||||
return
|
||||
} else if *migrateFrom {
|
||||
bridge.MigrateDatabase()
|
||||
return
|
||||
func (br *GMBridge) GetConfigPtr() interface{} {
|
||||
br.Config = &config.Config{
|
||||
BaseConfig: &br.Bridge.Config,
|
||||
}
|
||||
bridge.Init()
|
||||
bridge.Log.Infoln("Bridge initialization complete, starting...")
|
||||
bridge.Start()
|
||||
bridge.Log.Infoln("Bridge started!")
|
||||
br.Config.BaseConfig.Bridge = &br.Config.Bridge
|
||||
return br.Config
|
||||
}
|
||||
|
||||
if *cpuprofile != "" {
|
||||
println("profiling")
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
func (bridge *GMBridge) GetPortalByGMID(key database.PortalKey) *Portal {
|
||||
bridge.portalsLock.Lock()
|
||||
defer bridge.portalsLock.Unlock()
|
||||
portal, ok := bridge.portalsByGMID[key]
|
||||
if !ok {
|
||||
dbPortal := bridge.DB.Portal.GetByGMID(key)
|
||||
return bridge.loadDBPortal(dbPortal, &key)
|
||||
}
|
||||
return portal
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetAllPortals() []*Portal {
|
||||
return br.dbPortalsToPortals(br.DB.Portal.GetAll())
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetAllIPortals() (iportals []bridge.Portal) {
|
||||
portals := br.GetAllPortals()
|
||||
iportals = make([]bridge.Portal, len(portals))
|
||||
for i, portal := range portals {
|
||||
iportals[i] = portal
|
||||
}
|
||||
return iportals
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetAllPortalsByGMID(gmid groupme.ID) []*Portal {
|
||||
return br.dbPortalsToPortals(br.DB.Portal.GetAllByGMID(gmid))
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) GetPortalByMXID(mxid id.RoomID) *Portal {
|
||||
bridge.portalsLock.Lock()
|
||||
defer bridge.portalsLock.Unlock()
|
||||
portal, ok := bridge.portalsByMXID[mxid]
|
||||
if !ok {
|
||||
return bridge.loadDBPortal(bridge.DB.Portal.GetByMXID(mxid), nil)
|
||||
}
|
||||
return portal
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetIPortal(mxid id.RoomID) bridge.Portal {
|
||||
p := br.GetPortalByMXID(mxid)
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (br *GMBridge) getUserByMXID(userID id.UserID, onlyIfExists bool) *User {
|
||||
_, isPuppet := br.ParsePuppetMXID(userID)
|
||||
if isPuppet || userID == br.Bot.UserID {
|
||||
return nil
|
||||
}
|
||||
br.usersLock.Lock()
|
||||
defer br.usersLock.Unlock()
|
||||
user, ok := br.usersByMXID[userID]
|
||||
if !ok {
|
||||
userIDPtr := &userID
|
||||
if onlyIfExists {
|
||||
userIDPtr = nil
|
||||
}
|
||||
defer f.Close() // error handling omitted for example
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
return br.loadDBUser(br.DB.User.GetByMXID(userID), userIDPtr)
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetUserByMXID(userID id.UserID) *User {
|
||||
return br.getUserByMXID(userID, false)
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetIUser(userID id.UserID, create bool) bridge.User {
|
||||
u := br.getUserByMXID(userID, !create)
|
||||
if u == nil {
|
||||
return nil
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetUserByMXIDIfExists(userID id.UserID) *User {
|
||||
return br.getUserByMXID(userID, true)
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) GetUserByGMID(gmid groupme.ID) *User {
|
||||
bridge.usersLock.Lock()
|
||||
defer bridge.usersLock.Unlock()
|
||||
user, ok := bridge.usersByGMID[gmid]
|
||||
if !ok {
|
||||
return bridge.loadDBUser(bridge.DB.User.GetByGMID(gmid), nil)
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetAllUsers() []*User {
|
||||
br.usersLock.Lock()
|
||||
defer br.usersLock.Unlock()
|
||||
dbUsers := br.DB.User.GetAll()
|
||||
output := make([]*User, len(dbUsers))
|
||||
for index, dbUser := range dbUsers {
|
||||
user, ok := br.usersByMXID[dbUser.MXID]
|
||||
if !ok {
|
||||
user = br.loadDBUser(dbUser, nil)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
output[index] = user
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (br *GMBridge) loadDBUser(dbUser *database.User, mxid *id.UserID) *User {
|
||||
if dbUser == nil {
|
||||
if mxid == nil {
|
||||
return nil
|
||||
}
|
||||
dbUser = br.DB.User.New()
|
||||
dbUser.MXID = *mxid
|
||||
dbUser.Insert()
|
||||
}
|
||||
user := br.NewUser(dbUser)
|
||||
br.usersByMXID[user.MXID] = user
|
||||
if len(user.GMID) > 0 {
|
||||
br.usersByGMID[user.GMID] = user
|
||||
}
|
||||
if len(user.ManagementRoom) > 0 {
|
||||
br.managementRooms[user.ManagementRoom] = user
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
func (br *GMBridge) NewUser(dbUser *database.User) *User {
|
||||
user := &User{
|
||||
User: dbUser,
|
||||
bridge: br,
|
||||
log: br.Log.Sub("User").Sub(string(dbUser.MXID)),
|
||||
|
||||
chatListReceived: make(chan struct{}, 1),
|
||||
syncPortalsDone: make(chan struct{}, 1),
|
||||
syncStart: make(chan struct{}, 1),
|
||||
messageInput: make(chan PortalMessage),
|
||||
messageOutput: make(chan PortalMessage, br.Config.Bridge.PortalMessageBuffer),
|
||||
}
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
<-c
|
||||
user.PermissionLevel = user.bridge.Config.Bridge.Permissions.Get(user.MXID)
|
||||
user.Whitelisted = user.PermissionLevel >= bridgeconfig.PermissionLevelUser
|
||||
user.Admin = user.PermissionLevel >= bridgeconfig.PermissionLevelAdmin
|
||||
user.BridgeState = br.NewBridgeStateQueue(user)
|
||||
go user.handleMessageLoop()
|
||||
go user.runMessageRingBuffer()
|
||||
return user
|
||||
}
|
||||
|
||||
bridge.Log.Infoln("Interrupt received, stopping...")
|
||||
bridge.Stop()
|
||||
bridge.Log.Infoln("Bridge stopped.")
|
||||
//os.Exit(0)
|
||||
func (bridge *GMBridge) GetAllPuppetsWithCustomMXID() []*Puppet {
|
||||
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAllWithCustomMXID())
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) GetAllPuppets() []*Puppet {
|
||||
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAll())
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
output := make([]*Puppet, len(dbPuppets))
|
||||
for index, dbPuppet := range dbPuppets {
|
||||
if dbPuppet == nil {
|
||||
continue
|
||||
}
|
||||
puppet, ok := bridge.puppets[dbPuppet.GMID]
|
||||
if !ok {
|
||||
puppet = bridge.NewPuppet(dbPuppet)
|
||||
bridge.puppets[dbPuppet.GMID] = puppet
|
||||
if len(dbPuppet.CustomMXID) > 0 {
|
||||
bridge.puppetsByCustomMXID[dbPuppet.CustomMXID] = puppet
|
||||
}
|
||||
}
|
||||
output[index] = puppet
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) FormatPuppetMXID(gmid groupme.ID) id.UserID {
|
||||
return id.NewUserID(
|
||||
bridge.Config.Bridge.FormatUsername(gmid.String()),
|
||||
bridge.Config.Homeserver.Domain)
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) NewPuppet(dbPuppet *database.Puppet) *Puppet {
|
||||
return &Puppet{
|
||||
Puppet: dbPuppet,
|
||||
bridge: bridge,
|
||||
log: bridge.Log.Sub(fmt.Sprintf("Puppet/%s", dbPuppet.GMID)),
|
||||
|
||||
MXID: bridge.FormatPuppetMXID(dbPuppet.GMID),
|
||||
}
|
||||
}
|
||||
|
||||
func (br *GMBridge) IsGhost(id id.UserID) bool {
|
||||
_, ok := br.ParsePuppetMXID(id)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (br *GMBridge) GetIGhost(id id.UserID) bridge.Ghost {
|
||||
p := br.GetPuppetByMXID(id)
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) ParsePuppetMXID(mxid id.UserID) (groupme.ID, bool) {
|
||||
if userIDRegex == nil {
|
||||
userIDRegex = regexp.MustCompile(fmt.Sprintf("^@%s:%s$",
|
||||
bridge.Config.Bridge.FormatUsername("([0-9]+)"),
|
||||
bridge.Config.Homeserver.Domain))
|
||||
}
|
||||
match := userIDRegex.FindStringSubmatch(string(mxid))
|
||||
if match == nil || len(match) != 2 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return groupme.ID(match[1]), true
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) GetPuppetByMXID(mxid id.UserID) *Puppet {
|
||||
gmid, ok := bridge.ParsePuppetMXID(mxid)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return bridge.GetPuppetByGMID(gmid)
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) GetPuppetByGMID(gmid groupme.ID) *Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
puppet, ok := bridge.puppets[gmid]
|
||||
if !ok {
|
||||
dbPuppet := bridge.DB.Puppet.Get(gmid)
|
||||
if dbPuppet == nil {
|
||||
dbPuppet = bridge.DB.Puppet.New()
|
||||
dbPuppet.GMID = gmid
|
||||
dbPuppet.Insert()
|
||||
}
|
||||
puppet = bridge.NewPuppet(dbPuppet)
|
||||
bridge.puppets[puppet.GMID] = puppet
|
||||
if len(puppet.CustomMXID) > 0 {
|
||||
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||
}
|
||||
}
|
||||
return puppet
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
puppet, ok := bridge.puppetsByCustomMXID[mxid]
|
||||
if !ok {
|
||||
dbPuppet := bridge.DB.Puppet.GetByCustomMXID(mxid)
|
||||
if dbPuppet == nil {
|
||||
return nil
|
||||
}
|
||||
puppet = bridge.NewPuppet(dbPuppet)
|
||||
bridge.puppets[puppet.GMID] = puppet
|
||||
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||
}
|
||||
return puppet
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) dbPortalsToPortals(dbPortals []*database.Portal) []*Portal {
|
||||
bridge.portalsLock.Lock()
|
||||
defer bridge.portalsLock.Unlock()
|
||||
output := make([]*Portal, len(dbPortals))
|
||||
for index, dbPortal := range dbPortals {
|
||||
if dbPortal == nil {
|
||||
continue
|
||||
}
|
||||
portal, ok := bridge.portalsByGMID[dbPortal.Key]
|
||||
if !ok {
|
||||
portal = bridge.loadDBPortal(dbPortal, nil)
|
||||
}
|
||||
output[index] = portal
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) loadDBPortal(dbPortal *database.Portal, key *database.PortalKey) *Portal {
|
||||
if dbPortal == nil {
|
||||
if key == nil {
|
||||
return nil
|
||||
}
|
||||
dbPortal = bridge.DB.Portal.New()
|
||||
dbPortal.Key = *key
|
||||
dbPortal.Insert()
|
||||
}
|
||||
portal := bridge.NewPortal(dbPortal)
|
||||
bridge.portalsByGMID[portal.Key] = portal
|
||||
if len(portal.MXID) > 0 {
|
||||
bridge.portalsByMXID[portal.MXID] = portal
|
||||
}
|
||||
return portal
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) NewManualPortal(key database.PortalKey) *Portal {
|
||||
portal := &Portal{
|
||||
Portal: bridge.DB.Portal.New(),
|
||||
bridge: bridge,
|
||||
log: bridge.Log.Sub(fmt.Sprintf("Portal/%s", key)),
|
||||
|
||||
recentlyHandled: make([]string, recentlyHandledLength),
|
||||
|
||||
messages: make(chan PortalMessage, bridge.Config.Bridge.PortalMessageBuffer),
|
||||
}
|
||||
portal.Key = key
|
||||
go portal.handleMessageLoop()
|
||||
return portal
|
||||
}
|
||||
|
||||
func (bridge *GMBridge) NewPortal(dbPortal *database.Portal) *Portal {
|
||||
portal := &Portal{
|
||||
Portal: dbPortal,
|
||||
bridge: bridge,
|
||||
log: bridge.Log.Sub(fmt.Sprintf("Portal/%s", dbPortal.Key)),
|
||||
|
||||
recentlyHandled: make([]string, recentlyHandledLength),
|
||||
|
||||
messages: make(chan PortalMessage, bridge.Config.Bridge.PortalMessageBuffer),
|
||||
matrixMessages: make(chan PortalMatrixMessage, bridge.Config.Bridge.PortalMessageBuffer),
|
||||
}
|
||||
go portal.handleMessageLoop()
|
||||
return portal
|
||||
}
|
||||
|
||||
func (br *GMBridge) CheckFeatures(versions *mautrix.RespVersions) (string, bool) {
|
||||
if br.Config.Bridge.HistorySync.Backfill {
|
||||
supported, known := versions.UnstableFeatures[unstableFeatureBatchSending]
|
||||
if !known {
|
||||
return "Backfilling is enabled in bridge config, but homeserver does not support MSC2716 batch sending", false
|
||||
} else if !supported {
|
||||
return "Backfilling is enabled in bridge config, but MSC2716 batch sending is not enabled on homeserver", false
|
||||
}
|
||||
}
|
||||
return "", true
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.SetHelpTitles(
|
||||
"go-groupme - A Matrix-GroupMe puppeting bridge.",
|
||||
"go-groupme [-h] [-c <path>] [-r <path>] [-g] [--migrate-db <source type> <source uri>]")
|
||||
err := flag.Parse()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
flag.PrintHelp()
|
||||
os.Exit(1)
|
||||
} else if *wantHelp {
|
||||
flag.PrintHelp()
|
||||
os.Exit(0)
|
||||
} else if *version {
|
||||
if Tag == Version {
|
||||
fmt.Printf("%s %s (%s)\n", Name, Tag, BuildTime)
|
||||
} else if len(Commit) > 8 {
|
||||
fmt.Printf("%s %s.%s (%s)\n", Name, Version, Commit[:8], BuildTime)
|
||||
} else {
|
||||
fmt.Printf("%s %s.unknown\n", Name, Version)
|
||||
}
|
||||
return
|
||||
br := &GMBridge{
|
||||
usersByMXID: make(map[id.UserID]*User),
|
||||
usersByGMID: make(map[groupme.ID]*User),
|
||||
spaceRooms: make(map[id.RoomID]*User),
|
||||
managementRooms: make(map[id.RoomID]*User),
|
||||
portalsByMXID: make(map[id.RoomID]*Portal),
|
||||
portalsByGMID: make(map[database.PortalKey]*Portal),
|
||||
puppets: make(map[groupme.ID]*Puppet),
|
||||
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
||||
}
|
||||
br.Bridge = bridge.Bridge{
|
||||
Name: "groupme-matrix",
|
||||
URL: "https://github.com/beeper/groupme",
|
||||
Description: "A Matrix-GroupMe puppeting bridge.",
|
||||
Version: "0.1.0",
|
||||
ProtocolName: "GroupMe",
|
||||
|
||||
NewBridge().Main()
|
||||
CryptoPickleKey: "github.com/beeper/groupme",
|
||||
|
||||
ConfigUpgrader: &configupgrade.StructUpgrader{
|
||||
SimpleUpgrader: configupgrade.SimpleUpgrader(config.DoUpgrade),
|
||||
Blocks: config.SpacedBlocks,
|
||||
Base: ExampleConfig,
|
||||
},
|
||||
|
||||
Child: br,
|
||||
}
|
||||
br.InitVersion(Tag, Commit, BuildTime)
|
||||
|
||||
br.Main()
|
||||
}
|
||||
|
455
matrix.go
455
matrix.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,450 +17,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
"maunium.net/go/mautrix/bridge"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/format"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"github.com/beeper/groupme/database"
|
||||
)
|
||||
|
||||
type MatrixHandler struct {
|
||||
bridge *Bridge
|
||||
as *appservice.AppService
|
||||
log maulogger.Logger
|
||||
cmd *CommandHandler
|
||||
}
|
||||
|
||||
func NewMatrixHandler(bridge *Bridge) *MatrixHandler {
|
||||
handler := &MatrixHandler{
|
||||
bridge: bridge,
|
||||
as: bridge.AS,
|
||||
log: bridge.Log.Sub("Matrix"),
|
||||
cmd: NewCommandHandler(bridge),
|
||||
}
|
||||
bridge.EventProcessor.On(event.EventMessage, handler.HandleMessage)
|
||||
bridge.EventProcessor.On(event.EventEncrypted, handler.HandleEncrypted)
|
||||
bridge.EventProcessor.On(event.EventSticker, handler.HandleMessage)
|
||||
bridge.EventProcessor.On(event.EventRedaction, handler.HandleRedaction)
|
||||
bridge.EventProcessor.On(event.StateMember, handler.HandleMembership)
|
||||
bridge.EventProcessor.On(event.StateRoomName, handler.HandleRoomMetadata)
|
||||
bridge.EventProcessor.On(event.StateRoomAvatar, handler.HandleRoomMetadata)
|
||||
bridge.EventProcessor.On(event.StateTopic, handler.HandleRoomMetadata)
|
||||
bridge.EventProcessor.On(event.StateEncryption, handler.HandleEncryption)
|
||||
return handler
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleEncryption(evt *event.Event) {
|
||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
||||
if evt.Content.AsEncryption().Algorithm != id.AlgorithmMegolmV1 {
|
||||
return
|
||||
}
|
||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
||||
if portal != nil && !portal.Encrypted {
|
||||
mx.log.Debugfln("%s enabled encryption in %s", evt.Sender, evt.RoomID)
|
||||
portal.Encrypted = true
|
||||
portal.Update()
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) joinAndCheckMembers(evt *event.Event, intent *appservice.IntentAPI) *mautrix.RespJoinedMembers {
|
||||
resp, err := intent.JoinRoomByID(evt.RoomID)
|
||||
if err != nil {
|
||||
mx.log.Debugfln("Failed to join room %s as %s with invite from %s: %v", evt.RoomID, intent.UserID, evt.Sender, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
members, err := intent.JoinedMembers(resp.RoomID)
|
||||
if err != nil {
|
||||
mx.log.Debugfln("Failed to get members in room %s after accepting invite from %s as %s: %v", resp.RoomID, evt.Sender, intent.UserID, err)
|
||||
_, _ = intent.LeaveRoom(resp.RoomID)
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(members.Joined) < 2 {
|
||||
mx.log.Debugln("Leaving empty room", resp.RoomID, "after accepting invite from", evt.Sender, "as", intent.UserID)
|
||||
_, _ = intent.LeaveRoom(resp.RoomID)
|
||||
return nil
|
||||
}
|
||||
return members
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleBotInvite(evt *event.Event) {
|
||||
intent := mx.as.BotIntent()
|
||||
|
||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
|
||||
members := mx.joinAndCheckMembers(evt, intent)
|
||||
if members == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !user.Whitelisted {
|
||||
_, _ = intent.SendNotice(evt.RoomID, "You are not whitelisted to use this bridge.\n"+
|
||||
"If you're the owner of this bridge, see the bridge.permissions section in your config file.")
|
||||
_, _ = intent.LeaveRoom(evt.RoomID)
|
||||
return
|
||||
}
|
||||
|
||||
if evt.RoomID == mx.bridge.Config.Bridge.Relaybot.ManagementRoom {
|
||||
_, _ = intent.SendNotice(evt.RoomID, "This is the relaybot management room. Send `!wa help` to get a list of commands.")
|
||||
mx.log.Debugln("Joined relaybot management room", evt.RoomID, "after invite from", evt.Sender)
|
||||
return
|
||||
}
|
||||
|
||||
hasPuppets := false
|
||||
for mxid, _ := range members.Joined {
|
||||
if mxid == intent.UserID || mxid == evt.Sender {
|
||||
continue
|
||||
} else if _, ok := mx.bridge.ParsePuppetMXID(mxid); ok {
|
||||
hasPuppets = true
|
||||
continue
|
||||
}
|
||||
mx.log.Debugln("Leaving multi-user room", evt.RoomID, "after accepting invite from", evt.Sender)
|
||||
_, _ = intent.SendNotice(evt.RoomID, "This bridge is user-specific, please don't invite me into rooms with other users.")
|
||||
_, _ = intent.LeaveRoom(evt.RoomID)
|
||||
return
|
||||
}
|
||||
|
||||
if !hasPuppets && (len(user.ManagementRoom) == 0 || evt.Content.AsMember().IsDirect) {
|
||||
user.SetManagementRoom(evt.RoomID)
|
||||
_, _ = intent.SendNotice(user.ManagementRoom, "This room has been registered as your bridge management/status room. Send `help` to get a list of commands.")
|
||||
mx.log.Debugln(evt.RoomID, "registered as a management room with", evt.Sender)
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) handlePrivatePortal(roomID id.RoomID, inviter *User, puppet *Puppet, key database.PortalKey) {
|
||||
portal := mx.bridge.GetPortalByJID(key)
|
||||
func (br *GMBridge) CreatePrivatePortal(roomID id.RoomID, brInviter bridge.User, brGhost bridge.Ghost) {
|
||||
inviter := brInviter.(*User)
|
||||
puppet := brGhost.(*Puppet)
|
||||
key := database.NewPortalKey(puppet.GMID, inviter.GMID)
|
||||
portal := br.GetPortalByGMID(key)
|
||||
|
||||
if len(portal.MXID) == 0 {
|
||||
mx.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
||||
br.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
||||
return
|
||||
}
|
||||
|
||||
err := portal.MainIntent().EnsureInvited(portal.MXID, inviter.MXID)
|
||||
if err != nil {
|
||||
mx.log.Warnfln("Failed to invite %s to existing private chat portal %s with %s: %v. Redirecting portal to new room...", inviter.MXID, portal.MXID, puppet.JID, err)
|
||||
mx.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
||||
ok := portal.ensureUserInvited(inviter)
|
||||
if !ok {
|
||||
br.Log.Warnfln("Failed to invite %s to existing private chat portal %s with %s. Redirecting portal to new room...", inviter.MXID, portal.MXID, puppet.GMID)
|
||||
br.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
||||
return
|
||||
}
|
||||
intent := puppet.DefaultIntent()
|
||||
_, _ = intent.SendNotice(roomID, "You already have a private chat portal with me at %s")
|
||||
mx.log.Debugln("Leaving private chat room", roomID, "as", puppet.MXID, "after accepting invite from", inviter.MXID, "as we already have chat with the user")
|
||||
errorMessage := fmt.Sprintf("You already have a private chat portal with me at [%[1]s](https://matrix.to/#/%[1]s)", portal.MXID)
|
||||
errorContent := format.RenderMarkdown(errorMessage, true, false)
|
||||
_, _ = intent.SendMessageEvent(roomID, event.EventMessage, errorContent)
|
||||
br.Log.Debugfln("Leaving private chat room %s as %s after accepting invite from %s as we already have chat with the user", roomID, puppet.MXID, inviter.MXID)
|
||||
_, _ = intent.LeaveRoom(roomID)
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
||||
func (br *GMBridge) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
||||
// TODO check if room is already encrypted
|
||||
var existingEncryption event.EncryptionEventContent
|
||||
var encryptionEnabled bool
|
||||
err := portal.MainIntent().StateEvent(roomID, event.StateEncryption, "", &existingEncryption)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to check if encryption is enabled in private chat room %s", roomID)
|
||||
} else {
|
||||
encryptionEnabled = existingEncryption.Algorithm == id.AlgorithmMegolmV1
|
||||
}
|
||||
portal.MXID = roomID
|
||||
portal.Topic = "WhatsApp private chat"
|
||||
portal.Key = database.PortalKey{puppet.JID, inviter.JID}
|
||||
|
||||
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
||||
m, _ := mx.bridge.StateStore.TryGetMemberRaw(portal.MXID, puppet.MXID)
|
||||
portal.Name = m.DisplayName
|
||||
portal.AvatarURL = types.ContentURI{id.MustParseContentURI(m.AvatarURL)}
|
||||
print("possible bug with pointer above")
|
||||
portal.Avatar = m.Avatar
|
||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta || br.Config.Bridge.Encryption.Default || encryptionEnabled {
|
||||
portal.Name = puppet.Displayname
|
||||
portal.AvatarURL = puppet.AvatarURL
|
||||
portal.Avatar = puppet.Avatar
|
||||
_, _ = portal.MainIntent().SetRoomName(portal.MXID, portal.Name)
|
||||
_, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL.ContentURI)
|
||||
_, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL)
|
||||
} else {
|
||||
portal.Name = ""
|
||||
}
|
||||
portal.log.Infoln("Created private chat portal in %s after invite from", roomID, inviter.MXID)
|
||||
portal.log.Infofln("Created private chat portal in %s after invite from %s", roomID, inviter.MXID)
|
||||
intent := puppet.DefaultIntent()
|
||||
|
||||
if mx.bridge.Config.Bridge.Encryption.Default {
|
||||
_, err := intent.InviteUser(roomID, &mautrix.ReqInviteUser{UserID: mx.bridge.Bot.UserID})
|
||||
if br.Config.Bridge.Encryption.Default || encryptionEnabled {
|
||||
_, err := intent.InviteUser(roomID, &mautrix.ReqInviteUser{UserID: br.Bot.UserID})
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to invite bridge bot to enable e2be:", err)
|
||||
}
|
||||
err = mx.bridge.Bot.EnsureJoined(roomID)
|
||||
err = br.Bot.EnsureJoined(roomID)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to join as bridge bot to enable e2be:", err)
|
||||
}
|
||||
_, err = intent.SendStateEvent(roomID, event.StateEncryption, "", &event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1})
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to enable e2be:", err)
|
||||
if !encryptionEnabled {
|
||||
_, err = intent.SendStateEvent(roomID, event.StateEncryption, "", portal.GetEncryptionEventContent())
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to enable e2be:", err)
|
||||
}
|
||||
}
|
||||
mx.as.StateStore.SetMembership(roomID, inviter.MXID, event.MembershipJoin)
|
||||
mx.as.StateStore.SetMembership(roomID, puppet.MXID, event.MembershipJoin)
|
||||
mx.as.StateStore.SetMembership(roomID, mx.bridge.Bot.UserID, event.MembershipJoin)
|
||||
br.AS.StateStore.SetMembership(roomID, inviter.MXID, event.MembershipJoin)
|
||||
br.AS.StateStore.SetMembership(roomID, puppet.MXID, event.MembershipJoin)
|
||||
br.AS.StateStore.SetMembership(roomID, br.Bot.UserID, event.MembershipJoin)
|
||||
portal.Encrypted = true
|
||||
}
|
||||
portal.Update()
|
||||
portal.Update(nil)
|
||||
portal.UpdateBridgeInfo()
|
||||
_, _ = intent.SendNotice(roomID, "Private chat portal created")
|
||||
|
||||
err := portal.FillInitialHistory(inviter)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to fill history:", err)
|
||||
}
|
||||
|
||||
inviter.addPortalToCommunity(portal)
|
||||
inviter.addPuppetToCommunity(puppet)
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandlePuppetInvite(evt *event.Event, inviter *User, puppet *Puppet) {
|
||||
intent := puppet.DefaultIntent()
|
||||
members := mx.joinAndCheckMembers(evt, intent)
|
||||
if members == nil {
|
||||
return
|
||||
}
|
||||
var hasBridgeBot, hasOtherUsers bool
|
||||
for mxid, _ := range members.Joined {
|
||||
if mxid == intent.UserID || mxid == inviter.MXID {
|
||||
continue
|
||||
} else if mxid == mx.bridge.Bot.UserID {
|
||||
hasBridgeBot = true
|
||||
} else {
|
||||
hasOtherUsers = true
|
||||
}
|
||||
}
|
||||
if !hasBridgeBot && !hasOtherUsers {
|
||||
key := database.NewPortalKey(puppet.JID, inviter.JID)
|
||||
mx.handlePrivatePortal(evt.RoomID, inviter, puppet, key)
|
||||
} else if !hasBridgeBot {
|
||||
mx.log.Debugln("Leaving multi-user room", evt.RoomID, "as", puppet.MXID, "after accepting invite from", evt.Sender)
|
||||
_, _ = intent.SendNotice(evt.RoomID, "Please invite the bridge bot first if you want to bridge to a WhatsApp group.")
|
||||
_, _ = intent.LeaveRoom(evt.RoomID)
|
||||
} else {
|
||||
_, _ = intent.SendNotice(evt.RoomID, "This puppet will remain inactive until this room is bridged to a WhatsApp group.")
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleMembership(evt *event.Event) {
|
||||
if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet {
|
||||
return
|
||||
}
|
||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
||||
|
||||
if mx.bridge.Crypto != nil {
|
||||
mx.bridge.Crypto.HandleMemberEvent(evt)
|
||||
}
|
||||
|
||||
content := evt.Content.AsMember()
|
||||
if content.Membership == event.MembershipInvite && id.UserID(evt.GetStateKey()) == mx.as.BotMXID() {
|
||||
mx.HandleBotInvite(evt)
|
||||
return
|
||||
}
|
||||
|
||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
if user == nil || !user.Whitelisted || !user.IsConnected() {
|
||||
return
|
||||
}
|
||||
|
||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
||||
if portal == nil {
|
||||
puppet := mx.bridge.GetPuppetByMXID(id.UserID(evt.GetStateKey()))
|
||||
if content.Membership == event.MembershipInvite && puppet != nil {
|
||||
mx.HandlePuppetInvite(evt, user, puppet)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
isSelf := id.UserID(evt.GetStateKey()) == evt.Sender
|
||||
|
||||
if content.Membership == event.MembershipLeave {
|
||||
if isSelf {
|
||||
if evt.Unsigned.PrevContent != nil {
|
||||
_ = evt.Unsigned.PrevContent.ParseRaw(evt.Type)
|
||||
prevContent, ok := evt.Unsigned.PrevContent.Parsed.(*event.MemberEventContent)
|
||||
if ok {
|
||||
if portal.IsPrivateChat() || prevContent.Membership == "join" {
|
||||
portal.HandleMatrixLeave(user)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
portal.HandleMatrixKick(user, evt)
|
||||
}
|
||||
} else if content.Membership == event.MembershipInvite && !isSelf {
|
||||
portal.HandleMatrixInvite(user, evt)
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleRoomMetadata(evt *event.Event) {
|
||||
// defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
||||
// user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
// if user == nil || !user.Whitelisted || !user.IsConnected() {
|
||||
// return
|
||||
// }
|
||||
|
||||
// portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
||||
// if portal == nil || portal.IsPrivateChat() {
|
||||
// return
|
||||
// }
|
||||
|
||||
// var resp <-chan string
|
||||
// var err error
|
||||
// switch content := evt.Content.Parsed.(type) {
|
||||
// case *event.RoomNameEventContent:
|
||||
// resp, err = user.Conn.UpdateGroupSubject(content.Name, portal.Key.JID)
|
||||
// case *event.TopicEventContent:
|
||||
// resp, err = user.Conn.UpdateGroupDescription(portal.Key.JID, content.Topic)
|
||||
// case *event.RoomAvatarEventContent:
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// mx.log.Errorln(err)
|
||||
// } else {
|
||||
// out := <-resp
|
||||
// mx.log.Infoln(out)
|
||||
// }
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) shouldIgnoreEvent(evt *event.Event) bool {
|
||||
if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet {
|
||||
return true
|
||||
}
|
||||
isCustomPuppet, ok := evt.Content.Raw["net.maunium.whatsapp.puppet"].(bool)
|
||||
if ok && isCustomPuppet && mx.bridge.GetPuppetByCustomMXID(evt.Sender) != nil {
|
||||
return true
|
||||
}
|
||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
if !user.RelaybotWhitelisted {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const sessionWaitTimeout = 5 * time.Second
|
||||
|
||||
func (mx *MatrixHandler) HandleEncrypted(evt *event.Event) {
|
||||
println("IDK iF encryption works yet")
|
||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
||||
if mx.shouldIgnoreEvent(evt) || mx.bridge.Crypto == nil {
|
||||
return
|
||||
}
|
||||
|
||||
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
||||
if errors.Is(err, NoSessionFound) {
|
||||
content := evt.Content.AsEncrypted()
|
||||
mx.log.Debugfln("Couldn't find session %s trying to decrypt %s, waiting %d seconds...", content.SessionID, evt.ID, int(sessionWaitTimeout.Seconds()))
|
||||
if mx.bridge.Crypto.WaitForSession(evt.RoomID, content.SenderKey, content.SessionID, sessionWaitTimeout) {
|
||||
mx.log.Debugfln("Got session %s after waiting, trying to decrypt %s again", content.SessionID, evt.ID)
|
||||
decrypted, err = mx.bridge.Crypto.Decrypt(evt)
|
||||
} else {
|
||||
go mx.waitLongerForSession(evt)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
|
||||
_, _ = mx.bridge.Bot.SendNotice(evt.RoomID, fmt.Sprintf(
|
||||
"\u26a0 Your message was not bridged: %v", err))
|
||||
return
|
||||
}
|
||||
mx.bridge.EventProcessor.Dispatch(decrypted)
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) waitLongerForSession(evt *event.Event) {
|
||||
const extendedTimeout = sessionWaitTimeout * 2
|
||||
|
||||
content := evt.Content.AsEncrypted()
|
||||
mx.log.Debugfln("Couldn't find session %s trying to decrypt %s, waiting %d more seconds...",
|
||||
content.SessionID, evt.ID, int(extendedTimeout.Seconds()))
|
||||
|
||||
resp, err := mx.bridge.Bot.SendNotice(evt.RoomID, fmt.Sprintf(
|
||||
"\u26a0 Your message was not bridged: the bridge hasn't received the decryption keys. "+
|
||||
"The bridge will retry for %d seconds. If this error keeps happening, try restarting your client.",
|
||||
int(extendedTimeout.Seconds())))
|
||||
if err != nil {
|
||||
mx.log.Errorfln("Failed to send decryption error to %s: %v", evt.RoomID, err)
|
||||
}
|
||||
update := event.MessageEventContent{MsgType: event.MsgNotice}
|
||||
|
||||
if mx.bridge.Crypto.WaitForSession(evt.RoomID, content.SenderKey, content.SessionID, extendedTimeout) {
|
||||
mx.log.Debugfln("Got session %s after waiting more, trying to decrypt %s again", content.SessionID, evt.ID)
|
||||
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
||||
if err == nil {
|
||||
mx.bridge.EventProcessor.Dispatch(decrypted)
|
||||
_, _ = mx.bridge.Bot.RedactEvent(evt.RoomID, resp.EventID)
|
||||
return
|
||||
}
|
||||
mx.log.Warnfln("Failed to decrypt %s: %v", err)
|
||||
update.Body = fmt.Sprintf("\u26a0 Your message was not bridged: %v", err)
|
||||
} else {
|
||||
mx.log.Debugfln("Didn't get %s, giving up on %s", content.SessionID, evt.ID)
|
||||
update.Body = "\u26a0 Your message was not bridged: the bridge hasn't received the decryption keys. " +
|
||||
"If this keeps happening, try restarting your client."
|
||||
}
|
||||
|
||||
newContent := update
|
||||
update.NewContent = &newContent
|
||||
if resp != nil {
|
||||
update.RelatesTo = &event.RelatesTo{
|
||||
Type: event.RelReplace,
|
||||
EventID: resp.EventID,
|
||||
}
|
||||
}
|
||||
_, _ = mx.bridge.Bot.SendMessageEvent(evt.RoomID, event.EventMessage, &update)
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleMessage(evt *event.Event) {
|
||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
||||
if mx.shouldIgnoreEvent(evt) {
|
||||
return
|
||||
}
|
||||
|
||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
content := evt.Content.AsMessage()
|
||||
if user.Whitelisted && content.MsgType == event.MsgText {
|
||||
commandPrefix := mx.bridge.Config.Bridge.CommandPrefix
|
||||
hasCommandPrefix := strings.HasPrefix(content.Body, commandPrefix)
|
||||
if hasCommandPrefix {
|
||||
content.Body = strings.TrimLeft(content.Body[len(commandPrefix):], " ")
|
||||
}
|
||||
if hasCommandPrefix || evt.RoomID == user.ManagementRoom {
|
||||
mx.cmd.Handle(evt.RoomID, user, content.Body)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
||||
if portal != nil && (user.Whitelisted || portal.HasRelaybot()) {
|
||||
portal.HandleMatrixMessage(user, evt)
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleRedaction(evt *event.Event) {
|
||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
||||
if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet {
|
||||
return
|
||||
}
|
||||
|
||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
|
||||
if !user.Whitelisted {
|
||||
return
|
||||
}
|
||||
|
||||
if !user.HasSession() {
|
||||
return
|
||||
} else if !user.IsConnected() {
|
||||
msg := format.RenderMarkdown(fmt.Sprintf("[%[1]s](https://matrix.to/#/%[1]s): \u26a0 "+
|
||||
"You are not connected to WhatsApp, so your redaction was not bridged. "+
|
||||
"Use `%[2]s reconnect` to reconnect.", user.MXID, mx.bridge.Config.Bridge.CommandPrefix), true, false)
|
||||
msg.MsgType = event.MsgNotice
|
||||
_, _ = mx.bridge.Bot.SendMessageEvent(evt.RoomID, event.EventMessage, msg)
|
||||
return
|
||||
}
|
||||
|
||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
||||
if portal != nil {
|
||||
portal.HandleMatrixRedaction(user, evt)
|
||||
}
|
||||
}
|
||||
|
207
messagetracking.go
Normal file
207
messagetracking.go
Normal file
@ -0,0 +1,207 @@
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/bridge/status"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
var (
|
||||
errMessageTakingLong = errors.New("bridging the message is taking longer than usual")
|
||||
)
|
||||
|
||||
func errorToStatusReason(err error) (reason event.MessageStatusReason, status event.MessageStatus, isCertain, sendNotice bool, humanMessage string) {
|
||||
switch {
|
||||
case errors.Is(err, errMessageTakingLong):
|
||||
return event.MessageStatusTooOld, event.MessageStatusPending, false, true, err.Error()
|
||||
default:
|
||||
return event.MessageStatusGenericError, event.MessageStatusRetriable, false, true, ""
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) sendErrorMessage(evt *event.Event, err error, msgType string, confirmed bool, editID id.EventID) id.EventID {
|
||||
if !portal.bridge.Config.Bridge.MessageErrorNotices {
|
||||
return ""
|
||||
}
|
||||
certainty := "may not have been"
|
||||
if confirmed {
|
||||
certainty = "was not"
|
||||
}
|
||||
msg := fmt.Sprintf("\u26a0 Your %s %s bridged: %v", msgType, certainty, err)
|
||||
if errors.Is(err, errMessageTakingLong) {
|
||||
msg = fmt.Sprintf("\u26a0 Bridging your %s is taking longer than usual", msgType)
|
||||
}
|
||||
content := &event.MessageEventContent{
|
||||
MsgType: event.MsgNotice,
|
||||
Body: msg,
|
||||
}
|
||||
if editID != "" {
|
||||
content.SetEdit(editID)
|
||||
} else {
|
||||
content.SetReply(evt)
|
||||
}
|
||||
resp, err := portal.sendMainIntentMessage(content)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to send bridging error message:", err)
|
||||
return ""
|
||||
}
|
||||
return resp.EventID
|
||||
}
|
||||
|
||||
func (portal *Portal) sendStatusEvent(evtID, lastRetry id.EventID, err error) {
|
||||
if !portal.bridge.Config.Bridge.MessageStatusEvents {
|
||||
return
|
||||
}
|
||||
if lastRetry == evtID {
|
||||
lastRetry = ""
|
||||
}
|
||||
intent := portal.bridge.Bot
|
||||
if !portal.Encrypted {
|
||||
// Bridge bot isn't present in unencrypted DMs
|
||||
intent = portal.MainIntent()
|
||||
}
|
||||
content := event.BeeperMessageStatusEventContent{
|
||||
Network: portal.getBridgeInfoStateKey(),
|
||||
RelatesTo: event.RelatesTo{
|
||||
Type: event.RelReference,
|
||||
EventID: evtID,
|
||||
},
|
||||
LastRetry: lastRetry,
|
||||
}
|
||||
if err == nil {
|
||||
content.Status = event.MessageStatusSuccess
|
||||
} else {
|
||||
content.Reason, content.Status, _, _, content.Message = errorToStatusReason(err)
|
||||
content.Error = err.Error()
|
||||
}
|
||||
_, err = intent.SendMessageEvent(portal.MXID, event.BeeperMessageStatus, &content)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to send message status event:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) sendDeliveryReceipt(eventID id.EventID) {
|
||||
if portal.bridge.Config.Bridge.DeliveryReceipts {
|
||||
err := portal.bridge.Bot.MarkRead(portal.MXID, eventID)
|
||||
if err != nil {
|
||||
portal.log.Debugfln("Failed to send delivery receipt for %s: %v", eventID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) sendMessageMetrics(evt *event.Event, err error, part string, ms *metricSender) {
|
||||
var msgType string
|
||||
switch evt.Type {
|
||||
case event.EventMessage:
|
||||
msgType = "message"
|
||||
case event.EventReaction:
|
||||
msgType = "reaction"
|
||||
case event.EventRedaction:
|
||||
msgType = "redaction"
|
||||
default:
|
||||
msgType = "unknown event"
|
||||
}
|
||||
evtDescription := evt.ID.String()
|
||||
if evt.Type == event.EventRedaction {
|
||||
evtDescription += fmt.Sprintf(" of %s", evt.Redacts)
|
||||
}
|
||||
origEvtID := evt.ID
|
||||
if retryMeta := evt.Content.AsMessage().MessageSendRetry; retryMeta != nil {
|
||||
origEvtID = retryMeta.OriginalEventID
|
||||
}
|
||||
if err != nil {
|
||||
level := log.LevelError
|
||||
if part == "Ignoring" {
|
||||
level = log.LevelDebug
|
||||
}
|
||||
portal.log.Logfln(level, "%s %s %s from %s: %v", part, msgType, evtDescription, evt.Sender, err)
|
||||
reason, statusCode, isCertain, sendNotice, _ := errorToStatusReason(err)
|
||||
checkpointStatus := status.ReasonToCheckpointStatus(reason, statusCode)
|
||||
portal.bridge.SendMessageCheckpoint(evt, status.MsgStepRemote, err, checkpointStatus, ms.getRetryNum())
|
||||
if sendNotice {
|
||||
ms.setNoticeID(portal.sendErrorMessage(evt, err, msgType, isCertain, ms.getNoticeID()))
|
||||
}
|
||||
portal.sendStatusEvent(origEvtID, evt.ID, err)
|
||||
} else {
|
||||
portal.log.Debugfln("Handled Matrix %s %s", msgType, evtDescription)
|
||||
portal.sendDeliveryReceipt(evt.ID)
|
||||
portal.bridge.SendMessageSuccessCheckpoint(evt, status.MsgStepRemote, ms.getRetryNum())
|
||||
portal.sendStatusEvent(origEvtID, evt.ID, nil)
|
||||
if prevNotice := ms.popNoticeID(); prevNotice != "" {
|
||||
_, _ = portal.MainIntent().RedactEvent(portal.MXID, prevNotice, mautrix.ReqRedact{
|
||||
Reason: "error resolved",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type metricSender struct {
|
||||
portal *Portal
|
||||
previousNotice id.EventID
|
||||
lock sync.Mutex
|
||||
completed bool
|
||||
retryNum int
|
||||
}
|
||||
|
||||
func (ms *metricSender) getRetryNum() int {
|
||||
if ms != nil {
|
||||
return ms.retryNum
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (ms *metricSender) getNoticeID() id.EventID {
|
||||
if ms == nil {
|
||||
return ""
|
||||
}
|
||||
return ms.previousNotice
|
||||
}
|
||||
|
||||
func (ms *metricSender) popNoticeID() id.EventID {
|
||||
if ms == nil {
|
||||
return ""
|
||||
}
|
||||
evtID := ms.previousNotice
|
||||
ms.previousNotice = ""
|
||||
return evtID
|
||||
}
|
||||
|
||||
func (ms *metricSender) setNoticeID(evtID id.EventID) {
|
||||
if ms != nil && ms.previousNotice == "" {
|
||||
ms.previousNotice = evtID
|
||||
}
|
||||
}
|
||||
|
||||
func (ms *metricSender) sendMessageMetrics(evt *event.Event, err error, part string, completed bool) {
|
||||
ms.lock.Lock()
|
||||
defer ms.lock.Unlock()
|
||||
if !completed && ms.completed {
|
||||
return
|
||||
}
|
||||
ms.portal.sendMessageMetrics(evt, err, part, ms)
|
||||
ms.retryNum++
|
||||
ms.completed = completed
|
||||
}
|
75
metrics.go
75
metrics.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -27,11 +27,12 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
"github.com/beeper/groupme/database"
|
||||
)
|
||||
|
||||
type MetricsHandler struct {
|
||||
@ -43,7 +44,7 @@ type MetricsHandler struct {
|
||||
ctx context.Context
|
||||
stopRecorder func()
|
||||
|
||||
messageHandling *prometheus.HistogramVec
|
||||
matrixEventHandling *prometheus.HistogramVec
|
||||
countCollection prometheus.Histogram
|
||||
disconnections *prometheus.CounterVec
|
||||
puppetCount prometheus.Gauge
|
||||
@ -56,17 +57,17 @@ type MetricsHandler struct {
|
||||
unencryptedPrivateCount prometheus.Gauge
|
||||
|
||||
connected prometheus.Gauge
|
||||
connectedState map[types.GroupMeID]bool
|
||||
connectedState map[groupme.ID]bool
|
||||
loggedIn prometheus.Gauge
|
||||
loggedInState map[types.GroupMeID]bool
|
||||
loggedInState map[groupme.ID]bool
|
||||
syncLocked prometheus.Gauge
|
||||
syncLockedState map[types.GroupMeID]bool
|
||||
syncLockedState map[groupme.ID]bool
|
||||
bufferLength *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
func NewMetricsHandler(address string, log log.Logger, db *database.Database) *MetricsHandler {
|
||||
portalCount := promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "whatsapp_portals_total",
|
||||
Name: "groupme_portals_total",
|
||||
Help: "Number of portal rooms on Matrix",
|
||||
}, []string{"type", "encrypted"})
|
||||
return &MetricsHandler{
|
||||
@ -75,28 +76,28 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
||||
log: log,
|
||||
running: false,
|
||||
|
||||
messageHandling: promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
matrixEventHandling: promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Name: "matrix_event",
|
||||
Help: "Time spent processing Matrix events",
|
||||
}, []string{"event_type"}),
|
||||
countCollection: promauto.NewHistogram(prometheus.HistogramOpts{
|
||||
Name: "whatsapp_count_collection",
|
||||
Help: "Time spent collecting the whatsapp_*_total metrics",
|
||||
Name: "groupme_count_collection",
|
||||
Help: "Time spent collecting the groupme_*_total metrics",
|
||||
}),
|
||||
disconnections: promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "whatsapp_disconnections",
|
||||
Help: "Number of times a Matrix user has been disconnected from WhatsApp",
|
||||
Name: "groupme_disconnections",
|
||||
Help: "Number of times a Matrix user has been disconnected from GroupMe",
|
||||
}, []string{"user_id"}),
|
||||
puppetCount: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "whatsapp_puppets_total",
|
||||
Help: "Number of WhatsApp users bridged into Matrix",
|
||||
Name: "groupme_puppets_total",
|
||||
Help: "Number of GroupMe users bridged into Matrix",
|
||||
}),
|
||||
userCount: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "whatsapp_users_total",
|
||||
Name: "groupme_users_total",
|
||||
Help: "Number of Matrix users using the bridge",
|
||||
}),
|
||||
messageCount: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "whatsapp_messages_total",
|
||||
Name: "groupme_messages_total",
|
||||
Help: "Number of messages bridged",
|
||||
}),
|
||||
portalCount: portalCount,
|
||||
@ -109,17 +110,17 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
||||
Name: "bridge_logged_in",
|
||||
Help: "Users logged into the bridge",
|
||||
}),
|
||||
loggedInState: make(map[types.GroupMeID]bool),
|
||||
loggedInState: make(map[groupme.ID]bool),
|
||||
connected: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_connected",
|
||||
Help: "Bridge users connected to WhatsApp",
|
||||
Help: "Bridge users connected to GroupMe",
|
||||
}),
|
||||
connectedState: make(map[types.GroupMeID]bool),
|
||||
connectedState: make(map[groupme.ID]bool),
|
||||
syncLocked: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_sync_locked",
|
||||
Help: "Bridge users locked in post-login sync",
|
||||
}),
|
||||
syncLockedState: make(map[types.GroupMeID]bool),
|
||||
syncLockedState: make(map[groupme.ID]bool),
|
||||
bufferLength: promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "bridge_buffer_size",
|
||||
Help: "Number of messages in buffer",
|
||||
@ -129,14 +130,14 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
||||
|
||||
func noop() {}
|
||||
|
||||
func (mh *MetricsHandler) TrackEvent(eventType event.Type) func() {
|
||||
func (mh *MetricsHandler) TrackMatrixEvent(eventType event.Type) func() {
|
||||
if !mh.running {
|
||||
return noop
|
||||
}
|
||||
start := time.Now()
|
||||
return func() {
|
||||
duration := time.Now().Sub(start)
|
||||
mh.messageHandling.
|
||||
mh.matrixEventHandling.
|
||||
With(prometheus.Labels{"event_type": eventType.Type}).
|
||||
Observe(duration.Seconds())
|
||||
}
|
||||
@ -149,13 +150,13 @@ func (mh *MetricsHandler) TrackDisconnection(userID id.UserID) {
|
||||
mh.disconnections.With(prometheus.Labels{"user_id": string(userID)}).Inc()
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackLoginState(jid types.GroupMeID, loggedIn bool) {
|
||||
func (mh *MetricsHandler) TrackLoginState(gmid groupme.ID, loggedIn bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
currentVal, ok := mh.loggedInState[jid]
|
||||
currentVal, ok := mh.loggedInState[gmid]
|
||||
if !ok || currentVal != loggedIn {
|
||||
mh.loggedInState[jid] = loggedIn
|
||||
mh.loggedInState[gmid] = loggedIn
|
||||
if loggedIn {
|
||||
mh.loggedIn.Inc()
|
||||
} else {
|
||||
@ -164,13 +165,13 @@ func (mh *MetricsHandler) TrackLoginState(jid types.GroupMeID, loggedIn bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackConnectionState(jid types.GroupMeID, connected bool) {
|
||||
func (mh *MetricsHandler) TrackConnectionState(gmid groupme.ID, connected bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
currentVal, ok := mh.connectedState[jid]
|
||||
currentVal, ok := mh.connectedState[gmid]
|
||||
if !ok || currentVal != connected {
|
||||
mh.connectedState[jid] = connected
|
||||
mh.connectedState[gmid] = connected
|
||||
if connected {
|
||||
mh.connected.Inc()
|
||||
} else {
|
||||
@ -179,13 +180,13 @@ func (mh *MetricsHandler) TrackConnectionState(jid types.GroupMeID, connected bo
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackSyncLock(jid types.GroupMeID, locked bool) {
|
||||
func (mh *MetricsHandler) TrackSyncLock(gmid groupme.ID, locked bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
currentVal, ok := mh.syncLockedState[jid]
|
||||
currentVal, ok := mh.syncLockedState[gmid]
|
||||
if !ok || currentVal != locked {
|
||||
mh.syncLockedState[jid] = locked
|
||||
mh.syncLockedState[gmid] = locked
|
||||
if locked {
|
||||
mh.syncLocked.Inc()
|
||||
} else {
|
||||
@ -230,10 +231,10 @@ func (mh *MetricsHandler) updateStats() {
|
||||
// var encryptedGroupCount, encryptedPrivateCount, unencryptedGroupCount, unencryptedPrivateCount int
|
||||
// err = mh.db.QueryRowContext(mh.ctx, `
|
||||
// SELECT
|
||||
// COUNT(CASE WHEN jid LIKE '%@g.us' AND encrypted THEN 1 END) AS encrypted_group_portals,
|
||||
// COUNT(CASE WHEN jid LIKE '%@s.whatsapp.net' AND encrypted THEN 1 END) AS encrypted_private_portals,
|
||||
// COUNT(CASE WHEN jid LIKE '%@g.us' AND NOT encrypted THEN 1 END) AS unencrypted_group_portals,
|
||||
// COUNT(CASE WHEN jid LIKE '%@s.whatsapp.net' AND NOT encrypted THEN 1 END) AS unencrypted_private_portals
|
||||
// COUNT(CASE WHEN gmid LIKE '%@g.us' AND encrypted THEN 1 END) AS encrypted_group_portals,
|
||||
// COUNT(CASE WHEN gmid LIKE '%@s.groupme.net' AND encrypted THEN 1 END) AS encrypted_private_portals,
|
||||
// COUNT(CASE WHEN gmid LIKE '%@g.us' AND NOT encrypted THEN 1 END) AS unencrypted_group_portals,
|
||||
// COUNT(CASE WHEN gmid LIKE '%@s.groupme.net' AND NOT encrypted THEN 1 END) AS unencrypted_private_portals
|
||||
// FROM portal WHERE mxid<>''
|
||||
// `).Scan(&encryptedGroupCount, &encryptedPrivateCount, &unencryptedGroupCount, &unencryptedPrivateCount)
|
||||
// if err != nil {
|
||||
|
17
no-crypto.go
17
no-crypto.go
@ -1,17 +0,0 @@
|
||||
// +build !cgo nocrypto
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
func NewCryptoHelper(bridge *Bridge) Crypto {
|
||||
if !bridge.Config.Bridge.Encryption.Allow {
|
||||
bridge.Log.Warnln("Bridge built without end-to-bridge encryption, but encryption is enabled in config")
|
||||
}
|
||||
bridge.Log.Debugln("Bridge built without end-to-bridge encryption")
|
||||
return nil
|
||||
}
|
||||
|
||||
var NoSessionFound = errors.New("nil")
|
342
provisioning.go
342
provisioning.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -21,29 +21,21 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type ProvisioningAPI struct {
|
||||
bridge *Bridge
|
||||
bridge *GMBridge
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Init() {
|
||||
prov.log = prov.bridge.Log.Sub("Provisioning")
|
||||
prov.log.Debugln("Enabling provisioning API at", prov.bridge.Config.AppService.Provisioning.Prefix)
|
||||
r := prov.bridge.AS.Router.PathPrefix(prov.bridge.Config.AppService.Provisioning.Prefix).Subrouter()
|
||||
prov.log.Debugln("Enabling provisioning API at", prov.bridge.Config.Bridge.Provisioning.Prefix)
|
||||
r := prov.bridge.AS.Router.PathPrefix(prov.bridge.Config.Bridge.Provisioning.Prefix).Subrouter()
|
||||
r.Use(prov.AuthMiddleware)
|
||||
r.HandleFunc("/ping", prov.Ping).Methods(http.MethodGet)
|
||||
r.HandleFunc("/login", prov.Login)
|
||||
r.HandleFunc("/logout", prov.Logout).Methods(http.MethodPost)
|
||||
r.HandleFunc("/delete_session", prov.DeleteSession).Methods(http.MethodPost)
|
||||
r.HandleFunc("/delete_connection", prov.DeleteConnection).Methods(http.MethodPost)
|
||||
r.HandleFunc("/disconnect", prov.Disconnect).Methods(http.MethodPost)
|
||||
r.HandleFunc("/reconnect", prov.Reconnect).Methods(http.MethodPost)
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) AuthMiddleware(h http.Handler) http.Handler {
|
||||
@ -53,15 +45,15 @@ func (prov *ProvisioningAPI) AuthMiddleware(h http.Handler) http.Handler {
|
||||
authParts := strings.Split(r.Header.Get("Sec-WebSocket-Protocol"), ",")
|
||||
for _, part := range authParts {
|
||||
part = strings.TrimSpace(part)
|
||||
if strings.HasPrefix(part, "net.maunium.whatsapp.auth-") {
|
||||
auth = part[len("net.maunium.whatsapp.auth-"):]
|
||||
if strings.HasPrefix(part, "com.beeper.groupme.auth-") {
|
||||
auth = part[len("com.beeper.groupme.auth-"):]
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if strings.HasPrefix(auth, "Bearer ") {
|
||||
auth = auth[len("Bearer "):]
|
||||
}
|
||||
if auth != prov.bridge.Config.AppService.Provisioning.SharedSecret {
|
||||
if auth != prov.bridge.Config.Bridge.Provisioning.SharedSecret {
|
||||
jsonResponse(w, http.StatusForbidden, map[string]interface{}{
|
||||
"error": "Invalid auth token",
|
||||
"errcode": "M_FORBIDDEN",
|
||||
@ -85,326 +77,8 @@ type Response struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) DeleteSession(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Session == nil && user.Conn == nil {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "Nothing to purge: no session information stored and no active connection.",
|
||||
// ErrCode: "no session",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// user.SetSession(nil)
|
||||
// if user.Conn != nil {
|
||||
// _, _ = user.Conn.Disconnect()
|
||||
// user.Conn.RemoveHandlers()
|
||||
// user.Conn = nil
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// }
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Session information purged"})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) DeleteConnection(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Conn == nil {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You don't have a WhatsApp connection.",
|
||||
// ErrCode: "not connected",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err == nil && len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// user.Conn.RemoveHandlers()
|
||||
// user.Conn = nil
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Disconnected from WhatsApp and connection deleted"})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Disconnect(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value("user").(*User)
|
||||
if user.Conn == nil {
|
||||
jsonResponse(w, http.StatusNotFound, Error{
|
||||
Error: "You don't have a WhatsApp connection.",
|
||||
ErrCode: "no connection",
|
||||
})
|
||||
return
|
||||
}
|
||||
//sess, err :=
|
||||
//user.Conn.Stop(context.TODO())
|
||||
// if err == whatsapp.ErrNotConnected {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You were not connected",
|
||||
// ErrCode: "not connected",
|
||||
// })
|
||||
// return
|
||||
// } else if err != nil {
|
||||
// user.log.Warnln("Error while disconnecting:", err)
|
||||
// jsonResponse(w, http.StatusInternalServerError, Error{
|
||||
// Error: fmt.Sprintf("Unknown error while disconnecting: %v", err),
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
jsonResponse(w, http.StatusOK, Response{true, "Disconnected from WhatsApp"})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Reconnect(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Conn == nil {
|
||||
// if user.Session == nil {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: "No existing connection and no session. Please log in first.",
|
||||
// ErrCode: "no session",
|
||||
// })
|
||||
// } else {
|
||||
// user.Connect(false)
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Created connection to WhatsApp."})
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// wasConnected := true
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err == whatsapp.ErrNotConnected {
|
||||
// wasConnected = false
|
||||
// } else if err != nil {
|
||||
// user.log.Warnln("Error while disconnecting:", err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
|
||||
// err = user.Conn.Restore()
|
||||
// if err == whatsapp.ErrInvalidSession {
|
||||
// if user.Session != nil {
|
||||
// user.log.Debugln("Got invalid session error when reconnecting, but user has session. Retrying using RestoreWithSession()...")
|
||||
// var sess whatsapp.Session
|
||||
// sess, err = user.Conn.RestoreWithSession(*user.Session)
|
||||
// if err == nil {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// } else {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: "You're not logged in",
|
||||
// ErrCode: "not logged in",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// } else if err == whatsapp.ErrLoginInProgress {
|
||||
// jsonResponse(w, http.StatusConflict, Error{
|
||||
// Error: "A login or reconnection is already in progress.",
|
||||
// ErrCode: "login in progress",
|
||||
// })
|
||||
// return
|
||||
// } else if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
// jsonResponse(w, http.StatusConflict, Error{
|
||||
// Error: "You were already connected.",
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Error while reconnecting:", err)
|
||||
// if err.Error() == "restore session connection timed out" {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: "Reconnection timed out. Is WhatsApp on your phone reachable?",
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: fmt.Sprintf("Unknown error while reconnecting: %v", err),
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// }
|
||||
// user.log.Debugln("Disconnecting due to failed session restore in reconnect command...")
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// user.log.Errorln("Failed to disconnect after failed session restore in reconnect command:", err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// user.ConnectionErrors = 0
|
||||
// user.PostLogin()
|
||||
|
||||
// var msg string
|
||||
// if wasConnected {
|
||||
// msg = "Reconnected successfully."
|
||||
// } else {
|
||||
// msg = "Connected successfully."
|
||||
// }
|
||||
|
||||
// jsonResponse(w, http.StatusOK, Response{true, msg})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Ping(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// wa := map[string]interface{}{
|
||||
// "has_session": user.Client != nil,
|
||||
// "management_room": user.ManagementRoom,
|
||||
// "jid": user.JID,
|
||||
// "conn": nil,
|
||||
// "ping": nil,
|
||||
// }
|
||||
// if user.Conn != nil {
|
||||
// wa["conn"] = map[string]interface{}{
|
||||
// "is_connected": user.IsConnected(),
|
||||
// "is_logged_in": user.IsLoggedIn(),
|
||||
// "is_login_in_progress": user.IsLoginInProgress(),
|
||||
// }
|
||||
// err := user.Conn.AdminTest()
|
||||
// wa["ping"] = map[string]interface{}{
|
||||
// "ok": err == nil,
|
||||
// "err": err,
|
||||
// }
|
||||
// }
|
||||
// resp := map[string]interface{}{
|
||||
// "mxid": user.MXID,
|
||||
// "admin": user.Admin,
|
||||
// "whitelisted": user.Whitelisted,
|
||||
// "relaybot_whitelisted": user.RelaybotWhitelisted,
|
||||
// "whatsapp": wa,
|
||||
// }
|
||||
// jsonResponse(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func jsonResponse(w http.ResponseWriter, status int, response interface{}) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Logout(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Session == nil {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You're not logged in",
|
||||
// ErrCode: "not logged in",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
// force := strings.ToLower(r.URL.Query().Get("force")) != "false"
|
||||
|
||||
// if user.Conn == nil {
|
||||
// if !force {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You're not connected",
|
||||
// ErrCode: "not connected",
|
||||
// })
|
||||
// }
|
||||
// } else {
|
||||
// err := user.Conn.Logout()
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Error while logging out:", err)
|
||||
// if !force {
|
||||
// jsonResponse(w, http.StatusInternalServerError, Error{
|
||||
// Error: fmt.Sprintf("Unknown error while logging out: %v", err),
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// _, err = user.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Error while disconnecting after logout:", err)
|
||||
// }
|
||||
// user.Conn.RemoveHandlers()
|
||||
// user.Conn = nil
|
||||
// }
|
||||
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// user.removeFromJIDMap()
|
||||
|
||||
// // TODO this causes a foreign key violation, which should be fixed
|
||||
// //ce.User.JID = ""
|
||||
// user.SetSession(nil)
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Logged out successfully."})
|
||||
}
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
Subprotocols: []string{"net.maunium.whatsapp.login"},
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) {
|
||||
userID := r.URL.Query().Get("user_id")
|
||||
user := prov.bridge.GetUserByMXID(id.UserID(userID))
|
||||
|
||||
if len(ce.Args) < 1 {
|
||||
// Return error that the token needs to be longer than 0 length
|
||||
// ce.Reply(`Get your access token from https://dev.groupme.com/ which should be the first argument to login`)
|
||||
return
|
||||
}
|
||||
user.Token = ce.Args[0]
|
||||
|
||||
user.addToJIDMap()
|
||||
// ce.Reply("Successfully logged in, synchronizing chats...")
|
||||
user.PostLogin()
|
||||
user.Connect()
|
||||
|
||||
// c, err := upgrader.Upgrade(w, r, nil)
|
||||
// if err != nil {
|
||||
// prov.log.Errorfln("Failed to upgrade connection to websocket:", err)
|
||||
// return
|
||||
// }
|
||||
// defer c.Close()
|
||||
|
||||
// if !user.Connect(true) {
|
||||
// user.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.")
|
||||
// _ = c.WriteJSON(Error{
|
||||
// Error: "Failed to connect to WhatsApp",
|
||||
// ErrCode: "connection error",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
// qrChan := make(chan string, 3)
|
||||
// go func() {
|
||||
// for code := range qrChan {
|
||||
// if code == "stop" {
|
||||
// return
|
||||
// }
|
||||
// _ = c.WriteJSON(map[string]interface{}{
|
||||
// "code": code,
|
||||
// })
|
||||
// }
|
||||
// }()
|
||||
// session, err := user.Conn.LoginWithRetry(qrChan, user.bridge.Config.Bridge.LoginQRRegenCount)
|
||||
// qrChan <- "stop"
|
||||
// if err != nil {
|
||||
// var msg string
|
||||
// if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
// msg = "You're already logged in"
|
||||
// } else if err == whatsapp.ErrLoginInProgress {
|
||||
// msg = "You have a login in progress already."
|
||||
// } else if err == whatsapp.ErrLoginTimedOut {
|
||||
// msg = "QR code scan timed out. Please try again."
|
||||
// } else {
|
||||
// user.log.Warnln("Failed to log in:", err)
|
||||
// msg = fmt.Sprintf("Unknown error while logging in: %v", err)
|
||||
// }
|
||||
// _ = c.WriteJSON(Error{
|
||||
// Error: msg,
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// user.ConnectionErrors = 0
|
||||
// user.JID = strings.Replace(user.Conn.Info.Wid, whatsappExt.OldUserSuffix, whatsappExt.NewUserSuffix, 1)
|
||||
// user.addToJIDMap()
|
||||
// user.SetSession(&session)
|
||||
// _ = c.WriteJSON(map[string]interface{}{
|
||||
// "success": true,
|
||||
// "jid": user.JID,
|
||||
// })
|
||||
// user.PostLogin()
|
||||
}
|
||||
|
277
puppet.go
277
puppet.go
@ -1,5 +1,5 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2020 Tulir Asokan
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
@ -17,137 +17,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"gitea.watsonlabs.net/watsonb8/groupme-lib"
|
||||
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/matrix-groupme-go/database"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/groupmeExt"
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
whatsappExt "github.com/karmanyaahm/matrix-groupme-go/whatsapp-ext"
|
||||
"github.com/beeper/groupme/database"
|
||||
)
|
||||
|
||||
var userIDRegex *regexp.Regexp
|
||||
|
||||
func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.GroupMeID, bool) {
|
||||
if userIDRegex == nil {
|
||||
userIDRegex = regexp.MustCompile(fmt.Sprintf("^@%s:%s$",
|
||||
bridge.Config.Bridge.FormatUsername("([0-9]+)"),
|
||||
bridge.Config.Homeserver.Domain))
|
||||
}
|
||||
match := userIDRegex.FindStringSubmatch(string(mxid))
|
||||
if match == nil || len(match) != 2 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
jid := types.GroupMeID(match[1])
|
||||
return jid, true
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetPuppetByMXID(mxid id.UserID) *Puppet {
|
||||
jid, ok := bridge.ParsePuppetMXID(mxid)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return bridge.GetPuppetByJID(jid)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetPuppetByJID(jid types.GroupMeID) *Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
puppet, ok := bridge.puppets[jid]
|
||||
if !ok {
|
||||
dbPuppet := bridge.DB.Puppet.Get(jid)
|
||||
if dbPuppet == nil {
|
||||
dbPuppet = bridge.DB.Puppet.New()
|
||||
dbPuppet.JID = jid
|
||||
dbPuppet.Insert()
|
||||
}
|
||||
puppet = bridge.NewPuppet(dbPuppet)
|
||||
bridge.puppets[puppet.JID] = puppet
|
||||
if len(puppet.CustomMXID) > 0 {
|
||||
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||
}
|
||||
}
|
||||
return puppet
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
puppet, ok := bridge.puppetsByCustomMXID[mxid]
|
||||
if !ok {
|
||||
dbPuppet := bridge.DB.Puppet.GetByCustomMXID(mxid)
|
||||
if dbPuppet == nil {
|
||||
return nil
|
||||
}
|
||||
puppet = bridge.NewPuppet(dbPuppet)
|
||||
bridge.puppets[puppet.JID] = puppet
|
||||
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||
}
|
||||
return puppet
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetAllPuppetsWithCustomMXID() []*Puppet {
|
||||
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAllWithCustomMXID())
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetAllPuppets() []*Puppet {
|
||||
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAll())
|
||||
}
|
||||
|
||||
func (bridge *Bridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
output := make([]*Puppet, len(dbPuppets))
|
||||
for index, dbPuppet := range dbPuppets {
|
||||
if dbPuppet == nil {
|
||||
continue
|
||||
}
|
||||
puppet, ok := bridge.puppets[dbPuppet.JID]
|
||||
if !ok {
|
||||
puppet = bridge.NewPuppet(dbPuppet)
|
||||
bridge.puppets[dbPuppet.JID] = puppet
|
||||
if len(dbPuppet.CustomMXID) > 0 {
|
||||
bridge.puppetsByCustomMXID[dbPuppet.CustomMXID] = puppet
|
||||
}
|
||||
}
|
||||
output[index] = puppet
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (bridge *Bridge) FormatPuppetMXID(jid types.GroupMeID) id.UserID {
|
||||
return id.NewUserID(
|
||||
bridge.Config.Bridge.FormatUsername(
|
||||
strings.Replace(
|
||||
jid,
|
||||
whatsappExt.NewUserSuffix, "", 1)),
|
||||
bridge.Config.Homeserver.Domain)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) NewPuppet(dbPuppet *database.Puppet) *Puppet {
|
||||
return &Puppet{
|
||||
Puppet: dbPuppet,
|
||||
bridge: bridge,
|
||||
log: bridge.Log.Sub(fmt.Sprintf("Puppet/%s", dbPuppet.JID)),
|
||||
|
||||
MXID: bridge.FormatPuppetMXID(dbPuppet.JID),
|
||||
}
|
||||
}
|
||||
|
||||
type Puppet struct {
|
||||
*database.Puppet
|
||||
|
||||
bridge *Bridge
|
||||
bridge *GMBridge
|
||||
log log.Logger
|
||||
|
||||
typingIn id.RoomID
|
||||
@ -158,17 +46,29 @@ type Puppet struct {
|
||||
customIntent *appservice.IntentAPI
|
||||
customTypingIn map[id.RoomID]bool
|
||||
customUser *User
|
||||
|
||||
syncLock sync.Mutex
|
||||
}
|
||||
|
||||
func (puppet *Puppet) ClearCustomMXID() {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// Public Properties
|
||||
|
||||
func (puppet *Puppet) GetMXID() id.UserID {
|
||||
return puppet.MXID
|
||||
}
|
||||
|
||||
func (puppet *Puppet) PhoneNumber() string {
|
||||
println("phone num")
|
||||
return strings.Replace(puppet.JID, whatsappExt.NewUserSuffix, "", 1)
|
||||
return puppet.GMID.String()
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
|
||||
func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI {
|
||||
if (!portal.IsPrivateChat() && puppet.customIntent == nil) ||
|
||||
(portal.backfilling && portal.bridge.Config.Bridge.InviteOwnPuppetForBackfilling) ||
|
||||
portal.Key.JID == puppet.JID {
|
||||
if puppet.customIntent == nil || portal.Key.GMID == puppet.GMID {
|
||||
return puppet.DefaultIntent()
|
||||
}
|
||||
return puppet.customIntent
|
||||
@ -182,136 +82,97 @@ func (puppet *Puppet) DefaultIntent() *appservice.IntentAPI {
|
||||
return puppet.bridge.AS.Intent(puppet.MXID)
|
||||
}
|
||||
|
||||
//func (puppet *Puppet) SetRoomMetadata(name, avatarURL string) bool {
|
||||
//
|
||||
//}
|
||||
|
||||
func (puppet *Puppet) UpdateAvatar(source *User, portalMXID id.RoomID, avatar string) bool {
|
||||
memberRaw, _ := puppet.bridge.StateStore.TryGetMemberRaw(portalMXID, puppet.MXID) //TODO Handle
|
||||
|
||||
if memberRaw.Avatar == avatar {
|
||||
return false // up to date
|
||||
}
|
||||
|
||||
if len(avatar) == 0 {
|
||||
var err error
|
||||
// err = puppet.DefaultIntent().SetRoomAvatarURL(portalMXID, id.ContentURI{})
|
||||
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to remove avatar:", err, puppet.MXID)
|
||||
os.Exit(1)
|
||||
func (puppet *Puppet) UpdateAvatar(source *User, forcePortalSync bool) bool {
|
||||
changed := source.updateAvatar(puppet.GMID, &puppet.Avatar, &puppet.AvatarURL, &puppet.AvatarSet, puppet.log, puppet.DefaultIntent())
|
||||
if !changed || puppet.Avatar == "unauthorized" {
|
||||
if forcePortalSync {
|
||||
go puppet.updatePortalAvatar()
|
||||
}
|
||||
memberRaw.Avatar = avatar
|
||||
memberRaw.AvatarURL = ""
|
||||
|
||||
go puppet.updatePortalAvatar()
|
||||
|
||||
puppet.bridge.StateStore.SetMemberRaw(&memberRaw) //TODO handle
|
||||
return true
|
||||
return changed
|
||||
}
|
||||
|
||||
//TODO check its actually groupme?
|
||||
image, mime, err := groupmeExt.DownloadImage(avatar + ".large")
|
||||
if err != nil {
|
||||
puppet.log.Warnln(err)
|
||||
return false
|
||||
}
|
||||
|
||||
resp, err := puppet.DefaultIntent().UploadBytes(*image, mime)
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to upload avatar:", err)
|
||||
return false
|
||||
}
|
||||
// err = puppet.DefaultIntent().SetRoomAvatarURL(portalMXID, resp.ContentURI)
|
||||
err := puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL)
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to set avatar:", err)
|
||||
} else {
|
||||
puppet.AvatarSet = true
|
||||
}
|
||||
|
||||
memberRaw.AvatarURL = resp.ContentURI.String()
|
||||
memberRaw.Avatar = avatar
|
||||
|
||||
puppet.bridge.StateStore.SetMemberRaw(&memberRaw) //TODO handle
|
||||
|
||||
go puppet.updatePortalAvatar()
|
||||
return true
|
||||
}
|
||||
|
||||
func (puppet *Puppet) UpdateName(source *User, portalMXID id.RoomID, contact groupme.Member) bool {
|
||||
newName, quality := puppet.bridge.Config.Bridge.FormatDisplayname(contact)
|
||||
|
||||
memberRaw, _ := puppet.bridge.StateStore.TryGetMemberRaw(portalMXID, puppet.MXID) //TODO Handle
|
||||
quality = quality //quality not used
|
||||
|
||||
if memberRaw.DisplayName != newName { //&& quality >= puppet.NameQuality[portalMXID] {
|
||||
var err error
|
||||
// err = puppet.DefaultIntent().SetRoomDisplayName(portalMXID, newName)
|
||||
|
||||
func (puppet *Puppet) UpdateName(member groupme.Member, forcePortalSync bool) bool {
|
||||
newName := puppet.bridge.Config.Bridge.FormatDisplayname(puppet.GMID, member)
|
||||
if puppet.Displayname != newName || !puppet.NameSet {
|
||||
oldName := puppet.Displayname
|
||||
puppet.Displayname = newName
|
||||
puppet.NameSet = false
|
||||
err := puppet.DefaultIntent().SetDisplayName(newName)
|
||||
if err == nil {
|
||||
memberRaw.DisplayName = newName
|
||||
// puppet.NameQuality[portalMXID] = quality
|
||||
|
||||
puppet.bridge.StateStore.SetMemberRaw(&memberRaw) //TODO handle; maybe .Update() ?
|
||||
puppet.log.Debugln("Updated name", oldName, "->", newName)
|
||||
puppet.NameSet = true
|
||||
go puppet.updatePortalName()
|
||||
} else {
|
||||
puppet.log.Warnln("Failed to set display name:", err)
|
||||
}
|
||||
return true
|
||||
} else if forcePortalSync {
|
||||
go puppet.updatePortalName()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (puppet *Puppet) updatePortalMeta(meta func(portal *Portal)) {
|
||||
if puppet.bridge.Config.Bridge.PrivateChatPortalMeta {
|
||||
for _, portal := range puppet.bridge.GetAllPortalsByJID(puppet.JID) {
|
||||
if puppet.bridge.Config.Bridge.PrivateChatPortalMeta || puppet.bridge.Config.Bridge.Encryption.Allow {
|
||||
for _, portal := range puppet.bridge.GetAllPortalsByGMID(puppet.GMID) {
|
||||
if !puppet.bridge.Config.Bridge.PrivateChatPortalMeta && !portal.Encrypted {
|
||||
continue
|
||||
}
|
||||
// Get room create lock to prevent races between receiving contact info and room creation.
|
||||
portal.roomCreateLock.Lock()
|
||||
meta(portal)
|
||||
portal.roomCreateLock.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (puppet *Puppet) updatePortalAvatar() {
|
||||
puppet.updatePortalMeta(func(portal *Portal) {
|
||||
|
||||
m, _ := puppet.bridge.StateStore.TryGetMemberRaw(portal.MXID, puppet.MXID)
|
||||
if portal.Avatar == puppet.Avatar && portal.AvatarURL == puppet.AvatarURL && portal.AvatarSet {
|
||||
return
|
||||
}
|
||||
portal.AvatarURL = puppet.AvatarURL
|
||||
portal.Avatar = puppet.Avatar
|
||||
portal.AvatarSet = false
|
||||
defer portal.Update(nil)
|
||||
if len(portal.MXID) > 0 {
|
||||
_, err := portal.MainIntent().SetRoomAvatar(portal.MXID, id.MustParseContentURI(m.AvatarURL))
|
||||
_, err := portal.MainIntent().SetRoomAvatar(portal.MXID, puppet.AvatarURL)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to set avatar:", err)
|
||||
} else {
|
||||
portal.AvatarSet = true
|
||||
portal.UpdateBridgeInfo()
|
||||
}
|
||||
}
|
||||
portal.AvatarURL = types.ContentURI{id.MustParseContentURI(m.AvatarURL)}
|
||||
portal.Avatar = m.Avatar
|
||||
portal.Update()
|
||||
})
|
||||
}
|
||||
|
||||
func (puppet *Puppet) updatePortalName() {
|
||||
puppet.updatePortalMeta(func(portal *Portal) {
|
||||
m, _ := puppet.bridge.StateStore.TryGetMemberRaw(portal.MXID, puppet.MXID)
|
||||
if len(portal.MXID) > 0 {
|
||||
_, err := portal.MainIntent().SetRoomName(portal.MXID, m.DisplayName)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to set name:", err)
|
||||
}
|
||||
}
|
||||
portal.Name = m.DisplayName
|
||||
portal.Update()
|
||||
portal.UpdateName(puppet.Displayname, groupme.ID(""), true)
|
||||
})
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Sync(source *User, portalMXID id.RoomID, contact groupme.Member) {
|
||||
if contact.UserID.String() == "system" {
|
||||
puppet.log.Warnln("Trying to sync system puppet")
|
||||
return
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Sync(source *User, member *groupme.Member, forceAvatarSync bool, forcePortalSync bool) {
|
||||
puppet.syncLock.Lock()
|
||||
defer puppet.syncLock.Unlock()
|
||||
err := puppet.DefaultIntent().EnsureRegistered()
|
||||
if err != nil {
|
||||
puppet.log.Errorln("Failed to ensure registered:", err)
|
||||
}
|
||||
|
||||
update := false
|
||||
update = puppet.UpdateName(source, portalMXID, contact) || update
|
||||
update = puppet.UpdateAvatar(source, portalMXID, contact.ImageURL) || update
|
||||
update = puppet.UpdateName(*member, forcePortalSync) || update
|
||||
update = puppet.UpdateAvatar(source, forcePortalSync) || update
|
||||
if update {
|
||||
puppet.Update()
|
||||
}
|
||||
|
97
segment.go
Normal file
97
segment.go
Normal file
@ -0,0 +1,97 @@
|
||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||
//
|
||||
// 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
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
const SegmentURL = "https://api.segment.io/v1/track"
|
||||
|
||||
type SegmentClient struct {
|
||||
key string
|
||||
userID string
|
||||
log log.Logger
|
||||
client http.Client
|
||||
}
|
||||
|
||||
var Segment SegmentClient
|
||||
|
||||
func (sc *SegmentClient) trackSync(userID id.UserID, event string, properties map[string]interface{}) error {
|
||||
var buf bytes.Buffer
|
||||
var segmentUserID string
|
||||
if Segment.userID != "" {
|
||||
segmentUserID = Segment.userID
|
||||
} else {
|
||||
segmentUserID = userID.String()
|
||||
}
|
||||
err := json.NewEncoder(&buf).Encode(map[string]interface{}{
|
||||
"userId": segmentUserID,
|
||||
"event": event,
|
||||
"properties": properties,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", SegmentURL, &buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.SetBasicAuth(sc.key, "")
|
||||
resp, err := sc.client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("unexpected status code %d", resp.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *SegmentClient) IsEnabled() bool {
|
||||
return len(sc.key) > 0
|
||||
}
|
||||
|
||||
func (sc *SegmentClient) Track(userID id.UserID, event string, properties ...map[string]interface{}) {
|
||||
if !sc.IsEnabled() {
|
||||
return
|
||||
} else if len(properties) > 1 {
|
||||
panic("Track should be called with at most one property map")
|
||||
}
|
||||
|
||||
go func() {
|
||||
props := map[string]interface{}{}
|
||||
if len(properties) > 0 {
|
||||
props = properties[0]
|
||||
}
|
||||
props["bridge"] = "groupme"
|
||||
err := sc.trackSync(userID, event, props)
|
||||
if err != nil {
|
||||
sc.log.Errorfln("Error tracking %s: %v", event, err)
|
||||
} else {
|
||||
sc.log.Debugln("Tracked", event)
|
||||
}
|
||||
}()
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type ContentURI struct {
|
||||
id.ContentURI
|
||||
}
|
||||
|
||||
func (m *ContentURI) Scan(value interface{}) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
//return errors.New(fmt.Sprint("Failed to unmarshal value:", value))
|
||||
}
|
||||
if len(bytes) == 0 {
|
||||
uri, _ := id.ParseContentURI("")
|
||||
*m = ContentURI{uri}
|
||||
return nil
|
||||
}
|
||||
return m.UnmarshalText(bytes)
|
||||
}
|
||||
|
||||
func (m ContentURI) Value() (driver.Value, error) {
|
||||
return m.String(), nil
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 types
|
||||
|
||||
// GroupMeID is a WhatsApp JID.
|
||||
type GroupMeID = string
|
||||
|
||||
// WhatsAppMessageID is the internal ID of a WhatsApp message.
|
||||
type WhatsAppMessageID = string
|
||||
|
||||
//AuthToken is the authentication token
|
||||
type AuthToken = string
|
||||
|
||||
type TmpID = GroupMeID
|
@ -1,72 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type CallInfoType string
|
||||
|
||||
const (
|
||||
CallOffer CallInfoType = "offer"
|
||||
CallOfferVideo CallInfoType = "offer_video"
|
||||
CallTransport CallInfoType = "transport"
|
||||
CallRelayLatency CallInfoType = "relaylatency"
|
||||
CallTerminate CallInfoType = "terminate"
|
||||
)
|
||||
|
||||
type CallInfo struct {
|
||||
ID string `json:"id"`
|
||||
Type CallInfoType `json:"type"`
|
||||
From string `json:"from"`
|
||||
|
||||
Platform string `json:"platform"`
|
||||
Version []int `json:"version"`
|
||||
|
||||
Data [][]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type CallInfoHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleCallInfo(CallInfo)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageCall(message []byte) {
|
||||
var event CallInfo
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
event.From = strings.Replace(event.From, OldUserSuffix, NewUserSuffix, 1)
|
||||
for _, handler := range ext.handlers {
|
||||
callInfoHandler, ok := handler.(CallInfoHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(callInfoHandler) {
|
||||
callInfoHandler.HandleCallInfo(event)
|
||||
} else {
|
||||
go callInfoHandler.HandleCallInfo(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type ChatUpdateCommand string
|
||||
|
||||
const (
|
||||
ChatUpdateCommandAction ChatUpdateCommand = "action"
|
||||
)
|
||||
|
||||
type ChatUpdate struct {
|
||||
JID string `json:"id"`
|
||||
Command ChatUpdateCommand `json:"cmd"`
|
||||
Data ChatUpdateData `json:"data"`
|
||||
}
|
||||
|
||||
type ChatActionType string
|
||||
|
||||
const (
|
||||
ChatActionNameChange ChatActionType = "subject"
|
||||
ChatActionAddTopic ChatActionType = "desc_add"
|
||||
ChatActionRemoveTopic ChatActionType = "desc_remove"
|
||||
ChatActionRestrict ChatActionType = "restrict"
|
||||
ChatActionAnnounce ChatActionType = "announce"
|
||||
ChatActionPromote ChatActionType = "promote"
|
||||
ChatActionDemote ChatActionType = "demote"
|
||||
ChatActionIntroduce ChatActionType = "introduce"
|
||||
ChatActionCreate ChatActionType = "create"
|
||||
ChatActionRemove ChatActionType = "remove"
|
||||
ChatActionAdd ChatActionType = "add"
|
||||
)
|
||||
|
||||
type ChatUpdateData struct {
|
||||
Action ChatActionType
|
||||
SenderJID string
|
||||
|
||||
NameChange struct {
|
||||
Name string `json:"subject"`
|
||||
SetAt int64 `json:"s_t"`
|
||||
SetBy string `json:"s_o"`
|
||||
}
|
||||
|
||||
AddTopic struct {
|
||||
Topic string `json:"desc"`
|
||||
ID string `json:"descId"`
|
||||
SetAt int64 `json:"descTime"`
|
||||
SetBy string `json:"descOwner"`
|
||||
}
|
||||
|
||||
RemoveTopic struct {
|
||||
ID string `json:"descId"`
|
||||
}
|
||||
|
||||
Introduce struct {
|
||||
CreationTime int64 `json:"creation"`
|
||||
Admins []string `json:"admins"`
|
||||
SuperAdmins []string `json:"superadmins"`
|
||||
Regulars []string `json:"regulars"`
|
||||
}
|
||||
|
||||
Restrict bool
|
||||
|
||||
Announce bool
|
||||
|
||||
UserChange struct {
|
||||
JIDs []string `json:"participants"`
|
||||
}
|
||||
}
|
||||
|
||||
func (cud *ChatUpdateData) UnmarshalJSON(data []byte) error {
|
||||
var arr []json.RawMessage
|
||||
err := json.Unmarshal(data, &arr)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(arr) < 3 {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = json.Unmarshal(arr[0], &cud.Action)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(arr[1], &cud.SenderJID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cud.SenderJID = strings.Replace(cud.SenderJID, OldUserSuffix, NewUserSuffix, 1)
|
||||
|
||||
var unmarshalTo interface{}
|
||||
switch cud.Action {
|
||||
case ChatActionIntroduce, ChatActionCreate:
|
||||
err = json.Unmarshal(arr[2], &cud.NameChange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(arr[2], &cud.AddTopic)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
unmarshalTo = &cud.Introduce
|
||||
case ChatActionNameChange:
|
||||
unmarshalTo = &cud.NameChange
|
||||
case ChatActionAddTopic:
|
||||
unmarshalTo = &cud.AddTopic
|
||||
case ChatActionRemoveTopic:
|
||||
unmarshalTo = &cud.RemoveTopic
|
||||
case ChatActionRestrict:
|
||||
unmarshalTo = &cud.Restrict
|
||||
case ChatActionAnnounce:
|
||||
unmarshalTo = &cud.Announce
|
||||
case ChatActionPromote, ChatActionDemote, ChatActionRemove, ChatActionAdd:
|
||||
unmarshalTo = &cud.UserChange
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
err = json.Unmarshal(arr[2], unmarshalTo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cud.NameChange.SetBy = strings.Replace(cud.NameChange.SetBy, OldUserSuffix, NewUserSuffix, 1)
|
||||
for index, jid := range cud.UserChange.JIDs {
|
||||
cud.UserChange.JIDs[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
||||
}
|
||||
for index, jid := range cud.Introduce.SuperAdmins {
|
||||
cud.Introduce.SuperAdmins[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
||||
}
|
||||
for index, jid := range cud.Introduce.Admins {
|
||||
cud.Introduce.Admins[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
||||
}
|
||||
for index, jid := range cud.Introduce.Regulars {
|
||||
cud.Introduce.Regulars[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ChatUpdateHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleChatUpdate(ChatUpdate)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageChatUpdate(message []byte) {
|
||||
var event ChatUpdate
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
event.JID = strings.Replace(event.JID, OldUserSuffix, NewUserSuffix, 1)
|
||||
for _, handler := range ext.handlers {
|
||||
chatUpdateHandler, ok := handler.(ChatUpdateHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(chatUpdateHandler) {
|
||||
chatUpdateHandler.HandleChatUpdate(event)
|
||||
} else {
|
||||
go chatUpdateHandler.HandleChatUpdate(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type CommandType string
|
||||
|
||||
const (
|
||||
CommandPicture CommandType = "picture"
|
||||
CommandDisconnect CommandType = "disconnect"
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
Type CommandType `json:"type"`
|
||||
JID string `json:"jid"`
|
||||
|
||||
*ProfilePicInfo
|
||||
Kind string `json:"kind"`
|
||||
|
||||
Raw json.RawMessage `json:"-"`
|
||||
}
|
||||
|
||||
type CommandHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleCommand(Command)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageCommand(message []byte) {
|
||||
var event Command
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
event.Raw = message
|
||||
event.JID = strings.Replace(event.JID, OldUserSuffix, NewUserSuffix, 1)
|
||||
for _, handler := range ext.handlers {
|
||||
commandHandler, ok := handler.(CommandHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(commandHandler) {
|
||||
commandHandler.HandleCommand(event)
|
||||
} else {
|
||||
go commandHandler.HandleCommand(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type ConnInfo struct {
|
||||
ProtocolVersion []int `json:"protoVersion"`
|
||||
BinaryVersion int `json:"binVersion"`
|
||||
Phone struct {
|
||||
WhatsAppVersion string `json:"wa_version"`
|
||||
MCC string `json:"mcc"`
|
||||
MNC string `json:"mnc"`
|
||||
OSVersion string `json:"os_version"`
|
||||
DeviceManufacturer string `json:"device_manufacturer"`
|
||||
DeviceModel string `json:"device_model"`
|
||||
OSBuildNumber string `json:"os_build_number"`
|
||||
} `json:"phone"`
|
||||
Features map[string]interface{} `json:"features"`
|
||||
PushName string `json:"pushname"`
|
||||
}
|
||||
|
||||
type ConnInfoHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleConnInfo(ConnInfo)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageConn(message []byte) {
|
||||
var event ConnInfo
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
for _, handler := range ext.handlers {
|
||||
connInfoHandler, ok := handler.(ConnInfoHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(connInfoHandler) {
|
||||
connInfoHandler.HandleConnInfo(event)
|
||||
} else {
|
||||
go connInfoHandler.HandleConnInfo(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
)
|
||||
|
||||
type CreateGroupResponse struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.GroupMeID `json:"gid"`
|
||||
Participants map[types.GroupMeID]struct {
|
||||
Code string `json:"code"`
|
||||
} `json:"participants"`
|
||||
|
||||
Source string `json:"-"`
|
||||
}
|
||||
|
||||
type actualCreateGroupResponse struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.GroupMeID `json:"gid"`
|
||||
Participants []map[types.GroupMeID]struct {
|
||||
Code string `json:"code"`
|
||||
} `json:"participants"`
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) CreateGroup(subject string, participants []types.GroupMeID) (*CreateGroupResponse, error) {
|
||||
// respChan, err := ext.Conn.CreateGroup(subject, participants)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var resp CreateGroupResponse
|
||||
// var actualResp actualCreateGroupResponse
|
||||
// resp.Source = <-respChan
|
||||
// fmt.Println(">>>>>>", resp.Source)
|
||||
// err = json.Unmarshal([]byte(resp.Source), &actualResp)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// resp.Status = actualResp.Status
|
||||
// resp.GroupID = actualResp.GroupID
|
||||
// resp.Participants = make(map[types.GroupMeID]struct {
|
||||
// Code string `json:"code"`
|
||||
// })
|
||||
// for _, participantMap := range actualResp.Participants {
|
||||
// for jid, status := range participantMap {
|
||||
// resp.Participants[jid] = status
|
||||
// }
|
||||
// }
|
||||
// return &resp, nil
|
||||
return nil, nil
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type JSONMessage []json.RawMessage
|
||||
|
||||
type JSONMessageType string
|
||||
|
||||
const (
|
||||
MessageMsgInfo JSONMessageType = "MsgInfo"
|
||||
MessageMsg JSONMessageType = "Msg"
|
||||
MessagePresence JSONMessageType = "Presence"
|
||||
MessageStream JSONMessageType = "Stream"
|
||||
MessageConn JSONMessageType = "Conn"
|
||||
MessageProps JSONMessageType = "Props"
|
||||
MessageCmd JSONMessageType = "Cmd"
|
||||
MessageChat JSONMessageType = "Chat"
|
||||
MessageCall JSONMessageType = "Call"
|
||||
)
|
||||
|
||||
func (ext *ExtendedConn) HandleError(error) {}
|
||||
|
||||
type UnhandledJSONMessageHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleUnhandledJSONMessage(string)
|
||||
}
|
||||
|
||||
type JSONParseErrorHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleJSONParseError(error)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) jsonParseError(err error) {
|
||||
for _, handler := range ext.handlers {
|
||||
errorHandler, ok := handler.(JSONParseErrorHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
errorHandler.HandleJSONParseError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) HandleJsonMessage(message string) {
|
||||
msg := JSONMessage{}
|
||||
err := json.Unmarshal([]byte(message), &msg)
|
||||
if err != nil || len(msg) < 2 {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
|
||||
var msgType JSONMessageType
|
||||
json.Unmarshal(msg[0], &msgType)
|
||||
|
||||
switch msgType {
|
||||
case MessagePresence:
|
||||
ext.handleMessagePresence(msg[1])
|
||||
case MessageStream:
|
||||
ext.handleMessageStream(msg[1:])
|
||||
case MessageConn:
|
||||
ext.handleMessageConn(msg[1])
|
||||
case MessageProps:
|
||||
ext.handleMessageProps(msg[1])
|
||||
case MessageMsgInfo, MessageMsg:
|
||||
ext.handleMessageMsgInfo(msgType, msg[1])
|
||||
case MessageCmd:
|
||||
ext.handleMessageCommand(msg[1])
|
||||
case MessageChat:
|
||||
ext.handleMessageChatUpdate(msg[1])
|
||||
case MessageCall:
|
||||
ext.handleMessageCall(msg[1])
|
||||
default:
|
||||
for _, handler := range ext.handlers {
|
||||
ujmHandler, ok := handler.(UnhandledJSONMessageHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(ujmHandler) {
|
||||
ujmHandler.HandleUnhandledJSONMessage(message)
|
||||
} else {
|
||||
go ujmHandler.HandleUnhandledJSONMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type MsgInfoCommand string
|
||||
|
||||
const (
|
||||
MsgInfoCommandAck MsgInfoCommand = "ack"
|
||||
MsgInfoCommandAcks MsgInfoCommand = "acks"
|
||||
)
|
||||
|
||||
type Acknowledgement int
|
||||
|
||||
const (
|
||||
AckMessageSent Acknowledgement = 1
|
||||
AckMessageDelivered Acknowledgement = 2
|
||||
AckMessageRead Acknowledgement = 3
|
||||
)
|
||||
|
||||
type JSONStringOrArray []string
|
||||
|
||||
func (jsoa *JSONStringOrArray) UnmarshalJSON(data []byte) error {
|
||||
var str string
|
||||
if json.Unmarshal(data, &str) == nil {
|
||||
*jsoa = []string{str}
|
||||
return nil
|
||||
}
|
||||
var strs []string
|
||||
json.Unmarshal(data, &strs)
|
||||
*jsoa = strs
|
||||
return nil
|
||||
}
|
||||
|
||||
type MsgInfo struct {
|
||||
Command MsgInfoCommand `json:"cmd"`
|
||||
IDs JSONStringOrArray `json:"id"`
|
||||
Acknowledgement Acknowledgement `json:"ack"`
|
||||
MessageFromJID string `json:"from"`
|
||||
SenderJID string `json:"participant"`
|
||||
ToJID string `json:"to"`
|
||||
Timestamp int64 `json:"t"`
|
||||
}
|
||||
|
||||
type MsgInfoHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleMsgInfo(MsgInfo)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageMsgInfo(msgType JSONMessageType, message []byte) {
|
||||
var event MsgInfo
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
event.MessageFromJID = strings.Replace(event.MessageFromJID, OldUserSuffix, NewUserSuffix, 1)
|
||||
event.SenderJID = strings.Replace(event.SenderJID, OldUserSuffix, NewUserSuffix, 1)
|
||||
event.ToJID = strings.Replace(event.ToJID, OldUserSuffix, NewUserSuffix, 1)
|
||||
if msgType == MessageMsg {
|
||||
event.SenderJID = event.ToJID
|
||||
}
|
||||
for _, handler := range ext.handlers {
|
||||
msgInfoHandler, ok := handler.(MsgInfoHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(msgInfoHandler) {
|
||||
msgInfoHandler.HandleMsgInfo(event)
|
||||
} else {
|
||||
go msgInfoHandler.HandleMsgInfo(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type Presence struct {
|
||||
JID string `json:"id"`
|
||||
SenderJID string `json:"participant"`
|
||||
Status whatsapp.Presence `json:"type"`
|
||||
Timestamp int64 `json:"t"`
|
||||
Deny bool `json:"deny"`
|
||||
}
|
||||
|
||||
type PresenceHandler interface {
|
||||
whatsapp.Handler
|
||||
HandlePresence(Presence)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessagePresence(message []byte) {
|
||||
var event Presence
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
event.JID = strings.Replace(event.JID, OldUserSuffix, NewUserSuffix, 1)
|
||||
if len(event.SenderJID) == 0 {
|
||||
event.SenderJID = event.JID
|
||||
} else {
|
||||
event.SenderJID = strings.Replace(event.SenderJID, OldUserSuffix, NewUserSuffix, 1)
|
||||
}
|
||||
for _, handler := range ext.handlers {
|
||||
presenceHandler, ok := handler.(PresenceHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(presenceHandler) {
|
||||
presenceHandler.HandlePresence(event)
|
||||
} else {
|
||||
go presenceHandler.HandlePresence(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type ProtocolProps struct {
|
||||
WebPresence bool `json:"webPresence"`
|
||||
NotificationQuery bool `json:"notificationQuery"`
|
||||
FacebookCrashLog bool `json:"fbCrashlog"`
|
||||
Bucket string `json:"bucket"`
|
||||
GIFSearch string `json:"gifSearch"`
|
||||
Spam bool `json:"SPAM"`
|
||||
SetBlock bool `json:"SET_BLOCK"`
|
||||
MessageInfo bool `json:"MESSAGE_INFO"`
|
||||
MaxFileSize int `json:"maxFileSize"`
|
||||
Media int `json:"media"`
|
||||
GroupNameLength int `json:"maxSubject"`
|
||||
GroupDescriptionLength int `json:"groupDescLength"`
|
||||
MaxParticipants int `json:"maxParticipants"`
|
||||
VideoMaxEdge int `json:"videoMaxEdge"`
|
||||
ImageMaxEdge int `json:"imageMaxEdge"`
|
||||
ImageMaxKilobytes int `json:"imageMaxKBytes"`
|
||||
Edit int `json:"edit"`
|
||||
FwdUIStartTimestamp int `json:"fwdUiStartTs"`
|
||||
GroupsV3 int `json:"groupsV3"`
|
||||
RestrictGroups int `json:"restrictGroups"`
|
||||
AnnounceGroups int `json:"announceGroups"`
|
||||
}
|
||||
|
||||
type ProtocolPropsHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleProtocolProps(ProtocolProps)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageProps(message []byte) {
|
||||
var event ProtocolProps
|
||||
err := json.Unmarshal(message, &event)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
for _, handler := range ext.handlers {
|
||||
protocolPropsHandler, ok := handler.(ProtocolPropsHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(protocolPropsHandler) {
|
||||
protocolPropsHandler.HandleProtocolProps(event)
|
||||
} else {
|
||||
go protocolPropsHandler.HandleProtocolProps(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
"github.com/Rhymen/go-whatsapp/binary/proto"
|
||||
)
|
||||
|
||||
type MessageRevokeHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleMessageRevoke(key MessageRevocation)
|
||||
}
|
||||
|
||||
type MessageRevocation struct {
|
||||
Id string
|
||||
RemoteJid string
|
||||
FromMe bool
|
||||
Participant string
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) HandleRawMessage(message *proto.WebMessageInfo) {
|
||||
protoMsg := message.GetMessage().GetProtocolMessage()
|
||||
if protoMsg != nil && protoMsg.GetType() == proto.ProtocolMessage_REVOKE {
|
||||
key := protoMsg.GetKey()
|
||||
deletedMessage := MessageRevocation{
|
||||
Id: key.GetId(),
|
||||
RemoteJid: key.GetRemoteJid(),
|
||||
FromMe: key.GetFromMe(),
|
||||
Participant: key.GetParticipant(),
|
||||
}
|
||||
for _, handler := range ext.handlers {
|
||||
mrHandler, ok := handler.(MessageRevokeHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(mrHandler) {
|
||||
mrHandler.HandleMessageRevoke(deletedMessage)
|
||||
} else {
|
||||
go mrHandler.HandleMessageRevoke(deletedMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
type StreamType string
|
||||
|
||||
const (
|
||||
StreamUpdate = "update"
|
||||
StreamSleep = "asleep"
|
||||
)
|
||||
|
||||
type StreamEvent struct {
|
||||
Type StreamType
|
||||
|
||||
IsOutdated bool
|
||||
Version string
|
||||
|
||||
Extra []json.RawMessage
|
||||
}
|
||||
|
||||
type StreamEventHandler interface {
|
||||
whatsapp.Handler
|
||||
HandleStreamEvent(StreamEvent)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) handleMessageStream(message []json.RawMessage) {
|
||||
var event StreamEvent
|
||||
err := json.Unmarshal(message[0], &event.Type)
|
||||
if err != nil {
|
||||
ext.jsonParseError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if event.Type == StreamUpdate && len(message) >= 3 {
|
||||
_ = json.Unmarshal(message[1], &event.IsOutdated)
|
||||
_ = json.Unmarshal(message[2], &event.Version)
|
||||
if len(message) >= 4 {
|
||||
event.Extra = message[3:]
|
||||
}
|
||||
} else if len(message) >= 2 {
|
||||
event.Extra = message[1:]
|
||||
}
|
||||
|
||||
for _, handler := range ext.handlers {
|
||||
streamHandler, ok := handler.(StreamEventHandler)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if ext.shouldCallSynchronously(streamHandler) {
|
||||
streamHandler.HandleStreamEvent(event)
|
||||
} else {
|
||||
go streamHandler.HandleStreamEvent(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 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 whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
)
|
||||
|
||||
const (
|
||||
OldUserSuffix = "@c.us"
|
||||
NewUserSuffix = "@s.whatsapp.net"
|
||||
)
|
||||
|
||||
type ExtendedConn struct {
|
||||
*whatsapp.Conn
|
||||
|
||||
handlers []whatsapp.Handler
|
||||
}
|
||||
|
||||
func ExtendConn(conn *whatsapp.Conn) *ExtendedConn {
|
||||
ext := &ExtendedConn{
|
||||
Conn: conn,
|
||||
}
|
||||
ext.Conn.AddHandler(ext)
|
||||
return ext
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) AddHandler(handler whatsapp.Handler) {
|
||||
ext.Conn.AddHandler(handler)
|
||||
ext.handlers = append(ext.handlers, handler)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) RemoveHandler(handler whatsapp.Handler) bool {
|
||||
ext.Conn.RemoveHandler(handler)
|
||||
for i, v := range ext.handlers {
|
||||
if v == handler {
|
||||
ext.handlers = append(ext.handlers[:i], ext.handlers[i+1:]...)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) RemoveHandlers() {
|
||||
ext.Conn.RemoveHandlers()
|
||||
ext.handlers = make([]whatsapp.Handler, 0)
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) shouldCallSynchronously(handler whatsapp.Handler) bool {
|
||||
sh, ok := handler.(whatsapp.SyncHandler)
|
||||
return ok && sh.ShouldCallSynchronously()
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) ShouldCallSynchronously() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type GroupInfo struct {
|
||||
JID string `json:"jid"`
|
||||
OwnerJID string `json:"owner"`
|
||||
|
||||
Name string `json:"subject"`
|
||||
NameSetTime int64 `json:"subjectTime"`
|
||||
NameSetBy string `json:"subjectOwner"`
|
||||
|
||||
Announce bool `json:"announce"` // Can only admins send messages?
|
||||
|
||||
Topic string `json:"desc"`
|
||||
TopicID string `json:"descId"`
|
||||
TopicSetAt int64 `json:"descTime"`
|
||||
TopicSetBy string `json:"descOwner"`
|
||||
|
||||
GroupCreated int64 `json:"creation"`
|
||||
|
||||
Status int16 `json:"status"`
|
||||
|
||||
Participants []struct {
|
||||
JID string `json:"id"`
|
||||
IsAdmin bool `json:"isAdmin"`
|
||||
IsSuperAdmin bool `json:"isSuperAdmin"`
|
||||
} `json:"participants"`
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) GetGroupMetaData(jid string) (*GroupInfo, error) {
|
||||
data, err := ext.Conn.GetGroupMetaData(jid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get group metadata: %v", err)
|
||||
}
|
||||
content := <-data
|
||||
|
||||
info := &GroupInfo{}
|
||||
err = json.Unmarshal([]byte(content), info)
|
||||
if err != nil {
|
||||
return info, fmt.Errorf("failed to unmarshal group metadata: %v", err)
|
||||
}
|
||||
|
||||
for index, participant := range info.Participants {
|
||||
info.Participants[index].JID = strings.Replace(participant.JID, OldUserSuffix, NewUserSuffix, 1)
|
||||
}
|
||||
info.NameSetBy = strings.Replace(info.NameSetBy, OldUserSuffix, NewUserSuffix, 1)
|
||||
info.TopicSetBy = strings.Replace(info.TopicSetBy, OldUserSuffix, NewUserSuffix, 1)
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
type ProfilePicInfo struct {
|
||||
URL string `json:"eurl"`
|
||||
Tag string `json:"tag"`
|
||||
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func (ppi *ProfilePicInfo) Download() (io.ReadCloser, error) {
|
||||
resp, err := http.Get(ppi.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
func (ppi *ProfilePicInfo) DownloadBytes() ([]byte, error) {
|
||||
body, err := ppi.Download()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer body.Close()
|
||||
data, err := ioutil.ReadAll(body)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) GetProfilePicThumb(jid string) (*ProfilePicInfo, error) {
|
||||
data, err := ext.Conn.GetProfilePicThumb(jid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get avatar: %v", err)
|
||||
}
|
||||
content := <-data
|
||||
info := &ProfilePicInfo{}
|
||||
err = json.Unmarshal([]byte(content), info)
|
||||
if err != nil {
|
||||
return info, fmt.Errorf("failed to unmarshal avatar info: %v", err)
|
||||
}
|
||||
return info, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user