Skip to content

Commit

Permalink
fix: salary advance ui (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
minhluuquang authored Nov 24, 2023
1 parent d4bd944 commit 9d3320e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions pkg/discord/interaction_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (d *Discord) onInteractionCreate(s *discordgo.Session, i *discordgo.Interac
d.Command.View.Salary().ErrorAdvanceSalary(&model.DiscordMessage{
ChannelId: i.ChannelID,
Author: i.Interaction.User,
})
}, err)
return
}

Expand All @@ -44,12 +44,13 @@ func (d *Discord) onInteractionCreate(s *discordgo.Session, i *discordgo.Interac
Type: discordgo.InteractionResponseUpdateMessage,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
base.Normalize(i.Interaction.User, &discordgo.MessageEmbed{
Title: "Your request is submitted\n",
base.Normalize(s, &discordgo.MessageEmbed{
Title: "Request Approved!\n",
Description: fmt.Sprint(
"We will send you the receipt after the transaction succeeds.\n",
"Your ICY credit is on the way, we will send you a notification shortly.\n",
fmt.Sprintf("`Amount. ` %s\n", fmt.Sprintf("<:ICY:1049620715374133288> **%s icy**", userInput)),
fmt.Sprintf("`Receiver.` %s\n", fmt.Sprintf("<@%s>", i.Interaction.User.ID)),
"then try $bals in Mochi app to see your balances.",
),
}),
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/discord/view/base/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func SendEmbededMessage(ses *discordgo.Session, original *model.DiscordMessage,
}

func SendEmbededMessageWithChannel(ses *discordgo.Session, original *model.DiscordMessage, embed *discordgo.MessageEmbed, channelId string) error {
_, err := ses.ChannelMessageSendEmbed(channelId, Normalize(original.Author, embed))
_, err := ses.ChannelMessageSendEmbed(channelId, Normalize(ses, embed))
return err
}

// Normalize add some default to embeded message if not set
func Normalize(user *discordgo.User, response *discordgo.MessageEmbed) *discordgo.MessageEmbed {
func Normalize(s *discordgo.Session, response *discordgo.MessageEmbed) *discordgo.MessageEmbed {
if response.Timestamp == "" {
response.Timestamp = time.Now().Format(time.RFC3339)
}
Expand All @@ -35,7 +35,7 @@ func Normalize(user *discordgo.User, response *discordgo.MessageEmbed) *discordg
}
if response.Footer == nil {
response.Footer = &discordgo.MessageEmbedFooter{
IconURL: user.AvatarURL("128"),
IconURL: s.State.User.AvatarURL("128"),
Text: "?help to see all commands",
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/discord/view/salary/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/dwarvesf/fortress-discord/pkg/model"

type Viewer interface {
CompleteAdvanceSalary(original *model.DiscordMessage, salaryAdvance model.SalaryAdvance) error
ErrorAdvanceSalary(original *model.DiscordMessage) error
ErrorAdvanceSalary(original *model.DiscordMessage, err error) error
EnterAmountAdvanceSalary(original *model.DiscordMessage, checkSalaryAdvance model.CheckSalaryAdvance) error
Help() error
}
18 changes: 9 additions & 9 deletions pkg/discord/view/salary/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func (e *Salary) EnterAmountAdvanceSalary(original *model.DiscordMessage, checkS
if original.ChannelId == channel.ID {
message := discordgo.MessageSend{
Embeds: []*discordgo.MessageEmbed{
base.Normalize(original.Author, &discordgo.MessageEmbed{
Title: "Enter ICY amount you want to borrow",
Description: fmt.Sprintf("The maximum ICY you can borrow: :icy: %s ICY ($%s)\nPlease enter the ICY amount :point_down:", checkSalaryAdvance.AmountIcy, checkSalaryAdvance.AmountUSD),
base.Normalize(e.ses, &discordgo.MessageEmbed{
Title: "Enter amount",
Description: fmt.Sprintf("You can advance a maximum of: <:ICY:1049620715374133288> %s ICY (%s) credit\nthe given credit will be paid automatically in your next pay check.\nEnter the ICY amount :point_down:", checkSalaryAdvance.AmountIcy, checkSalaryAdvance.AmountUSD),
}),
},
Components: []discordgo.MessageComponent{
Expand All @@ -46,11 +46,11 @@ func (e *Salary) EnterAmountAdvanceSalary(original *model.DiscordMessage, checkS

// if public channel
msg := &discordgo.MessageEmbed{
Title: "DM Fortress",
Description: "?salary advance is only used in DM with Fortress! Please send a message to Fortress bot!",
Title: "Fortress",
Description: "?salary advance is a DM-only command. Please slide into our DM and try again.",
}

return base.SendEmbededMessageWithChannel(e.ses, original, msg, channel.ID)
return base.SendEmbededMessageWithChannel(e.ses, original, msg, original.ChannelId)
}

// CompleteAdvanceSalary implements Viewer.
Expand All @@ -69,10 +69,10 @@ func (s *Salary) CompleteAdvanceSalary(original *model.DiscordMessage, salaryAdv
return base.SendEmbededMessage(s.ses, original, msg)
}

func (s *Salary) ErrorAdvanceSalary(original *model.DiscordMessage) error {
func (s *Salary) ErrorAdvanceSalary(original *model.DiscordMessage, err error) error {
msg := &discordgo.MessageEmbed{
Title: "Ok",
Description: "Ok",
Title: "Salary Advance Error!",
Description: err.Error(),
}

return base.SendEmbededMessage(s.ses, original, msg)
Expand Down

0 comments on commit 9d3320e

Please sign in to comment.