Skip to content

Commit

Permalink
Merge pull request #9 from AlexPresso/prepare_v1
Browse files Browse the repository at this point in the history
Zunivers v1.0 changes
  • Loading branch information
AlexPresso authored Mar 22, 2022
2 parents 7aa491d + 437ede7 commit 0a425c2
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 19 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ This project is not affiliated with the ZUnivers's project. It's a community pro
## Features

-`!daily` reminder
- ✅ Notify for new patchnotes
- ✅ Notify for configuration changes
- ✅ Notify for new webapp versions
- ✅ Notify for new items/item changes
- ✅ Notify for new packs/packs changes
- ✅ Notify for new banners/banners changes
- ✅ Notify for new "ascension" season
- ✅ Notify for new event/events changes
- ✅ Notify for new achievements/achievements changes
- ✅ Notifies for new patchnotes
- ✅ Notifies for configuration changes
- ✅ Notifies for new webapp versions
- ✅ Notifies for new items/item changes
- ✅ Notifies for new packs/packs changes
- ✅ Notifies for new banners/banners changes
- ✅ Notifies for new "ascension" season
- ✅ Notifies for new event/events changes
- ✅ Notifies for new achievements/achievements changes
- ✅ Notifies for new challenges
- ✅ Multiple webhooks dispatching

## Usage
Expand Down
6 changes: 4 additions & 2 deletions config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
"new_banner": "Une nouvelle bannière a été ajoutée !",
"banner_changed": "Une bannière a été modifiée !",
"new_event": "Un nouvel event a débuté !",
"event_changed": "Un event a été modifié",
"event_changed": "Un event a été modifié3",
"event_removed": "Un event s'est terminé.",
"new_achievement_category": "Une catégorie de succès a été ajoutée.",
"achievement_category_changed": "Une catégorie de succès a été modifiée.",
"new_achievement": "Un succès a été ajouté.",
"achievement_changed": "Un succès a été modifié."
"achievement_changed": "Un succès a été modifié.",
"challenge_changed": "Un challenge a été modifié.",
"new_challenge": "Un nouveau challenge a débuté3"
}
}
1 change: 1 addition & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Init() (db *gorm.DB) {
&structures.Event{},
&structures.AchievementCategory{},
&structures.Achievement{},
&structures.Challenge{},
)

if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions services/webhookService.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,25 @@ func fillEmbed(embed *discord.Embed, oldObject, newObject interface{}) {
}

func processDisplay(field *discord.EmbedField, oldValue, newValue interface{}, parts []string) {
split := strings.Split(parts[1], "|")
format := "`%v`"
if len(split) > 1 {
format = split[1]
}

oldValueText := ""
if oldValue != nil {
if utils.IsTime(oldValue) {
if utils.TimeDifference(oldValue, newValue) {
oldValueText = fmt.Sprintf("`%s` → ", fmt.Sprint(oldValue))
oldValueText = fmt.Sprintf("`%s` → ", fmt.Sprintf(format, oldValue))
}
} else if oldValue != newValue {
oldValueText = fmt.Sprintf("`%s` → ", fmt.Sprint(oldValue))
oldValueText = fmt.Sprintf("`%s` → ", fmt.Sprintf(format, oldValue))
}
}

field.Value += fmt.Sprintf("__%s:__ %s`%s`\n", parts[1], oldValueText, fmt.Sprint(newValue))
value := fmt.Sprintf("__%s:__ %s%s\n", split[0], oldValueText, fmt.Sprintf(format, newValue))
field.Value += value
}

func processImage(embed *discord.Embed, newValue interface{}, parts []string) {
Expand Down
5 changes: 5 additions & 0 deletions services/zuniversService.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ func FetchAchievements(categoryId string) (achProgress []structures.AchievementP
err = utils.Request("/public/achievement/Alex'Presso%235480/"+categoryId, "GET", nil, &achProgress)
return
}

func FetchChallenges() (chProgress []structures.ChallengeProgress, err error) {
err = utils.Request("/public/challenge", "GET", nil, &chProgress)
return
}
17 changes: 17 additions & 0 deletions structures/Challenge.go
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"`
}
2 changes: 1 addition & 1 deletion structures/Event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ type Event struct {
EndDate *DateTime `json:"endDate" zu:"display=Fin"`
ImageURL string `json:"imageUrl" zu:"imageUrl=%s"`
Name string `json:"name" zu:"display=Nom"`
BalanceCost int `json:"balanceCost" zu:"Coût im"`
BalanceCost int `json:"balanceCost" zu:"display=Coût d'invocation"`
}
4 changes: 2 additions & 2 deletions structures/Item.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ type Item struct {
Genre string `json:"genre" zu:"display=Genre"`
Name string `json:"name" zu:"display=Nom"`
Rarity uint32 `json:"rarity" zu:"display=Rareté"`
Slug string `json:"slug" zu:"url=/item/%s"`
Slug string `json:"slug" zu:"url=/carte/%s"`
}

type Pack struct {
gorm.Model

PackID string `json:"id"`
Name string `json:"name" zu:"display=Nom"`
Name string `json:"name" zu:"display=Nom;url=/catalogue/%s"`
}
4 changes: 2 additions & 2 deletions structures/Patchnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ type Patchnote struct {

PatchnoteID string `json:"id"`
Title string `json:"title" zu:"display=Titre"`
CreatedBy string `json:"createdBy" zu:"display=Auteur"`
CreatedBy string `json:"createdBy" zu:"display=Auteur|<@%s>"`
Date *DateTime `json:"date" zu:"display=Date"`
ImageUrl string `json:"imageUrl" zu:"imageUrl=%s"`
Slug string `json:"slug" zu:"url=/post/%s"`
Slug string `json:"slug" zu:"url=/actu/%s"`
}
45 changes: 45 additions & 0 deletions tasks/checkChallenges.go
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)
}
1 change: 1 addition & 0 deletions tasks/taskManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func checkInfos(db *gorm.DB) {
checkEvents(db, embeds)
checkAchievementCategories(db, embeds)
checkSeason(db, embeds)
checkChallenges(db, embeds)

utils.Log("Checked for infos.")

Expand Down

0 comments on commit 0a425c2

Please sign in to comment.