Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
surskitt committed Feb 23, 2020
2 parents 5c4ecb1 + 764aec8 commit cefe68c
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 3 deletions.
39 changes: 36 additions & 3 deletions .github/workflows/buildx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ env:
IMAGE_NAME: shanedabes/ircbot

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

push:
needs: build
- name: Lint
uses: docker://mushus/golangci-linter:1.1.2

- name: Test
uses: shoukoo/golang-pipeline/go1.13/test@master

docker:
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'
Expand Down Expand Up @@ -60,3 +66,30 @@ jobs:
--platform linux/amd64,linux/arm,linux/arm64/v8 \
--tag ${IMAGE_ID}:${VERSION} \
--file ./Dockerfile .
release:
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.8

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

- Add qwantz (dinosaur comics) plugin

## 1.0.0

- Initial release
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
_ "github.com/shanedabes/ircbot/plugins/clock"
_ "github.com/shanedabes/ircbot/plugins/donger"
_ "github.com/shanedabes/ircbot/plugins/lastfm"
_ "github.com/shanedabes/ircbot/plugins/qwantz"
_ "github.com/shanedabes/ircbot/plugins/tenor"
_ "github.com/shanedabes/ircbot/plugins/trakt"
_ "github.com/shanedabes/ircbot/plugins/twitter"
Expand Down
84 changes: 84 additions & 0 deletions plugins/qwantz/qwantz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package qwantz

import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"

"github.com/go-chat-bot/bot"
)

const (
qwantzURL = "http://www.qwantz.com"
reg = `(http:\/\/www\.qwantz\.com\/index.php\?comic=\d+)">([^<]+)`
)

type comic struct {
url string
desc string
}

func (c comic) String() string {
return fmt.Sprintf("%s - %s", c.desc, c.url)
}

func httpError(code int, status string) error {
return fmt.Errorf("status code error: %d %s", code, status)
}

func getPage(url string) (page string, err error) {
res, err := http.Get("http://www.qwantz.com")
if err != nil {
return "", err
}
defer res.Body.Close()

if res.StatusCode != 200 {
return "", httpError(res.StatusCode, res.Status)
}

contents, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", err
}
return string(contents), nil
}

func extractRandComic(url string) (out comic, err error) {
page, err := getPage(url)

if err != nil {
return out, err
}

r, _ := regexp.Compile(reg)
rr := r.FindStringSubmatch(page)
comicURL := rr[1]
desc := rr[2]

return comic{
url: comicURL,
desc: strings.ReplaceAll(desc, "\n", " "),
}, nil
}

func qwantz(command *bot.Cmd) (msg string, err error) {
comic, err := extractRandComic(qwantzURL)

if err != nil {
return "", err
}

return comic.String(), nil
}

func init() {
bot.RegisterCommand(
"qwantz",
"Post random dinosaur comic",
"",
qwantz,
)
}
18 changes: 18 additions & 0 deletions plugins/qwantz/qwantz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package qwantz

import (
"testing"

"github.com/stretchr/testify/assert"
)

func testComic(t *testing.T) {
c := comic{
url: "test.com",
desc: "comic desc",
}

expected := "comic desc - test.com"

assert.Equal(t, c.String(), expected)
}

0 comments on commit cefe68c

Please sign in to comment.