Skip to content
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

cc/threads: fix a few more bugs #1685

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions common/templates/context_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,9 @@ func (c *Context) tmplCreateThread(channel, msgID, name interface{}, optionals .
return nil, errors.New("createThread 'private' must be a boolean")
}
case 1:
duration := tmplToInt(opt)
if duration < 60 || duration > 10080 {
return nil, errors.New("createThread 'auto_archive_duration' must be and integer between 60 and 10080")
start.AutoArchiveDuration = tmplToInt(opt)
if start.AutoArchiveDuration < 60 || start.AutoArchiveDuration > 10080 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this check exactly 60, 1440, 4320, and 10080, as stated in the thread metadata docs?
Currently giving any other value won't create the thread, with integers between 60 and 10080 failing silently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done this in 191fa78, I've also added a designated type and constants for auto archive duration for readability in 283301f.

return nil, errors.New("createThread 'auto_archive_duration' must be an integer between 60 and 10080")
}
case 2:
switch opt := opt.(type) {
Expand All @@ -1093,6 +1093,10 @@ func (c *Context) tmplCreateThread(channel, msgID, name interface{}, optionals .
}
}

if cstate.Type == discordgo.ChannelTypeGuildNews {
start.Type = discordgo.ChannelTypeGuildNewsThread
}

var ctxThread *discordgo.Channel
var err error
if mID > 0 {
Expand Down Expand Up @@ -1428,7 +1432,7 @@ func processThreadArgs(newThread bool, parent *dstate.ChannelState, values ...in
case "auto_archive_duration":
duration := tmplToInt(val)
if duration < 60 || duration > 10080 {
return c, errors.New("'auto_archive_duration' must be and integer between 60 and 10080")
return c, errors.New("'auto_archive_duration' must be an integer between 60 and 10080")
}
c.AutoArchiveDuration = &duration
case "invitable":
Expand Down
2 changes: 1 addition & 1 deletion lib/discordgo/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const (
)

func (t ChannelType) IsThread() bool {
return t == ChannelTypeGuildPrivateThread || t == ChannelTypeGuildPublicThread
return t == ChannelTypeGuildPrivateThread || t == ChannelTypeGuildPublicThread || t == ChannelTypeGuildNewsThread
}

// A Channel holds all data related to an individual Discord channel.
Expand Down