From 4fb4ffe4ceb6bab9ace2589ff13a95d9d9e611bf Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Thu, 10 Oct 2024 18:00:02 +0300 Subject: [PATCH] config: add base network config --- pkg/connector/config.go | 37 +++++++++++++++++++++++++++---- pkg/connector/connector.go | 2 +- pkg/connector/example-config.yaml | 18 +++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 pkg/connector/example-config.yaml diff --git a/pkg/connector/config.go b/pkg/connector/config.go index e7e68e9..f4edba5 100644 --- a/pkg/connector/config.go +++ b/pkg/connector/config.go @@ -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, + } } diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index fab799c..16e300d 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -27,7 +27,7 @@ import ( type TwitterConnector struct { br *bridgev2.Bridge - Config *TwitterConfig + Config *Config } var _ bridgev2.NetworkConnector = (*TwitterConnector)(nil) diff --git a/pkg/connector/example-config.yaml b/pkg/connector/example-config.yaml new file mode 100644 index 0000000..d0badcc --- /dev/null +++ b/pkg/connector/example-config.yaml @@ -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