Skip to content

Commit

Permalink
feat: discord integration
Browse files Browse the repository at this point in the history
  • Loading branch information
igorgoldobin committed Feb 12, 2024
1 parent 8d4417e commit d1bf819
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 91 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy to Azure Staging

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: build.yml
name: build-artifact
path: ./deploy

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "16"

- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: auroria-test-faucet # Replace with your Azure App Service name
slot-name: staging
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE_STAGING }} # Azure publish profile secret
package: ./deploy # Path to the downloaded artifact
6 changes: 5 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var (

hcaptchaSiteKeyFlag = flag.String("hcaptcha_sitekey", os.Getenv("HCAPTCHA_SITEKEY"), "hCaptcha sitekey")
hcaptchaSecretFlag = flag.String("hcaptcha_secret", os.Getenv("HCAPTCHA_SECRET"), "hCaptcha secret")

discordClientId = flag.String("discord_client_id", os.Getenv("DISCORD_CLIENTID"), "Discord client id for oauth2")
discordClientSecret = flag.String("discord_client_secret", os.Getenv("DISCORD_CLIENTSECRET"), "Discord client secret for oauth2")
discordRedirectUrl = flag.String("discord_redirect_url", os.Getenv("DISCORD_REDIRECTURL"), "Discord redirect url for oauth2")
)

func init() {
Expand Down Expand Up @@ -80,7 +84,7 @@ func Execute() {
}
payoutFlag := flag.Int("faucet.amount", faucetAmount, "Number of Ethers to transfer per user request")

config := server.NewConfig(*netnameFlag, *symbolFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *hcaptchaSiteKeyFlag, *hcaptchaSecretFlag)
config := server.NewConfig(*netnameFlag, *symbolFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *hcaptchaSiteKeyFlag, *hcaptchaSecretFlag, *discordClientId, *discordClientSecret, *discordRedirectUrl)
go server.NewServer(txBuilder, config).Run()

c := make(chan os.Signal, 1)
Expand Down
40 changes: 23 additions & 17 deletions internal/server/config.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package server

type Config struct {
network string
symbol string
httpPort int
interval int
payout int
proxyCount int
hcaptchaSiteKey string
hcaptchaSecret string
network string
symbol string
httpPort int
interval int
payout int
proxyCount int
hcaptchaSiteKey string
hcaptchaSecret string
discordClientId string
discordClientSecret string
discordRedirectUrl string
}

func NewConfig(network, symbol string, httpPort, interval, payout, proxyCount int, hcaptchaSiteKey, hcaptchaSecret string) *Config {
func NewConfig(network, symbol string, httpPort, interval, payout, proxyCount int, hcaptchaSiteKey, hcaptchaSecret, discordClientId, discordClientSecret, discordRedirectUrl string) *Config {
return &Config{
network: network,
symbol: symbol,
httpPort: httpPort,
interval: interval,
payout: payout,
proxyCount: proxyCount,
hcaptchaSiteKey: hcaptchaSiteKey,
hcaptchaSecret: hcaptchaSecret,
network: network,
symbol: symbol,
httpPort: httpPort,
interval: interval,
payout: payout,
proxyCount: proxyCount,
hcaptchaSiteKey: hcaptchaSiteKey,
hcaptchaSecret: hcaptchaSecret,
discordClientId: discordClientId,
discordClientSecret: discordClientSecret,
discordRedirectUrl: discordRedirectUrl,
}
}
42 changes: 39 additions & 3 deletions internal/server/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,37 @@ type claimRequest struct {
Address string `json:"address"`
}

type loginRequest struct {
Code string `json:"code"`
}

type claimResponse struct {
Message string `json:"msg"`
}

type loginResponse struct {
Message string `json:"msg"`
}

type discordTokenResponse struct {
AccessToken string `json:"access_token"`
Error string `json:"error"`
ErrorDesc string `json:"error_description"`
}

type infoResponse struct {
Account string `json:"account"`
Network string `json:"network"`
Payout string `json:"payout"`
Symbol string `json:"symbol"`
HcaptchaSiteKey string `json:"hcaptcha_sitekey,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
Forward string `json:"forward,omitempty"`
RealIP string `json:"real_ip,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
Forward string `json:"forward,omitempty"`
RealIP string `json:"real_ip,omitempty"`
}

type authResponse struct {
Token string `json:"token"`
}

type malformedRequest struct {
Expand Down Expand Up @@ -95,6 +113,24 @@ func readAddress(r *http.Request) (string, error) {
return claimReq.Address, nil
}

func readCode(r *http.Request) (string, error) {
var loginReq loginRequest
if err := decodeJSONBody(r, &loginReq); err != nil {
return "", err
}

return loginReq.Code, nil
}

func readToken(r *http.Request) (string, error) {
var discordRes discordTokenResponse
if err := decodeJSONBody(r, &discordRes); err != nil {
return "", err
}

return discordRes.AccessToken, nil
}

func renderJSON(w http.ResponseWriter, v interface{}, code int) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
Expand Down
Loading

0 comments on commit d1bf819

Please sign in to comment.