Browse Source

Add config option for number of private channels to automatically bridge on startup

Tulir Asokan 3 years ago
parent
commit
33a002a053
4 changed files with 7 additions and 2 deletions
  1. 2 0
      config/bridge.go
  2. 1 0
      config/upgrade.go
  3. 3 0
      example-config.yaml
  4. 1 2
      user.go

+ 2 - 0
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"`

+ 1 - 0
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")

+ 3 - 0
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.

+ 1 - 2
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 {