-
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.
Merge pull request #81 from dwarvesf/feat/cmd-ogif
feat: cmd ogif
- Loading branch information
Showing
18 changed files
with
390 additions
and
50 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,66 @@ | ||
package ogif | ||
|
||
import ( | ||
"strings" | ||
"time" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
"github.com/dwarvesf/fortress-discord/pkg/utils/stringutils" | ||
) | ||
|
||
func (c command) Prefix() []string { | ||
return []string{"ogif"} | ||
} | ||
|
||
// Execute is where we handle logic for each command | ||
func (c command) Execute(message *model.DiscordMessage) error { | ||
now := time.Now() | ||
userID := message.Author.ID | ||
timePeriod := "30d" | ||
isUserOmitted := false | ||
|
||
if len(message.ContentArgs) > 1 { | ||
if message.ContentArgs[1] == "help" { | ||
return c.Help(message) | ||
} | ||
|
||
extractedID := stringutils.ExtractDiscordID(message.ContentArgs[1]) | ||
if extractedID != "" { | ||
userID = extractedID | ||
} else { | ||
isUserOmitted = true | ||
timePeriod = strings.Join(message.ContentArgs[1:], "") | ||
} | ||
} | ||
|
||
if len(message.ContentArgs) > 2 && !isUserOmitted { | ||
timePeriod = strings.Join(message.ContentArgs[2:], "") | ||
} | ||
|
||
after, timeAmount, timeUnit, err := stringutils.ParseTimePeriod(now, timePeriod) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.FetchOgifStats(message, userID, *after, timeAmount, timeUnit) | ||
} | ||
|
||
func (c command) Name() string { | ||
return "OGIF command" | ||
} | ||
|
||
func (c command) Help(message *model.DiscordMessage) error { | ||
return c.view.Ogif().Help(message) | ||
} | ||
|
||
func (c command) DefaultCommand(message *model.DiscordMessage) error { | ||
return nil | ||
} | ||
|
||
func (c command) PermissionCheck(message *model.DiscordMessage) (bool, []string) { | ||
return true, []string{} | ||
} | ||
|
||
func (c command) ChannelPermissionCheck(message *model.DiscordMessage) bool { | ||
return true | ||
} |
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,9 @@ | ||
package ogif | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/base" | ||
) | ||
|
||
type Commander interface { | ||
base.TextCommander | ||
} |
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 ogif | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/config" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/service" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/view" | ||
"github.com/dwarvesf/fortress-discord/pkg/logger" | ||
) | ||
|
||
type command 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 &command{ | ||
L: l, | ||
svc: svc, | ||
view: view, | ||
cfg: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ogif | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (c command) FetchOgifStats(msg *model.DiscordMessage, discordID string, after time.Time, timeAmount int, timeUnit string) error { | ||
logger := c.L.AddField("discordID", discordID).AddField("after", after) | ||
stats, err := c.svc.Event().GetOgifStats(discordID, after) | ||
if err != nil { | ||
logger.Error(err, "error when get ogif stats") | ||
return err | ||
} | ||
|
||
return c.view.Ogif().RenderOgifStats(msg, discordID, stats, timeAmount, timeUnit) | ||
} |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package event | ||
|
||
import "github.com/dwarvesf/fortress-discord/pkg/model" | ||
import ( | ||
"time" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type EventServicer interface { | ||
GetUpcomingEvents() ([]*model.Event, error) | ||
GetGuildScheduledEvents() ([]*model.DiscordEvent, error) | ||
CreateGuildScheduledEvent(*model.DiscordEvent) error | ||
SetSpeakers(message *model.DiscordMessage) error | ||
GetOgifStats(discordID string, after time.Time) (model.OgifStats, 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,34 @@ | ||
package ogif | ||
|
||
import ( | ||
"github.com/bwmarrin/discordgo" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/view/base" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (e *Ogif) Help(message *model.DiscordMessage) error { | ||
embed := &discordgo.MessageEmbed{ | ||
Title: "OGIF Command Help", | ||
Description: "The OGIF command allows you to fetch and display OGIF stats for a user.", | ||
Color: 0x00ff00, // Green color | ||
Fields: []*discordgo.MessageEmbedField{ | ||
{ | ||
Name: "Usage", | ||
Value: "`ogif [user_mention] [time_period]`", | ||
}, | ||
{ | ||
Name: "Parameters", | ||
Value: "- `user_mention`: Optional. Mention the user to fetch stats for. If omitted, uses the command author.\n- `time_period`: Optional. Time period for stats (e.g., '7d', '30d', '3m'). Default is 30 days.", | ||
}, | ||
{ | ||
Name: "Examples", | ||
Value: "- `ogif`\n- `ogif @user`\n- `ogif @user 7d`\n- `ogif 14d`", | ||
}, | ||
}, | ||
Footer: &discordgo.MessageEmbedFooter{ | ||
Text: "For more information, contact the bot administrator.", | ||
}, | ||
} | ||
|
||
return base.SendEmbededMessage(e.ses, message, embed) | ||
} |
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,10 @@ | ||
package ogif | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type OgifViewer interface { | ||
RenderOgifStats(original *model.DiscordMessage, userID string, stats model.OgifStats, timeAmount int, timeUnit string) error | ||
Help(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ogif | ||
|
||
import "github.com/bwmarrin/discordgo" | ||
|
||
type Ogif struct { | ||
ses *discordgo.Session | ||
} | ||
|
||
func New(ses *discordgo.Session) OgifViewer { | ||
return &Ogif{ | ||
ses: ses, | ||
} | ||
} |
Oops, something went wrong.