Skip to content

Commit

Permalink
feat: define color codes (#208)
Browse files Browse the repository at this point in the history
Co-authored-by: Sepehr Dehghani <[email protected]>
  • Loading branch information
b00f and sepehr-dh99 authored Dec 29, 2024
1 parent 6ac9bd6 commit 346b32d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
5 changes: 3 additions & 2 deletions internal/engine/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"slices"

"github.com/pagu-project/Pagu/internal/entity"
"github.com/pagu-project/Pagu/pkg/color"
)

var (
Expand Down Expand Up @@ -40,7 +41,7 @@ type HandlerFunc func(caller *entity.User, cmd *Command, args map[string]string)

type Command struct {
Emoji string
Color string
Color color.ColorCode
Name string
Help string
Args []Args // should be nil for commands.
Expand All @@ -52,7 +53,7 @@ type Command struct {
}

type CommandResult struct {
Color string
Color color.ColorCode
Title string
Error string
Message string
Expand Down
9 changes: 5 additions & 4 deletions internal/platforms/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"github.com/pagu-project/Pagu/internal/engine"
"github.com/pagu-project/Pagu/internal/engine/command"
"github.com/pagu-project/Pagu/internal/entity"
"github.com/pagu-project/Pagu/pkg/color"
"github.com/pagu-project/Pagu/pkg/log"
"github.com/pagu-project/Pagu/pkg/utils"
)

type Bot struct {
cfg *config.DiscordBot
Session *discordgo.Session
engine *engine.BotEngine
cfg *config.DiscordBot
target string
}

Expand Down Expand Up @@ -220,7 +221,7 @@ func (bot *Bot) respondErrMsg(errStr string, s *discordgo.Session, i *discordgo.
errorEmbed := &discordgo.MessageEmbed{
Title: "Error",
Description: errStr,
Color: RED,
Color: color.Yellow.ToInt(),
}
bot.respondEmbed(errorEmbed, s, i)
}
Expand All @@ -231,13 +232,13 @@ func (bot *Bot) respondResultMsg(res command.CommandResult, s *discordgo.Session
resEmbed = &discordgo.MessageEmbed{
Title: "Successful",
Description: res.Message,
Color: GREEN,
Color: color.Green.ToInt(),
}
} else {
resEmbed = &discordgo.MessageEmbed{
Title: "Failed",
Description: res.Message,
Color: YELLOW,
Color: color.Yellow.ToInt(),
}
}

Expand Down
7 changes: 0 additions & 7 deletions internal/platforms/discord/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import (
"github.com/bwmarrin/discordgo"
)

const (
GREEN = 0x008000
RED = 0xFF0000
YELLOW = 0xFFFF00
PACTUS = 0x052D5A
)

func newStatus(name string, value any) discordgo.UpdateStatusData {
return discordgo.UpdateStatusData{
Status: "online",
Expand Down
19 changes: 19 additions & 0 deletions pkg/color/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package color

type ColorCode int

const (
Green ColorCode = 0x008000
Red ColorCode = 0xFF0000
Yellow ColorCode = 0xFFFF00
Black ColorCode = 0x000000
Pactus ColorCode = 0x052D5A
)

func (ColorCode) String() string {
return "todo"
}

func (c ColorCode) ToInt() int {
return int(c)
}

0 comments on commit 346b32d

Please sign in to comment.