1
1
package commands
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"fmt"
6
7
"time"
@@ -42,13 +43,16 @@ func (c *Commands) Decode(data discord.SlashCommandInteractionData, e *handler.C
42
43
if version > 0 {
43
44
content += fmt .Sprintf ("track was encoded with version: `%d`\n " , version )
44
45
}
46
+ var decodedData []byte
45
47
if decoded != nil {
46
- decodedData , _ := json .MarshalIndent (decoded , "" , " " )
47
- content += fmt .Sprintf ("```json\n %s\n ```" , decodedData )
48
+ decodedData , _ = json .MarshalIndent (decoded , "" , " " )
48
49
}
49
50
51
+ msg := jsonMessage (content , decodedData )
52
+
50
53
return e .CreateMessage (discord.MessageCreate {
51
- Content : content ,
54
+ Content : msg .Content ,
55
+ Files : msg .Files ,
52
56
})
53
57
}
54
58
@@ -66,16 +70,36 @@ func (c *Commands) Decode(data discord.SlashCommandInteractionData, e *handler.C
66
70
return err
67
71
}
68
72
69
- decodedData , err := json .MarshalIndent (decoded , "" , " " )
70
- if err != nil {
71
- _ , err = e .UpdateInteractionResponse (discord.MessageUpdate {
72
- Content : json .Ptr (fmt .Sprintf ("failed to decode track: %s" , err )),
73
- })
74
- return err
75
- }
73
+ decodedData , _ := json .MarshalIndent (decoded , "" , " " )
74
+
75
+ msg := jsonMessage ("" , decodedData )
76
76
77
77
_ , err = e .UpdateInteractionResponse (discord.MessageUpdate {
78
- Content : json .Ptr (fmt .Sprintf ("```json\n %s\n ```" , decodedData )),
78
+ Content : & msg .Content ,
79
+ Files : msg .Files ,
79
80
})
80
81
return err
81
82
}
83
+
84
+ type message struct {
85
+ Content string
86
+ Files []* discord.File
87
+ }
88
+
89
+ func jsonMessage (msg string , jsonData []byte ) message {
90
+ var (
91
+ content string
92
+ files []* discord.File
93
+ )
94
+
95
+ if len ([]rune (msg ))+ len (jsonData ) > 2020 {
96
+ content = msg
97
+ files = append (files , discord .NewFile ("track.json" , "" , bytes .NewReader (jsonData )))
98
+ } else {
99
+ content = fmt .Sprintf ("%s\n \n ```json\n %s\n ```" , msg , jsonData )
100
+ }
101
+ return message {
102
+ Content : content ,
103
+ Files : files ,
104
+ }
105
+ }
0 commit comments