-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
311 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package reddit | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
const ( | ||
// defaultGolangChannelID is the default Discord channel ID for Golang news. | ||
defaultGolangChannelID = "1257546039997501613" | ||
) | ||
|
||
// SyncGolangNews fetches new Golang news from Reddit and sends it to Discord. | ||
func (c *controller) SyncGolangNews(ctx context.Context) error { | ||
logger := c.logger.Field("func", "GolangNews") | ||
|
||
popular, emerging, err := c.service.Reddit.FetchGolangNews(ctx) | ||
if err != nil { | ||
logger.Error(err, "failed to fetch Golang news") | ||
return err | ||
} | ||
|
||
if len(popular) == 0 && len(emerging) == 0 { | ||
logger.Info("no new Golang news") | ||
return nil | ||
} | ||
|
||
logger.Infof("new Golang news: %d popular, %d emerging", len(popular), len(emerging)) | ||
|
||
golangChannelID := c.config.Discord.IDs.GolangChannel | ||
if golangChannelID == "" { | ||
golangChannelID = defaultGolangChannelID | ||
} | ||
|
||
if err := c.service.Discord.SendGolangNewsMessage(golangChannelID, emerging, popular); err != nil { | ||
logger.Error(err, "failed to send Golang news message to discord") | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package reddit | ||
|
||
import "context" | ||
|
||
type IController interface { | ||
// SyncGolangNews fetches new Golang news from Reddit and sends it to Discord. | ||
SyncGolangNews(ctx context.Context) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package reddit | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-api/pkg/config" | ||
"github.com/dwarvesf/fortress-api/pkg/logger" | ||
"github.com/dwarvesf/fortress-api/pkg/service" | ||
"github.com/dwarvesf/fortress-api/pkg/store" | ||
) | ||
|
||
type controller struct { | ||
store *store.Store | ||
service *service.Service | ||
logger logger.Logger | ||
config *config.Config | ||
} | ||
|
||
func New(store *store.Store, service *service.Service, logger logger.Logger, cfg *config.Config) IController { | ||
return &controller{ | ||
store: store, | ||
service: service, | ||
logger: logger, | ||
config: cfg, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.