Skip to content

Commit

Permalink
Merge pull request #194 from disgoorg/patch/command-mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed Aug 22, 2022
2 parents 389446f + 1cbb850 commit 72321bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions discord/application_command.go
Expand Up @@ -180,6 +180,10 @@ func (c SlashCommand) CreatedAt() time.Time {
return c.id.Time()
}

func (c SlashCommand) Mention() string {
return SlashCommandMention(c.id, c.name)
}

func (SlashCommand) applicationCommand() {}

var _ ApplicationCommand = (*UserCommand)(nil)
Expand Down
23 changes: 16 additions & 7 deletions discord/mentionable.go
Expand Up @@ -12,13 +12,14 @@ type MentionType struct {
}

var (
MentionTypeUser = MentionType{regexp.MustCompile(`<@!?(\d+)>`)}
MentionTypeRole = MentionType{regexp.MustCompile(`<@&(\d+)>`)}
MentionTypeChannel = MentionType{regexp.MustCompile(`<#(\d+)>`)}
MentionTypeEmoji = MentionType{regexp.MustCompile(`<a?:(\w+):(\d+)>`)}
MentionTypeTimestamp = MentionType{regexp.MustCompile(`<t:(?P<time>-?\d{1,17})(?::(?P<format>[tTdDfFR]))?>`)}
MentionTypeHere = MentionType{regexp.MustCompile(`@here`)}
MentionTypeEveryone = MentionType{regexp.MustCompile(`@everyone`)}
MentionTypeUser = MentionType{regexp.MustCompile(`<@!?(\d+)>`)}
MentionTypeRole = MentionType{regexp.MustCompile(`<@&(\d+)>`)}
MentionTypeChannel = MentionType{regexp.MustCompile(`<#(\d+)>`)}
MentionTypeEmoji = MentionType{regexp.MustCompile(`<a?:(\w+):(\d+)>`)}
MentionTypeTimestamp = MentionType{regexp.MustCompile(`<t:(?P<time>-?\d{1,17})(?::(?P<format>[tTdDfFR]))?>`)}
MentionTypeSlashCommand = MentionType{regexp.MustCompile(`</(\w+) ?((\w+)|(\w+ \w+)):(\d+)>`)}
MentionTypeHere = MentionType{regexp.MustCompile(`@here`)}
MentionTypeEveryone = MentionType{regexp.MustCompile(`@everyone`)}
)

type Mentionable interface {
Expand Down Expand Up @@ -57,3 +58,11 @@ func TimestampMention(timestamp int64) string {
func FormattedTimestampMention(timestamp int64, style TimestampStyle) string {
return fmt.Sprintf("<t:%d:%s>", timestamp, style)
}

// SlashCommandMention creates a slash command mention.
// You can also pass a subcommand (and/or a subcommand group respectively) to the path.
//
// mention := SlashCommandMention(id, "command group subcommand")
func SlashCommandMention(id snowflake.ID, path string) string {
return fmt.Sprintf("</%s:%d>", path, id)
}

0 comments on commit 72321bc

Please sign in to comment.