-
Notifications
You must be signed in to change notification settings - Fork 13
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
18 changed files
with
61 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"sort" | ||
|
||
"github.com/kehiy/RoboPac/discord" | ||
) | ||
|
||
func main() { | ||
referrals, err := LoadReferralData("./referral.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
sort.Slice(referrals, func(i, j int) bool { // sort referrals based on points in descending order | ||
return referrals[i].Points > referrals[j].Points | ||
}) | ||
|
||
top10 := [10]discord.Referral{} | ||
for i, r := range referrals { | ||
if i >= 10 { | ||
break | ||
} | ||
top10[i] = r | ||
} | ||
|
||
data, err := json.Marshal(top10) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = os.WriteFile("top10.json", data, 0o600) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func LoadReferralData(path string) ([]discord.Referral, error) { | ||
file, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
referrals := map[string]discord.Referral{} | ||
err = json.Unmarshal(file, &referrals) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result := []discord.Referral{} | ||
for _, r := range referrals { | ||
result = append(result, r) | ||
} | ||
|
||
return result, nil | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.