Skip to content

Commit

Permalink
properly get channel
Browse files Browse the repository at this point in the history
  • Loading branch information
IoIxD committed Jul 23, 2024
1 parent cabbb57 commit 51f4f12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import (
"github.com/diamondburned/arikawa/v3/state"
)

func (s *server) channel(channelID discord.ChannelID) (*discord.Channel, error) {
s.fetchedInactiveMu.Lock()
defer s.fetchedInactiveMu.Unlock()
channel, err := s.discord.Channel(channelID)
if err != nil {
return nil, err
}
return channel, nil
}

func (s *server) channels(guildID discord.GuildID) ([]discord.Channel, error) {
s.fetchedInactiveMu.Lock()
defer s.fetchedInactiveMu.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *server) publicActiveThreads(gid discord.GuildID) ([]discord.Channel, er
if channel.Type != discord.GuildPublicThread {
continue
}
parent, err := s.discord.Cabinet.Channel(channel.ParentID)
parent, err := s.channel(channel.ParentID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -447,7 +447,7 @@ func (s *server) getForum(w http.ResponseWriter, r *http.Request) {
}
var posts []Post
for _, thread := range channels {
parent, err := s.discord.Cabinet.Channel(thread.ParentID)
parent, err := s.channel(thread.ParentID)
if err != nil {
s.displayErr(w, http.StatusInternalServerError,
fmt.Errorf("fetching parent channel's type: %w", err))
Expand Down Expand Up @@ -659,7 +659,7 @@ func (s *server) forumFromReq(w http.ResponseWriter, r *http.Request) (*discord.
return nil, false
}
forumID := discord.ChannelID(forumIDsf)
forum, err := s.discord.Cabinet.Channel(forumID)
forum, err := s.channel(forumID)
if err != nil {
if discordStatusIs(err, http.StatusNotFound) {
s.displayErr(w, http.StatusNotFound, nil)
Expand Down

0 comments on commit 51f4f12

Please sign in to comment.