-
Notifications
You must be signed in to change notification settings - Fork 3
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
12 changed files
with
249 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package brainery | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (e *Brainery) Report(message *model.DiscordMessage) error { | ||
rawFormattedContent := formatString(message.RawContent) | ||
args := strings.Split(rawFormattedContent, " ") | ||
targetChannelID := message.ChannelId | ||
|
||
reportView := "weekly" | ||
if len(args) > 1 { | ||
reportView = args[2] | ||
} | ||
|
||
if !(reportView == "weekly" || reportView == "monthly") { | ||
return e.view.Error().Raise(message, "Report view should be weekly or monthly") | ||
} | ||
|
||
extractChannelID := extractPattern(rawFormattedContent, discordChannelIDRegexPattern) | ||
if len(extractChannelID) > 1 { | ||
return e.view.Error().Raise(message, "There is more than one target channel in your message.") | ||
} | ||
|
||
if len(extractChannelID) == 1 { | ||
targetChannelID = extractChannelID[0] | ||
} | ||
|
||
result, err := e.svc.Brainery().Report(reportView) | ||
if err != nil { | ||
return e.view.Error().Raise(message, err.Error()) | ||
} | ||
|
||
return e.view.Brainery().Report(message, reportView, result, targetChannelID) | ||
} |
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 |
---|---|---|
@@ -1,12 +1,33 @@ | ||
package brainery | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/config" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/base" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/service" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/view" | ||
"github.com/dwarvesf/fortress-discord/pkg/logger" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type Brainery struct { | ||
L logger.Logger | ||
svc service.Servicer | ||
view view.Viewer | ||
cfg *config.Config | ||
} | ||
|
||
func New(l logger.Logger, svc service.Servicer, view view.Viewer, cfg *config.Config) Commander { | ||
return &Brainery{ | ||
L: l, | ||
svc: svc, | ||
view: view, | ||
cfg: cfg, | ||
} | ||
} | ||
|
||
type Commander interface { | ||
base.TextCommander | ||
|
||
Post(message *model.DiscordMessage) error | ||
Report(message *model.DiscordMessage) 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
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,14 @@ | ||
package brainery | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (e *Brainery) Report(view string) (*model.BraineryMetric, error) { | ||
data, err := e.adapter.Fortress().GetBraineryReport(view) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, 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 |
---|---|---|
@@ -1,7 +1,37 @@ | ||
package brainery | ||
|
||
import "github.com/dwarvesf/fortress-discord/pkg/model" | ||
import ( | ||
"time" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/adapter" | ||
"github.com/dwarvesf/fortress-discord/pkg/logger" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type Brainery struct { | ||
adapter adapter.IAdapter | ||
l logger.Logger | ||
} | ||
|
||
func New(adapter adapter.IAdapter, l logger.Logger) Service { | ||
return &Brainery{ | ||
adapter: adapter, | ||
l: l, | ||
} | ||
} | ||
|
||
type PostInput struct { | ||
URL string | ||
Author string | ||
Reward string | ||
Description string | ||
PublishedAt *time.Time | ||
Tags []string | ||
Github string | ||
DiscordID string | ||
} | ||
|
||
type Service interface { | ||
Post(in *PostInput) (*model.Brainery, error) | ||
Report(view string) (*model.BraineryMetric, 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
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.