Compare commits
62 Commits
master
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2420f19c9 | ||
|
|
2019dc4643 | ||
|
|
9bb35bb30a | ||
|
|
3cad5680b0 | ||
|
|
f97494626f | ||
|
|
b5a55a1b77 | ||
|
|
02b5842107 | ||
|
|
d345044b3a | ||
|
|
b3aff0828c | ||
|
|
3d4518f961 | ||
|
|
37e8fa52af | ||
|
|
a370c76ba4 | ||
|
|
2fe9de279d | ||
|
|
33776b1129 | ||
|
|
733cd87896 | ||
|
|
ebf20670df | ||
|
|
14c5705473 | ||
|
|
c72dcd0ec3 | ||
|
|
61d500946e | ||
|
|
65bb218260 | ||
|
|
d8d90a8414 | ||
|
|
2e95aa0234 | ||
|
|
480f5b6cc9 | ||
|
|
97793ad622 | ||
|
|
d581a9bf32 | ||
|
|
13f80a6972 | ||
|
|
20bd455a44 | ||
|
|
cadef92efb | ||
|
|
f6f020ff48 | ||
|
|
a93139fcf2 | ||
|
|
d9ddfaf2cc | ||
|
|
05d4096766 | ||
|
|
6a33cceebb | ||
|
|
5cd626a5a4 | ||
|
|
e2f25eaab4 | ||
|
|
ea058baff5 | ||
|
|
d9e1efbaf0 | ||
|
|
af506f828d | ||
|
|
5c42616a3a | ||
|
|
6cc5e042d5 | ||
|
|
03e6f069c9 | ||
|
|
4db28f5c0b | ||
|
|
d876f4ced9 | ||
|
|
fb4d7977aa | ||
|
|
68a02e2f24 | ||
|
|
30394b35e5 | ||
|
|
87961c5081 | ||
|
|
562ec6acaf | ||
|
|
3169953f3f | ||
|
|
d119425236 | ||
|
|
ce1bbbc445 | ||
|
|
f4ec8a7a49 | ||
|
|
bec52ad5a5 | ||
|
|
5411730a96 | ||
|
|
187f9816ca | ||
|
|
feab8e661c | ||
|
|
96b63a4e83 | ||
|
|
fcddca2226 | ||
|
|
28d78bdb8c | ||
|
|
35882993c2 | ||
|
|
85bcb31d56 | ||
|
|
23c0434ed3 |
@ -1,6 +0,0 @@
|
||||
.git
|
||||
.github
|
||||
.gitea
|
||||
.env
|
||||
.idea
|
||||
goff
|
||||
@ -1,135 +0,0 @@
|
||||
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
|
||||
96
.github/workflows/main.yml
vendored
96
.github/workflows/main.yml
vendored
@ -1,64 +1,64 @@
|
||||
name: Build and Push Container
|
||||
name: CI
|
||||
|
||||
# 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:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.wayfinderak.com
|
||||
IMAGE_NAME: wayfinderak/goff
|
||||
- v[0-9]+.[0-9]+.[0-9]+
|
||||
- v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]+
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Get Version
|
||||
id: get_version
|
||||
uses: battila7/get-version-action@v2.0.0
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Gitea registry
|
||||
uses: docker/login-action@v3
|
||||
- name: install buildx
|
||||
id: buildx
|
||||
uses: crazy-max/ghaction-docker-buildx@v1
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
version: latest
|
||||
|
||||
- name: Prepare image tags
|
||||
id: prep
|
||||
shell: bash
|
||||
- name: Docker Login
|
||||
# You may pin to the exact commit or the version.
|
||||
# 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
|
||||
env:
|
||||
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
|
||||
run: |
|
||||
short_sha="${GITHUB_SHA::7}"
|
||||
tags="${REGISTRY}/${IMAGE_NAME}:sha-${short_sha}"
|
||||
docker buildx build --push \
|
||||
--tag ${{ secrets.DR_URL }}/goff:$IMAGE_TAG \
|
||||
--platform linux/amd64,linux/arm/v7,linux/arm64 .
|
||||
|
||||
if [[ "${GITHUB_REF_TYPE}" == "branch" && ("${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main") ]]; then
|
||||
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:latest"
|
||||
fi
|
||||
- name: Update deployment file
|
||||
run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|${{ secrets.DR_URL }}/goff:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml
|
||||
|
||||
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
|
||||
- uses: azure/k8s-set-context@v1
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.prep.outputs.tags }}
|
||||
method: kubeconfig
|
||||
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
||||
id: setcontext
|
||||
|
||||
- name: Deploy to Kubernetes
|
||||
run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
|
||||
|
||||
- name: Verify deployment
|
||||
run: kubectl rollout status deployment/goff
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,2 @@
|
||||
.env
|
||||
.idea
|
||||
|
||||
portainer-app.env
|
||||
|
||||
22
Dockerfile
22
Dockerfile
@ -1,18 +1,20 @@
|
||||
FROM golang:1.22-alpine AS builder
|
||||
FROM golang:1.14-alpine as dev
|
||||
|
||||
WORKDIR /src
|
||||
RUN apk add --no-cache ca-certificates git tzdata
|
||||
WORKDIR /go/src/Goff
|
||||
COPY ./go.mod .
|
||||
COPY ./go.sum .
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
ARG TARGETARCH=amd64
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o /out/goff ./cmd/goff
|
||||
RUN go install github.com/dustinpianalto/goff/...
|
||||
|
||||
FROM alpine:3.20
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
CMD [ "go", "run", "cmd/goff/main.go"]
|
||||
|
||||
COPY --from=builder /out/goff /usr/local/bin/goff
|
||||
from alpine
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/goff"]
|
||||
WORKDIR /bin
|
||||
|
||||
COPY --from=dev /go/bin/goff ./goff
|
||||
|
||||
CMD [ "goff" ]
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
# 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
Normal file → Executable file
0
cmd/goff/main
Normal file → Executable file
@ -4,15 +4,15 @@ import (
|
||||
"fmt"
|
||||
"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/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"
|
||||
"os"
|
||||
@ -124,7 +124,6 @@ func getPrefixes(guildID string) []string {
|
||||
log.Println(err)
|
||||
return []string{"Go.", "go."}
|
||||
}
|
||||
defer rows.Close()
|
||||
var prefixes []string
|
||||
for rows.Next() {
|
||||
var prefix string
|
||||
|
||||
@ -21,33 +21,6 @@ spec:
|
||||
app: goff
|
||||
spec:
|
||||
containers:
|
||||
- name: pgbouncer
|
||||
image: timoha/pgbouncer:1.15.0
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "0.5"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "1"
|
||||
env:
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: goff
|
||||
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:
|
||||
- containerPort: 5432
|
||||
- name: goff
|
||||
image: <IMAGE>
|
||||
resources:
|
||||
@ -79,4 +52,4 @@ spec:
|
||||
name: goff
|
||||
key: email_password
|
||||
imagePullSecrets:
|
||||
- name: registry-1
|
||||
- name: registry-2
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
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
2
go.mod
@ -1,4 +1,4 @@
|
||||
module gitea.wayfinderak.com/wayfinderak/goff
|
||||
module github.com/dustinpianalto/goff
|
||||
|
||||
go 1.14
|
||||
|
||||
|
||||
@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/services"
|
||||
)
|
||||
|
||||
// Guild management commands
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
)
|
||||
|
||||
func OnMessageUpdate(session *discordgo.Session, m *discordgo.MessageUpdate) {
|
||||
|
||||
@ -2,15 +2,15 @@ package exts
|
||||
|
||||
import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/fun"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/roles"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tags"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tasks"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/user_management"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/utils"
|
||||
"github.com/dustinpianalto/goff/internal/exts/fun"
|
||||
"github.com/dustinpianalto/goff/internal/exts/guild_management"
|
||||
"github.com/dustinpianalto/goff/internal/exts/roles"
|
||||
"github.com/dustinpianalto/goff/internal/exts/tags"
|
||||
"github.com/dustinpianalto/goff/internal/exts/tasks"
|
||||
"github.com/dustinpianalto/goff/internal/exts/user_management"
|
||||
"github.com/dustinpianalto/goff/internal/exts/utils"
|
||||
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/p_interpreter"
|
||||
"github.com/dustinpianalto/goff/internal/exts/p_interpreter"
|
||||
)
|
||||
|
||||
func AddCommandHandlers(h *disgoman.CommandManager) {
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
)
|
||||
|
||||
var LoggingChannel = make(chan *LogEvent, 10)
|
||||
|
||||
@ -7,9 +7,9 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
|
||||
"github.com/dustinpianalto/goff"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/services"
|
||||
)
|
||||
|
||||
var MakeRoleSelfAssignableCommand = &disgoman.Command{
|
||||
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
|
||||
"github.com/dustinpianalto/goff"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/services"
|
||||
)
|
||||
|
||||
var AddTagCommand = &disgoman.Command{
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
"github.com/olebedev/when"
|
||||
"github.com/olebedev/when/rules/common"
|
||||
"github.com/olebedev/when/rules/en"
|
||||
|
||||
@ -4,8 +4,8 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
|
||||
"github.com/dustinpianalto/goff"
|
||||
"github.com/dustinpianalto/goff/internal/services"
|
||||
)
|
||||
|
||||
func OnGuildMemberAdd(s *discordgo.Session, member *discordgo.GuildMemberAdd) {
|
||||
|
||||
@ -7,8 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/discord_utils"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff/internal/discord_utils"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
)
|
||||
|
||||
func OnGuildMemberAddLogging(s *discordgo.Session, member *discordgo.GuildMemberAdd) {
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
|
||||
"github.com/dustinpianalto/goff/internal/exts/logging"
|
||||
)
|
||||
|
||||
var KickUserCommand = &disgoman.Command{
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/discord_utils"
|
||||
"github.com/dustinpianalto/goff/internal/discord_utils"
|
||||
)
|
||||
|
||||
var PingCommand = &disgoman.Command{
|
||||
@ -80,9 +80,9 @@ var GitCommand = &disgoman.Command{
|
||||
|
||||
func gitCommandFunc(ctx disgoman.Context, _ []string) {
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Title: "Hi there, my code is on Gitea",
|
||||
Title: "Hi there, My code is on Github",
|
||||
Color: 0,
|
||||
URL: "https://gitea.wayfinderak.com/wayfinderak/goff",
|
||||
URL: "https://github.com/dustinpianalto/Goff",
|
||||
}
|
||||
_, err := ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed)
|
||||
if err != nil {
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
@ -17,23 +16,17 @@ func ConnectDatabase(dbConnString string) {
|
||||
db, err := sql.Open("postgres", dbConnString)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Can't connect to the database. %v", err))
|
||||
} else {
|
||||
fmt.Println("Database Connected.")
|
||||
}
|
||||
|
||||
db.SetMaxOpenConns(5)
|
||||
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.SetMaxOpenConns(75) // The RDS instance has a max of 75 open connections
|
||||
db.SetMaxIdleConns(5)
|
||||
db.SetConnMaxLifetime(300)
|
||||
DB = db
|
||||
}
|
||||
|
||||
func InitializeDatabase() {
|
||||
_, err := DB.Exec("CREATE TABLE IF NOT EXISTS users(" +
|
||||
_, err := DB.Query("CREATE TABLE IF NOT EXISTS users(" +
|
||||
"id varchar(30) primary key," +
|
||||
"banned bool not null default false," +
|
||||
"logging bool not null default true," +
|
||||
@ -45,7 +38,7 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS guilds(" +
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS guilds(" +
|
||||
"id varchar(30) primary key," +
|
||||
"welcome_message varchar(1000) NOT NULL DEFAULT ''," +
|
||||
"goodbye_message varchar(1000) NOT NULL DEFAULT ''," +
|
||||
@ -55,14 +48,14 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS prefixes(" +
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS prefixes(" +
|
||||
"id serial primary key," +
|
||||
"prefix varchar(10) not null unique default 'Go.'" +
|
||||
")")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS tags(" +
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS tags(" +
|
||||
"id serial primary key," +
|
||||
"tag varchar(100) not null unique," +
|
||||
"content varchar(1000) not null," +
|
||||
@ -73,21 +66,21 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS x_users_guilds(" +
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS x_users_guilds(" +
|
||||
"guild_id varchar(30) not null references guilds(id)," +
|
||||
"user_id varchar(30) not null references users(id)" +
|
||||
")")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" +
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" +
|
||||
"guild_id varchar(30) not null references guilds(id)," +
|
||||
"prefix_id int not null references prefixes(id)" +
|
||||
")")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS tasks(" +
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS tasks(" +
|
||||
"id serial primary key," +
|
||||
"type varchar(10) not null," +
|
||||
"content text not null," +
|
||||
@ -101,7 +94,7 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec(`CREATE TABLE IF NOT EXISTS postfixes(
|
||||
_, err = DB.Query(`CREATE TABLE IF NOT EXISTS postfixes(
|
||||
id serial primary key,
|
||||
name varchar(100) not null,
|
||||
time timestamp not null default NOW())`)
|
||||
@ -126,37 +119,37 @@ func InitializeDatabase() {
|
||||
}
|
||||
|
||||
func LoadTestData() {
|
||||
_, err := DB.Exec("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " +
|
||||
_, err := DB.Query("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " +
|
||||
"('351794468870946827', false, true, '76561198024193239', true, true, true)," +
|
||||
"('692908139506434065', false, true, '', true, false, false)," +
|
||||
"('396588996706304010', false, true, '', true, true, false)")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " +
|
||||
_, err = DB.Query("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " +
|
||||
"('265828729970753537', 'Hey there is someone new here.', 'Well fine then... Just leave without saying goodbye')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("INSERT INTO prefixes (prefix) VALUES ('Godev.'), ('godev.'), ('godev,')")
|
||||
_, err = DB.Query("INSERT INTO prefixes (prefix) VALUES ('Godev.'), ('godev.'), ('godev,')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " +
|
||||
_, err = DB.Query("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " +
|
||||
"('265828729970753537', '351794468870946827')," +
|
||||
"('265828729970753537', '692908139506434065')," +
|
||||
"('265828729970753537', '396588996706304010')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " +
|
||||
_, err = DB.Query("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " +
|
||||
"('265828729970753537', 1)," +
|
||||
"('265828729970753537', 2)," +
|
||||
"('265828729970753537', 3)")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Exec("INSERT INTO tags (tag, content, creator, guild_id) VALUES " +
|
||||
_, err = DB.Query("INSERT INTO tags (tag, content, creator, guild_id) VALUES " +
|
||||
"('test', 'This is a test of the tag system', '351794468870946827', '265828729970753537')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"github.com/dustinpianalto/goff"
|
||||
)
|
||||
|
||||
type GuildService struct {
|
||||
|
||||
@ -47,10 +47,8 @@ func RunPostfixes() {
|
||||
continue
|
||||
}
|
||||
if rows.Next() {
|
||||
rows.Close()
|
||||
continue
|
||||
} else {
|
||||
rows.Close()
|
||||
err := postfix.Invoke(false)
|
||||
if err != nil {
|
||||
continue
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"github.com/dustinpianalto/goff"
|
||||
)
|
||||
|
||||
type RoleService struct {
|
||||
|
||||
@ -3,7 +3,7 @@ package postgres
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"github.com/dustinpianalto/goff"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package services
|
||||
|
||||
import "gitea.wayfinderak.com/wayfinderak/goff"
|
||||
import "github.com/dustinpianalto/goff"
|
||||
|
||||
var UserService goff.UserService
|
||||
var GuildService goff.GuildService
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/pkg/puzzles"
|
||||
"github.com/dustinpianalto/goff/pkg/puzzles"
|
||||
imap "github.com/emersion/go-imap"
|
||||
"github.com/emersion/go-imap/client"
|
||||
"github.com/emersion/go-message/mail"
|
||||
|
||||
@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"github.com/dustinpianalto/goff"
|
||||
"github.com/dustinpianalto/goff/internal/postgres"
|
||||
"github.com/emersion/go-message/mail"
|
||||
)
|
||||
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/goff?sslmode=disable
|
||||
DISCORDGO_TOKEN=replace-me
|
||||
GOFF_EMAIL_USERNAME=replace-me
|
||||
GOFF_EMAIL_PASSWORD=replace-me
|
||||
@ -1,9 +0,0 @@
|
||||
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"
|
||||
Loading…
x
Reference in New Issue
Block a user