Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random select of social1 translation. #172

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
github.com/dennwc/varint v1.0.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v27.0.2+incompatible // indirect
github.com/docker/docker v27.0.3+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down
2 changes: 1 addition & 1 deletion kyc/social/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var (
//nolint:gochecknoglobals // Its loaded once at startup.
allLanguageTemplateType = [1]languageTemplateType{postContentLanguageTemplateType}
//nolint:gochecknoglobals // Its loaded once at startup.
allTemplates = make(map[tenantName]map[users.KYCStep]map[Type]map[languageTemplateType]map[languageCode]*languageTemplate, len(AllSupportedKYCSteps))
allTemplates = make(map[tenantName]map[users.KYCStep]map[Type]map[languageTemplateType]map[languageCode][]*languageTemplate, len(AllSupportedKYCSteps))
)

type (
Expand Down
31 changes: 23 additions & 8 deletions kyc/social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package social
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"math/big"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -42,23 +44,24 @@ func loadTranslations() { //nolint:funlen,gocognit,revive // .
content, fErr := translations.ReadFile(fmt.Sprintf("translations/%v/%v/%v/%v/%v", tenantFile.Name(), kycStep, socialType, templateType, file.Name()))
log.Panic(fErr) //nolint:revive // Nope.
language := strings.Split(file.Name(), ".")[0]
language = strings.Split(language, "-")[0]
templName := fmt.Sprintf("translations_%v_%v_%v_%v_%v", tenantFile.Name(), kycStep, socialType, templateType, language)
tmpl := languageTemplate{Content: fixTemplateParameters(string(content))}
tmpl.content = template.Must(template.New(templName).Parse(tmpl.Content))

if _, found := allTemplates[tenantName(tenantFile.Name())]; !found {
allTemplates[tenantName(tenantFile.Name())] = make(map[users.KYCStep]map[social.StrategyType]map[languageTemplateType]map[string]*languageTemplate)
allTemplates[tenantName(tenantFile.Name())] = make(map[users.KYCStep]map[social.StrategyType]map[languageTemplateType]map[string][]*languageTemplate)
}
if _, found := allTemplates[tenantName(tenantFile.Name())][kycStep]; !found {
allTemplates[tenantName(tenantFile.Name())][kycStep] = make(map[Type]map[languageTemplateType]map[languageCode]*languageTemplate, len(AllTypes))
allTemplates[tenantName(tenantFile.Name())][kycStep] = make(map[social.StrategyType]map[languageTemplateType]map[string][]*languageTemplate, len(AllTypes)) //nolint:lll // .
}
if _, found := allTemplates[tenantName(tenantFile.Name())][kycStep][socialType]; !found {
allTemplates[tenantName(tenantFile.Name())][kycStep][socialType] = make(map[languageTemplateType]map[languageCode]*languageTemplate, len(&allLanguageTemplateType)) //nolint:lll // .
allTemplates[tenantName(tenantFile.Name())][kycStep][socialType] = make(map[languageTemplateType]map[string][]*languageTemplate, len(&allLanguageTemplateType)) //nolint:lll // .
}
if _, found := allTemplates[tenantName(tenantFile.Name())][kycStep][socialType][templateType]; !found {
allTemplates[tenantName(tenantFile.Name())][kycStep][socialType][templateType] = make(map[languageCode]*languageTemplate, len(files))
allTemplates[tenantName(tenantFile.Name())][kycStep][socialType][templateType] = make(map[string][]*languageTemplate, len(files))
}
allTemplates[tenantName(tenantFile.Name())][kycStep][socialType][templateType][language] = &tmpl
allTemplates[tenantName(tenantFile.Name())][kycStep][socialType][templateType][language] = append(allTemplates[tenantName(tenantFile.Name())][kycStep][socialType][templateType][language], &tmpl) //nolint:lll // .
}
}
}
Expand Down Expand Up @@ -390,17 +393,29 @@ func detectReason(err error) string {

func (vm *VerificationMetadata) expectedPostText(user *users.User, tname tenantName) string {
var templ *languageTemplate
if val, found := allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType][vm.Language]; found {
templ = val
if _, found := allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType][vm.Language]; found {
randVal := getRandomIndex(int64(len(allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType][vm.Language])))
templ = allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType][vm.Language][randVal]
} else {
templ = allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType]["en"]
randVal := getRandomIndex(int64(len(allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType]["en"])))
templ = allTemplates[tname][vm.KYCStep][vm.Social][postContentLanguageTemplateType]["en"][randVal]
}
bf := new(bytes.Buffer)
log.Panic(errors.Wrapf(templ.content.Execute(bf, user), "failed to execute postContentLanguageTemplateType template for data:%#v", user))

