Skip to content

Commit

Permalink
Merge pull request #2 from leighmacdonald/cleanups
Browse files Browse the repository at this point in the history
Big cleanup and refactor pass for first public release
  • Loading branch information
leighmacdonald authored Mar 23, 2024
2 parents f5acb94 + afb2fa2 commit 15bfeaf
Show file tree
Hide file tree
Showing 26 changed files with 1,154 additions and 3,922 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: build

on:
push:
pull_request:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions: write-all

jobs:
lint-golangci:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: 'latest'
args: --timeout=10m

staticcheck:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
- run: go install honnef.co/go/tools/cmd/staticcheck@latest
- run: make static

tests:
needs: [lint-golangci, staticcheck]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Run tests
run: make test

release:
name: "tf2bdd release"
runs-on: "ubuntu-latest"
needs: [tests]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- run: git fetch --force --tags

- uses: actions/setup-go@v5
with:
go-version: '1.22'

- run: go mod tidy

- uses: goreleaser/goreleaser-action@v5
if: success() && startsWith(github.ref, 'refs/tags/v')
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload snapshot
if: success() && ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: actions/upload-artifact@v3
with:
name: snapshot
path: build/*
retention-days: 1

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Build & publish image
if: success() && startsWith(github.ref, 'refs/tags/v')
run: |
docker build . --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}
docker build . --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea
/tf2bdd
*.sqlite
*.sqlite
/tf2bdd.exe

dist/
121 changes: 121 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
#- contextcheck
- cyclop
- decorder
#- depguard
- dogsled
#- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
#- exhaustruct
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
#- gochecknoglobals
- gochecknoinits
#- gocognit
#- goconst
- gocritic
- gocyclo
- godot
- godox
#- goerr113
- gofmt
- gofumpt
- goheader
- goimports
#- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- interfacebloat
#- ireturn
#- lll
- loggercheck
- maintidx
- makezero
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
#- paralleltest
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
#- staticcheck
- stylecheck
#- tagliatelle
- tenv
- testableexamples
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- varnamelen
- wastedassign
- whitespace
#- wrapcheck
#- wsl
#- zerologlint

linters-settings:
tagliatelle:
case:
use-field-name: true
rules:
json: snake
yaml: snake
funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
# Default: 60
lines: 130
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
statements: -1
cyclop:
max-complexity: 25

44 changes: 44 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows

release:
github:
owner: leighmacdonald
name: tf2bdd
draft: false
replace_existing_draft: true
prerelease: auto
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine as build
FROM golang:1.22-alpine as build
WORKDIR /build
RUN apk add build-base
COPY go.sum go.mod ./
Expand Down
29 changes: 17 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ all: build
vet:
@go vet . ./...

fmt:
@go fmt . ./...

deps:
@go get github.com/golangci/golangci-lint/cmd/golangci-lint

Expand All @@ -18,15 +15,6 @@ run:
test:
@go test $(GO_FLAGS) -race -cover . ./...

testcover:
@go test -race -coverprofile c.out $(GO_FLAGS) ./...

lint:
golangci-lint run

bench:
@go test -run=NONE -bench=. $(GO_FLAGS) ./...

clean:
@go clean $(GO_FLAGS) -i

Expand All @@ -37,3 +25,20 @@ runimage:
@docker run --rm --name tf2bdd -it \
--mount type=bind,source=$(CURDIR)/db.sqlite,target=/app/db.sqlite \
leighmacdonald/tf2bdd:1.0.0 || true

fmt:
gci write . --skip-generated -s standard -s default
gofumpt -l -w .

check:
@golangci-lint run --timeout 3m

static:
@staticcheck -go 1.22 ./...

check_deps:
go install github.com/daixiang0/gci@v0.13.1
go install mvdan.cc/gofumpt@v0.6.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.0
go install honnef.co/go/tools/cmd/staticcheck@v0.4.7
go install github.com/goreleaser/goreleaser@v1.24.0
62 changes: 48 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
# TF2BDd

Simple service to send new player lists to the bot detector.
Very simple service to allow tools like those listed below to download and integrate player list contributions from outside sources. This
is designed to work over discord as a bot, allowing multiple people to contribute their lists and have them merged into
a single master list. The results served over an HTTP endpoint `/v1/steamids`. Data is backed by a very simple sqlite database.

## Usage
- [tf2_bot_detector](https://github.com/PazerOP/tf2_bot_detector)
- [bd](https://github.com/leighmacdonald/bd)
- [MAC](https://github.com/MegaAntiCheat)

If you have other examples of software that is able to update lists over http like these, please open a PR to add them to the list.

Example results from the [@trusted](https://trusted.roto.lol/v1/steamids) list.

## Commands

Bot command list:

- `!add <steamid/profile> [attributes]` Add the user to the master ban list. eg: `suspicious/cheater/bot`. If none are defined, it will use cheater by default.
- `!del <steamid/profile>` Remove the player from the master list
- `!check <steamid/profile>` Checks if the user exists in the database
- `!count` Shows the current count of players tracked
- `!import <attached_playerlist_files>` Imports the steam ids from a players custom ban list, multiple can be attached
- `!steamid <steamid/vanity_name/profile_link>` Accepts any steamid format including bare vanity name and profile link. Will print out all forms.

Discord [slash commands](https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ) are not
currently supported as this was written before that was an option, however if there is enough
demand, or somebody creates a PR for it, I will add them.

## Building From Source

$ git clone git@github.com:leighmacdonald/tf2bdd.git
$ cd tf2bdd
$ go build
$ export STEAM_TOKEN=steam_web_api_token
$ export BOT_TOKEN=discord_bot_token

## Running Binary

You can either use the binary you build from source, or download the latest release from the [releases](https://github.com/leighmacdonald/tf2bdd/releases)
page.

$ export STEAM_TOKEN=steam_web_api_token # Your steam api key, for resolving vanity names
$ export BOT_TOKEN=discord_bot_token # Your discord bot token
$ export BOT_CLIENTID=12345 # Discord client id
$ export BOT_ROLES=11111111111,222222222 # Roles allowed to use non-readonly commands
$ ./tf2bdd

## Commands

Bot command list:
You will probably want to create something like a systemd service to automate this.

## Running Docker

`!add <steamid/profile> [attributes]` Add the user to the master ban list. Valid attributes are 0 or more of: `racist sus/suspicious cheater exploiter`. If none are defined, it will use cheater by default.
`!del <steamid/profile>` Remove the player from the master list
`!check <steamid/profile>` Checks if the user exists in the database
`!count` Shows the current count of players tracked
`!import <attach_a_json_file>` Imports the steam ids from a players custom ban list
`!steamid <steamid/profile>` Get the various steam ids

docker run --rm --name tf2bdd -it \
-p 127.0.0.1:8899:8899 \
--env BOT_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--env STEAM_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--env BOT_CLIENTID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--env BOT_ROLES=111111111111,22222222222 \
--mount type=bind,source="$(pwd)"/db.sqlite,target=/app/db.sqlite \
ghcr.io/leighmacdonald/tf2bdd:latest
Loading

0 comments on commit 15bfeaf

Please sign in to comment.