Skip to content

Commit

Permalink
feat: post brainery to target channel (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
namnhce authored Jun 21, 2023
1 parent 6fabde4 commit c5f9a64
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/discord/command/brainery/brainery.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
urlRegexPattern = `((?:https?://)[^\s]+)`
githubRegexPattern = `gh:(\w+)`
descriptionRegexPattern = `d:"(.*?)"`
channelRegexParttern = `<#(\d+)>`
)

const defaultBraineryReward = "0"
Expand All @@ -55,6 +56,7 @@ func (e *Brainery) Post(message *model.DiscordMessage) error {
extractReward := extractPattern(rawFormattedContent, icyRewardRegexPattern)
extractGithub := extractPattern(rawFormattedContent, githubRegexPattern)
extractDesc := extractPattern(rawFormattedContent, descriptionRegexPattern)
extractChannel := extractPattern(rawFormattedContent, channelRegexParttern)

if len(extractURL) == 0 || len(extractURL) > 1 {
return e.view.Error().Raise(message, "There is no URL or more than one URL in your message.")
Expand Down Expand Up @@ -83,6 +85,10 @@ func (e *Brainery) Post(message *model.DiscordMessage) error {
desc = extractDesc[0]
}

if len(extractChannel) > 0 {
targetChannelID = extractChannel[0]
}

mbrainery := &brainery.PostInput{
URL: extractURL[0],
DiscordID: extractDiscordID[0],
Expand Down

0 comments on commit c5f9a64

Please sign in to comment.