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

This commit is contained in:
Tulir Asokan
2022-07-08 22:43:52 +03:00
parent ca8682657c
commit 33a002a053
4 changed files with 7 additions and 2 deletions

View File

@@ -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"`

View File

@@ -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")

View File

@@ -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.

View File

@@ -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 {