return bf.String()
}

func getRandomIndex(maxVal int64) uint64 {
if maxVal == 1 {
return 0
}
n, err := rand.Int(rand.Reader, big.NewInt(maxVal))
log.Panic(errors.Wrap(err, "crypto random generator failed"))

return n.Uint64()
}

func (r *repository) expectedPostURL(metadata *VerificationMetadata) (url string) {
if metadata.Social == TwitterType {
switch metadata.KYCStep { //nolint:exhaustive // Not needed. Everything else is validated before this.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎉 Verified on @sunwaves_token! You can find me as "{{.Username}}".

👉 Transforming festival experiences with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🔓 Verified on @sunwaves_token! Connect with me as "{{.Username}}".

🌍 Innovating the festival scene within the #ION ecosystem using @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌟 Proud to be on @sunwaves_token! Username: "{{.Username}}".

🌍 Revolutionizing festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎟️ Verified on @sunwaves_token! You can find me as "{{.Username}}".

✨ Transforming festival experiences with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎈 My account on @sunwaves_token is now live as "{{.Username}}".

🌍 Bringing next-level festivals to the #ION ecosystem powered by @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
💡 I've officially joined @sunwaves_token as "{{.Username}}".

💥 Enhancing festival magic within the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🚀 Just verified my account on @sunwaves_token as "{{.Username}}".

👉 Taking festivals to new heights in the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌟 Verified on @sunwaves_token! Now known as "{{.Username}}".

✨ Revolutionizing festivals in the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🔥 My account on @sunwaves_token is now active as "{{.Username}}".

🚀 Elevating the festival experience in the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎵 Join me on @sunwaves_token as "{{.Username}}".

🎉 Innovating festival vibes in the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🤩 Verified on @sunwaves_token! My username: "{{.Username}}".

✨ Bringing festivals to the next level with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌐 My @sunwaves_token account is now live as "{{.Username}}".

🚀 Transforming festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🔒 My account on @sunwaves_token is now live as "{{.Username}}".

🚀 Bringing next-level festivals to the #ION ecosystem powered by @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
💥 Officially verified on @sunwaves_token as "{{.Username}}".

🌍 Elevating festival experiences in the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎉 Excited to announce my verification on @sunwaves_token as "{{.Username}}".

✨ Innovating the festival scene with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌟 Proud to be verified on @sunwaves_token as "{{.Username}}".

🚀 Redefining festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
💼 Verified on @sunwaves_token! Find me as "{{.Username}}".

🌐 Taking festivals to new heights with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
📢 Just verified my account on @sunwaves_token as "{{.Username}}".

🎪 Transforming the festival experience with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌟 My @sunwaves_token account is now live as "{{.Username}}".

✨ Elevating festivals in the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
💥 Proud to announce my verification on @sunwaves_token as "{{.Username}}".

🚀 Revolutionizing the festival scene with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎟️ Verified on @sunwaves_token! My username: "{{.Username}}".

✨ Taking festivals to the next level with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🚀 Officially on @sunwaves_token as "{{.Username}}".

🌐 Transforming festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎈 Verified on @sunwaves_token! Find me as "{{.Username}}".

✨ Innovating the festival experience with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
⭐ I've officially joined @sunwaves_token as "{{.Username}}".

✨ Enhancing festival magic within the #ION ecosystem with @ice_blockchain.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
💡 Proud to be on @sunwaves_token as "{{.Username}}".

🚀 Redefining festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎉 My @sunwaves_token account is live as "{{.Username}}".

✨ Transforming the festival scene with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌟 Verified on @sunwaves_token! Username: "{{.Username}}".

🚀 Elevating festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
💥 Excited to announce my verification on @sunwaves_token as "{{.Username}}".

✨ Innovating the festival experience with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🌐 Proud to be verified on @sunwaves_token as "{{.Username}}".

🚀 Redefining the festival scene with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎵 Verified on @sunwaves_token! Connect with me as "{{.Username}}".

🤩 Taking festivals to new heights with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🎊 My @sunwaves_token account is now live as "{{.Username}}".

✨ Elevating festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🔓 Verified on @sunwaves_token! Find me as "{{.Username}}".

🚀 Transforming the festival scene with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
📢 Officially on @sunwaves_token as "{{.Username}}".

🌐 Innovating festivals with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
🔑 Proud to be verified on @sunwaves_token as "{{.Username}}".

✨ Elevating the festival experience with @ice_blockchain in the #ION ecosystem.

https://sunwavestoken.com/@{{.Username}}

#SUNWAVES $SW $ICE
Loading
Loading