-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
3,639 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ vendor/ | |
|
||
# go build result | ||
ircbot | ||
|
||
env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
Oops, something went wrong.