-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
119 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea/ | ||
*.iml | ||
.env | ||
tokens.json | ||
tokens.json | ||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"server_address": "0.0.0.0:8080", | ||
"production_mode": true, | ||
"sentry_dsn": null, | ||
"discord": { | ||
"public_key": "", | ||
"allowed_guilds": [12345678901234567] | ||
}, | ||
"patreon": { | ||
"client_id": "", | ||
"client_secret": "", | ||
"campaign_id": 1111111, | ||
"tokens_file_path": "tokens.json" | ||
}, | ||
"tiers": { | ||
"1234": "Super", | ||
"5678": "Ultra" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
- DISCORD_PUBLIC_KEY | ||
- DISCORD_ALLOWED_GUILDS | ||
- PATREON_CLIENT_ID | ||
- PATREON_CLIENT_SECRET | ||
- PATREON_CAMPAIN_ID | ||
- SERVER_ADDR | ||
- SENTRY_DSN | ||
- PRODUCTION_MODE | ||
- **DISCORD_PUBLIC_KEY**: The public key for your Discord application to verify interactions. | ||
- **DISCORD_ALLOWED_GUILDS**: A comma-separated list of Discord guild IDs that commands will be accepted in. | ||
- **PATREON_CLIENT_ID**: The client ID string for your Patreon app. | ||
- **PATREON_CLIENT_SECRET**: The client secret string for your Patreon app. | ||
- **PATREON_CAMPAIGN_ID**: The ID of the Patreon campaign to use for fetching pledges. | ||
- **SERVER_ADDR**: The address to bind the web server for HTTP interactions to (e.g. `:8080). | ||
- **SENTRY_DSN**: Optional, used for error reporting. | ||
- **PRODUCTION_MODE**: Currently only used to determine the log format. | ||
- **TIERS**: A comma-separated list of Patreon tier IDs and names, in the format `1234:Name,5678:Name`, and so on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/caarlos0/env/v9" | ||
"github.com/pkg/errors" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
ServerAddr string `env:"SERVER_ADDR,required"` | ||
ProductionMode bool `env:"PRODUCTION_MODE" envDefault:"false"` | ||
SentryDsn string `env:"SENTRY_DSN"` | ||
ServerAddr string `env:"SERVER_ADDR,required" json:"server_address"` | ||
ProductionMode bool `env:"PRODUCTION_MODE" envDefault:"false" json:"production_mode"` | ||
SentryDsn *string `env:"SENTRY_DSN" json:"sentry_dsn"` | ||
|
||
Discord struct { | ||
PublicKey string `env:"PUBLIC_KEY,required"` | ||
AllowedGuilds []uint64 `env:"ALLOWED_GUILDS,required"` | ||
} `envPrefix:"DISCORD_"` | ||
PublicKey string `env:"PUBLIC_KEY,required" json:"public_key"` | ||
AllowedGuilds []uint64 `env:"ALLOWED_GUILDS,required" json:"allowed_guilds"` | ||
} `envPrefix:"DISCORD_" json:"discord"` | ||
|
||
Patreon struct { | ||
ClientId string `env:"CLIENT_ID,required"` | ||
ClientSecret string `env:"CLIENT_SECRET,required"` | ||
CampaignId int `env:"CAMPAIGN_ID,required"` | ||
TokensFilePath string `env:"TOKENS_FILE_PATH" envDefault:"tokens.json"` | ||
} `envPrefix:"PATREON_"` | ||
ClientId string `env:"CLIENT_ID,required" json:"client_id"` | ||
ClientSecret string `env:"CLIENT_SECRET,required" json:"client_secret"` | ||
CampaignId int `env:"CAMPAIGN_ID,required" json:"campaign_id"` | ||
TokensFilePath string `env:"TOKENS_FILE_PATH" envDefault:"tokens.json" json:"tokens_file_path"` | ||
} `envPrefix:"PATREON_" json:"patreon"` | ||
|
||
Tiers map[uint64]string `env:"TIERS" json:"tiers"` | ||
} | ||
|
||
func LoadConfig() (conf Config, err error) { | ||
err = env.Parse(&conf) | ||
return | ||
func LoadConfig() (Config, error) { | ||
var conf Config | ||
if _, err := os.Stat("config.json"); err == nil { | ||
f, err := os.Open("config.json") | ||
if err != nil { | ||
return Config{}, errors.Wrap(err, "failed to open config.json") | ||
} | ||
|
||
if err := json.NewDecoder(f).Decode(&conf); err != nil { | ||
return Config{}, errors.Wrap(err, "failed to decode config.json") | ||
} | ||
|
||
if conf.Patreon.TokensFilePath == "" { | ||
conf.Patreon.TokensFilePath = "tokens.json" | ||
} | ||
} else if errors.Is(err, os.ErrNotExist) { // If config.json does not exist, load from envvars | ||
if err := env.Parse(&conf); err != nil { | ||
return Config{}, errors.Wrap(err, "failed to parse env vars") | ||
} | ||
} else { | ||
return conf, errors.Wrap(err, "failed to check if config.json exists") | ||
} | ||
|
||
return conf, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ type ( | |
Patron struct { | ||
Attributes | ||
Id uint64 | ||
Tiers []Tier | ||
Tiers []uint64 | ||
DiscordId *uint64 | ||
} | ||
|
||
|