add snap plugin

This commit is contained in:
Aaron Bieber 2020-02-23 14:35:07 -07:00
parent 479c5cf32f
commit 91323758bc
3 changed files with 61 additions and 1 deletions

View File

@ -11,7 +11,8 @@
|HighFive|`o/|\o`|Everyone loves highfives.| |HighFive|`o/|\o`|Everyone loves highfives.|
|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?(\w+)$`|Produces a link to man.openbsd.org.| |OpenBSDMan|`(?i)^man: ([1-9]?p?)\s?(.+)$`|Produces a link to man.openbsd.org.|
|Snap|`(?i)^snap:$`|checks the current build date of OpenBSD snapshots.|
|Source|`(?i)where is your (source|code)`|Tell people where they can find more information about myself.| |Source|`(?i)where is your (source|code)`|Tell people where they can find more information about myself.|
|Thanks|`(?i)^thank you|thank you$|^thanks|thanks$|^ty|ty$`|Bots should be respectful. Respond to thanks.| |Thanks|`(?i)^thank you|thank you$|^thanks|thanks$|^ty|ty$`|Bots should be respectful. Respond to thanks.|
|Version|`(?i)version$`|Show a bit of information about what we are.| |Version|`(?i)version$`|Show a bit of information about what we are.|

View File

@ -136,6 +136,7 @@ var Plugs = Plugins{
&Hi{}, &Hi{},
&LoveYou{}, &LoveYou{},
&OpenBSDMan{}, &OpenBSDMan{},
&Snap{},
&Source{}, &Source{},
&Thanks{}, &Thanks{},
&Version{}, &Version{},

58
plugins/snap.go Normal file
View File

@ -0,0 +1,58 @@
package plugins
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"regexp"
"github.com/matrix-org/gomatrix"
)
// Snap responds to OpenBSD snapshot checks
type Snap struct {
}
// Descr describes this plugin
func (p *Snap) Descr() string {
return "checks the current build date of OpenBSD snapshots."
}
// Re returns the federation check matching string
func (p *Snap) Re() string {
return `(?i)^snap:$`
}
// Match determines if we should call the response for Snap
func (p *Snap) Match(user, msg string) bool {
re := regexp.MustCompile(p.Re())
return re.MatchString(msg)
}
// SetStore we don't need a store here.
func (p *Snap) SetStore(s PluginStore) {}
// RespondText to looking up of federation check requests
func (p *Snap) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
log.Printf("%s: responding to '%s'", p.Name(), ev.Sender)
resp, err := http.Get("https://ftp.usa.openbsd.org/pub/OpenBSD/snapshots/amd64/BUILDINFO")
if err != nil {
SendText(c, ev.RoomID, fmt.Sprintf("%s", err))
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
SendText(c, ev.RoomID, fmt.Sprintf("%s", err))
return
}
SendText(c, ev.RoomID, string(body))
}
// Name Snap!
func (p *Snap) Name() string {
return "Snap"
}