@@ -7,14 +7,20 @@ import (
77 "darkbot/app/forumer/forum_types"
88 "darkbot/app/settings/logus"
99 "darkbot/app/settings/types"
10+ "fmt"
1011 "strings"
1112 "time"
13+
14+ "github.com/bwmarrin/discordgo"
1215)
1316
17+ type iThreadsRequester interface {
18+ GetLatestThreads (opts ... threadPageParam ) ([]* forum_types.LatestThread , error )
19+ }
1420type Forumer struct {
1521 Discorder discorder.Discorder
1622 * configurator.Configurators
17- threads_requester * ThreadsRequester
23+ threads_requester iThreadsRequester
1824 post_requester * PostRequester
1925
2026 cache map [ThreadCacheKey ]* forum_types.Post
@@ -33,11 +39,11 @@ func NewThreadCacheKey(thread *forum_types.LatestThread) ThreadCacheKey {
3339type forumerParam func (forum * Forumer )
3440
3541func WithThreadsRequester (
36- threads_page_requester * ThreadsRequester ) forumerParam {
42+ threads_page_requester iThreadsRequester ) forumerParam {
3743 return func (forum * Forumer ) { forum .threads_requester = threads_page_requester }
3844}
39- func WithDetailedPostRequest (threads_page_requester * ThreadsRequester ) forumerParam {
40- return func (forum * Forumer ) { forum .threads_requester = threads_page_requester }
45+ func WithDetailedPostRequest (post_requester * PostRequester ) forumerParam {
46+ return func (forum * Forumer ) { forum .post_requester = post_requester }
4147}
4248
4349func NewForumer (dbpath types.Dbpath , opts ... forumerParam ) * Forumer {
@@ -47,6 +53,7 @@ func NewForumer(dbpath types.Dbpath, opts ...forumerParam) *Forumer {
4753 Configurators : configurator .NewConfigugurators (dbpath ),
4854 threads_requester : NewLatestThreads (),
4955 post_requester : NewDetailedPostRequester (),
56+ cache : make (map [ThreadCacheKey ]* forum_types.Post ),
5057 }
5158
5259 for _ , opt := range opts {
@@ -90,9 +97,7 @@ func (v *Forumer) update() {
9097 }
9198
9299 for _ , thread := range threads {
93-
94100 v .GetPost (thread , func (new_post * forum_types.Post ) {
95- // Insert code to push post to channels
96101 for _ , channel := range channelIDs {
97102 watch_tags , err := v .Forum .Watch .TagsList (channel )
98103 if logus .CheckDebug (err , "failed to get watch tags" ) {
@@ -121,18 +126,36 @@ func (v *Forumer) update() {
121126 continue
122127 }
123128
124- // Check against deduplication
129+ duplication_checker := discorder .NewDeduplicator (func (msgs []discorder.DiscordMessage ) bool {
130+ for _ , msg := range msgs {
131+ content := msg .Content
132+ for _ , embed := range msg .Embeds {
133+ content += embed .Description
134+ }
135+
136+ if strings .Contains (content , string (new_post .PostID )) &&
137+ strings .Contains (content , string (new_post .ThreadID )) {
138+ return true
139+ }
140+ }
141+ return false
142+ })
125143 v .Discorder .SendDeduplicatedMsg (
126- discorder .NewDeduplicator (),
127- new_post .Render (),
128- channel ,
129- )
144+ duplication_checker , channel , func (channel types.DiscordChannelID , dg * discordgo.Session ) error {
145+ dg_msg := & discordgo.MessageSend {Embed : & discordgo.MessageEmbed {}}
146+ dg_msg .Embed .Title = `✉️ You've got mail`
147+ dg_msg .Embed .Timestamp = string (new_post .LastUpdated )
148+
149+ var content strings.Builder
150+ content .WriteString (fmt .Sprintf ("New post in [%s](<%s>)\n " , new_post .ThreadFullName , new_post .PostPermamentLink ))
151+ content .WriteString (fmt .Sprintf ("Topic started by [%s](<%s>)" , new_post .PostAuthorName , new_post .PostAuthorLink ))
152+ content .WriteString (fmt .Sprintf ("```%s```" , new_post .PostContent [:600 ]))
153+ dg_msg .Embed .Description = content .String ()
154+ return nil
155+ })
130156 }
131-
132157 })
133158 }
134-
135- _ = channelIDs
136159}
137160
138161func (v * Forumer ) Run () {
0 commit comments