From 33a002a0532a7acbe9b9305bc62aa6b897a09303 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 8 Jul 2022 22:43:52 +0300 Subject: [PATCH] Add config option for number of private channels to automatically bridge on startup --- config/bridge.go | 2 ++ config/upgrade.go | 1 + example-config.yaml | 3 +++ user.go | 3 +-- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config/bridge.go b/config/bridge.go index b6b01b2..8e00da1 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -34,6 +34,8 @@ type BridgeConfig struct { GuildNameTemplate string `yaml:"guild_name_template"` PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"` + PrivateChannelCreateLimit int `yaml:"startup_private_channel_create_limit"` + DeliveryReceipts bool `yaml:"delivery_receipts"` MessageStatusEvents bool `yaml:"message_status_events"` MessageErrorNotices bool `yaml:"message_error_notices"` diff --git a/config/upgrade.go b/config/upgrade.go index 1a4aa4f..4579b62 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -30,6 +30,7 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Str, "bridge", "channel_name_template") helper.Copy(up.Str, "bridge", "guild_name_template") helper.Copy(up.Bool, "bridge", "private_chat_portal_meta") + helper.Copy(up.Bool, "bridge", "startup_private_channel_create_limit") helper.Copy(up.Int, "bridge", "portal_message_buffer") helper.Copy(up.Bool, "bridge", "delivery_receipts") helper.Copy(up.Bool, "bridge", "message_status_events") diff --git a/example-config.yaml b/example-config.yaml index 465c67d..bced601 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -93,6 +93,9 @@ bridge: portal_message_buffer: 128 + # Number of private channel portals to create on bridge startup. + # Other portals will be created when receiving messages. + startup_private_channel_create_limit: 5 # Should the bridge send a read receipt from the bridge bot when a message has been sent to Discord? delivery_receipts: false # Whether the bridge should send the message status as a custom com.beeper.message_send_status event. diff --git a/user.go b/user.go index 7f9d829..80b1e90 100644 --- a/user.go +++ b/user.go @@ -544,10 +544,9 @@ func (user *User) readyHandler(_ *discordgo.Session, r *discordgo.Ready) { user.handleGuild(guild, updateTS, portalsInSpace[guild.ID]) } user.PrunePortalList(updateTS) - const maxCreate = 5 for i, ch := range r.PrivateChannels { portal := user.GetPortalByMeta(ch) - user.handlePrivateChannel(portal, ch, updateTS, i < maxCreate, portalsInSpace[portal.Key.ChannelID]) + user.handlePrivateChannel(portal, ch, updateTS, i < user.bridge.Config.Bridge.PrivateChannelCreateLimit, portalsInSpace[portal.Key.ChannelID]) } if r.ReadState.Version > user.ReadStateVersion {