Compare commits

..

80 Commits

Author SHA1 Message Date
205a3832d9 Stop tracking Portainer secrets
All checks were successful
Build and Push Container / build-and-push (push) Successful in 2m13s
2026-05-07 18:39:32 -08:00
969b30c0e0 Fix database initialization connection leaks 2026-05-07 18:34:18 -08:00
dfcd250892 Tag latest image from master branch 2026-05-07 15:17:33 -08:00
0944afa940 Add Portainer deployment files 2026-05-07 13:55:20 -08:00
96f80ab358 Update .gitea/workflows/build-and-push.yml 2026-03-23 06:07:10 +00:00
b9440de296 Update .gitea/workflows/build-and-push.yml 2026-03-23 06:04:51 +00:00
77bd46d0e1 Update .gitea/workflows/build-and-push.yml 2026-03-23 06:01:16 +00:00
303f2a2ee0 Update .gitea/workflows/build-and-push.yml 2026-03-23 05:41:43 +00:00
61747d60cb Migrate deployment to Gitea Actions and Portainer 2026-03-22 11:43:22 -08:00
Dustin Pianalto
a1924236ee Add pgbouncer 2021-10-10 20:26:32 -08:00
Dustin Pianalto
ebdfcd0f92 Add pgbouncer 2021-10-10 19:56:13 -08:00
Dustin Pianalto
e0b98f54c9 Add pgbouncer 2021-10-10 19:31:01 -08:00
Dustin Pianalto
5ddc67f9e0 Add pgbouncer 2021-10-10 19:23:52 -08:00
Dustin Pianalto
41d72c2e05 Add pgbouncer 2021-10-10 18:37:26 -08:00
Dustin Pianalto
b29fb01e84 Add pgbouncer 2021-10-10 18:18:40 -08:00
Dusty.P
52c59282c3 Update deployment.yml 2021-10-05 23:45:08 -08:00
Dustin Pianalto
085bec0d69 Merge branch 'master' of github.com:dustinpianalto/Goff 2021-10-05 23:34:30 -08:00
Dusty.P
ecc384017b Update main.yml 2021-10-05 23:09:00 -08:00
Dustin Pianalto
9c5b5e8873 Update deployment 2021-10-02 16:18:48 -08:00
Dustin Pianalto
1bb6564669 Update GH action and deployment 2021-10-02 14:13:28 -08:00
Dustin Pianalto
7c9d6599e0 Don't check roles when adding 2021-08-18 14:24:20 -08:00
Dustin Pianalto
77dd0c3e42 Add guild member update handler 2021-08-18 11:26:25 -08:00
Dustin Pianalto
5bfc22f471 Don't add auto role until after membership check 2021-08-18 11:01:24 -08:00
Dustin Pianalto
30f658ad41 Don't add auto role until after membership check 2021-08-18 11:00:31 -08:00
Dustin Pianalto
c85ad5c91f Add milliseconds to timestamp 2021-07-23 12:54:23 -08:00
Dustin Pianalto
5c773ff149 Add milliseconds to timestamp 2021-07-23 12:39:35 -08:00
Dustin Pianalto
03bd0cba72 Add snowflake command 2021-07-23 12:34:09 -08:00
Dustin Pianalto
a5b0e99c80 Don't log message edits if the After is blank (problem with message embeds) 2021-07-01 19:54:12 -08:00
Dustin Pianalto
7e6f3dd89f Fix bug in getting tasks 2021-06-22 12:58:42 -08:00
Dustin Pianalto
f48b530914 Add Auto Role Feature 2021-06-22 02:20:08 -08:00
Dustin Pianalto
2c71273199 Add Auto Role Feature 2021-06-22 02:15:42 -08:00
Dustin Pianalto
5bbef73a05 Add Auto Role Feature 2021-06-22 02:02:47 -08:00
Dustin Pianalto
24e684ef31 Add Auto Role Feature 2021-06-22 01:58:31 -08:00
Dustin Pianalto
6f30cf6668 Add Auto Role Feature 2021-06-22 01:47:22 -08:00
Dustin Pianalto
f1c541bdc6 Add Auto Role Feature 2021-06-22 01:44:22 -08:00
Dustin Pianalto
4fbe9196cb Update actions 2021-06-22 01:37:41 -08:00
Dustin Pianalto
cfce631155 Add Auto Role Feature 2021-06-22 01:29:38 -08:00
Dustin Pianalto
8c9a64b060 Initial DO workflow test 2021-01-13 00:15:42 -09:00
Dustin Pianalto
72375a9389 Initial DO workflow test 2021-01-12 23:29:51 -09:00
Dustin Pianalto
0f97a11a19 Initial DO workflow test 2021-01-12 23:20:04 -09:00
Dustin Pianalto
8f704eca28 Initial DO workflow test 2021-01-12 23:18:19 -09:00
Dustin Pianalto
2469a4f7ba Initial DO workflow test 2021-01-12 23:16:29 -09:00
Dusty.P
4a9cb0afaa Merge pull request #8 from dustinpianalto/development
Add action to deploy to ECS after image is built
2020-10-11 22:33:27 -08:00
Dustin Pianalto
2b0ed3e229 Add action to deploy to ECS after image is built 2020-10-11 22:23:05 -08:00
Dusty.P
b09dd20f7b Merge pull request #7 from dustinpianalto/development
Add user to guild on user create
2020-10-09 23:48:07 -08:00
Dustin Pianalto
de10dab45a Add user to guild on user create 2020-10-09 23:43:56 -08:00
Dusty.P
3d281c7891 Merge pull request #6 from dustinpianalto/development
Attempt to insert user into db before creating tag
2020-10-09 23:26:02 -08:00
Dustin Pianalto
8784ef8ef8 Attempt to insert user into db before creating tag 2020-10-09 23:21:35 -08:00
Dusty.P
a5e7b79a82 Merge pull request #5 from dustinpianalto/development
Deploy v0.0.8
2020-10-09 21:56:52 -08:00
Dustin Pianalto
e6d0e1aa09 Change default prefix back for main 2020-10-09 21:46:28 -08:00
Dustin Pianalto
134af6b013 Reorg and add services 2020-10-09 21:34:47 -08:00
Dustin Pianalto
96b9c3825c Merge branch 'development' of github.com:dustinpianalto/Goff into development 2020-09-23 12:05:05 -08:00
Dustin Pianalto
3f59bf2697 Remove unnecessary rpn package
the rpn parser was moved to it's own repo and already imported in go.mod
2020-09-23 12:04:52 -08:00
Dusty.P
6efbb4a0be Create README.md 2020-09-23 11:43:54 -08:00
Dustin Pianalto
fc0f1b0ed3 Repo Reorg 2020-09-18 18:39:51 -08:00
Dustin Pianalto
a4b3fc5a21 Change db variable name 2020-09-14 12:42:25 -08:00
Dustin Pianalto
3efca50194 Adjust Connection Pool 2020-09-14 12:36:14 -08:00
Dustin Pianalto
5413c257ab Start Restructure of project 2020-09-14 00:10:24 -08:00
Dusty.P
48abbb0cde Merge pull request #4 from dustinpianalto/development
Add sar and ping role when posting puzzle
2020-09-02 01:54:34 -08:00
Dustin Pianalto
ece695ffe2 Add sar and ping role when posting puzzle 2020-09-02 01:49:29 -08:00
Dusty.P
4bac801c6f Merge pull request #3 from dustinpianalto/development
Fix addtag removing newlines
2020-09-01 21:40:46 -08:00
Dustin Pianalto
6583e48284 Fix addtag removing newlines 2020-09-01 21:36:14 -08:00
Dusty.P
a586763e81 Merge pull request #2 from dustinpianalto/development
Adding actions and reorg
2020-08-30 22:08:47 -08:00
Dustin Pianalto
100f52bfee Merge branch 'master' into development 2020-08-30 21:53:25 -08:00
Dustin Pianalto
81bc385253 Remove branch check and also push latest tag 2020-08-30 17:57:19 -08:00
Dustin Pianalto
bf4a9f906e Test github.ref to get branch name 2020-08-30 17:09:13 -08:00
Dustin Pianalto
77f932e992 Test github.ref to get branch name 2020-08-30 17:07:37 -08:00
Dustin Pianalto
1c1d212e5e revert to previous method of getting branch name 2020-08-30 16:51:00 -08:00
Dustin Pianalto
f17d110dfd Check branch name 2020-08-30 16:46:05 -08:00
Dustin Pianalto
d780ef6725 Fix globs 2020-08-30 16:19:35 -08:00
Dustin Pianalto
069cec2465 Fix globs 2020-08-30 16:03:44 -08:00
Dustin Pianalto
e629f48333 Fix globs 2020-08-30 16:03:01 -08:00
Dustin Pianalto
e931ec5cf9 Fix globs 2020-08-30 16:00:59 -08:00
Dustin Pianalto
f03bc7b9ed Fix globs 2020-08-30 15:45:28 -08:00
Dustin Pianalto
7272c47c29 Add action to build and push to ECR 2020-08-30 15:43:45 -08:00
Dustin Pianalto
abe0230f95 Delete old organization 2020-08-30 00:10:11 -08:00
Dustin Pianalto
19d173af0a Reorganize and update Dockerfile 2020-08-30 00:08:40 -08:00
Dusty.P
85e35e0f2c Update init.go 2020-08-29 18:42:38 -08:00
Dusty.P
68379c3562 Merge pull request #1 from dustinpianalto/development
Add Puzzle parser
2020-08-29 18:37:59 -08:00
Dusty.P
3d44258370 Merge branch 'master' into development 2020-08-29 18:27:47 -08:00
33 changed files with 336 additions and 126 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
.git
.github
.gitea
.env
.idea
goff

