add snap plugin
This commit is contained in:
parent
479c5cf32f
commit
91323758bc
@ -11,7 +11,8 @@
|
||||
|HighFive|`o/|\o`|Everyone loves highfives.|
|
||||
|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.|
|
||||
|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.|
|
||||
|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.|
|
||||
|
@ -136,6 +136,7 @@ var Plugs = Plugins{
|
||||
&Hi{},
|
||||
&LoveYou{},
|
||||
&OpenBSDMan{},
|
||||
&Snap{},
|
||||
&Source{},
|
||||
&Thanks{},
|
||||
&Version{},
|
||||
|
58
plugins/snap.go
Normal file
58
plugins/snap.go
Normal 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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user