Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from keshon/dev-new-structure
Browse files Browse the repository at this point in the history
opt: major structure overhaul
  • Loading branch information
keshon authored Dec 7, 2023
2 parents 033fdc0 + e62dc25 commit e8b3060
Show file tree
Hide file tree
Showing 51 changed files with 1,605 additions and 1,190 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DISCORD_COMMAND_PREFIX="!"

# Discord bot token acquired from Discord Developer Portal
DISCORD_BOT_TOKEN=<INSERT TOKEN HERE>
DISCORD_BOT_TOKEN=INSERT_TOKEN_HERE

# Enable REST API server
REST_ENABLED=true
Expand Down
2 changes: 1 addition & 1 deletion build-and-run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ for /f "tokens=3" %%i in ('go version') do set GO_VERSION=%%i
rem Get the build date
for /f "tokens=*" %%a in ('powershell -command "Get-Date -UFormat '%%Y-%%m-%%dT%%H:%%M:%%SZ'"') do set BUILD_DATE=%%a

go build -o melodix.exe -ldflags "-X app/internal/version.BuildDate=%BUILD_DATE% -X app/internal/version.GoVersion=%GO_VERSION%" cmd\main.go && melodix.exe
go build -o melodix.exe -ldflags "-X github.com/keshon/melodix-discord-player/internal/version.BuildDate=%BUILD_DATE% -X github.com/keshon/melodix-discord-player/internal/version.GoVersion=%GO_VERSION%" cmd\main.go && melodix.exe
2 changes: 1 addition & 1 deletion build-and-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ GO_VERSION=$(go version | awk '{print $3}')
# Get the build date
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

go build -o melodix -ldflags "-X app/internal/version.BuildDate=$BUILD_DATE -X app/internal/version.GoVersion=$GO_VERSION" cmd/main.go && ./melodix
go build -o melodix -ldflags "-X github.com/keshon/melodix-discord-player/internal/version.BuildDate=$BUILD_DATE -X github.com/keshon/melodix-discord-player/internal/version.GoVersion=$GO_VERSION" cmd/main.go && ./melodix
2 changes: 1 addition & 1 deletion build-release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ for /f "tokens=3" %%i in ('go version') do set GO_VERSION=%%i
rem Get the build date
for /f "tokens=*" %%a in ('powershell -command "Get-Date -UFormat '%%Y-%%m-%%dT%%H:%%M:%%SZ'"') do set BUILD_DATE=%%a

go build -o melodix.exe -ldflags "-s -X app/internal/version.BuildDate=%BUILD_DATE% -X app/internal/version.GoVersion=%GO_VERSION%" cmd\main.go
go build -o melodix.exe -ldflags "-s -X github.com/keshon/melodix-discord-player/internal/version.BuildDate=%BUILD_DATE% -X github.com/keshon/melodix-discord-player/internal/version.GoVersion=%GO_VERSION%" cmd\main.go

upx melodix.exe
2 changes: 1 addition & 1 deletion build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ GO_VERSION=$(go version | awk '{print $3}')
# Get the build date
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

go build -o melodix -ldflags "-s -X app/internal/version.BuildDate=$BUILD_DATE -X app/internal/version.GoVersion=$GO_VERSION" cmd/main.go
go build -o melodix -ldflags "-s -X github.com/keshon/melodix-discord-player/internal/version.BuildDate=$BUILD_DATE -X github.com/keshon/melodix-discord-player/internal/version.GoVersion=$GO_VERSION" cmd/main.go

upx melodix
22 changes: 12 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package main

import (
"app/internal/config"
"app/internal/db"
"app/internal/manager"
"app/internal/melodix"
"app/internal/version"
"net"
"os"
"os/signal"
Expand All @@ -15,9 +10,16 @@ import (
"github.com/gin-gonic/gin"
"github.com/gookit/slog"
"github.com/gookit/slog/handler"

"github.com/keshon/melodix-discord-player/internal/config"
"github.com/keshon/melodix-discord-player/internal/db"
"github.com/keshon/melodix-discord-player/internal/manager"
"github.com/keshon/melodix-discord-player/internal/rest"
"github.com/keshon/melodix-discord-player/internal/version"
"github.com/keshon/melodix-discord-player/music/discord"
)

var botInstances map[string]*melodix.BotInstance
var botInstances map[string]*discord.BotInstance

func main() {
slog.Configure(func(logger *slog.SugaredLogger) {
Expand Down Expand Up @@ -51,7 +53,7 @@ func main() {
os.Exit(0)
}

botInstances = make(map[string]*melodix.BotInstance)
botInstances = make(map[string]*discord.BotInstance)

guildManager := manager.NewGuildManager(dg, botInstances)
guildManager.Start()
Expand Down Expand Up @@ -101,8 +103,8 @@ func getGuildsOrSetDefault() ([]string, error) {
}

func startBotInstances(session *discordgo.Session, guildID string) {
botInstances[guildID] = &melodix.BotInstance{
Melodix: melodix.NewDiscord(session, guildID),
botInstances[guildID] = &discord.BotInstance{
Melodix: discord.NewDiscord(session, guildID),
}
botInstances[guildID].Melodix.Start(guildID)
}
Expand All @@ -114,7 +116,7 @@ func startRestServer(isReleaseMode bool, hostname string) {

router := gin.Default()

restAPI := melodix.NewRest(botInstances)
restAPI := rest.NewRest(botInstances)
restAPI.Start(router)

go func() {
Expand Down
4 changes: 2 additions & 2 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GIT_URL=https://github.com/keshon/melodix-discord-player.git
DISCORD_COMMAND_PREFIX=l

# Discord bot token aquired from Discord Developer Portal
DISCORD_BOT_TOKEN=<INSERT TOKEN HERE>
DISCORD_BOT_TOKEN=INSERT_TOKEN_HERE

# Enable REST API server
REST_ENABLED=true
Expand All @@ -30,7 +30,7 @@ REST_ENABLED=true
REST_GIN_RELEASE=true

# Hostname for REST API server, may optionally contain port e.g. "localhost:9000"
REST_HOSTNAME=${HOST}
REST_HOSTNAME=0.0.0.0

# Audio frame duration (can be 20, 40, or 60 ms)
# Everything above 20 will ruin sound quality
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- DISCORD_BOT_TOKEN
- REST_ENABLED
- REST_GIN_RELEASE
- REST_HOSTNAME
- DCA_FRAME_DURATION
- DCA_BITRATE
- DCA_PACKET_LOSS
Expand Down
39 changes: 14 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,68 +1,57 @@
module app
module github.com/keshon/melodix-discord-player

go 1.21

toolchain go1.21.1

require (
github.com/Clinet/discordgo-embed v0.0.0-20220113222025-bafe0c917646
github.com/bwmarrin/discordgo v0.27.1
github.com/gin-gonic/gin v1.9.1
github.com/gookit/slog v0.5.4
github.com/joho/godotenv v1.5.1
github.com/jonas747/ogg v0.0.0-20161220051205-b4f6f4cf3757
github.com/kkdai/youtube/v2 v2.9.0
github.com/stretchr/testify v1.8.4
gorm.io/driver/sqlite v1.5.4
gorm.io/gorm v1.25.5
)

require go.uber.org/multierr v1.10.0 // indirect

require (
github.com/bitly/go-simplejson v0.5.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dop251/goja v0.0.0-20231014103939-873a1496dc8e // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.5 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gookit/goutil v0.6.14 // indirect
github.com/gookit/gsr v0.1.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/zap v1.26.0
golang.org/x/arch v0.5.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e8b3060

Please sign in to comment.