View File

@ -0,0 +1,135 @@
name: Build and Push Container
on:
push:
branches:
- master
- main
tags:
- v*
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
REGISTRY: gitea.wayfinderak.com
IMAGE_NAME: gitea.wayfinderak.com/wayfinderak/goff
container:
options: --dns 172.16.30.10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go and Docker CLI if needed
shell: bash
run: |
set -euo pipefail
need_apt=0
need_apk=0
if ! command -v go >/dev/null 2>&1 || ! command -v docker >/dev/null 2>&1; then
if command -v apt-get >/dev/null 2>&1; then
need_apt=1
elif command -v apk >/dev/null 2>&1; then
need_apk=1
else
echo "No supported package manager found" >&2
exit 1
fi
fi
if [ "$need_apt" -eq 1 ]; then
apt-get update
if ! command -v go >/dev/null 2>&1; then
apt-get install -y golang-go
fi
if ! command -v docker >/dev/null 2>&1; then
apt-get install -y docker.io curl dnsutils iputils-ping
fi
fi
if [ "$need_apk" -eq 1 ]; then
if ! command -v go >/dev/null 2>&1; then
apk add --no-cache go
fi
if ! command -v docker >/dev/null 2>&1; then
apk add --no-cache docker-cli curl bind-tools iputils
fi
fi
go version
docker version
- name: Run tests
run: go test ./...
- name: Log in to Gitea Container Registry
shell: bash
run: |
set -euo pipefail
for attempt in 1 2 3; do
echo "docker login attempt $attempt"
if echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "$REGISTRY" -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin; then
exit 0
fi
sleep 5
done
echo "docker login failed after 3 attempts" >&2
exit 1
- name: Determine image tags
id: meta
shell: bash
env:
REF: ${{ gitea.ref }}
REF_NAME: ${{ gitea.ref_name }}
SHA: ${{ gitea.sha }}
run: |
set -euo pipefail
tags=()
if [[ "$REF" == refs/tags/* ]]; then
version="$REF_NAME"
tags+=("$IMAGE_NAME:$version")
tags+=("$IMAGE_NAME:latest")
else
branch="$REF_NAME"
branch_safe="$(echo "$branch" | tr '/_' '--')"
sha_short="$(echo "$SHA" | cut -c1-7)"
tags+=("$IMAGE_NAME:$branch_safe")
tags+=("$IMAGE_NAME:$branch_safe-$sha_short")
if [[ "$branch" == "main" || "$branch" == "master" ]]; then
tags+=("$IMAGE_NAME:latest")
fi
fi
printf 'tags<<EOF\n' >> "$GITHUB_OUTPUT"
printf '%s\n' "${tags[@]}" >> "$GITHUB_OUTPUT"
printf 'EOF\n' >> "$GITHUB_OUTPUT"
- name: Build image
shell: bash
run: |
set -euo pipefail
mapfile -t tags <<'EOF'
${{ steps.meta.outputs.tags }}
EOF
build_args=()
for tag in "${tags[@]}"; do
build_args+=(--tag "$tag")
done
docker build "${build_args[@]}" .
- name: Push image
shell: bash
run: |
set -euo pipefail
while IFS= read -r tag; do
[ -n "$tag" ] || continue
docker push "$tag"
done <<'EOF'
${{ steps.meta.outputs.tags }}
EOF

View File

@ -1,64 +1,64 @@
name: CI name: Build and Push Container
# Controls when the action will run. Triggers the workflow on push to master or development
# with a tag like v1.0.0 or v1.0.0-dev
on: on:
push: push:
tags: branches:
- v[0-9]+.[0-9]+.[0-9]+ - master
- v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]+ - main
tags:
- v*
workflow_dispatch:
env:
REGISTRY: gitea.wayfinderak.com
IMAGE_NAME: wayfinderak/goff
jobs: jobs:
build: docker:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps: steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout
- uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Get Version
id: get_version
uses: battila7/get-version-action@v2.0.0
- name: install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: Docker Login - name: Set up QEMU
# You may pin to the exact commit or the version. uses: docker/setup-qemu-action@v3
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v1.10.0
with:
registry: ${{ secrets.DR_URL }}
# Username used to log against the Docker registry
username: ${{ secrets.DH_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.DH_PASSWORD }}
# Log out from the Docker registry at the end of a job
logout: true
- name: Docker Build & Push - name: Set up Docker Buildx
env: uses: docker/setup-buildx-action@v3
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
- name: Log in to Gitea registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Prepare image tags
id: prep
shell: bash
run: | run: |
docker buildx build --push \ short_sha="${GITHUB_SHA::7}"
--tag ${{ secrets.DR_URL }}/goff:$IMAGE_TAG \ tags="${REGISTRY}/${IMAGE_NAME}:sha-${short_sha}"
--platform linux/amd64,linux/arm/v7,linux/arm64 .
- name: Update deployment file if [[ "${GITHUB_REF_TYPE}" == "branch" && ("${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main") ]]; then
run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|${{ secrets.DR_URL }}/goff:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:latest"
fi
- uses: azure/k8s-set-context@v1 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
version="${GITHUB_REF_NAME#v}"
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:${version}"
fi
{
echo 'tags<<EOF'
echo "$tags"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Build and push image
uses: docker/build-push-action@v6
with: with:
method: kubeconfig context: .
kubeconfig: ${{ secrets.KUBE_CONFIG }} push: true
id: setcontext platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}
- name: Deploy to Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
- name: Verify deployment
run: kubectl rollout status deployment/goff -n discord-bots

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.env .env
.idea .idea
portainer-app.env

View File

@ -1,20 +1,18 @@
FROM golang:1.14-alpine as dev FROM golang:1.22-alpine AS builder
WORKDIR /go/src/Goff WORKDIR /src
COPY ./go.mod . RUN apk add --no-cache ca-certificates git tzdata
COPY ./go.sum .
COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . . COPY . .
RUN go install github.com/dustinpianalto/goff/... ARG TARGETARCH=amd64
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o /out/goff ./cmd/goff
CMD [ "go", "run", "cmd/goff/main.go"] FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata
from alpine COPY --from=builder /out/goff /usr/local/bin/goff
WORKDIR /bin ENTRYPOINT ["/usr/local/bin/goff"]
COPY --from=dev /go/bin/goff ./goff
CMD [ "goff" ]

26
PORTAINER_DEPLOYMENT.md Normal file
View File

@ -0,0 +1,26 @@
# Portainer deployment notes
Generated from the current Kubernetes deployment in namespace `discord-bots`. Secret values are in the local `portainer-*.env` files.
## Kubernetes source
- Deployment: `goff`
- Replicas: `1`
- Rolling update: maxSurge `1`, maxUnavailable `1`
- minReadySeconds: `120`
- Labels/selectors: `app=goff`
- Image pull secrets: `none required for Portainer stack`
## Containers
- `pgbouncer`: image `timoha/pgbouncer:1.15.0`; env: DATABASE_URL, SERVER_TLS_SSLMODE, AUTH_TYPE; ports: 5432; requests: {'cpu': '500m', 'memory': '256Mi'}; limits: {'cpu': '1', 'memory': '512Mi'}
- `goff`: image `gitea.wayfinderak.com/wayfinderak/goff:latest`; env: DATABASE_URL, DISCORDGO_TOKEN, GOFF_EMAIL_USERNAME, GOFF_EMAIL_PASSWORD; ports: none; requests: {'cpu': '1', 'memory': '512Mi'}; limits: {'cpu': '2', 'memory': '1Gi'}
## Portainer files
- `portainer-stack.yml` - Docker Compose stack to paste/use in Portainer.
- `portainer-app.env` - bot runtime secrets/env.
## Portainer database connection
This Portainer stack does not include pgbouncer. `DATABASE_URL` in `portainer-app.env` points directly at the external PostgreSQL service copied from the Kubernetes pgbouncer upstream URL.

0
cmd/goff/main Executable file → Normal file
View File

View File

@ -4,15 +4,15 @@ import (
"fmt" "fmt"
"log" "log"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tasks"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/user_management"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
"gitea.wayfinderak.com/wayfinderak/goff/pkg/email"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts"
"github.com/dustinpianalto/goff/internal/exts/guild_management"
"github.com/dustinpianalto/goff/internal/exts/logging"
"github.com/dustinpianalto/goff/internal/exts/tasks"
"github.com/dustinpianalto/goff/internal/exts/user_management"
"github.com/dustinpianalto/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services"
"github.com/dustinpianalto/goff/pkg/email"
//"github.com/MikeModder/anpan" //"github.com/MikeModder/anpan"
"os" "os"
@ -124,6 +124,7 @@ func getPrefixes(guildID string) []string {
log.Println(err) log.Println(err)
return []string{"Go.", "go."} return []string{"Go.", "go."}
} }
defer rows.Close()
var prefixes []string var prefixes []string
for rows.Next() { for rows.Next() {
var prefix string var prefix string

View File

@ -36,6 +36,16 @@ spec:
secretKeyRef: secretKeyRef:
name: goff name: goff
key: pgbouncer_url key: pgbouncer_url
- name: SERVER_TLS_SSLMODE
valueFrom:
secretKeyRef:
name: goff
key: pgbouncer_ssl
- name: AUTH_TYPE
valueFrom:
secretKeyRef:
name: goff
key: pgbouncer_auth
ports: ports:
- containerPort: 5432 - containerPort: 5432
- name: goff - name: goff

10
docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
services:
goff:
image: ${IMAGE:-gitea.wayfinderak.com/wayfinderak/goff:${IMAGE_TAG:-latest}}
container_name: goff
restart: unless-stopped
environment:
DATABASE_URL: ${DATABASE_URL}
DISCORDGO_TOKEN: ${DISCORDGO_TOKEN}
GOFF_EMAIL_USERNAME: ${GOFF_EMAIL_USERNAME}
GOFF_EMAIL_PASSWORD: ${GOFF_EMAIL_PASSWORD}

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/dustinpianalto/goff module gitea.wayfinderak.com/wayfinderak/goff
go 1.14 go 1.14

View File

@ -6,8 +6,8 @@ import (
"strings" "strings"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services" "gitea.wayfinderak.com/wayfinderak/goff/internal/services"
) )
// Guild management commands // Guild management commands

View File

@ -5,7 +5,7 @@ import (
"log" "log"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
) )
func OnMessageUpdate(session *discordgo.Session, m *discordgo.MessageUpdate) { func OnMessageUpdate(session *discordgo.Session, m *discordgo.MessageUpdate) {

View File

@ -2,15 +2,15 @@ package exts
import ( import (
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts/fun" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/fun"
"github.com/dustinpianalto/goff/internal/exts/guild_management" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
"github.com/dustinpianalto/goff/internal/exts/roles" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/roles"
"github.com/dustinpianalto/goff/internal/exts/tags" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tags"
"github.com/dustinpianalto/goff/internal/exts/tasks" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tasks"
"github.com/dustinpianalto/goff/internal/exts/user_management" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/user_management"
"github.com/dustinpianalto/goff/internal/exts/utils" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/utils"
"github.com/dustinpianalto/goff/internal/exts/p_interpreter" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/p_interpreter"
) )
func AddCommandHandlers(h *disgoman.CommandManager) { func AddCommandHandlers(h *disgoman.CommandManager) {

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
) )
var LoggingChannel = make(chan *LogEvent, 10) var LoggingChannel = make(chan *LogEvent, 10)

View File

@ -7,9 +7,9 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services" "gitea.wayfinderak.com/wayfinderak/goff/internal/services"
) )
var MakeRoleSelfAssignableCommand = &disgoman.Command{ var MakeRoleSelfAssignableCommand = &disgoman.Command{

View File

@ -7,9 +7,9 @@ import (
"strings" "strings"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services" "gitea.wayfinderak.com/wayfinderak/goff/internal/services"
) )
var AddTagCommand = &disgoman.Command{ var AddTagCommand = &disgoman.Command{

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
) )
type Task struct { type Task struct {

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/olebedev/when" "github.com/olebedev/when"
"github.com/olebedev/when/rules/common" "github.com/olebedev/when/rules/common"
"github.com/olebedev/when/rules/en" "github.com/olebedev/when/rules/en"

View File

@ -4,8 +4,8 @@ import (
"log" "log"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
"github.com/dustinpianalto/goff/internal/services" "gitea.wayfinderak.com/wayfinderak/goff/internal/services"
) )
func OnGuildMemberAdd(s *discordgo.Session, member *discordgo.GuildMemberAdd) { func OnGuildMemberAdd(s *discordgo.Session, member *discordgo.GuildMemberAdd) {

View File

@ -7,8 +7,8 @@ import (
"time" "time"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/discord_utils" "gitea.wayfinderak.com/wayfinderak/goff/internal/discord_utils"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
) )
func OnGuildMemberAddLogging(s *discordgo.Session, member *discordgo.GuildMemberAdd) { func OnGuildMemberAddLogging(s *discordgo.Session, member *discordgo.GuildMemberAdd) {

View File

@ -8,7 +8,7 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts/logging" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
) )
var KickUserCommand = &disgoman.Command{ var KickUserCommand = &disgoman.Command{

View File

@ -9,7 +9,7 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/discord_utils" "gitea.wayfinderak.com/wayfinderak/goff/internal/discord_utils"
) )
var PingCommand = &disgoman.Command{ var PingCommand = &disgoman.Command{
@ -80,9 +80,9 @@ var GitCommand = &disgoman.Command{
func gitCommandFunc(ctx disgoman.Context, _ []string) { func gitCommandFunc(ctx disgoman.Context, _ []string) {
embed := &discordgo.MessageEmbed{ embed := &discordgo.MessageEmbed{
Title: "Hi there, My code is on Github", Title: "Hi there, my code is on Gitea",
Color: 0, Color: 0,
URL: "https://github.com/dustinpianalto/Goff", URL: "https://gitea.wayfinderak.com/wayfinderak/goff",
} }
_, err := ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed) _, err := ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed)
if err != nil { if err != nil {

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"log" "log"
"time"
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
@ -16,17 +17,23 @@ func ConnectDatabase(dbConnString string) {
db, err := sql.Open("postgres", dbConnString) db, err := sql.Open("postgres", dbConnString)
if err != nil { if err != nil {
panic(fmt.Sprintf("Can't connect to the database. %v", err)) panic(fmt.Sprintf("Can't connect to the database. %v", err))
} else {
fmt.Println("Database Connected.")
} }
db.SetMaxOpenConns(75) // The RDS instance has a max of 75 open connections
db.SetMaxIdleConns(5) db.SetMaxOpenConns(5)
db.SetConnMaxLifetime(300) db.SetMaxIdleConns(2)
db.SetConnMaxLifetime(30 * time.Minute)
db.SetConnMaxIdleTime(5 * time.Minute)
if err = db.Ping(); err != nil {
panic(fmt.Sprintf("Can't ping the database. %v", err))
}
fmt.Println("Database Connected.")
DB = db DB = db
} }
func InitializeDatabase() { func InitializeDatabase() {
_, err := DB.Query("CREATE TABLE IF NOT EXISTS users(" + _, err := DB.Exec("CREATE TABLE IF NOT EXISTS users(" +
"id varchar(30) primary key," + "id varchar(30) primary key," +
"banned bool not null default false," + "banned bool not null default false," +
"logging bool not null default true," + "logging bool not null default true," +
@ -38,7 +45,7 @@ func InitializeDatabase() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("CREATE TABLE IF NOT EXISTS guilds(" + _, err = DB.Exec("CREATE TABLE IF NOT EXISTS guilds(" +
"id varchar(30) primary key," + "id varchar(30) primary key," +
"welcome_message varchar(1000) NOT NULL DEFAULT ''," + "welcome_message varchar(1000) NOT NULL DEFAULT ''," +
"goodbye_message varchar(1000) NOT NULL DEFAULT ''," + "goodbye_message varchar(1000) NOT NULL DEFAULT ''," +
@ -48,14 +55,14 @@ func InitializeDatabase() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("CREATE TABLE IF NOT EXISTS prefixes(" + _, err = DB.Exec("CREATE TABLE IF NOT EXISTS prefixes(" +
"id serial primary key," + "id serial primary key," +
"prefix varchar(10) not null unique default 'Go.'" + "prefix varchar(10) not null unique default 'Go.'" +
")") ")")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("CREATE TABLE IF NOT EXISTS tags(" + _, err = DB.Exec("CREATE TABLE IF NOT EXISTS tags(" +
"id serial primary key," + "id serial primary key," +
"tag varchar(100) not null unique," + "tag varchar(100) not null unique," +
"content varchar(1000) not null," + "content varchar(1000) not null," +
@ -66,21 +73,21 @@ func InitializeDatabase() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("CREATE TABLE IF NOT EXISTS x_users_guilds(" + _, err = DB.Exec("CREATE TABLE IF NOT EXISTS x_users_guilds(" +
"guild_id varchar(30) not null references guilds(id)," + "guild_id varchar(30) not null references guilds(id)," +
"user_id varchar(30) not null references users(id)" + "user_id varchar(30) not null references users(id)" +
")") ")")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" + _, err = DB.Exec("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" +
"guild_id varchar(30) not null references guilds(id)," + "guild_id varchar(30) not null references guilds(id)," +
"prefix_id int not null references prefixes(id)" + "prefix_id int not null references prefixes(id)" +
")") ")")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("CREATE TABLE IF NOT EXISTS tasks(" + _, err = DB.Exec("CREATE TABLE IF NOT EXISTS tasks(" +
"id serial primary key," + "id serial primary key," +
"type varchar(10) not null," + "type varchar(10) not null," +
"content text not null," + "content text not null," +
@ -94,7 +101,7 @@ func InitializeDatabase() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query(`CREATE TABLE IF NOT EXISTS postfixes( _, err = DB.Exec(`CREATE TABLE IF NOT EXISTS postfixes(
id serial primary key, id serial primary key,
name varchar(100) not null, name varchar(100) not null,
time timestamp not null default NOW())`) time timestamp not null default NOW())`)
@ -119,37 +126,37 @@ func InitializeDatabase() {
} }
func LoadTestData() { func LoadTestData() {
_, err := DB.Query("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " + _, err := DB.Exec("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " +
"('351794468870946827', false, true, '76561198024193239', true, true, true)," + "('351794468870946827', false, true, '76561198024193239', true, true, true)," +
"('692908139506434065', false, true, '', true, false, false)," + "('692908139506434065', false, true, '', true, false, false)," +
"('396588996706304010', false, true, '', true, true, false)") "('396588996706304010', false, true, '', true, true, false)")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " + _, err = DB.Exec("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " +
"('265828729970753537', 'Hey there is someone new here.', 'Well fine then... Just leave without saying goodbye')") "('265828729970753537', 'Hey there is someone new here.', 'Well fine then... Just leave without saying goodbye')")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("INSERT INTO prefixes (prefix) VALUES ('Godev.'), ('godev.'), ('godev,')") _, err = DB.Exec("INSERT INTO prefixes (prefix) VALUES ('Godev.'), ('godev.'), ('godev,')")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " + _, err = DB.Exec("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " +
"('265828729970753537', '351794468870946827')," + "('265828729970753537', '351794468870946827')," +
"('265828729970753537', '692908139506434065')," + "('265828729970753537', '692908139506434065')," +
"('265828729970753537', '396588996706304010')") "('265828729970753537', '396588996706304010')")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " + _, err = DB.Exec("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " +
"('265828729970753537', 1)," + "('265828729970753537', 1)," +
"('265828729970753537', 2)," + "('265828729970753537', 2)," +
"('265828729970753537', 3)") "('265828729970753537', 3)")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
_, err = DB.Query("INSERT INTO tags (tag, content, creator, guild_id) VALUES " + _, err = DB.Exec("INSERT INTO tags (tag, content, creator, guild_id) VALUES " +
"('test', 'This is a test of the tag system', '351794468870946827', '265828729970753537')") "('test', 'This is a test of the tag system', '351794468870946827', '265828729970753537')")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -4,7 +4,7 @@ import (
"database/sql" "database/sql"
"log" "log"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
) )
type GuildService struct { type GuildService struct {

View File

@ -47,8 +47,10 @@ func RunPostfixes() {
continue continue
} }
if rows.Next() { if rows.Next() {
rows.Close()
continue continue
} else { } else {
rows.Close()
err := postfix.Invoke(false) err := postfix.Invoke(false)
if err != nil { if err != nil {
continue continue

View File

@ -4,7 +4,7 @@ import (
"database/sql" "database/sql"
"log" "log"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
) )
type RoleService struct { type RoleService struct {

View File

@ -3,7 +3,7 @@ package postgres
import ( import (
"database/sql" "database/sql"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
) )
type UserService struct { type UserService struct {

View File

@ -1,6 +1,6 @@
package services package services
import "github.com/dustinpianalto/goff" import "gitea.wayfinderak.com/wayfinderak/goff"
var UserService goff.UserService var UserService goff.UserService
var GuildService goff.GuildService var GuildService goff.GuildService

View File

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/pkg/puzzles" "gitea.wayfinderak.com/wayfinderak/goff/pkg/puzzles"
imap "github.com/emersion/go-imap" imap "github.com/emersion/go-imap"
"github.com/emersion/go-imap/client" "github.com/emersion/go-imap/client"
"github.com/emersion/go-message/mail" "github.com/emersion/go-message/mail"

View File

@ -8,8 +8,8 @@ import (
"time" "time"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff" "gitea.wayfinderak.com/wayfinderak/goff"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/emersion/go-message/mail" "github.com/emersion/go-message/mail"
) )

View File

@ -0,0 +1,4 @@
DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/goff?sslmode=disable
DISCORDGO_TOKEN=replace-me
GOFF_EMAIL_USERNAME=replace-me
GOFF_EMAIL_PASSWORD=replace-me

9
portainer-stack.yml Normal file
View File

@ -0,0 +1,9 @@
services:
goff:
image: gitea.wayfinderak.com/wayfinderak/goff:latest
container_name: goff
restart: unless-stopped
env_file:
- ./portainer-app.env
mem_limit: 1g
cpus: "2.0"