Compare commits

..

No commits in common. "ba484557b83a03ed72d4a48002f4e7f6a057e5ae" and "2ee81c19c8f1f4ea1816416cf45ac01297c3160d" have entirely different histories.

6 changed files with 16 additions and 114 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
sco sco
.DS_Store

View File

@ -29,7 +29,6 @@ default: fmt
fmt: fmt:
go fmt ./... go fmt ./...
goimports -l -w .
docker-build: docker-build:
docker build -t $(IMAGENAME) . docker build -t $(IMAGENAME) .
@ -42,9 +41,5 @@ build: ./$(FN)
go-get: go-get:
cd cmd/$(FN) && go get -v cd cmd/$(FN) && go get -v
vet: ./$(FN): */*.go cmd/*/*.go go-get
go vet ./...
bash -c 'test -z "$$(gofmt -l .)"'
./$(FN): */*.go cmd/*/*.go go-get vet
cd cmd/$(FN) && go build -o ../../$(FN) $(GOFLAGS) . cd cmd/$(FN) && go build -o ../../$(FN) $(GOFLAGS) .

View File

@ -1,17 +1,16 @@
package bot package bot
//import "github.com/kr/pretty" import "github.com/kr/pretty"
import ( import (
"fmt" "fmt"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/rs/zerolog/log"
"os" "os"
"os/signal" "os/signal"
"regexp" "regexp"
"strings" "strings"
"syscall" "syscall"
"time" "time"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/rs/zerolog/log"
) )
type Bot struct { type Bot struct {
@ -52,7 +51,7 @@ func (b *Bot) identify() {
Msg("starting") Msg("starting")
} }
func (b *Bot) Main() { func (b *Bot) Main() int {
println(b.BotName) println(b.BotName)
b.StartupUnixTime = time.Now().Unix() b.StartupUnixTime = time.Now().Unix()
@ -107,6 +106,7 @@ func (b *Bot) Main() {
// You can block forever with // You can block forever with
select {} select {}
return 0
} }
func (b *Bot) MakeSureServerIsRunning() { func (b *Bot) MakeSureServerIsRunning() {
@ -285,10 +285,9 @@ func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
return return
} }
if post.Message == "" { // FIXME check and see if the message from mm is a bot message, if so,
// null message, we can probably ignore it. // ignore it
return pretty.Print(post)
}
if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched { if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched {
b.Shutdown() b.Shutdown()

View File

@ -1,12 +1,11 @@
package bot package bot
import ( import (
"os"
"time"
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"os"
"time"
) )
func (b *Bot) setupLogging() { func (b *Bot) setupLogging() {

View File

@ -2,92 +2,15 @@ package bot
//import "github.com/kr/pretty" //import "github.com/kr/pretty"
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/rs/zerolog/log"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"time" "time"
"github.com/rs/zerolog/log"
) )
type MetarResponse struct {
Meta struct {
Timestamp time.Time `json:"timestamp"`
StationsUpdated string `json:"stations_updated"`
} `json:"meta"`
Altimeter struct {
Repr string `json:"repr"`
Value float64 `json:"value"`
Spoken string `json:"spoken"`
} `json:"altimeter"`
Clouds []interface{} `json:"clouds"`
FlightRules string `json:"flight_rules"`
Other []interface{} `json:"other"`
Sanitized string `json:"sanitized"`
Visibility struct {
Repr string `json:"repr"`
Value int `json:"value"`
Spoken string `json:"spoken"`
} `json:"visibility"`
WindDirection struct {
Repr string `json:"repr"`
Value int `json:"value"`
Spoken string `json:"spoken"`
} `json:"wind_direction"`
WindGust struct {
Repr string `json:"repr"`
Value int `json:"value"`
Spoken string `json:"spoken"`
} `json:"wind_gust"`
WindSpeed struct {
Repr string `json:"repr"`
Value int `json:"value"`
Spoken string `json:"spoken"`
} `json:"wind_speed"`
WxCodes []interface{} `json:"wx_codes"`
Raw string `json:"raw"`
Station string `json:"station"`
Time struct {
Repr string `json:"repr"`
Dt time.Time `json:"dt"`
} `json:"time"`
Remarks string `json:"remarks"`
Dewpoint struct {
Repr string `json:"repr"`
Value int `json:"value"`
Spoken string `json:"spoken"`
} `json:"dewpoint"`
RemarksInfo struct {
DewpointDecimal struct {
Repr string `json:"repr"`
Value float64 `json:"value"`
Spoken string `json:"spoken"`
} `json:"dewpoint_decimal"`
TemperatureDecimal struct {
Repr string `json:"repr"`
Value float64 `json:"value"`
Spoken string `json:"spoken"`
} `json:"temperature_decimal"`
} `json:"remarks_info"`
RunwayVisibility []interface{} `json:"runway_visibility"`
Temperature struct {
Repr string `json:"repr"`
Value int `json:"value"`
Spoken string `json:"spoken"`
} `json:"temperature"`
WindVariableDirection []interface{} `json:"wind_variable_direction"`
Units struct {
Altimeter string `json:"altimeter"`
Altitude string `json:"altitude"`
Temperature string `json:"temperature"`
Visibility string `json:"visibility"`
WindSpeed string `json:"wind_speed"`
} `json:"units"`
}
func (b *Bot) HandleWeatherRequest(channelid string, postid string, message string) { func (b *Bot) HandleWeatherRequest(channelid string, postid string, message string) {
// we are using a very bare image with no CA cert bundle // we are using a very bare image with no CA cert bundle
@ -129,16 +52,7 @@ func (b *Bot) HandleWeatherRequest(channelid string, postid string, message stri
data, _ := ioutil.ReadAll(resp.Body) data, _ := ioutil.ReadAll(resp.Body)
var parsedMetarResponse MetarResponse
log.Info().Msgf("weather %s: %s", loc, data) log.Info().Msgf("weather %s: %s", loc, data)
b.SendMsgToChannel(fmt.Sprintf("weather %s: %s", loc, data), postid, channelid)
err = nil
err = json.Unmarshal([]byte(data), &parsedMetarResponse)
if err != nil {
b.SendMsgToChannel("error deserializing metar data", postid, channelid)
return
}
b.SendMsgToChannel(fmt.Sprintf("weather for `%s`: \n```\n%+v\n```\n", loc, parsedMetarResponse), postid, channelid)
} }

View File

@ -1,14 +1,10 @@
package main package main
import ( import "os"
"os" import "git.eeqj.de/sneak/sco/bot"
"git.eeqj.de/sneak/sco/bot"
)
var Version string var Version string
var Commit string var Commit string
var Buildarch string var Buildarch string
func main() { func main() {
@ -27,5 +23,5 @@ func main() {
b.AccountFirstname = "LSV" b.AccountFirstname = "LSV"
b.AccountLastname = "Serious Callers Only" b.AccountLastname = "Serious Callers Only"
}) })
mybot.Main() os.Exit(mybot.Main())
} }