Skip to content

Commit

Permalink
config: add base network config
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpShell committed Oct 10, 2024
1 parent 2a9f98e commit 4fb4ffe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
37 changes: 33 additions & 4 deletions pkg/connector/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
package connector

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

up "go.mau.fi/util/configupgrade"
)

type TwitterConfig struct {
//go:embed example-config.yaml
var ExampleConfig string

type Config struct {
Proxy string `yaml:"proxy"`
GetProxyURL string `yaml:"get_proxy_url"`

UsernameTemplate string `yaml:"username_template"`
DisplaynameTemplate string `yaml:"displayname_template"`
DisplayNameMaxLength int `yaml:"displayname_max_length"`

DeliveryReceipts bool `yaml:"delivery_receipts"`

//displaynameTemplate *template.Template `yaml:"-"`
}

func upgradeConfig(helper up.Helper) {
helper.Copy(up.Str|up.Null, "proxy")
helper.Copy(up.Str|up.Null, "get_proxy_url")

helper.Copy(up.Str, "username_template")
helper.Copy(up.Str, "displayname_template")
helper.Copy(up.Int, "displayname_max_length")

helper.Copy(up.Bool, "delivery_receipts")
}

func (tc *TwitterConnector) GetConfig() (example string, data any, upgrader configupgrade.Upgrader) {
return "", nil, configupgrade.NoopUpgrader
func (tc *TwitterConnector) GetConfig() (string, any, up.Upgrader) {
return ExampleConfig, &tc.Config, &up.StructUpgrader{
SimpleUpgrader: up.SimpleUpgrader(upgradeConfig),
Base: ExampleConfig,
}
}
2 changes: 1 addition & 1 deletion pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
type TwitterConnector struct {
br *bridgev2.Bridge

Config *TwitterConfig
Config *Config
}

var _ bridgev2.NetworkConnector = (*TwitterConnector)(nil)
Expand Down
18 changes: 18 additions & 0 deletions pkg/connector/example-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Proxy to use for all Twitter connections.
proxy: null
# Alternative to proxy: an HTTP endpoint that returns the proxy URL to use for Twitter connections.
get_proxy_url: null

# Localpart template of MXIDs for Twitter users.
# {userid} is replaced with the user ID of the Twitter user.
username_template: "twitter_{userid}"
# Displayname template for Twitter users.
# {displayname} is replaced with the display name of the Twitter user.
# {username} is replaced with the username of the Twitter user.
displayname_template: "{displayname} (Twitter)"
# Maximum length of displayname
displayname_max_length: 100

# Whether the bridge should send a read receipt from the bridge bot when a message has
# been sent to Twitter.
delivery_receipts: false

0 comments on commit 4fb4ffe

Please sign in to comment.