Helperbot V2
This commit is contained in:
15
plugins_src/plugin_aoc/go.mod
Normal file
15
plugins_src/plugin_aoc/go.mod
Normal file
@@ -0,0 +1,15 @@
|
||||
module git.bullercodeworks.com/brian/helperbot/plugins_src/plugin_aoc
|
||||
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.1
|
||||
git.bullercodeworks.com/brian/helperbot v0.0.0-20221201132802-09a662a8cd4b
|
||||
github.com/slack-go/slack v0.12.3
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/nlopes/slack v0.6.0 // indirect
|
||||
github.com/pkg/errors v0.8.0 // indirect
|
||||
)
|
24
plugins_src/plugin_aoc/go.sum
Normal file
24
plugins_src/plugin_aoc/go.sum
Normal file
@@ -0,0 +1,24 @@
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.1 h1:5pp9bPVpTKdErkEcIAqoyuMsvmpQkO8upJ+NUQ+MUv0=
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.1/go.mod h1:h/W8Nm8zsrVSjnoA6BRlf38LbaXHR/m6dIq804LOO3w=
|
||||
git.bullercodeworks.com/brian/helperbot v0.0.0-20221201132802-09a662a8cd4b h1:2BCAIENJo1r+h/+qHBJ3eCQTsa1kdsxwYFGTrPdZX3o=
|
||||
git.bullercodeworks.com/brian/helperbot v0.0.0-20221201132802-09a662a8cd4b/go.mod h1:mjMh+IvDRLyD1WscFcZ1OC78C3CgVUi9zIz5trnFK0Y=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
|
||||
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
|
||||
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/slack-go/slack v0.12.3 h1:92/dfFU8Q5XP6Wp5rr5/T5JHLM5c5Smtn53fhToAP88=
|
||||
github.com/slack-go/slack v0.12.3/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
1
plugins_src/plugin_aoc/go.work
Normal file
1
plugins_src/plugin_aoc/go.work
Normal file
@@ -0,0 +1 @@
|
||||
go 1.20
|
@@ -1,91 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"C"
|
||||
)
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/helperbot"
|
||||
"github.com/slack-go/slack"
|
||||
)
|
||||
|
||||
type StatsState struct {
|
||||
model helperbot.Model
|
||||
lag time.Duration
|
||||
}
|
||||
|
||||
var State StatsState
|
||||
|
||||
/* Plugin Interface Functions */
|
||||
func (s *StatsState) Name() string { return "slack-stats" }
|
||||
func (s *StatsState) Initialize(m helperbot.Model) error {
|
||||
s.model = m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StatsState) ProcessMessage(m helperbot.Message) {
|
||||
fmt.Printf("Processing Message: %s\n", m.GetMessage().Text)
|
||||
if m.GetSource() == "slack" {
|
||||
slackMsg := m.GetMessage()
|
||||
if len(slackMsg.Channel) == 0 {
|
||||
return
|
||||
}
|
||||
admin, err := s.model.GetSlackAdminDMId()
|
||||
if err != nil {
|
||||
s.SendAdminIdError()
|
||||
return
|
||||
}
|
||||
if slackMsg.Channel == admin {
|
||||
s.ProcessAdminDirectMessage(slackMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StatsState) ProcessRTMEvent(msg slack.RTMEvent) {
|
||||
switch ev := msg.Data.(type) {
|
||||
case *slack.LatencyReport:
|
||||
s.lag = ev.Value
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StatsState) Run() {}
|
||||
func (s *StatsState) Exit() {}
|
||||
|
||||
/* Other Functions */
|
||||
func (s *StatsState) ProcessAdminDirectMessage(slackMsg slack.Message) {
|
||||
msgPts := strings.Fields(slackMsg.Text)
|
||||
if len(msgPts) < 2 || msgPts[0] != "!stats" {
|
||||
return
|
||||
}
|
||||
switch msgPts[1] {
|
||||
case "lag", "latency":
|
||||
s.DoLatencyCommand(slackMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StatsState) DoLatencyCommand(slackMsg slack.Message) {
|
||||
if s.lag == 0 {
|
||||
s.SendSlackMessage("Unknown", slackMsg.Channel)
|
||||
return
|
||||
}
|
||||
s.SendSlackMessage(s.lag.String(), slackMsg.Channel)
|
||||
}
|
||||
|
||||
func (s *StatsState) SendSlackMessage(text, dest string) {
|
||||
s.model.SendMessage(s.Name(), "slack", s.BuildMessage("message", text, dest))
|
||||
}
|
||||
|
||||
func (s *StatsState) SendAdminIdError() {
|
||||
s.model.SendMessage(s.Name(), "error", s.BuildMessage("error", "Error getting Admin DM Id", ""))
|
||||
}
|
||||
|
||||
func (s *StatsState) BuildMessage(tp, text, ch string) slack.Message {
|
||||
ret := slack.Message{}
|
||||
ret.Type = tp
|
||||
ret.Text = text
|
||||
ret.Channel = ch
|
||||
return ret
|
||||
}
|
3
plugins_src/plugin_stats/go.mod
Normal file
3
plugins_src/plugin_stats/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module git.bullercodeworks.com/brian/helperbot/plugins_src/plugin_stats
|
||||
|
||||
go 1.20
|
1
plugins_src/plugin_stats/go.work
Normal file
1
plugins_src/plugin_stats/go.work
Normal file
@@ -0,0 +1 @@
|
||||
go 1.20
|
80
plugins_src/plugin_stats/plugin_stats.go
Normal file
80
plugins_src/plugin_stats/plugin_stats.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"C"
|
||||
)
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/helperbot/models"
|
||||
"github.com/slack-go/slack"
|
||||
)
|
||||
|
||||
type StatsState struct {
|
||||
model models.Model
|
||||
lag time.Duration
|
||||
}
|
||||
|
||||
var State StatsState
|
||||
|
||||
/* Plugin Interface Functions */
|
||||
func (s *StatsState) Name() string { return "slack-stats" }
|
||||
func (s *StatsState) Initialize(m models.Model) error {
|
||||
s.model = m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StatsState) ProcessMessage(m models.BotMessage) bool {
|
||||
fmt.Printf("Stats: Processing Message: %s\n", m)
|
||||
if m.GetSource() == models.MsgSrcSlack {
|
||||
admin := s.model.GetSlackAdminDMId()
|
||||
if m.Target == admin {
|
||||
return s.ProcessAdminDirectMessage(m)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *StatsState) ProcessRTMEvent(msg slack.RTMEvent) bool {
|
||||
switch ev := msg.Data.(type) {
|
||||
case *slack.LatencyReport:
|
||||
s.lag = ev.Value
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *StatsState) Run() {}
|
||||
func (s *StatsState) Exit() {}
|
||||
|
||||
/* Other Functions */
|
||||
func (s *StatsState) ProcessAdminDirectMessage(m models.BotMessage) bool {
|
||||
msgPts := strings.Fields(m.Text)
|
||||
if len(msgPts) < 2 || msgPts[0] != "!stats" {
|
||||
return false
|
||||
}
|
||||
switch msgPts[1] {
|
||||
case "lag", "latency":
|
||||
s.DoLatencyCommand()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *StatsState) DoLatencyCommand() {
|
||||
if s.lag == 0 {
|
||||
s.SendSlackMessage("Unknown")
|
||||
return
|
||||
}
|
||||
s.SendSlackMessage(s.lag.String())
|
||||
}
|
||||
|
||||
func (s *StatsState) SendSlackMessage(text string) {
|
||||
admin := s.model.GetSlackAdminDMId()
|
||||
if admin != "" {
|
||||
s.model.SendMessage(models.NewBotMessage(s.Name(), models.MsgSrcSlack, models.MsgTpMessage, admin, text))
|
||||
} else {
|
||||
s.model.SendMessage(models.NewBotMessage(s.Name(), models.MsgSrcApp, models.MsgTpError, models.MsgSrcApp, "No Admin ID Found"))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user