-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from AlexPresso/prepare_v1
Zunivers v1.0 changes
- Loading branch information
Showing
11 changed files
with
98 additions
and
19 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
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
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,17 @@ | ||
package structures | ||
|
||
import "gorm.io/gorm" | ||
|
||
type ChallengeProgress struct { | ||
Challenge *Challenge `json:"challenge"` | ||
} | ||
|
||
type Challenge struct { | ||
gorm.Model | ||
|
||
ChallengeID string `json:"id"` | ||
Description string `json:"description" zu:"display=Description"` | ||
RewardLoreDust uint32 `json:"rewardLoreDust" zu:"display=Poussière de lore"` | ||
Score uint32 `json:"score" zu:"display=Score"` | ||
Type string `json:"type" zu:"display=Type"` | ||
} |
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
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,45 @@ | ||
package tasks | ||
|
||
import ( | ||
"github.com/alexpresso/zunivers-webhooks/services" | ||
"github.com/alexpresso/zunivers-webhooks/structures" | ||
"github.com/alexpresso/zunivers-webhooks/structures/discord" | ||
"github.com/alexpresso/zunivers-webhooks/utils" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func checkChallenges(db *gorm.DB, embeds *[]discord.Embed) { | ||
chProgress, err := services.FetchChallenges() | ||
if err != nil { | ||
utils.Log("An error occurred while fetching challenges: " + err.Error()) | ||
return | ||
} | ||
|
||
var challenges []*structures.Challenge | ||
var dbChallenges []structures.Challenge | ||
dbChallengesMap := make(map[string]*structures.Challenge) | ||
|
||
db.Find(&dbChallenges) | ||
for _, chall := range dbChallenges { | ||
chall := chall | ||
dbChallengesMap[chall.ChallengeID] = &chall | ||
} | ||
|
||
for i := 0; i < len(chProgress); i++ { | ||
challenge := &chProgress[i].Challenge | ||
challenges = append(challenges, *challenge) | ||
dbChallenge := dbChallengesMap[(*challenge).ChallengeID] | ||
|
||
if dbChallenge != nil { | ||
(*challenge).ID = dbChallenge.ID | ||
|
||
if utils.AreDifferent(**challenge, *dbChallenge) { | ||
*embeds = append(*embeds, *services.MakeEmbed("challenge_changed", *dbChallenge, **challenge)) | ||
} | ||
} else if len(dbChallengesMap) > 0 { | ||
*embeds = append(*embeds, *services.MakeEmbed("new_challenge", nil, **challenge)) | ||
} | ||
} | ||
|
||
db.Save(&challenges) | ||
} |
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