-
Notifications
You must be signed in to change notification settings - Fork 0
feat(discord): keep threads alive by auto-unarchiving on ThreadUpdate #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "github.com/bwmarrin/discordgo" | ||
| "github.com/gaucho-racing/sentinel/discord/pkg/logger" | ||
| ) | ||
|
|
||
| // KeepThreadAlive unarchives a thread that Discord just auto-archived and | ||
| // bumps its auto-archive window to the maximum (7 days) so the gateway only | ||
| // re-archives it weekly instead of on the channel's default window. The | ||
| // unarchive is silent — no message is posted and members aren't notified. | ||
| // Requires the bot to have MANAGE_THREADS in the guild. | ||
| func KeepThreadAlive(thread *discordgo.Channel) { | ||
| archived := false | ||
| _, err := Discord.ChannelEdit(thread.ID, &discordgo.ChannelEdit{ | ||
| Archived: &archived, | ||
| AutoArchiveDuration: 10080, | ||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In guilds without Discord's Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think we should be fine as i see the option for 7 days |
||
| }) | ||
| if err != nil { | ||
| logger.SugarLogger.Errorf("thread keepalive: failed to unarchive thread %s (%s): %v", thread.ID, thread.Name, err) | ||
| return | ||
| } | ||
| logger.SugarLogger.Infof("thread keepalive: unarchived thread %s (%s)", thread.ID, thread.Name) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this deploy starts with an already archived thread, or the bot is disconnected when a thread auto-archives, no
ThreadUpdateis delivered or replayed and this handler is the only path that invokesKeepThreadAlive. The affected thread therefore remains archived permanently; add a startup/Ready sweep and periodic reconciliation of archived, unlocked threads so missed events recover.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up