Compare commits

..

No commits in common. "b3c9157b3cefe7d9a44a228ec810b39cbf34e582" and "b48165fa0a79d624e8861b6557d39372bd79ffd5" have entirely different histories.

2 changed files with 3 additions and 94 deletions

View File

@ -1,30 +1,8 @@
kind: pipeline kind: pipeline
name: notify-pipeline-start name: default
steps: steps:
- name: slack - name: docker
image: plugins/slack
settings:
webhook:
from_secret: SLACK_WEBHOOK
link_names: true
template: >
{{#if build.pull }}
*Build started*: {{ repo.owner }}/{{ repo.name }} - <https://git.eeqj.de/{{ repo.owner }}/{{ repo.name }}/pull/{{ build.pull }}|Pull Request #{{ build.pull }}>
{{else}}
*Build started: {{ repo.owner }}/{{ repo.name }} - Build #{{ build.number }}* (type: `{{ build.event }}`)
{{/if}}
Commit: <https://git.eeqj.de/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}>
Branch: <https://git.eeqj.de/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}>
Author: {{ build.author }}
<{{ build.link }}|Visit build page ↗>
---
kind: pipeline
name: test-docker-build
steps:
- name: test-docker-build
image: plugins/docker image: plugins/docker
network_mode: bridge network_mode: bridge
settings: settings:
@ -33,35 +11,3 @@ steps:
tags: tags:
- ${DRONE_COMMIT_SHA} - ${DRONE_COMMIT_SHA}
- ${DRONE_BRANCH} - ${DRONE_BRANCH}
---
kind: pipeline
name: notify-pipeline-end
steps:
- name: slack
image: plugins/slack
settings:
webhook:
from_secret: SLACK_WEBHOOK
link_names: true
template: >
{{#if build.pull }}
*{{#success build.status}}✔{{ else }}✘{{/success}} {{ uppercasefirst build.status }}*: {{ repo.owner }}/{{ repo.name }} - <https://git.eeqj.de/{{ repo.owner }}/{{ repo.name }}/pull/{{ build.pull }}|Pull Request #{{ build.pull }}>
{{else}}
*{{#success build.status}}✔{{ else }}✘{{/success}} {{ uppercasefirst build.status }}: {{ repo.owner }}/{{ repo.name }} - Build #{{ build.number }}* (type: `{{ build.event }}`)
{{/if}}
Commit: <https://git.eeqj.de/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}>
Branch: <https://git.eeqj.de/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}>
Author: {{ build.author }}
Duration: {{ since build.created }}
<{{ build.link }}|Visit build page ↗>
depends_on:
- test-docker-build
trigger:
status:
- success
- failure

View File

@ -4,7 +4,6 @@ package bot
import ( import (
"fmt" "fmt"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"net/http"
"os" "os"
"os/signal" "os/signal"
"regexp" "regexp"
@ -72,7 +71,7 @@ func (b *Bot) Main() int {
// Lets create a bot channel for logging debug messages into // Lets create a bot channel for logging debug messages into
b.CreateBotDebuggingChannelIfNeeded() b.CreateBotDebuggingChannelIfNeeded()
msg := fmt.Sprintf("_**%s** (version `%s`) is now starting up", b.BotName, b.Version) msg := fmt.Sprintf("_**%s** has started up_\n\nrunning on version %s", b.BotName, b.Version)
b.SendMsgToDebuggingChannel(msg, "") b.SendMsgToDebuggingChannel(msg, "")
// Lets start listening to some channels via the websocket! // Lets start listening to some channels via the websocket!
@ -230,38 +229,6 @@ func (b *Bot) Shutdown() {
syscall.Kill(syscall.Getpid(), syscall.SIGINT) syscall.Kill(syscall.Getpid(), syscall.SIGINT)
} }
func (b *Bot) HandleWeatherRequest(channelid string, postid string, message string) {
msg := fmt.Sprintf("weather request received: `%s`", message)
b.SendMsgToChannel(msg, postid, channelid)
r := regexp.MustCompile(`metar\s+([A-Za-z]{4})`)
loc := r.FindString(message)
if loc == "" {
b.SendMsgToChannel("error, sorry", postid, channelid)
}
token := os.Getenv("METAR_API_TOKEN")
url := fmt.Sprintf("https://avwx.rest/api/metar/%s?options=&airport=true&reporting=true&format=json&onfail=cache", loc)
msg = fmt.Sprintf("calculated url: `%s`", url)
b.SendMsgToChannel(msg, postid, channelid)
client := http.Client{
Timeout: 5 * time.Second,
}
req, err := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", `Token `+token)
resp, err := client.Do(req)
if err != nil {
b.SendMsgToChannel(fmt.Sprintf("weather fetch error: %s", err), postid, channelid)
return
}
b.SendMsgToChannel(fmt.Sprintf("weather %s: %s", loc, resp), postid, channelid)
}
func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) { func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string))) post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
@ -270,10 +237,6 @@ func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
} }
//pretty.Print(post) //pretty.Print(post)
if matched, _ := regexp.MatchString(`(?:^|\W)metar(?:$|\W)`, post.Message); matched {
b.HandleWeatherRequest(post.ChannelId, post.Id, post.Message)
return
}
if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched { if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched {
b.SendMsgToChannel("yes I'm running", post.Id, post.ChannelId) b.SendMsgToChannel("yes I'm running", post.Id, post.ChannelId)