diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md old mode 100644 new mode 100755 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/config.example.toml b/config.example.toml old mode 100644 new mode 100755 diff --git a/database/database.go b/database/database.go old mode 100644 new mode 100755 diff --git a/database/postgres.go b/database/postgres.go old mode 100644 new mode 100755 diff --git a/discord.go b/discord.go old mode 100644 new mode 100755 diff --git a/funcmap.go b/funcmap.go old mode 100644 new mode 100755 diff --git a/go.mod b/go.mod old mode 100644 new mode 100755 diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 diff --git a/main.go b/main.go old mode 100644 new mode 100755 diff --git a/message.go b/message.go old mode 100644 new mode 100755 diff --git a/resources/static/favicon.ico b/resources/static/favicon.ico old mode 100644 new mode 100755 diff --git a/resources/static/style.css b/resources/static/style.css old mode 100644 new mode 100755 diff --git a/resources/templates/error.gohtml b/resources/templates/error.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/footer.gohtml b/resources/templates/footer.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/forum.gohtml b/resources/templates/forum.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/guild.gohtml b/resources/templates/guild.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/header.gohtml b/resources/templates/header.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/icons.gohtml b/resources/templates/icons.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/index.gohtml b/resources/templates/index.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/post.gohtml b/resources/templates/post.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/privacy.gohtml b/resources/templates/privacy.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/searchbar.html b/resources/templates/searchbar.html old mode 100644 new mode 100755 diff --git a/resources/templates/searchforum.gohtml b/resources/templates/searchforum.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/searchguild.gohtml b/resources/templates/searchguild.gohtml old mode 100644 new mode 100755 diff --git a/resources/templates/tos.gohtml b/resources/templates/tos.gohtml old mode 100644 new mode 100755 diff --git a/server.go b/server.go old mode 100644 new mode 100755 index 9b8fb77..353e68a --- a/server.go +++ b/server.go @@ -107,7 +107,7 @@ func newServer(st *state.State, fsys fs.FS, db database.Database, config config) }) }) }) - + getHead(r, "/privacy", srv.PrivacyPage) getHead(r, "/tos", srv.TOSPage) getHead(r, "/static/*", http.FileServer(http.FS(fsys)).ServeHTTP) @@ -200,19 +200,25 @@ func (s *server) publicActiveThreads(gid discord.GuildID) ([]discord.Channel, er if channel.Type != discord.GuildPublicThread { continue } + parent, err := s.discord.Cabinet.Channel(channel.ParentID) + if err != nil { + return nil, err + } + if parent.Type != discord.GuildForum { + continue + } threads = append(threads, channel) } return threads, nil } - func filter(ss []Post, test func(Post) bool) (ret []Post) { - for _, s := range ss { - if test(s) { - ret = append(ret, s) - } - } - return + for _, s := range ss { + if test(s) { + ret = append(ret, s) + } + } + return } func (s *server) getIndex(w http.ResponseWriter, r *http.Request) { @@ -298,7 +304,6 @@ func (s *server) getGuild(w http.ResponseWriter, r *http.Request) { s.executeTemplate(w, r, "guild.gohtml", ctx) } - func (s *server) searchGuild(w http.ResponseWriter, r *http.Request) { s.executeTemplate(w, r, "searchguild.gohtml", nil) } @@ -316,24 +321,24 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) { query := r.URL.Query().Get("q") if query == "" { - s.getForum(w,r) + s.getForum(w, r) return } ctx := struct { - Guild *discord.Guild - Forum *discord.Channel - Posts []Post - Prev int - Next int - URL string - Query string + Guild *discord.Guild + Forum *discord.Channel + Posts []Post + Prev int + Next int + URL string + Query string AppendedStr string }{Guild: guild, - Forum: forum, - URL: s.URL, - Query: query, - AppendedStr: "/search?q="+query, + Forum: forum, + URL: s.URL, + Query: query, + AppendedStr: "/search?q=" + query, } channels, err := s.channels(guild.ID) if err != nil { @@ -341,7 +346,7 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) { fmt.Errorf("fetching guild threads: %w", err)) return } - arr := strings.Split(query," ") + arr := strings.Split(query, " ") if query == "" { // Show blank page. @@ -364,17 +369,17 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) { } } if slices.Contains(titles, post.Channel.Name) { - continue; + continue } - if strings.Contains(strings.ToLower(post.Channel.Name),query) { + if strings.Contains(strings.ToLower(post.Channel.Name), query) { posts = append(posts, post) titles = append(titles, post.Channel.Name) } else { - for _, str := range(arr) { + for _, str := range arr { if len(str) <= 1 { - continue; + continue } - if strings.Contains(strings.ToLower(post.Channel.Name),strings.ToLower(str)) { + if strings.Contains(strings.ToLower(post.Channel.Name), strings.ToLower(str)) { posts = append(posts, post) titles = append(titles, post.Channel.Name) } @@ -382,7 +387,7 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) { } } sort.SliceStable(posts, func(i, j int) bool { - return strings.Contains(strings.ToLower(posts[i].Channel.Name),strings.ToLower(query)) + return strings.Contains(strings.ToLower(posts[i].Channel.Name), strings.ToLower(query)) }) page, err := strconv.Atoi(chi.URLParam(r, "page")) if err != nil || page < 1 { @@ -403,8 +408,6 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) { s.executeTemplate(w, r, "searchforum.gohtml", ctx) } - - type Post struct { discord.Channel Tags []discord.Tag @@ -425,13 +428,13 @@ func (s *server) getForum(w http.ResponseWriter, r *http.Request) { } ctx := struct { - Guild *discord.Guild - Forum *discord.Channel - Posts []Post - Prev int - Next int - URL string - Query string + Guild *discord.Guild + Forum *discord.Channel + Posts []Post + Prev int + Next int + URL string + Query string AppendedStr string }{Guild: guild, Forum: forum, @@ -444,6 +447,14 @@ 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) + if err != nil { + s.displayErr(w, http.StatusInternalServerError, + fmt.Errorf("fetching parent channel's type: %w", err)) + } + if parent.Type != discord.GuildForum { + continue + } if thread.ParentID != forum.ID || thread.Type != discord.GuildPublicThread { continue @@ -496,6 +507,10 @@ func (s *server) getPost(w http.ResponseWriter, r *http.Request) { if !ok { return } + + if forum.Type != discord.GuildForum { + return + } ctx := struct { Guild *discord.Guild Forum *discord.Channel diff --git a/sitemap.go b/sitemap.go old mode 100644 new mode 100755