Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
surskitt committed Feb 20, 2020
2 parents 406f441 + e43b3ee commit 5c4ecb1
Show file tree
Hide file tree
Showing 30 changed files with 3,639 additions and 189 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/buildx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: buildx

on:
pull_request:
branches: master

push:
branches: master
tags:
- '*'

env:
IMAGE_NAME: shanedabes/ircbot

jobs:
build:
runs-on: ubuntu-latest

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

push:
needs: build

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

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

- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest

- name: Login to registry
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u shanedabes --password-stdin

- name: Build and push
run: |
IMAGE_ID=$IMAGE_NAME
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker buildx build \
--push \
--platform linux/amd64,linux/arm,linux/arm64/v8 \
--tag ${IMAGE_ID}:${VERSION} \
--file ./Dockerfile .
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ vendor/

# go build result
ircbot

env
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial release
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:alpine AS build-env
ADD . /src
RUN cd /src && go build -o gowon

# final stage
FROM alpine
WORKDIR /app
COPY --from=build-env /src/gowon /app/
ENTRYPOINT ./gowon
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ services:
IRC_TENOR_API: "${IRC_TENOR_API}"
IRC_LASTFM_API: "${IRC_LASTFM_API}"
IRC_TRAKT_API: "${IRC_TRAKT_API}"
IRC_TWITTER_CONSUMER_KEY: "${IRC_TWITTER_CONSUMER_KEY}"
IRC_TWITTER_CONSUMER_SECRET: "${IRC_TWITTER_CONSUMER_SECRET}"
IRC_TWITTER_ACCESS_TOKEN: "${IRC_TWITTER_ACCESS_TOKEN}"
IRC_TWITTER_ACCESS_SECRET: "${IRC_TWITTER_ACCESS_SECRET}"
IRC_REPLIES: "${IRC_REPLIES}"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module github.com/shanedabes/ircbot
go 1.13

