Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit ebbec9e

Browse files
committed
v0.2.0
Added: - Mentions in html Fixed: - Not escaped html tags - Filenames in html are now working - Less panics now Changed: - go fmt-ed the who project - more margin between usename and text in html - Adding more logging info
1 parent 8abbd79 commit ebbec9e

File tree

24 files changed

+457
-366
lines changed

24 files changed

+457
-366
lines changed

components/main.go

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package components
22

33
import (
44
"fmt"
5+
"html/template"
56
"io/ioutil"
67
"math"
78
"os"
@@ -18,10 +19,10 @@ func preParseHTML(html string) string {
1819
}
1920

2021
func (theme Theme) parseComponent(component string) string {
21-
comp, err := ioutil.ReadFile(filepath.Join(theme.ThemeDir, "components", component + ".html"))
22+
comp, err := ioutil.ReadFile(filepath.Join(theme.ThemeDir, "components", component+".html"))
2223

2324
if os.IsNotExist(err) {
24-
baseComp, err := ioutil.ReadFile(filepath.Join(theme.BaseCss, "components", component + ".html"))
25+
baseComp, err := ioutil.ReadFile(filepath.Join(theme.BaseCss, "components", component+".html"))
2526
tools.PanicIfErr(err)
2627
comp = baseComp
2728
} else {
@@ -37,18 +38,17 @@ func (theme *Theme) LoadTheme(themeName string, DW_MEDIA bool) {
3738
} else {
3839
tools.PanicIfErr(err)
3940
}
40-
41+
4142
themeDir := filepath.Join("themes", themeName)
42-
43-
43+
4444
themeLoc, err := os.Stat(themeDir)
45-
45+
4646
if os.IsNotExist(err) || !themeLoc.IsDir() {
4747
panic("Cannot find theme!")
4848
} else {
4949
tools.PanicIfErr(err)
5050
}
51-
51+
5252
theme.ThemeDir = themeDir
5353
theme.BaseCss = filepath.Join("themes", "base")
5454

@@ -67,6 +67,7 @@ func (theme *Theme) LoadTheme(themeName string, DW_MEDIA bool) {
6767
theme.REPLY = theme.parseComponent("reply")
6868
theme.GIF = theme.parseComponent("gifs")
6969
theme.OTHER_MIME = theme.parseComponent("otherMime")
70+
theme.MENTION = theme.parseComponent("mention")
7071

7172
theme.DownloadMedia = DW_MEDIA
7273
}
@@ -77,10 +78,13 @@ var tabReg = regexp.MustCompile(`\t`)
7778

7879
func (theme Theme) MessageComponent(msg discord.Message, previousMsg discord.Message, firstMsg bool) string {
7980
content := msg.Content
80-
content = newLineReg.ReplaceAllString(content, "<br />")
8181

8282
attachContent := ""
8383

84+
content = template.HTMLEscapeString(content)
85+
86+
content = newLineReg.ReplaceAllString(content, "<br />")
87+
8488
for _, attach := range msg.Attachments {
8589
if attach.ContentType[:5] == "image" {
8690
mediaUrl := attach.Url
@@ -89,24 +93,24 @@ func (theme Theme) MessageComponent(msg discord.Message, previousMsg discord.Mes
8993
}
9094
attachContent += tools.ParseTemplate(theme.IMG, map[string]string{
9195
"IMG_URL": mediaUrl,
92-
"WIDTH": fmt.Sprint(math.Floor(0.8*float64(attach.Width))),
93-
"HEIGHT": fmt.Sprint(math.Floor(0.8*float64(attach.Height))),
96+
"WIDTH": fmt.Sprint(math.Floor(0.8 * float64(attach.Width))),
97+
"HEIGHT": fmt.Sprint(math.Floor(0.8 * float64(attach.Height))),
9498
})
9599
} else {
96100
attachContent += tools.ParseTemplate(theme.OTHER_MIME, map[string]string{
97-
"FILENAME": attach.MediaName(),
101+
"FILENAME": attach.Name,
98102
})
99103
}
100104
}
101-
105+
102106
gifContents := ""
103107

104108
for _, embed := range msg.Embeds {
105109
if embed.Type == discord.EMBED_GIF {
106110
gifContents += tools.ParseTemplate(theme.GIF, map[string]string{
107111
"VIDEO_URL": embed.Url,
108-
"WIDTH": fmt.Sprint(float64(embed.Thumbnail.Width)*0.7),
109-
"HEIGHT": fmt.Sprint(float64(embed.Thumbnail.Height)*0.7),
112+
"WIDTH": fmt.Sprint(float64(embed.Thumbnail.Width) * 0.7),
113+
"HEIGHT": fmt.Sprint(float64(embed.Thumbnail.Height) * 0.7),
110114
})
111115
if msg.Content == embed.GifContentUrl {
112116
content = ""
@@ -125,35 +129,44 @@ func (theme Theme) MessageComponent(msg discord.Message, previousMsg discord.Mes
125129
if msg.IsSystemType {
126130
return "TODO:"
127131
} else {
132+
for _, mention := range msg.Mentions {
133+
idReg := regexp.MustCompile(fmt.Sprintf(`&lt;@!?%v&gt;`, mention.ID))
134+
content = idReg.ReplaceAllString(content, tools.ParseTemplate(theme.MENTION, map[string]string{
135+
"MENTION_NAME": mention.Name,
136+
"MENTION_PREFIX": "@",
137+
}))
138+
}
139+
128140
if firstMsg {
129141
replyContent := ""
142+
130143
if msg.IsReply {
131144
replyContent = tools.ParseTemplate(theme.REPLY, map[string]string{
132-
"PFP": msg.ReplyTo.Author.URL(16),
133-
"NAME": msg.ReplyTo.Author.Name,
145+
"PFP": msg.ReplyTo.Author.URL(16),
146+
"NAME": msg.ReplyTo.Author.Name,
134147
"CONTENT": msg.ReplyTo.Content,
135148
})
136149
}
137-
150+
138151
return tools.ParseTemplate(theme.MSG_WITH_PFP, map[string]string{
139-
"PFP": msg.Author.URL(256),
140-
"USERNAME": msg.Author.Name,
141-
"DATE": discord.TimestampToTime(msg.Timestamp).Format("Mon 02/01/2006 03:04:05 PM"),
142-
"CONTENT": content,
143-
"ATTACH_CONTENT": attachContent,
144-
"ID": msg.ID,
145-
"REPLY_CONTENT": replyContent,
152+
"PFP": msg.Author.URL(256),
153+
"USERNAME": msg.Author.Name,
154+
"DATE": discord.TimestampToTime(msg.Timestamp).Format("Mon 02/01/2006 03:04:05 PM"),
155+
"CONTENT": content,
156+
"ATTACH_CONTENT": attachContent,
157+
"ID": msg.ID,
158+
"REPLY_CONTENT": replyContent,
146159
"STICKER_CONTENT": stickerContent,
147-
"GIFS": gifContents,
160+
"GIFS": gifContents,
148161
})
149162
} else {
150163
return tools.ParseTemplate(theme.MSG, map[string]string{
151-
"DATE": discord.TimestampToTime(msg.Timestamp).Format("15:04"),
152-
"CONTENT": content,
153-
"ATTACH_CONTENT": attachContent,
154-
"ID": msg.ID,
164+
"DATE": discord.TimestampToTime(msg.Timestamp).Format("15:04"),
165+
"CONTENT": content,
166+
"ATTACH_CONTENT": attachContent,
167+
"ID": msg.ID,
155168
"STICKER_CONTENT": stickerContent,
156-
"GIFS": gifContents,
169+
"GIFS": gifContents,
157170
})
158171
}
159172
}
@@ -175,37 +188,37 @@ func (theme Theme) TopBar(title string, channelType discord.ChannelType) string
175188
icon := ""
176189

177190
switch channelType {
178-
case discord.CHANNEL_TYPE_DM:
179-
icon = theme.SVG_DM
180-
case discord.CHANNEL_TYPE_GROUP_DM:
181-
icon = theme.SVG_GROUP_DM
182-
default:
183-
icon = theme.SVG_CHANNEL
191+
case discord.CHANNEL_TYPE_DM:
192+
icon = theme.SVG_DM
193+
case discord.CHANNEL_TYPE_GROUP_DM:
194+
icon = theme.SVG_GROUP_DM
195+
default:
196+
icon = theme.SVG_CHANNEL
184197
}
185-
198+
186199
return tools.ParseTemplate(theme.TOP_BAR, map[string]string{
187-
"ICON": icon,
200+
"ICON": icon,
188201
"TITLE": title,
189202
})
190203
}
191204

192205
func (theme Theme) StartDM(author discord.Author) string {
193206
return tools.ParseTemplate(theme.START_CHAN, map[string]string{
194207
"TITLE": author.Name,
195-
"ICON": author.URL(512),
208+
"ICON": author.URL(512),
196209
})
197210
}
198211

199212
func (theme Theme) StartChannel(channel discord.Channel) string {
200213
return tools.ParseTemplate(theme.START_CHAN, map[string]string{
201214
"TITLE": "Welcome to #" + channel.Name,
202-
"ICON": "assets/channelStart.png",
215+
"ICON": "assets/channelStart.png",
203216
})
204217
}
205218

206219
func (theme Theme) StartGroupDM(groupDM discord.Channel) string {
207220
return tools.ParseTemplate(theme.START_CHAN, map[string]string{
208221
"TITLE": groupDM.Name,
209-
"ICON": groupDM.Icon,
222+
"ICON": groupDM.Icon,
210223
})
211224
}

components/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Theme struct {
1818
STICKER,
1919
GIF,
2020
OTHER_MIME,
21+
MENTION,
2122
IMG string
2223
DownloadMedia bool
2324
}
@@ -30,4 +31,4 @@ type SystemMsgs struct {
3031
ICON_CH,
3132
PIN,
3233
MEM_JOIN string
33-
}
34+
}

config/autoDarwin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func (mask *HeadersMask) Auto() {
2424
tools.PanicIfErr(err)
2525
mask.PullDiscordVers(homeDir + "/Library/Application Support")
2626
mask.UserAgent = fmt.Sprintf("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) discord/%v Chrome/91.0.4472.164 Electron/13.4.0 Safari/537.36", mask.DiscordVersion)
27-
27+
2828
releaseChan := "stable"
2929

3030
if mask.UseCanary {
3131
releaseChan = "canary"
3232
}
33-
33+
3434
cmd := exec.Command("uname", "-r")
3535
osVersion, err := cmd.Output()
3636
tools.PanicIfErr(err)
@@ -44,4 +44,4 @@ func (mask *HeadersMask) Auto() {
4444
mask.PullBuildId(),
4545
)
4646
mask.EncodeSuperProps()
47-
}
47+
}

config/autoLinux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ func (mask *HeadersMask) Auto() {
2828

2929
mask.PullDiscordVers(homeDir + "/.config")
3030
mask.UserAgent = fmt.Sprintf("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) discord/%v Chrome/91.0.4472.164 Electron/13.6.6 Safari/537.36", mask.DiscordVersion)
31-
31+
3232
releaseChan := "stable"
3333

3434
if mask.UseCanary {
3535
releaseChan = "canary"
3636
}
37-
37+
3838
cmd := exec.Command("uname", "-r")
3939
osVersion, err := cmd.Output()
4040
tools.PanicIfErr(err)
@@ -49,7 +49,7 @@ func (mask *HeadersMask) Auto() {
4949
} else {
5050
winMgr += ","
5151
}
52-
52+
5353
osInfo, err := ioutil.ReadFile("/etc/os-release")
5454
tools.PanicIfErr(err)
5555
distro := ""
@@ -66,7 +66,7 @@ func (mask *HeadersMask) Auto() {
6666
}
6767

6868
mask.SuperProperties = fmt.Sprintf(
69-
`{"os":"Linux","browser":"Discord Client","release_channel":"%v","client_version":"%v","os_version":"%v","os_arch":"x64","system_locale":"%v","window_manager":"%vunknown","distro":"%v","client_build_number":%v,"client_event_source":null}`,
69+
`{"os":"Linux","browser":"Discord Client","release_channel":"%v","client_version":"%v","os_version":"%v","os_arch":"x64","system_locale":"%v","window_manager":"%vunknown","distro":"%v","client_build_number":%v,"client_event_source":null}`,
7070
releaseChan,
7171
mask.DiscordVersion,
7272
osVer,
@@ -76,4 +76,4 @@ func (mask *HeadersMask) Auto() {
7676
mask.PullBuildId(),
7777
)
7878
mask.EncodeSuperProps()
79-
}
79+
}

config/autoTools.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func (mask *HeadersMask) PullDiscordVers(discordPath string) {
1616
dExist := true
1717
normalD, err := ioutil.ReadDir(filepath.Join(discordPath, "discord"))
18-
18+
1919
if os.IsNotExist(err) {
2020
dExist = false
2121
} else {
@@ -24,7 +24,7 @@ func (mask *HeadersMask) PullDiscordVers(discordPath string) {
2424

2525
dCExist := true
2626
normalCD, err := ioutil.ReadDir(filepath.Join(discordPath, "discordcanary"))
27-
27+
2828
if os.IsNotExist(err) {
2929
dCExist = false
3030
} else {
@@ -42,7 +42,7 @@ func (mask *HeadersMask) PullDiscordVers(discordPath string) {
4242
fmt.Println("Warning! Canary discord found but stable not found, and the preferance is for stable! We will be using true for USE_CANARY for this download")
4343
mask.UseCanary = true
4444
}
45-
45+
4646
if mask.UseCanary {
4747
mask.DomainPrefix = "canary."
4848
}
@@ -52,7 +52,7 @@ func (mask *HeadersMask) PullDiscordVers(discordPath string) {
5252
if mask.UseCanary {
5353
discordFiles = normalCD
5454
}
55-
55+
5656
for _, fileInfo := range discordFiles {
5757
if !fileInfo.IsDir() {
5858
continue
@@ -78,20 +78,20 @@ func (mask HeadersMask) PullBuildId() string {
7878
resp, err := ioutil.ReadAll(respRaw.Body)
7979
tools.PanicIfErr(err)
8080
assets := discordAssetReg.FindAll(resp, 50)
81-
buildFileRaw, err := http.Get(fmt.Sprintf("https://%vdiscord.com/%v", mask.DomainPrefix, string(assets[len(assets) - 2])))
81+
buildFileRaw, err := http.Get(fmt.Sprintf("https://%vdiscord.com/%v", mask.DomainPrefix, string(assets[len(assets)-2])))
8282
tools.PanicIfErr(err)
8383
buildFile, err := ioutil.ReadAll(buildFileRaw.Body)
8484
tools.PanicIfErr(err)
85-
85+
8686
buildFileS := string(buildFile)
8787

8888
buildLoc := buildNumReg.FindStringIndex(buildFileS)
89-
89+
9090
if len(buildLoc) == 0 {
9191
panic("Build num not located! Auto loading has failed :(")
9292
}
9393

94-
return buildFileS[buildLoc[1]+3:buildLoc[1]+9]
94+
return buildFileS[buildLoc[1]+3 : buildLoc[1]+9]
9595
}
9696

9797
func (mask *HeadersMask) EncodeSuperProps() {
@@ -100,4 +100,4 @@ func (mask *HeadersMask) EncodeSuperProps() {
100100

101101
var localeReg = regexp.MustCompile(`.._..`)
102102
var versionReg = regexp.MustCompile(`\d+\.\d+\.\d+`)
103-
var quotesReg = regexp.MustCompile(`"`)
103+
var quotesReg = regexp.MustCompile(`"`)

config/autoWindows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package config
44

55
import (
66
"fmt"
7-
"os/exec"
87
"os"
8+
"os/exec"
99

1010
"github.com/ShadiestGoat/DiscordChatExporter/tools"
1111
"golang.org/x/sys/windows/registry"
@@ -49,4 +49,4 @@ func (mask *HeadersMask) Auto() {
4949
mask.Locale,
5050
mask.PullBuildId(),
5151
)
52-
}
52+
}

0 commit comments

Comments
 (0)