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
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.direnv
|
||||
.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
|
||||
}
|
||||
|
||||
func NewDiscordClient(clientID, clientSecret, botToken string) DiscordClient {
|
||||
return DiscordClient{
|
||||
func NewDiscordClient(clientID, clientSecret, botToken string) *DiscordClient {
|
||||
return &DiscordClient{
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
BotToken: botToken,
|
||||
|
|
|
@ -9,10 +9,17 @@ type GuildService struct {
|
|||
client IDiscordClient
|
||||
}
|
||||
|
||||
func NewGuildService(client IDiscordClient) *GuildService {
|
||||
return &GuildService{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (gs *GuildService) Client() IDiscordClient {
|
||||
return gs.client
|
||||
}
|
||||
|
||||
func (gs *GuildService) GetGuild(guildID string) (IGuild, error) {
|
||||
// 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)
|
||||
}
|
||||
|
||||
func (gs *GuildServiceMock) Client() IDiscordClient {
|
||||
args := gs.Called()
|
||||
return args.Get(0).(IDiscordClient)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/ed25519"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
|
||||
|
@ -22,10 +21,6 @@ type Interactions struct {
|
|||
}
|
||||
|
||||
func NewInteractions(publicKey string, guildsService discord.IGuildService) *Interactions {
|
||||
if publicKey == "" {
|
||||
publicKey = os.Getenv("DISCORD_PUBLIC_KEY")
|
||||
}
|
||||
|
||||
return &Interactions{
|
||||
PublicKey: ed25519.PublicKey(publicKey),
|
||||
Guilds: guildsService,
|
||||
|
@ -73,7 +68,6 @@ func (i *Interactions) PostHandler(c fiber.Ctx) error {
|
|||
return types.NewAPIError(http.StatusNotImplemented, "not implemented").Send(c)
|
||||
}
|
||||
|
||||
func (i *Interactions) Respond(ix Interaction, ir InteractionResponse) error {
|
||||
// TODO: make request to /webhooks/appid/{ix.Token}
|
||||
return nil
|
||||
}
|
||||
// func (i *Interactions) Respond(ix Interaction, ir InteractionResponse) error {
|
||||
// i.Guilds
|
||||
// }
|
||||
|
|
|
@ -18,15 +18,10 @@ import (
|
|||
func TestNewInteractions(t *testing.T) {
|
||||
pub, _, _ := ed25519.GenerateKey(nil)
|
||||
key := hex.EncodeToString(pub)
|
||||
t.Setenv("DISCORD_PUBLIC_KEY", key)
|
||||
|
||||
gsm := &discord.GuildServiceMock{}
|
||||
|
||||
i := interactions.NewInteractions("", 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)
|
||||
i := interactions.NewInteractions(key, gsm)
|
||||
assert.True(t, i.OK, "interactions OK")
|
||||
assert.Equal(t, string(i.PublicKey), key, "public key accepted from args")
|
||||
}
|
||||
|
|
10
main.go
10
main.go
|
@ -4,12 +4,20 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||
"git.sapphic.engineer/roleypoly/v4/roleypoly"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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")
|
||||
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/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/testing"
|
||||
)
|
||||
|
@ -27,8 +29,14 @@ func CreateFiberApp() *fiber.App {
|
|||
return app
|
||||
}
|
||||
|
||||
func SetupRoutes(app *fiber.App) {
|
||||
(&testing.TestingController{}).Routes(app.Group("/testing"))
|
||||
func SetupControllers(app *fiber.App, dc discord.IDiscordClient, publicKey string) {
|
||||
gs := discord.NewGuildService(dc)
|
||||
|
||||
(&testing.TestingController{
|
||||
Guilds: gs,
|
||||
}).Routes(app.Group("/testing"))
|
||||
|
||||
interactions.NewInteractions(publicKey, gs).Routes(app.Group("/interactions"))
|
||||
}
|
||||
|
||||
// func getStorageDirectory() string {
|
||||
|
|
|
@ -13,5 +13,5 @@ func TestHeadTitle(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