connector: limit the amount of private channels initially synced
Otherwise, we'll hit the ratelimit pretty easily.
This commit is contained in:
@@ -17,11 +17,13 @@
|
|||||||
package connector
|
package connector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
@@ -172,12 +174,18 @@ func (cl *DiscordClient) BeginSyncingIfUserLoginPresent(ctx context.Context) {
|
|||||||
log.Err(err).Msg("Couldn't save UserLogin after connecting")
|
log.Err(err).Msg("Couldn't save UserLogin after connecting")
|
||||||
}
|
}
|
||||||
|
|
||||||
go cl.syncChannels(ctx)
|
go cl.syncPrivateChannels(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscordClient) syncChannels(ctx context.Context) {
|
func (d *DiscordClient) syncPrivateChannels(ctx context.Context) {
|
||||||
for _, dm := range d.Session.State.PrivateChannels {
|
dms := slices.Clone(d.Session.State.PrivateChannels)
|
||||||
d.UserLogin.Log.Debug().Str("channel_id", dm.ID).Msg("Syncing private channel")
|
// Only sync the top n private channels with recent activity.
|
||||||
|
slices.SortFunc(dms, func(a, b *discordgo.Channel) int {
|
||||||
|
return cmp.Compare(b.LastMessageID, a.LastMessageID)
|
||||||
|
})
|
||||||
|
// TODO(skip): This is startup_private_channel_create_limit. Support this in the config.
|
||||||
|
for _, dm := range dms[:10] {
|
||||||
|
zerolog.Ctx(ctx).Debug().Str("channel_id", dm.ID).Msg("Syncing private channel with recent activity")
|
||||||
d.syncChannel(ctx, dm, true)
|
d.syncChannel(ctx, dm, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user