Compare commits
10 Commits
start-bot-
...
381bfb32b2
| Author | SHA1 | Date | |
|---|---|---|---|
| 381bfb32b2 | |||
| b86c11e81d | |||
| 7e55444346 | |||
| d6ebe0f0e5 | |||
|
|
0d30bae2d8 | ||
|
|
9db97ab6db | ||
|
|
fe75a2c36f | ||
|
|
369a057a7a | ||
|
|
9fe4e2fad1 | ||
|
|
baee73e7a3 |
19
.gitea/workflows/build-demo.yaml.disabled
Normal file
19
.gitea/workflows/build-demo.yaml.disabled
Normal file
@@ -0,0 +1,19 @@
|
||||
name: Gitea Actions Demo
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
Explore-Gitea-Actions:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
|
||||
- name: List files in the repository
|
||||
run: |
|
||||
ls ${{ gitea.workspace }}
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
47
.gitea/workflows/build-oci.yaml
Normal file
47
.gitea/workflows/build-oci.yaml
Normal file
@@ -0,0 +1,47 @@
|
||||
name: Container Build & Push
|
||||
|
||||
# add on pull requests too
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
env:
|
||||
REGISTRY: www.gitgud.foo
|
||||
OWNER: thegrind
|
||||
TAG: 1.0.0
|
||||
IMAGE_NAME: test
|
||||
steps:
|
||||
-
|
||||
name: Check out code
|
||||
uses: actions/checkout@v3
|
||||
- name: whereami
|
||||
run: ls -lath
|
||||
|
||||
-
|
||||
name: get dicks space
|
||||
run: |
|
||||
df -h
|
||||
|
||||
-
|
||||
name: Log in to the GitGud container registry
|
||||
run: |
|
||||
/usr/bin/docker login $REGISTRY \
|
||||
-u "${{ gitea.actor }}" \
|
||||
-p "${{ secrets.REGISTRY_PASSWORD }}"
|
||||
|
||||
-
|
||||
name: Build and push OCI image
|
||||
run: |
|
||||
IMAGE=$REGISTRY/$OWNER/$IMAGE_NAME:$TAG
|
||||
docker build -t $IMAGE .
|
||||
-
|
||||
name: Push OCI image
|
||||
run: |
|
||||
IMAGE=$REGISTRY/$OWNER/$IMAGE_NAME:$TAG
|
||||
docker push $IMAGE
|
||||
21
.gitea/workflows/tests.yml
Normal file
21
.gitea/workflows/tests.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Run Go Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.22'
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,4 +5,6 @@ output.opus
|
||||
.env
|
||||
*.wav
|
||||
*.opus
|
||||
*.webm
|
||||
*.webm
|
||||
*.tar.gz
|
||||
#*.old
|
||||
78
Dockerfile.builder
Normal file
78
Dockerfile.builder
Normal file
@@ -0,0 +1,78 @@
|
||||
# Use the official golang:1.22.12-bookworm image as the build stage
|
||||
FROM golang:1.22.12-bookworm
|
||||
|
||||
# Create a directory /app
|
||||
RUN mkdir /app
|
||||
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the current directory contents into /app
|
||||
COPY ./ /app/
|
||||
|
||||
# Update the package list and install necessary packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
wget \
|
||||
vim \
|
||||
git \
|
||||
debconf \
|
||||
ca-certificates \
|
||||
tar \
|
||||
autoconf \
|
||||
automake \
|
||||
build-essential \
|
||||
cmake \
|
||||
git-core \
|
||||
libass-dev \
|
||||
libfreetype6-dev \
|
||||
libgnutls28-dev \
|
||||
libmp3lame-dev \
|
||||
libsdl2-dev \
|
||||
libtool \
|
||||
libva-dev \
|
||||
libvdpau-dev \
|
||||
libvorbis-dev \
|
||||
libxcb1-dev \
|
||||
libxcb-shm0-dev \
|
||||
libxcb-xfixes0-dev \
|
||||
meson \
|
||||
ninja-build \
|
||||
pkg-config \
|
||||
texinfo \
|
||||
yasm \
|
||||
zlib1g-dev \
|
||||
libx264-dev \
|
||||
libx265-dev \
|
||||
libnuma-dev \
|
||||
libvpx-dev \
|
||||
libopus-dev \
|
||||
libunistring-dev \
|
||||
libaom-dev \
|
||||
libdav1d-dev && \
|
||||
# Download Go module dependencies
|
||||
go mod download && \
|
||||
# Download yt-dlp
|
||||
wget --no-check-certificate -c https://github.com/yt-dlp/yt-dlp/releases/download/2025.01.26/yt-dlp_linux &&\
|
||||
# Download ffmpeg
|
||||
wget --no-check-certificate -c https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-6.0.1-amd64-static.tar.xz &&\
|
||||
# Move yt-dlp to /usr/bin and set permissions
|
||||
mv yt-dlp_linux /usr/bin/yt-dlp && \
|
||||
chmod 755 /usr/bin/yt-dlp && \
|
||||
chmod +x /usr/bin/yt-dlp && \
|
||||
# Extract ffmpeg tarball
|
||||
tar -xf ffmpeg-6.0.1-amd64-static.tar.xz && \
|
||||
# Remove the tarball
|
||||
rm -rf ffmpeg-6.0.1-amd64-static.tar.xz && \
|
||||
# Set execute permissions for ffmpeg and ffprobe
|
||||
chmod +x ffmpeg-6.0.1-amd64-static/ffmpeg && \
|
||||
chmod +x ffmpeg-6.0.1-amd64-static/ffprobe && \
|
||||
# Copy ffmpeg and ffprobe to /usr/bin
|
||||
cp -R ffmpeg-6.0.1-amd64-static/ffmpeg /usr/bin/ && \
|
||||
cp -R ffmpeg-6.0.1-amd64-static/ffprobe /usr/bin/ && \
|
||||
# Remove the extracted ffmpeg directory
|
||||
rm -rf ffmpeg-6.0.1-amd64-static && \
|
||||
# Create a new user 'papibot'
|
||||
useradd papibot && \
|
||||
# Build the Go application
|
||||
CGO_ENABLED=0 GOOS=linux go build -o /app/papibot
|
||||
97
Dockerfile.old
Normal file
97
Dockerfile.old
Normal file
@@ -0,0 +1,97 @@
|
||||
# Use the official golang:1.22.12-bookworm image as the build stage
|
||||
FROM golang:1.22.12-bookworm as build
|
||||
|
||||
# Create a directory /app
|
||||
RUN mkdir /app
|
||||
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the current directory contents into /app
|
||||
COPY ./ /app/
|
||||
|
||||
# Update the package list and install necessary packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
wget \
|
||||
vim \
|
||||
git \
|
||||
debconf \
|
||||
ca-certificates \
|
||||
tar \
|
||||
autoconf \
|
||||
automake \
|
||||
build-essential \
|
||||
cmake \
|
||||
git-core \
|
||||
libass-dev \
|
||||
libfreetype6-dev \
|
||||
libgnutls28-dev \
|
||||
libmp3lame-dev \
|
||||
libsdl2-dev \
|
||||
libtool \
|
||||
libva-dev \
|
||||
libvdpau-dev \
|
||||
libvorbis-dev \
|
||||
libxcb1-dev \
|
||||
libxcb-shm0-dev \
|
||||
libxcb-xfixes0-dev \
|
||||
meson \
|
||||
ninja-build \
|
||||
pkg-config \
|
||||
texinfo \
|
||||
yasm \
|
||||
zlib1g-dev \
|
||||
libx264-dev \
|
||||
libx265-dev \
|
||||
libnuma-dev \
|
||||
libvpx-dev \
|
||||
libopus-dev \
|
||||
libunistring-dev \
|
||||
libaom-dev \
|
||||
libdav1d-dev && \
|
||||
# Download Go module dependencies
|
||||
go mod download && \
|
||||
# Download yt-dlp
|
||||
wget --no-check-certificate -c https://github.com/yt-dlp/yt-dlp/releases/download/2025.01.26/yt-dlp_linux &&\
|
||||
# Download ffmpeg
|
||||
wget --no-check-certificate -c https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-6.0.1-amd64-static.tar.xz &&\
|
||||
# Move yt-dlp to /usr/bin and set permissions
|
||||
mv yt-dlp_linux /usr/bin/yt-dlp && \
|
||||
chmod 755 /usr/bin/yt-dlp && \
|
||||
chmod +x /usr/bin/yt-dlp && \
|
||||
# Extract ffmpeg tarball
|
||||
tar -xf ffmpeg-6.0.1-amd64-static.tar.xz && \
|
||||
# Remove the tarball
|
||||
rm -rf ffmpeg-6.0.1-amd64-static.tar.xz && \
|
||||
# Set execute permissions for ffmpeg and ffprobe
|
||||
chmod +x ffmpeg-6.0.1-amd64-static/ffmpeg && \
|
||||
chmod +x ffmpeg-6.0.1-amd64-static/ffprobe && \
|
||||
# Copy ffmpeg and ffprobe to /usr/bin
|
||||
cp -R ffmpeg-6.0.1-amd64-static/ffmpeg /usr/bin/ && \
|
||||
cp -R ffmpeg-6.0.1-amd64-static/ffprobe /usr/bin/ && \
|
||||
# Remove the extracted ffmpeg directory
|
||||
rm -rf ffmpeg-6.0.1-amd64-static && \
|
||||
# Create a new user 'papibot'
|
||||
useradd papibot && \
|
||||
# Build the Go application
|
||||
CGO_ENABLED=0 GOOS=linux go build -o /app/papibot
|
||||
|
||||
# Use the official golang:1.22.12-bookworm image for the final stage
|
||||
FROM golang:1.22.12-bookworm
|
||||
|
||||
# Create a group and user 'papibot'
|
||||
RUN groupadd -r papibot && useradd -r -g papibot papibot
|
||||
|
||||
# Switch to the 'papibot' user
|
||||
USER papibot
|
||||
|
||||
# Copy the necessary files from the build stage
|
||||
COPY --from=build --chown=papibot:papibot /usr/bin/ /usr/bin
|
||||
COPY --from=build --chown=papibot:papibot /app/ /app/
|
||||
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app/
|
||||
|
||||
# Set the entry point to the built Go application
|
||||
ENTRYPOINT ["./papibot"]
|
||||
17
Dockerfile.runtime
Normal file
17
Dockerfile.runtime
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM www.gitgud.foo/thegrind/papibot-builder:latest as build
|
||||
|
||||
# Create a group and user 'papibot'
|
||||
RUN groupadd -r papibot && useradd -r -g papibot papibot
|
||||
|
||||
# Switch to the 'papibot' user
|
||||
USER papibot
|
||||
|
||||
# Copy the necessary files from the build stage
|
||||
COPY --from=build --chown=papibot:papibot /usr/bin/ /usr/bin
|
||||
COPY --from=build --chown=papibot:papibot /app/ /app/
|
||||
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app/
|
||||
|
||||
# Set the entry point to the built Go application
|
||||
ENTRYPOINT ["./papibot"]
|
||||
3
Makefile
Normal file
3
Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
test:
|
||||
@echo "Running tests for main and all packages"
|
||||
go test ./...
|
||||
18
README.md
18
README.md
@@ -2,11 +2,16 @@
|
||||
|
||||
Currently in development.
|
||||
|
||||
|
||||
## docker
|
||||
docker build -t papibot . ;docker run -d papibot:latest --name papibot
|
||||
|
||||
|
||||
## System requirements
|
||||
- `ffmpeg` make sure libopus is included
|
||||
- `yt-dlp`
|
||||
|
||||
## Current testing steps
|
||||
## Running locally
|
||||
|
||||
Copy .env.example to .env
|
||||
|
||||
@@ -14,4 +19,13 @@ Populate the discord bot keys
|
||||
|
||||
`go run .`
|
||||
|
||||
type `!` in any channel in the discord while you're in a voice channel.
|
||||
type `!` in any channel in the discord while you're in a voice channel.
|
||||
|
||||
## Build new builder container image
|
||||
```
|
||||
docker build -t www.gitgud.foo/thegrind/papibot-builder:<tag> Dockerfile.builder
|
||||
```
|
||||
|
||||
## Running tests locally
|
||||
|
||||
`make test`
|
||||
|
||||
54
pkg/validation/validation.go
Normal file
54
pkg/validation/validation.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
neturl "net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Errors
|
||||
var (
|
||||
ErrNotAUrl = errors.New("not a URL")
|
||||
ErrIncorrectProtocol = errors.New("incorrect url protocol")
|
||||
ErrServiceUnsupported = errors.New("not a URL")
|
||||
)
|
||||
|
||||
// Music hosts that we support
|
||||
var musicHosts = []string{
|
||||
"youtube.com",
|
||||
"www.youtube.com",
|
||||
}
|
||||
|
||||
func IsUrl(url string) (bool, *neturl.URL) {
|
||||
// If a URL has no scheme, this will fail.
|
||||
// So we'll add one if not present
|
||||
if !strings.Contains(url, "://") {
|
||||
url = fmt.Sprintf("https://%s", url)
|
||||
}
|
||||
|
||||
parsed, err := neturl.ParseRequestURI(url)
|
||||
|
||||
return (err == nil), parsed
|
||||
}
|
||||
|
||||
func IsMusicUrl(url string) (bool, error) {
|
||||
isUrl, parsed := IsUrl(url)
|
||||
|
||||
if !isUrl {
|
||||
return false, ErrNotAUrl
|
||||
}
|
||||
|
||||
// If we have a scheme and it's not http/https we fail
|
||||
if parsed.Scheme != "" && !strings.Contains(parsed.Scheme, "http") {
|
||||
return false, ErrIncorrectProtocol
|
||||
}
|
||||
|
||||
for _, host := range musicHosts {
|
||||
if host == parsed.Host {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, ErrServiceUnsupported
|
||||
}
|
||||
85
pkg/validation/validation_test.go
Normal file
85
pkg/validation/validation_test.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsUrl(t *testing.T) {
|
||||
is, _ := IsUrl("definitely not a url")
|
||||
|
||||
if is {
|
||||
t.Error("Non-url text detected as URL")
|
||||
}
|
||||
|
||||
is, _ = IsUrl("https://example.com")
|
||||
|
||||
if !is {
|
||||
t.Error("URL not detected as URL")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchemeHandling(t *testing.T) {
|
||||
// No scheme but valid url
|
||||
is, _ := IsUrl("youtube.com")
|
||||
|
||||
if !is {
|
||||
t.Error("URL without scheme came back as not a url")
|
||||
}
|
||||
|
||||
// Preserve scheme
|
||||
is, parsed := IsUrl("ftp://youtube.com")
|
||||
|
||||
if !is {
|
||||
t.Error("URL without scheme came back as not a url")
|
||||
}
|
||||
|
||||
if parsed.Scheme != "ftp" {
|
||||
t.Error("URL scheme was replaced incorrectly")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportedMusicUrls(t *testing.T) {
|
||||
// Test actual music url
|
||||
for _, url := range musicHosts {
|
||||
is, _ := IsMusicUrl(url)
|
||||
|
||||
if !is {
|
||||
t.Error("Supported service was detected as unsupported")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsMusicUrlErrors(t *testing.T) {
|
||||
// Not a URL
|
||||
is, err := IsMusicUrl("not a url")
|
||||
|
||||
if is {
|
||||
t.Error("Non-URL was detected as url")
|
||||
}
|
||||
|
||||
if err != ErrNotAUrl {
|
||||
t.Error("Incorrect error returned for Non-url link")
|
||||
}
|
||||
|
||||
// Incorrect protocol
|
||||
is, err = IsMusicUrl("ssh://youtube.com")
|
||||
|
||||
if is {
|
||||
t.Error("Incorrect protocol was not caught")
|
||||
}
|
||||
|
||||
if err != ErrIncorrectProtocol {
|
||||
t.Error("Incorrect error returned for incorrect protocol")
|
||||
}
|
||||
|
||||
// Unsupported service
|
||||
is, err = IsMusicUrl("https://www.deezer.com/")
|
||||
|
||||
if is {
|
||||
t.Error("Unsupported service was not caught")
|
||||
}
|
||||
|
||||
if err != ErrServiceUnsupported {
|
||||
t.Error("Unsupported service did not return the correct error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user