require (
github.com/dghubble/go-twitter v0.0.0-20190719072343-39e5462e111f
github.com/dghubble/oauth1 v0.6.0
github.com/go-chat-bot/bot v0.0.0-20191201225543-272d0f24a45f
github.com/go-chat-bot/plugins v0.0.0-20191201225443-abb8340baed8
github.com/stretchr/testify v1.4.0
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ github.com/a-h/generate v0.0.0-20190312091541-e59c34d33fb3 h1:Ddgcglj3p+q6QqZ5n4
github.com/a-h/generate v0.0.0-20190312091541-e59c34d33fb3/go.mod h1:traiLYQ0YD7qUMCdjo6/jSaJRPHXniX4HVs+PhEhYpc=
github.com/andygrunwald/go-jira v1.5.0/go.mod h1:yNYQrX3nGSrVdcVsM2mWz2pm7tTeDtYfRyVEkc3VUiY=
github.com/beevik/guid v0.0.0-20170504223318-d0ea8faecee0/go.mod h1:XzXWuOd1wJ63MtICHh5+PnvCuxsB/d58T8TswEhI/9I=
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudfoundry/gosigar v1.1.0/go.mod h1:3qLfc2GlfmwOx2+ZDaRGH3Y9fwQ0sQeaAleo2GV5pH0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/detached/gorocket v0.0.0-20170629192631-d44bbd3f26d2/go.mod h1:w5eKhlAkZwY6VBm2Sa1Evdte2+Fqhc+dnSk7/KTN5FM=
github.com/dghubble/go-twitter v0.0.0-20190719072343-39e5462e111f h1:M2wB039zeS1/LZtN/3A7tWyfctiOBL4ty5PURBmDdWU=
github.com/dghubble/go-twitter v0.0.0-20190719072343-39e5462e111f/go.mod h1:xfg4uS5LEzOj8PgZV7SQYRHbG7jPUnelEiaAVJxmhJE=
github.com/dghubble/oauth1 v0.6.0 h1:m1yC01Ohc/eF38jwZ8JUjL1a+XHHXtGQgK+MxQbmSx0=
github.com/dghubble/oauth1 v0.6.0/go.mod h1:8pFdfPkv/jr8mkChVbNVuJ0suiHe278BtWI4Tk1ujxk=
github.com/dghubble/sling v1.3.0 h1:pZHjCJq4zJvc6qVQ5wN1jo5oNZlNE0+8T/h0XeXBUKU=
github.com/dghubble/sling v1.3.0/go.mod h1:XXShWaBWKzNLhu2OxikSNFrlsvowtz4kyRuXUG7oQKY=
github.com/fatih/structs v1.0.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-chat-bot/bot v0.0.0-20191201225543-272d0f24a45f h1:n5PvkOuo4amEMa6B53nQMdPmqfrcjJDnhThtIh+KSNo=
Expand All @@ -31,6 +40,7 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand All @@ -57,6 +67,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
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/pyinx/gorocket v0.0.0-20170810024322-78ae1353729f/go.mod h1:nh/AiOs8vRCaqnSOHVzyta23ZLm5ck/st4brrxtQJEo=
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
Expand All @@ -66,6 +77,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8=
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/thoj/go-ircevent v0.0.0-20180816043103-14f3614f28c3 h1:389FrrKIAlxqQMTscCQ7VH3JAVuxb/pe53v2LBiA7z8=
Expand Down Expand Up @@ -133,6 +146,7 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/telegram-bot-api.v3 v3.0.0/go.mod h1:WxP4rAHcQNrXhQLGIK9aVLkpygV4Qq8YS3yjjJ/0VLA=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import (

_ "github.com/go-chat-bot/plugins/url"
_ "github.com/shanedabes/ircbot/plugins/checkiday"
_ "github.com/shanedabes/ircbot/plugins/choose"
_ "github.com/shanedabes/ircbot/plugins/clock"
_ "github.com/shanedabes/ircbot/plugins/donger"
_ "github.com/shanedabes/ircbot/plugins/lastfm"
_ "github.com/shanedabes/ircbot/plugins/tenor"
_ "github.com/shanedabes/ircbot/plugins/trakt"
_ "github.com/shanedabes/ircbot/plugins/twitter"
_ "github.com/shanedabes/ircbot/plugins/wikipedia"

"strings"
)
Expand Down
28 changes: 17 additions & 11 deletions plugins/checkiday/checkiday.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@ package checkiday
import (
"github.com/go-chat-bot/bot"
"github.com/go-chat-bot/plugins/web"

"github.com/shanedabes/ircbot/plugins/formatting"
"github.com/shanedabes/ircbot/plugins/irccolours"
)

const (
checkiday_api_url = "https://checkiday.com/api/3/?d"
checkidayAPIURL = "https://checkiday.com/api/3/?d"
)

type daysJson struct {
Holidays []struct {
Name string `json:"name"`
} `json:"holidays"`
type daysJSON struct {
Days []Day `json:"holidays"`
}

func (dj daysJson) days() (out []string) {
for _, d := range dj.Holidays {
func (ds daysJSON) List() (out []string) {
for _, d := range ds.Days {
out = append(out, d.Name)
}
return
}

// Day represents a single day result from checkiday
type Day struct {
Name string `json:"name"`
}

func (d Day) String() string {
return d.Name
}

func checkiday(command *bot.Cmd) (msg string, err error) {
data := &daysJson{}
err = web.GetJSON(checkiday_api_url, data)
data := &daysJSON{}
err = web.GetJSON(checkidayAPIURL, data)

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

cl := irccolours.ColouriseList(data.days())
cl := irccolours.ColouriseList(data.List())
dl := irccolours.FormattedTextToStringList(cl)
return formatting.ListToLines(dl, 400), nil
}
Expand Down
34 changes: 34 additions & 0 deletions plugins/checkiday/checkiday_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package checkiday

import (
"testing"

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

var (
d1 = Day{
Name: "test day",
}

d2 = Day{
Name: "test day 2",
}

dj = daysJSON{
Days: []Day{d1, d2},
}
)

func TestDay(t *testing.T) {
assert.Equal(t, d1.String(), "test day")
}

func TestDays(t *testing.T) {
expected := []string{
"test day",
"test day 2",
}

assert.Equal(t, dj.List(), expected)
}
29 changes: 29 additions & 0 deletions plugins/choose/choose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package choose

import (
"math/rand"
"strings"
"time"

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

func choose(command *bot.Cmd) (msg string, err error) {
args := command.RawArgs
words := strings.Split(args, "/")

rand.Seed(time.Now().Unix())
index := rand.Intn(len(words))
word := words[index]

return word, nil
}

func init() {
bot.RegisterCommand(
"choose",
"Choose one from options",
"red lolly/yellow lolly/green lolly",
choose,
)
}
33 changes: 33 additions & 0 deletions plugins/clock/clock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package clock

import (
"fmt"
"time"

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

func clock(command *bot.Cmd) (msg string, err error) {
tz := command.RawArgs

now := time.Now()

loc, err := time.LoadLocation(tz)

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

t := now.In(loc).Format("Jan 1 15:04:05")

return fmt.Sprintf("%s", t), nil
}

func init() {
bot.RegisterCommand(
"time",
"Post current time",
"Europe/London",
clock,
)
}
60 changes: 60 additions & 0 deletions plugins/donger/donger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package donger

import (
"fmt"
"math/rand"
"strings"
"time"

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

type dongers map[string][]string

func (d dongers) randomCat(r *rand.Rand) string {
keys := make([]string, len(d))

i := 0
for k := range d {
keys[i] = k
i++
}

return keys[r.Intn(len(keys))]
}

func (d *dongers) random(r *rand.Rand) string {
cat := d.randomCat(r)
return d.randomFromCat(r, cat)
}

func (d dongers) randomFromCat(r *rand.Rand, cat string) string {
if _, prs := d[cat]; prs == false {
return fmt.Sprintf("No %s category", cat)
}

ri := r.Intn(len(d[cat]))

return d[cat][ri]
}

func dongerGet(command *bot.Cmd) (msg string, err error) {
args := command.RawArgs
r := rand.New(rand.NewSource(time.Now().UnixNano()))

if len(args) > 0 {
cat := strings.Split(args, " ")[0]
return dongerCollection.randomFromCat(r, cat), nil
}

return dongerCollection.random(r), nil
}

func init() {
bot.RegisterCommand(
"donger",
"Post a random donger",
"angry",
dongerGet,
)
}
Loading

0 comments on commit 5c4ecb1

Please sign in to comment.