-
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
1 parent
cad8f2e
commit 3e2aea8
Showing
15 changed files
with
234 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package changelog | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (a *Changelog) Prefix() []string { | ||
return []string{"changelog"} | ||
} | ||
|
||
// Execute is where we handle logic for each command | ||
func (a *Changelog) Execute(message *model.DiscordMessage) error { | ||
// default command for only 1 args input from user, e.g `?earn` | ||
if len(message.ContentArgs) == 1 { | ||
return a.DefaultCommand(message) | ||
} | ||
|
||
// handle command for 2 args input from user, e.g `?earn list` | ||
switch message.ContentArgs[1] { | ||
case "list": | ||
return a.List(message) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *Changelog) Name() string { | ||
return "Changelog Command" | ||
} | ||
|
||
func (a *Changelog) Help(message *model.DiscordMessage) error { | ||
return nil | ||
} | ||
|
||
func (a *Changelog) DefaultCommand(message *model.DiscordMessage) error { | ||
return a.List(message) | ||
} | ||
|
||
func (a *Changelog) PermissionCheck(message *model.DiscordMessage) (bool, []string) { | ||
return true, []string{} | ||
} |
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,37 @@ | ||
package changelog | ||
|
||
import ( | ||
"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" | ||
"github.com/k0kubun/pp" | ||
) | ||
|
||
type Changelog struct { | ||
L logger.Logger | ||
svc service.Servicer | ||
view view.Viewer | ||
} | ||
|
||
func New(l logger.Logger, svc service.Servicer, view view.Viewer) ChangelogCommander { | ||
return &Changelog{ | ||
L: l, | ||
svc: svc, | ||
view: view, | ||
} | ||
} | ||
|
||
func (t *Changelog) List(message *model.DiscordMessage) error { | ||
// 1. get data from service | ||
data, err := t.svc.Changelog().GetListChangelogs() | ||
if err != nil { | ||
t.L.Error(err, "can't get list of Changelog") | ||
return err | ||
} | ||
|
||
pp.Println(data) | ||
|
||
// 2. render | ||
return t.view.Changelog().Changelog(message, data) | ||
} |
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,12 @@ | ||
package changelog | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/base" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type ChangelogCommander interface { | ||
base.TextCommander | ||
|
||
List(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,33 @@ | ||
package changelog | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/adapter" | ||
"github.com/dwarvesf/fortress-discord/pkg/logger" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type Changelog struct { | ||
adapter adapter.IAdapter | ||
l logger.Logger | ||
} | ||
|
||
func New(adapter adapter.IAdapter, l logger.Logger) ChangelogServicer { | ||
return &Changelog{ | ||
adapter: adapter, | ||
l: l, | ||
} | ||
} | ||
|
||
func (e *Changelog) GetListChangelogs() ([]*model.Changelog, error) { | ||
// get response from fortress | ||
adapterChangelog, err := e.adapter.Fortress().GetChangelogs() | ||
if err != nil { | ||
e.l.Error(err, "can't get open changelog from fortress") | ||
return nil, err | ||
} | ||
|
||
// normalized into in-app model | ||
changelog := adapterChangelog.Data | ||
|
||
return changelog, 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,7 @@ | ||
package changelog | ||
|
||
import "github.com/dwarvesf/fortress-discord/pkg/model" | ||
|
||
type ChangelogServicer interface { | ||
GetListChangelogs() ([]*model.Changelog, 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
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,43 @@ | ||
package changelog | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/view/base" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type Changelog struct { | ||
ses *discordgo.Session | ||
} | ||
|
||
func New(ses *discordgo.Session) ChangelogViewer { | ||
return &Changelog{ | ||
ses: ses, | ||
} | ||
} | ||
|
||
func (c *Changelog) Changelog(message *model.DiscordMessage, data []*model.Changelog) error { | ||
content := []string{ | ||
"**?earn**・earn $ICY for free", | ||
"**?trial**・list of trial tech", | ||
"**?assess**・list of assess tech", | ||
"**?adopt**・list of adopt tech", | ||
"**?hold**・list of on-hold tech", | ||
"**?new**・list of new subscribers", | ||
"**?event**・list of upcoming events", | ||
"**?hiring**・list of open positions", | ||
"**?staff**・list of staffing demands", | ||
"**?milestones**・list of projects milestones", | ||
"**?updates**・list of Dwarves updates", | ||
"**?digest**・list of Internal Digests", | ||
"**?memos**・list of Team memos", | ||
} | ||
msg := &discordgo.MessageEmbed{ | ||
Title: "**Changelog**", | ||
Description: strings.Join(content, "\n"), | ||
} | ||
|
||
return base.SendEmbededMessage(c.ses, message, msg) | ||
} |
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 changelog | ||
|
||
import "github.com/dwarvesf/fortress-discord/pkg/model" | ||
|
||
// ChangelogViewer is an interface for changelog view | ||
type ChangelogViewer interface { | ||
Changelog(message *model.DiscordMessage, data []*model.Changelog) 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
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,15 @@ | ||
package model | ||
|
||
// ChangelogDigest is a struct response from adapter, before process to in-app model | ||
type ChangelogDigest struct { | ||
Data []*Changelog `json:"data"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// Changelog is a model for changelog | ||
type Changelog struct { | ||
RowID string `json:"row_id"` | ||
Name string `json:"name"` | ||
Title string `json:"title"` | ||
ChangelogURL string `json:"changelog_url"` | ||
} |