extend pgp plugin to check email and fingerprint

This commit is contained in:
Aaron Bieber 2021-01-04 21:05:15 -07:00
parent 541bd27dd5
commit 26647bc235
2 changed files with 10 additions and 5 deletions

View File

@ -17,7 +17,7 @@
|Hi|`(?i)^hi|hi$`|Friendly bots say hi.| |Hi|`(?i)^hi|hi$`|Friendly bots say hi.|
|LoveYou|`(?i)i love you`|Spreading love where ever we can by responding when someone shows us love.| |LoveYou|`(?i)i love you`|Spreading love where ever we can by responding when someone shows us love.|
|OpenBSDMan|`(?i)^man: ([1-9][p]?)?\s?(.+)$`|Produces a link to man.openbsd.org.| |OpenBSDMan|`(?i)^man: ([1-9][p]?)?\s?(.+)$`|Produces a link to man.openbsd.org.|
|PGP|`(?i)^pgp: (.+@.+\..+)$`|Queries keys.openpgp.org| |PGP|`(?i)^pgp: (.+@.+\..+|[a-f0-9]+)$`|Queries keys.openpgp.org|
|Palette|`(?i)^#[a-f0-9]{6}$`|Creates an solid 56x56 image of the color specified.| |Palette|`(?i)^#[a-f0-9]{6}$`|Creates an solid 56x56 image of the color specified.|
|RFC|`(?i)^rfc\s?([0-9]+)$`|Produces a link to tools.ietf.org.| |RFC|`(?i)^rfc\s?([0-9]+)$`|Produces a link to tools.ietf.org.|
|Snap|`(?i)^snap:$`|checks the current build date of OpenBSD snapshots.| |Snap|`(?i)^snap:$`|checks the current build date of OpenBSD snapshots.|

View File

@ -27,7 +27,7 @@ func (p *PGP) Descr() string {
// Re is what our pgp request matches // Re is what our pgp request matches
func (p *PGP) Re() string { func (p *PGP) Re() string {
return `(?i)^pgp: (.+@.+\..+)$` return `(?i)^pgp: (.+@.+\..+|[a-f0-9]+)$`
} }
// Match checks for "pgp: " messages // Match checks for "pgp: " messages
@ -38,19 +38,24 @@ func (p *PGP) Match(_, msg string) bool {
func (p *PGP) fix(msg string) string { func (p *PGP) fix(msg string) string {
re := regexp.MustCompile(p.Re()) re := regexp.MustCompile(p.Re())
return re.ReplaceAllString(msg, "$1") return strings.ToUpper(re.ReplaceAllString(msg, "$1"))
} }
// RespondText to looking up of PGP info // RespondText to looking up of PGP info
func (p *PGP) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, post string) error { func (p *PGP) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, post string) error {
search := p.fix(post) search := p.fix(post)
searchURL := "https://keys.openpgp.org//vks/v1/by-fingerprint/%s"
if strings.ContainsAny(search, "@") {
searchURL = "https://keys.openpgp.org//vks/v1/by-email/%s"
}
escSearch, err := url.Parse(search) escSearch, err := url.Parse(search)
if err != nil { if err != nil {
return err return err
} }
u := fmt.Sprintf("https://keys.openpgp.org//vks/v1/by-email/%s", u := fmt.Sprintf(searchURL, escSearch)
escSearch)
resp, err := http.Get(u) resp, err := http.Get(u)
if err != nil { if err != nil {