Skip to content

Commit

Permalink
chore: add a way to send direct messages to manfred
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Dec 20, 2020
1 parent d4f97b2 commit 0217a5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chaos-bot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export sed 's/=.*//' .env
COMPILEDAEMON_OPTIONS ?= -exclude-dir=.git -color=true -build=go\ install -build-dir=.
run:
go install github.com/githubnemo/CompileDaemon
CompileDaemon $(COMPILEDAEMON_OPTIONS) -command="chaos-bot $(RUN_OPTS) discord-bot -discord-token=$(DISCORD_TOKEN)"
CompileDaemon $(COMPILEDAEMON_OPTIONS) -command="chaos-bot $(RUN_OPTS) discord-bot -discord-token=$(DISCORD_TOKEN) -manfred-channel=$(MANFRED_CHANNEL)"
.PHONY: run

install-run: install
Expand Down
11 changes: 11 additions & 0 deletions chaos-bot/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -120,6 +121,16 @@ func discordBotCmd(opts discordbotOpts) error {
httpJSONResponseEncoder(ctx, w, resp)
})

r.Post("/ping-manfred", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
resp := struct {
Msg string `json:"msg"`
}{}
json.NewDecoder(r.Body).Decode(&resp)
db.discordSession.ChannelMessageSend(opts.manfredChannel, fmt.Sprintf("HTTP ping: %q", resp.Msg))
httpJSONResponseEncoder(ctx, w, resp)
})

httpListener, err := net.Listen("tcp", db.opts.serverBind)
if err != nil {
return err
Expand Down

0 comments on commit 0217a5b

Please sign in to comment.