Skip to content

Commit

Permalink
Refactor code and improve changes detection
Browse files Browse the repository at this point in the history
Add github actions for lint, publish, and release
Update README
Add documentation
  • Loading branch information
shellbear committed May 3, 2020
1 parent c990dfd commit b3838e7
Show file tree
Hide file tree
Showing 213 changed files with 1,028 additions and 262,168 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Expand Up @@ -6,4 +6,4 @@ README.md
LICENSE
web-watcher
db.sqlite
vendor
dist/
Binary file added .github/images/gopher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,28 @@
name: lint

on:
push:
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:

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

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: go build -v .

- name: golangci-lint
uses: actions-contrib/golangci-lint@v1
env:
GOROOT: ""
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
@@ -0,0 +1,34 @@
name: github pages

on:
push:
branches:
- master

defaults:
run:
shell: bash
working-directory: www

jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0

- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'

- name: Build
run: hugo --minify

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./www/public
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,37 @@
name: release

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
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.14.x
-
name: Docker login
uses: azure/docker-login@v1
with:
login-server: docker.pkg.github.com
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -11,6 +11,10 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

.DS_Store

db.sqlite
web-watcher
.idea/*
vendor/
dist/
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "www/themes/hugo-apex-theme"]
path = www/themes/hugo-apex-theme
url = https://github.com/caarlos0/hugo-apex-theme.git
41 changes: 41 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,41 @@
before:
hooks:
- go mod download
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

release:
github:
owner: shellbear
name: web-watcher

dockers:
-
binaries:
- web-watcher
dockerfile: Dockerfile.cgo
image_templates:
- "docker.pkg.github.com/shellbear/web-watcher/web-watcher:{{ .Tag }}"
- "docker.pkg.github.com/shellbear/web-watcher/web-watcher:latest"
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"

6 changes: 2 additions & 4 deletions Dockerfile
Expand Up @@ -3,12 +3,10 @@ FROM golang:latest
WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .
RUN go build -o web-watcher .

RUN go build -o main .

CMD ["./main"]
ENTRYPOINT ["/app/web-watcher"]

5 changes: 5 additions & 0 deletions Dockerfile.cgo
@@ -0,0 +1,5 @@
FROM golang:latest

COPY web-watcher /

ENTRYPOINT ["/web-watcher"]
83 changes: 41 additions & 42 deletions README.md
@@ -1,78 +1,77 @@
# Web-watcher

A small discord bot which aims to monitor and send notifications on website changes.

## Installation

If you want to self host this bot, you have to first create a new Discord application and bot from the [developer portal](https://discordapp.com/developers/applications/).
You can follow this [tutorial](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) to achieve this step.

With go CLI:
```bash
go get github.com/ShellBear/web-watcher
```
<p align="center">
<img alt="Gopher" src=".github/images/gopher.png" height="140" />
<h3 align="center">web-watcher</h3>
<p align="center">A small Discord bot which aims to alert you on website changes.</p>
</p>

<p align="center">
<a href="https://goreportcard.com/report/github.com/shellbear/web-watcher" alt="Go Report Card">
<img src="https://goreportcard.com/badge/github.com/shellbear/web-watcher" />
</a>
<a href="https://github.com/shellbear/web-watcher/actions?query=workflow%3Alint" alt="Pipeline status">
<img src="https://github.com/shellbear/web-watcher/workflows/lint/badge.svg" />
</a>
<a href="https://github.com/shellbear/web-watcher/actions?query=workflow%3A%22github+pages%22" alt="Pipeline status">
<img src="https://github.com/shellbear/web-watcher/workflows/github%20pages/badge.svg" />
</a>
<img src="https://img.shields.io/github/go-mod/go-version/shellbear/web-watcher" alt="Go version" />
<a href="https://opensource.org/licenses/MIT" alt="Go version">
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" />
</a>
</p>

---

## Documentation

A full documentation is available at [https://shellbear.github.io/web-watcher](https://shellbear.github.io/web-watcher).

## Usage

```bash
export DISCORD_TOKEN=YOUR_DISCORD_TOKEN
web-watcher

# or

web-watcher --token YOUR_DISCORD_TOKEN
```

```bash
web-watcher --help

> web-watcher --help
Web-watcher discord Bot.

Options:
-delay int
Watch delay in minutes (default 60)
-prefix string
The discord commands prefix (default "!")
-ratio float
Changes detection ratio (default 1)
-token string
Discord token
```

By default the watch interval for every website is 1 Hour but you can easily change this with the `delay` parameter followed by the time interval in minutes.
By default, the watch interval for every website is 1 hour, but you can easily change this with the `interval` parameter
followed by the interval in minutes.

```bash
# Set watch interval to 10 minutes
web-watcher --token YOUR_DISCORD_TOKEN --delay 10
web-watcher --token YOUR_DISCORD_TOKEN --interval 10
```

## Commands
## Discord commands

#### !watch [URL]

Add an URL to the watchlist.
Add a URL to the watchlist.

#### !unwatch [URL]

Remove an URL from the watchlist.
Remove a URL from the watchlist.

#### !watchlist

Get the complete watchlist.

## Deploy

With docker:
```bash
docker build -t web-watcher .
```

And test:
```bash
docker run -e DISCORD_TOKEN=YOUR_DISCORD_TOKEN web-watcher
```

## Built With

- [go-difflib](https://github.com/pmezard/go-difflib) - Partial port of Python difflib package to Go
- [xxhash](https://github.com/cespare/xxhash) - Go implementation of the 64-bit xxHash algorithm (XXH64)
- [Gorm](https://github.com/jinzhu/gorm) - The fantastic ORM library for Golang
- [DiscordGo](https://github.com/bwmarrin/discordgo) - Go bindings for Discord

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

0 comments on commit b3838e7

Please sign in to comment.