+beat plugin

This commit is contained in:
Aaron Bieber 2020-02-12 20:12:44 -07:00
parent ba3f1a9f3c
commit 817b9fcc9c
3 changed files with 48 additions and 1 deletions

View File

@ -2,9 +2,9 @@
[![builds.sr.ht status](https://builds.sr.ht/~qbit/mcchunkie.svg)](https://builds.sr.ht/~qbit/mcchunkie?) [![builds.sr.ht status](https://builds.sr.ht/~qbit/mcchunkie.svg)](https://builds.sr.ht/~qbit/mcchunkie?)
|Plugin Name|Match|Description| |Plugin Name|Match|Description|
|----|---|---| |----|---|---|
|Beat|`(?i)^\.beat$|^what time is it\?$|^beat( )?time:?\??$`|Print the current [beat time](https://en.wikipedia.org/wiki/Swatch_Internet_Time).|
|Beer|`(?i)^beer: `|Queries [OpenDataSoft](https://public-us.opendatasoft.com/explore/dataset/open-beer-database/table/)'s beer database for a given beer.| |Beer|`(?i)^beer: `|Queries [OpenDataSoft](https://public-us.opendatasoft.com/explore/dataset/open-beer-database/table/)'s beer database for a given beer.|
|BotSnack|`(?i)botsnack`|Consumes a botsnack. This pleases mcchunkie and brings balance to the universe.| |BotSnack|`(?i)botsnack`|Consumes a botsnack. This pleases mcchunkie and brings balance to the universe.|
|HighFive|`o/|\o`|Everyone loves highfives.| |HighFive|`o/|\o`|Everyone loves highfives.|

46
plugins/beat.go Normal file
View File

@ -0,0 +1,46 @@
package plugins
import (
"fmt"
"regexp"
"time"
"github.com/matrix-org/gomatrix"
)
// Beat responds to beat messages
type Beat struct {
}
// Descr describes this plugin
func (h *Beat) Descr() string {
return "Print the current [beat time](https://en.wikipedia.org/wiki/Swatch_Internet_Time)."
}
// Re is the regex for matching hi messages.
func (h *Beat) Re() string {
return `(?i)^\.beat$|^what time is it\?$|^beat( )?time:?\??$`
}
// Match determines if we are highfiving
func (h *Beat) Match(user, msg string) bool {
re := regexp.MustCompile(h.Re())
return re.MatchString(msg)
}
// SetStore we don't need a store here
func (h *Beat) SetStore(s PluginStore) {}
// RespondText to hi events
func (h *Beat) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
n := time.Now()
utc1 := n.Unix() + 3600
r := utc1 % 86400
bt := float32(r) / 86.4
SendText(c, ev.RoomID, fmt.Sprintf("@%03d", int32(bt)))
}
// Name hi
func (h *Beat) Name() string {
return "Beat"
}

View File

@ -70,6 +70,7 @@ type Plugins []Plugin
// Plugs defines the "enabled" plugins. // Plugs defines the "enabled" plugins.
var Plugs = Plugins{ var Plugs = Plugins{
&Beat{},
&Beer{}, &Beer{},
&BotSnack{}, &BotSnack{},
&HighFive{}, &HighFive{},