Skip to content

Commit

Permalink
add basic pkg structure for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
JJTech0130 committed Jun 28, 2024
1 parent 2d44714 commit 8cc5250
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build.v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
if [[ -z "$LIBRARY_PATH" && -d /opt/homebrew ]]; then
echo "Using /opt/homebrew for LIBRARY_PATH and CPATH"
export LIBRARY_PATH=/opt/homebrew/lib
export CPATH=/opt/homebrew/include
fi
export MAUTRIX_VERSION=$(cat go.mod | grep 'maunium.net/go/mautrix ' | awk '{ print $2 }')
export GO_LDFLAGS="-s -w -X main.Tag=$(git describe --exact-match --tags 2>/dev/null) -X main.Commit=$(git rev-parse HEAD) -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`' -X 'maunium.net/go/mautrix.GoModVersion=$MAUTRIX_VERSION'"
go build -ldflags "$GO_LDFLAGS" -o mautrix-meta ./cmd/mautrix-meta "$@"
29 changes: 29 additions & 0 deletions cmd/mautrix-meta/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
_ "go.mau.fi/util/dbutil/litestream"
"maunium.net/go/mautrix/bridgev2/matrix/mxmain"

"go.mau.fi/mautrix-meta/pkg/connector"
)

// Information to find out exactly which commit the bridge was built from.
// These are filled at build time with the -X linker flag.
var (
Tag = "unknown"
Commit = "unknown"
BuildTime = "unknown"
)

func main() {
m := mxmain.BridgeMain{
Name: "mautrix-meta",
URL: "https://github.com/mautrix/meta",
Description: "A Matrix-Meta puppeting bridge.",
Version: "0.16.0",

Connector: connector.NewConnector(),
}
m.InitVersion(Tag, Commit, BuildTime)
m.Run()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // 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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ 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.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand Down
22 changes: 22 additions & 0 deletions pkg/connector/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package connector

import (
_ "embed"
up "go.mau.fi/util/configupgrade"

)

//go:embed example-config.yaml
var ExampleConfig string

type MetaConfig struct {
Mode string `yaml:"mode"`
}

func upgradeConfig(helper up.Helper) {
helper.Copy(up.Str, "mode")
}

func (s *MetaConnector) GetConfig() (string, any, up.Upgrader) {
return ExampleConfig, &s.Config, up.SimpleUpgrader(upgradeConfig)
}
57 changes: 57 additions & 0 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package connector

import (
"context"

"maunium.net/go/mautrix/bridgev2"
)

type MetaConnector struct {
Bridge *bridgev2.Bridge
Config *MetaConfig
}

func NewConnector() *MetaConnector {
return &MetaConnector{}
}

var _ bridgev2.NetworkConnector = (*MetaConnector)(nil)
var _ bridgev2.MaxFileSizeingNetwork = (*MetaConnector)(nil)

func (m *MetaConnector) SetMaxFileSize(maxSize int64) {
println("SetMaxFileSize unimplemented")
}

var metaGeneralCaps = &bridgev2.NetworkGeneralCapabilities{
DisappearingMessages: false,
AggressiveUpdateInfo: false,
}

func (m *MetaConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities {
return metaGeneralCaps
}

func (s *MetaConnector) GetName() bridgev2.BridgeName {
// Would be nice if we could use MetaConfig.Mode here, but it's not available yet?
return bridgev2.BridgeName{
DisplayName: "Meta",
NetworkURL: "https://meta.com",
NetworkIcon: "mxc://maunium.net/JxjlbZUlCPULEeHZSwleUXQv", // Instagram icon
NetworkID: "meta",
BeeperBridgeType: "meta",
DefaultPort: 29328,
}
}

func (m *MetaConnector) Init(*bridgev2.Bridge) {
println("Connector Init unimplemented")
}

func (m *MetaConnector) Start(context.Context) error {
println("Connector Start unimplemented")
return nil
}

func (m *MetaConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) error {
panic("unimplemented")
}
3 changes: 3 additions & 0 deletions pkg/connector/example-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Which service is this bridge for? Either "facebook" or "instagram".
# Remember to change the appservice id, bot profile info and bridge username_template too.
mode: instagram
49 changes: 49 additions & 0 deletions pkg/connector/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package connector

import (
"context"
"fmt"

"maunium.net/go/mautrix/bridgev2"
)

func (m *MetaConnector) CreateLogin(ctx context.Context, user *bridgev2.User, flowID string) (bridgev2.LoginProcess, error) {
if flowID != "cookies" {
return nil, fmt.Errorf("unknown flow ID %s", flowID)
}

return &CookieLogin{}, nil
}

func (m *MetaConnector) GetLoginFlows() []bridgev2.LoginFlow {
return []bridgev2.LoginFlow{{
Name: "Cookies",
Description: "Login using cookies from a web browser",
ID: "cookies",
}}
}

type CookieLogin struct {}

var _ bridgev2.LoginProcessCookies = (*CookieLogin)(nil)

func (p *CookieLogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
return &bridgev2.LoginStep{
Type: bridgev2.LoginStepTypeCookies,
StepID: "fi.mau.meta.cookies",
Instructions: "Please enter cookies from your browser",
CookiesParams: &bridgev2.LoginCookiesParams{

},
}, nil
}

func (c *CookieLogin) Cancel() {}

func (p *CookieLogin) SubmitCookies(ctx context.Context, cookies map[string]string) (*bridgev2.LoginStep, error) {
return &bridgev2.LoginStep{
Type: bridgev2.LoginStepTypeComplete,
StepID: "fi.mau.meta.complete",
Instructions: "Login successful",
}, nil
}

0 comments on commit 8cc5250

Please sign in to comment.