From 9d2fa18539433a63106cc80af987bcfa6dcc7e64 Mon Sep 17 00:00:00 2001 From: Wittano Bonarotti Date: Wed, 15 May 2024 22:46:04 +0200 Subject: [PATCH] refactor: split project for modules --- Makefile | 11 +++-- {audio => bot/audio}/file.go | 0 {audio => bot/audio}/file_test.go | 0 bot.go => bot/bot.go | 14 +++--- {command => bot/command}/joke.go | 4 +- {command => bot/command}/joke_test.go | 2 +- {command => bot/command}/list.go | 2 +- {command => bot/command}/response.go | 2 +- {command => bot/command}/spock.go | 6 +-- {command => bot/command}/stop.go | 0 {command => bot/command}/types.go | 1 - {command => bot/command}/welcome.go | 0 {config => bot/config}/env.go | 0 {config => bot/config}/env_dev.go | 0 {config => bot/config}/env_test.go | 0 {config => bot/config}/types.go | 0 bot/go.mod | 32 ++++++++++++ bot/go.sum | 70 +++++++++++++++++++++++++++ {joke => bot/joke}/database.go | 0 {joke => bot/joke}/database_test.go | 4 +- {joke => bot/joke}/humorapi.go | 2 +- {joke => bot/joke}/humorapi_test.go | 0 {joke => bot/joke}/jokedev.go | 0 {joke => bot/joke}/jokedev_test.go | 0 {joke => bot/joke}/types.go | 0 {log => bot/log}/types.go | 1 + {voice => bot/voice}/channel.go | 0 {voice => bot/voice}/play.go | 0 cmd/komputer/main.go | 4 +- cmd/server/main.go | 7 +++ cmd/tui/main.go | 9 ++++ go.mod | 24 +++++---- go.sum | 30 ++++++------ go.work | 6 +++ go.work.sum | 11 +++++ 35 files changed, 189 insertions(+), 53 deletions(-) rename {audio => bot/audio}/file.go (100%) rename {audio => bot/audio}/file_test.go (100%) rename bot.go => bot/bot.go (95%) rename {command => bot/command}/joke.go (99%) rename {command => bot/command}/joke_test.go (97%) rename {command => bot/command}/list.go (99%) rename {command => bot/command}/response.go (96%) rename {command => bot/command}/spock.go (96%) rename {command => bot/command}/stop.go (100%) rename {command => bot/command}/types.go (94%) rename {command => bot/command}/welcome.go (100%) rename {config => bot/config}/env.go (100%) rename {config => bot/config}/env_dev.go (100%) rename {config => bot/config}/env_test.go (100%) rename {config => bot/config}/types.go (100%) create mode 100644 bot/go.mod create mode 100644 bot/go.sum rename {joke => bot/joke}/database.go (100%) rename {joke => bot/joke}/database_test.go (97%) rename {joke => bot/joke}/humorapi.go (98%) rename {joke => bot/joke}/humorapi_test.go (100%) rename {joke => bot/joke}/jokedev.go (100%) rename {joke => bot/joke}/jokedev_test.go (100%) rename {joke => bot/joke}/types.go (100%) rename {log => bot/log}/types.go (94%) rename {voice => bot/voice}/channel.go (100%) rename {voice => bot/voice}/play.go (100%) create mode 100644 cmd/server/main.go create mode 100644 cmd/tui/main.go create mode 100644 go.work create mode 100644 go.work.sum diff --git a/Makefile b/Makefile index fa09331..ed4073d 100644 --- a/Makefile +++ b/Makefile @@ -11,15 +11,18 @@ endif .PHONY: test clean -dev: proto +bot-dev: proto CGO_ENABLED=1 GOOS=linux GOARCH=$(GOARCH) go build -tags dev -o $(OUTPUT_DIR)/komputer ./cmd/komputer/main.go -prod: proto +bot-prod: proto CGO_ENABLED=1 GOOS=linux GOARCH=$(GOARCH) go build -o $(OUTPUT_DIR)/komputer ./cmd/komputer/main.go +sever: proto + go build -o $(OUTPUT_DIR)/server ./cmd/server/main.go + tui: proto - go build -o $(OUTPUT_DIR)/tui ./tui/cmd/main.go + go build -o $(OUTPUT_DIR)/tui ./cmd/tui/main.go protobuf: cleanProto mkdir -p $(PROTOBUF_API_DEST) @@ -28,6 +31,8 @@ protobuf: cleanProto test: proto go test -race ./... +all: bot-dev bot-prod sever tui + install: prod test mkdir -p $(PROTOBUF_API_DEST) cp -r assets $(PROTOBUF_API_DEST) diff --git a/audio/file.go b/bot/audio/file.go similarity index 100% rename from audio/file.go rename to bot/audio/file.go diff --git a/audio/file_test.go b/bot/audio/file_test.go similarity index 100% rename from audio/file_test.go rename to bot/audio/file_test.go diff --git a/bot.go b/bot/bot.go similarity index 95% rename from bot.go rename to bot/bot.go index cd4eb77..86ca626 100644 --- a/bot.go +++ b/bot/bot.go @@ -1,4 +1,4 @@ -package komputer +package bot import ( "context" @@ -6,12 +6,12 @@ import ( "fmt" "github.com/bwmarrin/discordgo" "github.com/google/uuid" - "github.com/wittano/komputer/command" - "github.com/wittano/komputer/config" + "github.com/wittano/komputer/bot/command" + "github.com/wittano/komputer/bot/config" + "github.com/wittano/komputer/bot/joke" + "github.com/wittano/komputer/bot/log" + "github.com/wittano/komputer/bot/voice" "github.com/wittano/komputer/db" - "github.com/wittano/komputer/joke" - "github.com/wittano/komputer/log" - "github.com/wittano/komputer/voice" "log/slog" "time" ) @@ -145,7 +145,7 @@ func createCommands( MusicStopChs: spockVoice, GuildVoiceChats: guildVoiceChats, } - stop := command.StopCommand{spockVoice} + stop := command.StopCommand{MusicStopChs: spockVoice} list := command.NewListCommand() return map[string]command.DiscordSlashCommandHandler{ diff --git a/command/joke.go b/bot/command/joke.go similarity index 99% rename from command/joke.go rename to bot/command/joke.go index ffce29f..7a6e498 100644 --- a/command/joke.go +++ b/bot/command/joke.go @@ -5,8 +5,8 @@ import ( "errors" "fmt" "github.com/bwmarrin/discordgo" - "github.com/wittano/komputer/joke" - "github.com/wittano/komputer/log" + "github.com/wittano/komputer/bot/joke" + "github.com/wittano/komputer/bot/log" "go.mongodb.org/mongo-driver/bson/primitive" "log/slog" "math/rand" diff --git a/command/joke_test.go b/bot/command/joke_test.go similarity index 97% rename from command/joke_test.go rename to bot/command/joke_test.go index 9b0381a..fe4f7b3 100644 --- a/command/joke_test.go +++ b/bot/command/joke_test.go @@ -3,7 +3,7 @@ package command import ( "context" "errors" - "github.com/wittano/komputer/joke" + "github.com/wittano/komputer/bot/joke" "go.mongodb.org/mongo-driver/mongo" "testing" ) diff --git a/command/list.go b/bot/command/list.go similarity index 99% rename from command/list.go rename to bot/command/list.go index 0e6a922..e5e9823 100644 --- a/command/list.go +++ b/bot/command/list.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" "github.com/bwmarrin/discordgo" - "github.com/wittano/komputer/audio" + "github.com/wittano/komputer/bot/audio" "os" "regexp" "strings" diff --git a/command/response.go b/bot/command/response.go similarity index 96% rename from command/response.go rename to bot/command/response.go index ba5856c..bb373e0 100644 --- a/command/response.go +++ b/bot/command/response.go @@ -3,7 +3,7 @@ package command import ( "context" "github.com/bwmarrin/discordgo" - "github.com/wittano/komputer/log" + "github.com/wittano/komputer/bot/log" "log/slog" ) diff --git a/command/spock.go b/bot/command/spock.go similarity index 96% rename from command/spock.go rename to bot/command/spock.go index 1014784..18cdac9 100644 --- a/command/spock.go +++ b/bot/command/spock.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "github.com/bwmarrin/discordgo" - "github.com/wittano/komputer/audio" - "github.com/wittano/komputer/log" - "github.com/wittano/komputer/voice" + "github.com/wittano/komputer/bot/audio" + "github.com/wittano/komputer/bot/log" + "github.com/wittano/komputer/bot/voice" "log/slog" "os" ) diff --git a/command/stop.go b/bot/command/stop.go similarity index 100% rename from command/stop.go rename to bot/command/stop.go diff --git a/command/types.go b/bot/command/types.go similarity index 94% rename from command/types.go rename to bot/command/types.go index 99be675..66bfb13 100644 --- a/command/types.go +++ b/bot/command/types.go @@ -7,7 +7,6 @@ import ( const ( serverGuildKey = "SERVER_GUID" - requestIDKey = "requestID" ) type DiscordSlashCommandHandler interface { diff --git a/command/welcome.go b/bot/command/welcome.go similarity index 100% rename from command/welcome.go rename to bot/command/welcome.go diff --git a/config/env.go b/bot/config/env.go similarity index 100% rename from config/env.go rename to bot/config/env.go diff --git a/config/env_dev.go b/bot/config/env_dev.go similarity index 100% rename from config/env_dev.go rename to bot/config/env_dev.go diff --git a/config/env_test.go b/bot/config/env_test.go similarity index 100% rename from config/env_test.go rename to bot/config/env_test.go diff --git a/config/types.go b/bot/config/types.go similarity index 100% rename from config/types.go rename to bot/config/types.go diff --git a/bot/go.mod b/bot/go.mod new file mode 100644 index 0000000..ec845b8 --- /dev/null +++ b/bot/go.mod @@ -0,0 +1,32 @@ +module github.com/wittano/komputer/bot + +go 1.22.2 + +replace github.com/wittano/komputer => ./.. + +require ( + github.com/bwmarrin/discordgo v0.28.1 + github.com/google/uuid v1.6.0 + github.com/jarcoal/httpmock v1.3.1 + github.com/joho/godotenv v1.5.1 + github.com/wittano/komputer v0.0.0-00010101000000-000000000000 + go.mongodb.org/mongo-driver v1.15.0 + layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/gorilla/websocket v1.5.1 // indirect + github.com/klauspost/compress v1.17.8 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect +) diff --git a/bot/go.sum b/bot/go.sum new file mode 100644 index 0000000..42bfa40 --- /dev/null +++ b/bot/go.sum @@ -0,0 +1,70 @@ +github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4= +github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= +github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= +github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 h1:tBiBTKHnIjovYoLX/TPkcf+OjqqKGQrPtGT3Foz+Pgo= +github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76/go.mod h1:SQliXeA7Dhkt//vS29v3zpbEwoa+zb2Cn5xj5uO4K5U= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= +go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 h1:/S1gOotFo2sADAIdSGk1sDq1VxetoCWr6f5nxOG0dpY= +layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32/go.mod h1:yDtyzWZDFCVnva8NGtg38eH2Ns4J0D/6hD+MMeUGdF0= diff --git a/joke/database.go b/bot/joke/database.go similarity index 100% rename from joke/database.go rename to bot/joke/database.go diff --git a/joke/database_test.go b/bot/joke/database_test.go similarity index 97% rename from joke/database_test.go rename to bot/joke/database_test.go index e6dfab1..ee5e78e 100644 --- a/joke/database_test.go +++ b/bot/joke/database_test.go @@ -91,8 +91,8 @@ func TestDatabaseService_FindRandomJoke(t *testing.T) { mt := createMTest(t) mt.Run("get new joke, but nothing was found", func(t *mtest.T) { - t.AddMockResponses(mtest.CreateSuccessResponse(bson.E{"ok", "1"}, - bson.E{"_id", primitive.NewObjectID()})) + t.AddMockResponses(mtest.CreateSuccessResponse(bson.E{Key: "ok", Value: "1"}, + bson.E{Key: "_id", Value: primitive.NewObjectID()})) t.AddMockResponses(mtest.CreateCursorResponse(0, collectionName+".0", mtest.FirstBatch, bson.D{ {"_id", primitive.NewObjectID()}, {"question", testJoke.Question}, diff --git a/joke/humorapi.go b/bot/joke/humorapi.go similarity index 98% rename from joke/humorapi.go rename to bot/joke/humorapi.go index e0d0925..08599a0 100644 --- a/joke/humorapi.go +++ b/bot/joke/humorapi.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/wittano/komputer/log" + "github.com/wittano/komputer/bot/log" "io" "log/slog" "net/http" diff --git a/joke/humorapi_test.go b/bot/joke/humorapi_test.go similarity index 100% rename from joke/humorapi_test.go rename to bot/joke/humorapi_test.go diff --git a/joke/jokedev.go b/bot/joke/jokedev.go similarity index 100% rename from joke/jokedev.go rename to bot/joke/jokedev.go diff --git a/joke/jokedev_test.go b/bot/joke/jokedev_test.go similarity index 100% rename from joke/jokedev_test.go rename to bot/joke/jokedev_test.go diff --git a/joke/types.go b/bot/joke/types.go similarity index 100% rename from joke/types.go rename to bot/joke/types.go diff --git a/log/types.go b/bot/log/types.go similarity index 94% rename from log/types.go rename to bot/log/types.go index 255fe46..fd1cc1d 100644 --- a/log/types.go +++ b/bot/log/types.go @@ -11,6 +11,7 @@ const RequestIDKey = "requestID" type Func func(l slog.Logger) type Context struct { + // TODO Check out if I should change slog.Logger to zerolog.Logger Logger *slog.Logger Ctx context.Context } diff --git a/voice/channel.go b/bot/voice/channel.go similarity index 100% rename from voice/channel.go rename to bot/voice/channel.go diff --git a/voice/play.go b/bot/voice/play.go similarity index 100% rename from voice/play.go rename to bot/voice/play.go diff --git a/cmd/komputer/main.go b/cmd/komputer/main.go index 4e8b8ab..e355e25 100644 --- a/cmd/komputer/main.go +++ b/cmd/komputer/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/wittano/komputer" + "github.com/wittano/komputer/bot" "log" "os" "os/signal" @@ -12,7 +12,7 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - b, err := komputer.NewDiscordBot(ctx) + b, err := bot.NewDiscordBot(ctx) if err != nil { log.Fatal(err) return diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..b1b14d0 --- /dev/null +++ b/cmd/server/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello World!") +} diff --git a/cmd/tui/main.go b/cmd/tui/main.go new file mode 100644 index 0000000..20f0d0f --- /dev/null +++ b/cmd/tui/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello World!") +} diff --git a/go.mod b/go.mod index 1d54143..9bc6273 100644 --- a/go.mod +++ b/go.mod @@ -3,31 +3,29 @@ module github.com/wittano/komputer go 1.22.1 require ( - github.com/bwmarrin/discordgo v0.28.1 - github.com/google/uuid v1.6.0 - github.com/jarcoal/httpmock v1.3.1 - github.com/joho/godotenv v1.5.1 + github.com/wittano/komputer/bot v0.0.0-20240428063233-4f3d64674cea go.mongodb.org/mongo-driver v1.15.0 - layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 + google.golang.org/protobuf v1.34.1 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/bwmarrin/discordgo v0.28.1 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.1 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/klauspost/compress v1.17.8 // indirect github.com/montanaflynn/stats v0.7.1 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/net v0.24.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect - google.golang.org/grpc v1.64.0 // indirect - google.golang.org/protobuf v1.33.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 // indirect ) diff --git a/go.sum b/go.sum index 3010db3..c24c3e8 100644 --- a/go.sum +++ b/go.sum @@ -17,10 +17,12 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= -github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/wittano/komputer/bot v0.0.0-20240428063233-4f3d64674cea h1:64FXWXR4wA91+wBkc+u7eNkSN1xpJCCz0ZoMQtVKNtQ= +github.com/wittano/komputer/bot v0.0.0-20240428063233-4f3d64674cea/go.mod h1:uyVk/qIFrLCjC2NPDP5RfLBilqFK9D7UQ6YMPIH1cjk= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= @@ -35,14 +37,14 @@ go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGc golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= @@ -52,25 +54,21 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 h1:/S1gOotFo2sADAIdSGk1sDq1VxetoCWr6f5nxOG0dpY= layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32/go.mod h1:yDtyzWZDFCVnva8NGtg38eH2Ns4J0D/6hD+MMeUGdF0= diff --git a/go.work b/go.work new file mode 100644 index 0000000..c5da0de --- /dev/null +++ b/go.work @@ -0,0 +1,6 @@ +go 1.22.2 + +use ( + . + bot +) diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..cfcfbe0 --- /dev/null +++ b/go.work.sum @@ -0,0 +1,11 @@ +github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=