Skip to content

Commit b2a0439

Browse files
committed
fix user ids too long
1 parent 8b67141 commit b2a0439

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

almanax.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ func handleCreateAlmanax(w http.ResponseWriter, r *http.Request) {
298298
return
299299
}
300300
}
301-
requestedMentions[bonusId].Add(mention.DiscordId)
301+
discordId, err := mention.DiscordId.Int64()
302+
if err != nil {
303+
http.Error(w, "Invalid discord id.", http.StatusBadRequest)
304+
return
305+
}
306+
requestedMentions[bonusId].Add(uint64(discordId))
302307
}
303308
}
304309
}
@@ -935,7 +940,11 @@ func buildDiscordHookAlmanax(almanaxSend AlmanaxSend) ([]PreparedHook, error) {
935940
if mentions, ok := hookMentions[almBonusType.GetId()]; ok {
936941
var mentionStrings []string
937942
for _, mention := range mentions {
938-
idStr := strconv.FormatUint(mention.DiscordId, 10)
943+
discordId, err := mention.DiscordId.Int64()
944+
if err != nil {
945+
return nil, err
946+
}
947+
idStr := strconv.FormatInt(discordId, 10)
939948
found := false
940949
for _, alreadyInsertedMention := range mentionStrings {
941950
if strings.Contains(alreadyInsertedMention, idStr) {
@@ -973,7 +982,11 @@ func buildDiscordHookAlmanax(almanaxSend AlmanaxSend) ([]PreparedHook, error) {
973982

974983
var mentionStrings []string
975984
for _, mention := range mentions {
976-
idStr := strconv.FormatUint(mention.DiscordId, 10)
985+
discordId, err := mention.DiscordId.Int64()
986+
if err != nil {
987+
return nil, err
988+
}
989+
idStr := strconv.FormatInt(discordId, 10)
977990
if mention.IsRole {
978991
mentionStrings = append(mentionStrings, "<@&"+idStr+">")
979992
} else {

almanax_test.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log"
78
"net/http"
@@ -370,11 +371,11 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_Mentions() {
370371
Mentions: &map[string][]MentionDTO{
371372
"loot": {
372373
MentionDTO{
373-
DiscordId: 123,
374+
DiscordId: json.Number("123"),
374375
IsRole: false,
375376
},
376377
MentionDTO{
377-
DiscordId: 124,
378+
DiscordId: json.Number("124"),
378379
IsRole: true,
379380
},
380381
},
@@ -417,13 +418,13 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_Mentions() {
417418
Mentions: &map[string][]MentionDTO{
418419
"loot": {
419420
MentionDTO{
420-
DiscordId: 123,
421+
DiscordId: json.Number("666555333222111444"),
421422
IsRole: false,
422423
},
423424
},
424425
"rewardbonus": {
425426
MentionDTO{
426-
DiscordId: 123,
427+
DiscordId: json.Number("123"),
427428
IsRole: true,
428429
},
429430
},
@@ -433,7 +434,7 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_Mentions() {
433434
Expect(suite.T()).
434435
Status(http.StatusCreated).
435436
Assert(jsonpath.Chain().
436-
Equal("$.mentions.loot[0].discord_id", float64(123)).
437+
Equal("$.mentions.loot[0].discord_id", float64(666555333222111444)).
437438
Equal("$.mentions.loot[0].is_role", false).
438439
Equal("$.mentions.rewardbonus[0].discord_id", float64(123)).
439440
Equal("$.mentions.rewardbonus[0].is_role", true).
@@ -454,14 +455,14 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_Mentions() {
454455
Mentions: &map[string][]MentionDTO{
455456
"loot": {
456457
MentionDTO{
457-
DiscordId: 123,
458+
DiscordId: json.Number("123"),
458459
IsRole: false,
459460
PingDaysBefore: &pingDaysAhead,
460461
},
461462
},
462463
"rewardbonus": {
463464
MentionDTO{
464-
DiscordId: 123,
465+
DiscordId: json.Number("123"),
465466
IsRole: true,
466467
},
467468
},
@@ -494,11 +495,11 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Delete() {
494495
Mentions: &map[string][]MentionDTO{
495496
"loot": {
496497
MentionDTO{
497-
DiscordId: 123,
498+
DiscordId: json.Number("123"),
498499
IsRole: false,
499500
},
500501
MentionDTO{
501-
DiscordId: 124,
502+
DiscordId: json.Number("124"),
502503
IsRole: true,
503504
},
504505
},
@@ -649,11 +650,11 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_Intervals_And_Update() {
649650
Mentions: &map[string][]MentionDTO{
650651
"loot": {
651652
MentionDTO{
652-
DiscordId: 123,
653+
DiscordId: json.Number("123"),
653654
IsRole: false,
654655
},
655656
MentionDTO{
656-
DiscordId: 124,
657+
DiscordId: json.Number("124"),
657658
IsRole: true,
658659
},
659660
},
@@ -765,11 +766,11 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_And_Update() {
765766
Mentions: &map[string][]MentionDTO{
766767
"loot": {
767768
MentionDTO{
768-
DiscordId: 123,
769+
DiscordId: json.Number("123"),
769770
IsRole: false,
770771
},
771772
MentionDTO{
772-
DiscordId: 124,
773+
DiscordId: json.Number("124"),
773774
IsRole: true,
774775
},
775776
},
@@ -956,7 +957,7 @@ func (suite *AlmanaxTestSuite) Test_CRUD_Create_And_Update() {
956957
Mentions: &map[string][]MentionDTO{
957958
"loot": {
958959
{
959-
DiscordId: 42,
960+
DiscordId: json.Number("42"),
960961
IsRole: false,
961962
},
962963
},
@@ -1002,11 +1003,11 @@ func (suite *AlmanaxTestSuite) Test_GetFeeds() {
10021003
Mentions: &map[string][]MentionDTO{
10031004
"loot": {
10041005
MentionDTO{
1005-
DiscordId: 123,
1006+
DiscordId: json.Number("123"),
10061007
IsRole: false,
10071008
},
10081009
MentionDTO{
1009-
DiscordId: 124,
1010+
DiscordId: json.Number("124"),
10101011
IsRole: true,
10111012
},
10121013
},

types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"time"
56

67
"github.com/dofusdude/dodugo"
@@ -519,9 +520,9 @@ type SocialHookCreate struct {
519520
}
520521

521522
type MentionDTO struct {
522-
DiscordId uint64 `json:"discord_id"`
523-
IsRole bool `json:"is_role"`
524-
PingDaysBefore *int `json:"ping_days_before"`
523+
DiscordId json.Number `json:"discord_id"`
524+
IsRole bool `json:"is_role"`
525+
PingDaysBefore *int `json:"ping_days_before"`
525526
}
526527

527528
type AlmanaxHookPut struct {

0 commit comments

Comments
 (0)