readme, nix fixes
This commit is contained in:
parent
aafe3e2d21
commit
64bd10915b
12 changed files with 102 additions and 23 deletions
|
@ -0,0 +1,7 @@
|
||||||
|
DISCORD_CLIENT_ID=aa
|
||||||
|
DISCORD_CLIENT_SECRET=bb
|
||||||
|
DISCORD_PUBLIC_KEY=cc
|
||||||
|
DISCORD_BOT_TOKEN=dd
|
||||||
|
|
||||||
|
LISTEN_ADDR=:8169
|
||||||
|
STORAGE_DIR=./.storage
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
.direnv
|
.direnv
|
||||||
.env
|
.env
|
||||||
.storage
|
.storage
|
||||||
|
result
|
55
README.md
Normal file
55
README.md
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
# Roleypoly v4
|
||||||
|
|
||||||
|
yeah 4 of em..
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
use `nix shell` or `nix-shell` or maybe just run `go run .` or somethin its ok
|
||||||
|
|
||||||
|
please run `just precommit` before committing thx, it fixes weird build issues
|
||||||
|
|
||||||
|
## Deploying
|
||||||
|
|
||||||
|
roleypoly can be deployed as a docker container (built with nix) or nix package right now. more options to come (like prebuilt binaries)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix build .#container
|
||||||
|
docker load -i result
|
||||||
|
docker run -it --rm -p 8169:8169 localhost/roleypoly/roleypoly
|
||||||
|
```
|
||||||
|
|
||||||
|
or like if in irl nixos
|
||||||
|
|
||||||
|
```nix
|
||||||
|
#== flake.nix
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
roleypoly.url = "git+https://git.sapphic.engineer/roleypoly/v4";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and want to use docker (its ok)
|
||||||
|
|
||||||
|
```nix
|
||||||
|
#== roleypoly.nix
|
||||||
|
{ inputs, pkgs, ... }: {
|
||||||
|
virtualisation.oci-containers.containers.roleypoly = {
|
||||||
|
image = "roleypoly/roleypoly:latest";
|
||||||
|
imageFile = inputs.roleypoly.packages.${pkgs.system}.container;
|
||||||
|
ports = [ "8169:8169" ];
|
||||||
|
# probably include environment and stuff too
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or use `inputs.roleypoly.packages.${pkgs.system}.roleypoly` for the actual package for like a systemd thing
|
||||||
|
|
||||||
|
<33
|
||||||
|
|
||||||
|
## thanks
|
||||||
|
|
||||||
|
roleypoly has been a journey and a pleasure to make. thanks to everyone who has used it over the years. there will be no major updates after v4.
|
||||||
|
|
||||||
|
as always, with love
|
||||||
|
-- noe, aki, and aurelia!
|
|
@ -21,8 +21,8 @@ type DiscordClient struct {
|
||||||
ClientSecret string
|
ClientSecret string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiscordClient(clientID, clientSecret, botToken string) DiscordClient {
|
func NewDiscordClient(clientID, clientSecret, botToken string) *DiscordClient {
|
||||||
return DiscordClient{
|
return &DiscordClient{
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
ClientSecret: clientSecret,
|
ClientSecret: clientSecret,
|
||||||
BotToken: botToken,
|
BotToken: botToken,
|
||||||
|
|
|
@ -9,10 +9,17 @@ type GuildService struct {
|
||||||
client IDiscordClient
|
client IDiscordClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewGuildService(client IDiscordClient) *GuildService {
|
||||||
|
return &GuildService{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (gs *GuildService) Client() IDiscordClient {
|
func (gs *GuildService) Client() IDiscordClient {
|
||||||
return gs.client
|
return gs.client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *GuildService) GetGuild(guildID string) (IGuild, error) {
|
func (gs *GuildService) GetGuild(guildID string) (IGuild, error) {
|
||||||
// gs.client
|
// gs.client
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,3 +17,8 @@ func (gs *GuildServiceMock) GetGuild(guildID string) (IGuild, error) {
|
||||||
|
|
||||||
return args.Get(0).(IGuild), args.Error(1)
|
return args.Get(0).(IGuild), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gs *GuildServiceMock) Client() IDiscordClient {
|
||||||
|
args := gs.Called()
|
||||||
|
return args.Get(0).(IDiscordClient)
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
|
|
||||||
|
@ -22,10 +21,6 @@ type Interactions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInteractions(publicKey string, guildsService discord.IGuildService) *Interactions {
|
func NewInteractions(publicKey string, guildsService discord.IGuildService) *Interactions {
|
||||||
if publicKey == "" {
|
|
||||||
publicKey = os.Getenv("DISCORD_PUBLIC_KEY")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Interactions{
|
return &Interactions{
|
||||||
PublicKey: ed25519.PublicKey(publicKey),
|
PublicKey: ed25519.PublicKey(publicKey),
|
||||||
Guilds: guildsService,
|
Guilds: guildsService,
|
||||||
|
@ -73,7 +68,6 @@ func (i *Interactions) PostHandler(c fiber.Ctx) error {
|
||||||
return types.NewAPIError(http.StatusNotImplemented, "not implemented").Send(c)
|
return types.NewAPIError(http.StatusNotImplemented, "not implemented").Send(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interactions) Respond(ix Interaction, ir InteractionResponse) error {
|
// func (i *Interactions) Respond(ix Interaction, ir InteractionResponse) error {
|
||||||
// TODO: make request to /webhooks/appid/{ix.Token}
|
// i.Guilds
|
||||||
return nil
|
// }
|
||||||
}
|
|
||||||
|
|
|
@ -18,15 +18,10 @@ import (
|
||||||
func TestNewInteractions(t *testing.T) {
|
func TestNewInteractions(t *testing.T) {
|
||||||
pub, _, _ := ed25519.GenerateKey(nil)
|
pub, _, _ := ed25519.GenerateKey(nil)
|
||||||
key := hex.EncodeToString(pub)
|
key := hex.EncodeToString(pub)
|
||||||
t.Setenv("DISCORD_PUBLIC_KEY", key)
|
|
||||||
|
|
||||||
gsm := &discord.GuildServiceMock{}
|
gsm := &discord.GuildServiceMock{}
|
||||||
|
|
||||||
i := interactions.NewInteractions("", gsm)
|
i := interactions.NewInteractions(key, gsm)
|
||||||
assert.True(t, i.OK, "interactions OK")
|
|
||||||
assert.Equal(t, string(i.PublicKey), key, "public key fetched from environment")
|
|
||||||
|
|
||||||
i = interactions.NewInteractions(key, gsm)
|
|
||||||
assert.True(t, i.OK, "interactions OK")
|
assert.True(t, i.OK, "interactions OK")
|
||||||
assert.Equal(t, string(i.PublicKey), key, "public key accepted from args")
|
assert.Equal(t, string(i.PublicKey), key, "public key accepted from args")
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -4,12 +4,20 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||||
"git.sapphic.engineer/roleypoly/v4/roleypoly"
|
"git.sapphic.engineer/roleypoly/v4/roleypoly"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := roleypoly.CreateFiberApp()
|
app := roleypoly.CreateFiberApp()
|
||||||
roleypoly.SetupRoutes(app)
|
|
||||||
|
clientID := os.Getenv("DISCORD_CLIENT_ID")
|
||||||
|
clientSecret := os.Getenv("DISCORD_CLIENT_SECRET")
|
||||||
|
botToken := os.Getenv("DISCORD_BOT_TOKEN")
|
||||||
|
dc := discord.NewDiscordClient(clientID, clientSecret, botToken)
|
||||||
|
|
||||||
|
publicKey := os.Getenv("DISCORD_PUBLIC_KEY")
|
||||||
|
roleypoly.SetupControllers(app, dc, publicKey)
|
||||||
|
|
||||||
listenAddr := os.Getenv("LISTEN_ADDR")
|
listenAddr := os.Getenv("LISTEN_ADDR")
|
||||||
if listenAddr == "" {
|
if listenAddr == "" {
|
||||||
|
|
1
result
1
result
|
@ -1 +0,0 @@
|
||||||
/nix/store/pfv1lbrn6cawjj523cba1c56d835q6sd-docker-image-roleypoly.tar.gz
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"github.com/gofiber/fiber/v3/middleware/session"
|
"github.com/gofiber/fiber/v3/middleware/session"
|
||||||
"github.com/gofiber/template/html/v2"
|
"github.com/gofiber/template/html/v2"
|
||||||
|
|
||||||
|
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||||
|
"git.sapphic.engineer/roleypoly/v4/interactions"
|
||||||
"git.sapphic.engineer/roleypoly/v4/templates"
|
"git.sapphic.engineer/roleypoly/v4/templates"
|
||||||
"git.sapphic.engineer/roleypoly/v4/testing"
|
"git.sapphic.engineer/roleypoly/v4/testing"
|
||||||
)
|
)
|
||||||
|
@ -27,8 +29,14 @@ func CreateFiberApp() *fiber.App {
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRoutes(app *fiber.App) {
|
func SetupControllers(app *fiber.App, dc discord.IDiscordClient, publicKey string) {
|
||||||
(&testing.TestingController{}).Routes(app.Group("/testing"))
|
gs := discord.NewGuildService(dc)
|
||||||
|
|
||||||
|
(&testing.TestingController{
|
||||||
|
Guilds: gs,
|
||||||
|
}).Routes(app.Group("/testing"))
|
||||||
|
|
||||||
|
interactions.NewInteractions(publicKey, gs).Routes(app.Group("/interactions"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// func getStorageDirectory() string {
|
// func getStorageDirectory() string {
|
||||||
|
|
|
@ -13,5 +13,5 @@ func TestHeadTitle(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJ(t *testing.T) {
|
func TestJ(t *testing.T) {
|
||||||
assert.Equal(t, "a/b/c", utils.J("a", "b", "c"))
|
assert.Equal(t, "/a/b/c", utils.J("a", "b", "c"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue