Skip to content

Commit

Permalink
listen for pkgsite links
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhapz committed Oct 5, 2023
1 parent 86f9060 commit 8e29fca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func typEmbed(pkg doc.Package, typ doc.Type, full bool) (discord.Embed, bool) {
return discord.Embed{
Title: fmt.Sprintf("%s: %s", pkg.Name, typ.Name),
URL: fmt.Sprintf("https://pkg.go.dev/%s#%s", pkg.URL, typ.Name),
Description: fmt.Sprintf("```go\n%s\n```\n%s", def, c),
Description: fmt.Sprintf("```go\n%s```\n%s", def, c),
Color: accentColor,
}, dMore || cMore
}
Expand All @@ -43,7 +43,7 @@ func fnEmbed(pkg doc.Package, fn doc.Function, full bool) (discord.Embed, bool)
return discord.Embed{
Title: fmt.Sprintf("%s: %s", pkg.Name, fn.Name),
URL: fmt.Sprintf("https://pkg.go.dev/%s#%s", pkg.URL, fn.Name),
Description: fmt.Sprintf("```go\n%s\n```\n%s", def, c),
Description: fmt.Sprintf("```go\n%s```\n%s", def, c),
Color: accentColor,
}, dMore || cMore
}
Expand All @@ -54,7 +54,7 @@ func methodEmbed(pkg doc.Package, method doc.Method, full bool) (discord.Embed,
return discord.Embed{
Title: fmt.Sprintf("%s: %s.%s", pkg.Name, method.For, method.Name),
URL: fmt.Sprintf("https://pkg.go.dev/%s#%s.%s", pkg.URL, method.For, method.Name),
Description: fmt.Sprintf("```go\n%s\n```\n%s", def, c),
Description: fmt.Sprintf("```go\n%s```\n%s", def, c),
Color: accentColor,
}, dMore || cMore
}
Expand Down
10 changes: 9 additions & 1 deletion handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func (b *botState) OnCommand(e *gateway.InteractionCreateEvent) {
}
}

var cmdre = regexp.MustCompile(`\$\[([\w\d/.]+)\]`)
var (
cmdre = regexp.MustCompile(`\$\[([\w\d/.]+)\]`)
urlre = regexp.MustCompile(`pkg.go.dev/([\w\d/.#]+)`)
)

func (b *botState) OnMessage(m *gateway.MessageCreateEvent) {
if _, ok := b.cfg.Blacklist[discord.Snowflake(m.Author.ID)]; ok {
Expand All @@ -91,6 +94,11 @@ func (b *botState) OnMessage(m *gateway.MessageCreateEvent) {
queries = append(queries, v[1])
}

for _, v := range urlre.FindAllStringSubmatch(m.Content, 3) {
s := strings.ReplaceAll(v[1], "#", ".")
queries = append(queries, s)
}

b.handleDocsText(m, queries)
}

Expand Down

0 comments on commit 8e29fca

Please sign in to comment.