Skip to content

Commit bb0c8d0

Browse files
authored
Disabled html escaping (#7)
1 parent 350ac69 commit bb0c8d0

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

commands/decode.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (c *Commands) Decode(data discord.SlashCommandInteractionData, e *handler.C
4545
}
4646
var decodedData []byte
4747
if decoded != nil {
48-
decodedData, _ = json.MarshalIndent(decoded, "", " ")
48+
decodedData = MarshalNoEscape(decoded)
4949
}
5050

5151
msg := jsonMessage(content, decodedData)
@@ -70,7 +70,7 @@ func (c *Commands) Decode(data discord.SlashCommandInteractionData, e *handler.C
7070
return err
7171
}
7272

73-
decodedData, _ := json.MarshalIndent(decoded, "", " ")
73+
decodedData := MarshalNoEscape(decoded)
7474

7575
msg := jsonMessage("", decodedData)
7676

@@ -103,3 +103,12 @@ func jsonMessage(msg string, jsonData []byte) message {
103103
Files: files,
104104
}
105105
}
106+
107+
func MarshalNoEscape(v any) []byte {
108+
b := new(bytes.Buffer)
109+
e := json.NewEncoder(b)
110+
e.SetEscapeHTML(false)
111+
e.SetIndent("", " ")
112+
_ = e.Encode(v)
113+
return b.Bytes()
114+
}

commands/info.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/disgoorg/disgo/handler"
1010
"github.com/disgoorg/disgolink/v3/disgolink"
1111
"github.com/disgoorg/disgolink/v3/lavalink"
12-
"github.com/disgoorg/json"
1312
)
1413

1514
var info = discord.SlashCommandCreate{
@@ -75,12 +74,7 @@ func (c *Commands) InfoLavalink(data discord.SlashCommandInteractionData, e *han
7574
nodeInfos[node.Config().Name] = *nodeInfo
7675
})
7776

78-
rawInfo, err := json.MarshalIndent(nodeInfos, "", " ")
79-
if err != nil {
80-
return e.CreateMessage(discord.MessageCreate{
81-
Content: "Failed to marshal lavalink info: " + err.Error(),
82-
})
83-
}
77+
rawInfo := MarshalNoEscape(nodeInfos)
8478

8579
return e.CreateMessage(discord.MessageCreate{
8680
Embeds: []discord.Embed{

commands/now_playing.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/disgoorg/disgo/discord"
88
"github.com/disgoorg/disgo/handler"
9-
"github.com/disgoorg/json"
109

1110
"github.com/lavalink-devs/lavalink-bot/internal/res"
1211
)
@@ -32,13 +31,7 @@ func (c *Commands) NowPlaying(data discord.SlashCommandInteractionData, e *handl
3231

3332
var files []*discord.File
3433
if data.Bool("raw") {
35-
decodedData, err := json.MarshalIndent(track, "", " ")
36-
if err != nil {
37-
return e.CreateMessage(discord.MessageCreate{
38-
Content: fmt.Sprintf("Failed to marshal track: %s", err),
39-
Flags: discord.MessageFlagEphemeral,
40-
})
41-
}
34+
decodedData := MarshalNoEscape(track)
4235
files = append(files, &discord.File{
4336
Name: "track.json",
4437
Reader: bytes.NewReader(decodedData),

commands/resolve.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,7 @@ func (c *Commands) Resolve(data discord.SlashCommandInteractionData, e *handler.
4949
)
5050
switch result.LoadType {
5151
case lavalink.LoadTypeTrack, lavalink.LoadTypePlaylist, lavalink.LoadTypeSearch:
52-
decodedData, err := json.MarshalIndent(result.Data, "", " ")
53-
if err != nil {
54-
_, err = e.UpdateInteractionResponse(discord.MessageUpdate{
55-
Content: json.Ptr(fmt.Sprintf("failed to resolve identifier: %s", err)),
56-
})
57-
return err
58-
}
52+
decodedData := MarshalNoEscape(result.Data)
5953

6054
if len(decodedData) > 1900 {
6155
files = append(files, &discord.File{

0 commit comments

Comments
 (0)