Skip to content

Commit 293352b

Browse files
committed
support new account discriminators
1 parent 2f43da4 commit 293352b

File tree

5 files changed

+126
-51
lines changed

5 files changed

+126
-51
lines changed

server/forum_indexer.go

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,92 @@ func (indexer *ForumIndexer) Close() {
4141
close(indexer.closeSignal)
4242
}
4343

44+
type ForumAccount struct {
45+
Username string
46+
Discriminator int
47+
}
48+
4449
func (indexer *ForumIndexer) run() {
4550
log.Info("starting forum indexer")
4651

47-
accounts := []string{
48-
"Chris", "Jonathan", "Erik", "Mark_GGG", "Samantha", "Rory", "Rhys", "Andrew_GGG",
49-
"Damien_GGG", "Joel_GGG", "Ari", "Thomas", "BrianWeissman", "Edwin_GGG", "Support", "Dylan",
50-
"MaxS", "Ammon_GGG", "Jess_GGG", "Robbie_GGG", "GGG_Neon", "Jason_GGG", "Henry_GGG",
51-
"Michael_GGG", "Bex_GGG", "Cagan_GGG", "Kieren_GGG", "Yeran_GGG", "Gary_GGG", "Dan_GGG",
52-
"Jared_GGG", "Brian_GGG", "RobbieL_GGG", "Arthur_GGG", "NickK_GGG", "Felipe_GGG",
53-
"Alex_GGG", "Alexcc_GGG", "Andy", "CJ_GGG", "Eben_GGG", "Emma_GGG", "Ethan_GGG",
54-
"Fitzy_GGG", "Hartlin_GGG", "Jake_GGG", "Melissa_GGG", "MikeP_GGG", "Novynn", "Rob_GGG",
55-
"Roman_GGG", "Tom_GGG", "Natalia_GGG", "Jeff_GGG", "Lu_GGG", "JuliaS_GGG", "Alexander_GGG",
56-
"SamC_GGG", "AndrewE_GGG", "Kyle_GGG", "Stacey_GGG", "Jatin_GGG", "Community_Team",
57-
"Nick_GGG", "Guy_GGG", "Ben_GGG", "BenH_GGG", "Nav_GGG", "Will_GGG", "Scott_GGG", "JC_GGG",
58-
"Dylan_GGG", "Chulainn_GGG", "Vash_GGG", "Cameron_GGG", "Jacob_GGG", "Jenn_GGG",
59-
"CoryA_GGG", "Sian_GGG", "Drew_GGG", "Lisa_GGG", "ThomasK_GGG", "Whai_GGG", "Scopey",
60-
"Adam_GGG", "Nichelle_GGG", "Markus_GGG",
52+
accounts := []ForumAccount{
53+
{Username: "Chris"},
54+
{Username: "Jonathan"},
55+
{Username: "Mark_GGG"},
56+
{Username: "Rory"},
57+
{Username: "Rhys"},
58+
{Username: "Joel_GGG"},
59+
{Username: "Ari"},
60+
{Username: "Thomas"},
61+
{Username: "Support"},
62+
{Username: "Jess_GGG"},
63+
{Username: "Robbie_GGG"},
64+
{Username: "GGG_Neon"},
65+
{Username: "Jason_GGG"},
66+
{Username: "Henry_GGG"},
67+
{Username: "Michael_GGG"},
68+
{Username: "Bex_GGG"},
69+
{Username: "Cagan_GGG"},
70+
{Username: "Kieren_GGG"},
71+
{Username: "Yeran_GGG"},
72+
{Username: "Gary_GGG"},
73+
{Username: "Dan_GGG"},
74+
{Username: "Jared_GGG"},
75+
{Username: "Brian_GGG"},
76+
{Username: "RobbieL_GGG"},
77+
{Username: "Arthur_GGG"},
78+
{Username: "NickK_GGG"},
79+
{Username: "Felipe_GGG"},
80+
{Username: "Alex_GGG"},
81+
{Username: "Alexcc_GGG"},
82+
{Username: "CJ_GGG"},
83+
{Username: "Eben_GGG"},
84+
{Username: "Emma_GGG"},
85+
{Username: "Ethan_GGG"},
86+
{Username: "Fitzy_GGG"},
87+
{Username: "Hartlin_GGG"},
88+
{Username: "Jake_GGG"},
89+
{Username: "Melissa_GGG"},
90+
{Username: "MikeP_GGG"},
91+
{Username: "Novynn"},
92+
{Username: "Rob_GGG"},
93+
{Username: "Roman_GGG"},
94+
{Username: "Tom_GGG"},
95+
{Username: "Natalia_GGG"},
96+
{Username: "Jeff_GGG"},
97+
{Username: "Lu_GGG"},
98+
{Username: "JuliaS_GGG"},
99+
{Username: "Alexander_GGG"},
100+
{Username: "SamC_GGG"},
101+
{Username: "AndrewE_GGG"},
102+
{Username: "Kyle_GGG"},
103+
{Username: "Stacey_GGG"},
104+
{Username: "Jatin_GGG"},
105+
{Username: "Community_Team"},
106+
{Username: "Nick_GGG"},
107+
{Username: "Guy_GGG"},
108+
{Username: "Ben_GGG"},
109+
{Username: "BenH_GGG"},
110+
{Username: "Nav_GGG"},
111+
{Username: "Will_GGG"},
112+
{Username: "Scott_GGG"},
113+
{Username: "JC_GGG"},
114+
{Username: "Dylan_GGG"},
115+
{Username: "Chulainn_GGG"},
116+
{Username: "Vash_GGG"},
117+
{Username: "Cameron_GGG"},
118+
{Username: "Jacob_GGG"},
119+
{Username: "Jenn_GGG"},
120+
{Username: "CoryA_GGG"},
121+
{Username: "Sian_GGG"},
122+
{Username: "Drew_GGG"},
123+
{Username: "Lisa_GGG"},
124+
{Username: "ThomasK_GGG"},
125+
{Username: "Whai_GGG"},
126+
{Username: "Scopey"},
127+
{Username: "Adam_GGG"},
128+
{Username: "Nichelle_GGG"},
129+
{Username: "Markus_GGG"},
61130
}
62131

63132
timezone := (*time.Location)(nil)
@@ -99,7 +168,7 @@ func (indexer *ForumIndexer) run() {
99168
return
100169
default:
101170
if err := indexer.index(account, timezone); err != nil {
102-
log.WithError(err).Error("error indexing forum account: " + account)
171+
log.WithError(err).Error("error indexing forum account: " + account.Username)
103172
}
104173
time.Sleep(time.Second)
105174
}
@@ -143,7 +212,7 @@ var postURLExpression = regexp.MustCompile("^/forum/view-post/([0-9]+)")
143212
var threadURLExpression = regexp.MustCompile("^/forum/view-thread/([0-9]+)")
144213
var forumURLExpression = regexp.MustCompile("^/forum/view-forum/([0-9]+)")
145214

146-
func ScrapeForumPosts(doc *goquery.Document, timezone *time.Location) ([]*ForumPost, error) {
215+
func ScrapeForumPosts(doc *goquery.Document, poster ForumAccount, timezone *time.Location) ([]*ForumPost, error) {
147216
posts := []*ForumPost(nil)
148217

149218
err := error(nil)
@@ -154,7 +223,8 @@ func ScrapeForumPosts(doc *goquery.Document, timezone *time.Location) ([]*ForumP
154223

155224
doc.Find(".forumPostListTable > tbody > tr").EachWithBreak(func(i int, sel *goquery.Selection) bool {
156225
post := &ForumPost{
157-
Poster: sel.Find(".post_by_account").Text(),
226+
Poster: poster.Username,
227+
PosterDiscriminator: poster.Discriminator,
158228
}
159229

160230
body, err := sel.Find(".content").Html()
@@ -197,19 +267,19 @@ func ScrapeForumPosts(doc *goquery.Document, timezone *time.Location) ([]*ForumP
197267
return posts, nil
198268
}
199269

200-
func (indexer *ForumIndexer) forumPosts(poster string, page int, timezone *time.Location) ([]*ForumPost, error) {
201-
doc, err := indexer.requestDocument(fmt.Sprintf("/account/view-posts/%v/page/%v", poster, page))
270+
func (indexer *ForumIndexer) forumPosts(poster ForumAccount, page int, timezone *time.Location) ([]*ForumPost, error) {
271+
doc, err := indexer.requestDocument(fmt.Sprintf("/account/view-posts/%v-%04d/page/%v", poster.Username, poster.Discriminator, page))
202272
if err != nil {
203273
return nil, err
204274
}
205-
posts, err := ScrapeForumPosts(doc, timezone)
275+
posts, err := ScrapeForumPosts(doc, poster, timezone)
206276
if err != nil {
207277
return nil, err
208278
}
209279
return posts, nil
210280
}
211281

212-
func (indexer *ForumIndexer) index(poster string, timezone *time.Location) error {
282+
func (indexer *ForumIndexer) index(poster ForumAccount, timezone *time.Location) error {
213283
logger := log.WithFields(log.Fields{
214284
"poster": poster,
215285
})

server/forum_indexer_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func TestScrapeForumPosts(t *testing.T) {
2121
tz, err := time.LoadLocation("America/Los_Angeles")
2222
require.NoError(t, err)
2323

24-
posts, err := ScrapeForumPosts(doc, tz)
24+
poster := ForumAccount{Username: "Chris"}
25+
posts, err := ScrapeForumPosts(doc, poster, tz)
2526
require.NoError(t, err)
2627
assert.Equal(t, 10, len(posts))
2728

@@ -31,6 +32,7 @@ func TestScrapeForumPosts(t *testing.T) {
3132
assert.Equal(t, 54, p.ForumId)
3233
assert.Equal(t, 1830139, p.ThreadId)
3334
assert.Equal(t, "Chris", p.Poster)
35+
assert.Equal(t, 0, p.PosterDiscriminator)
3436
assert.Equal(t, "Photos of the Fan Meetup", p.ThreadTitle)
3537
assert.Equal(t, "Announcements", p.ForumName)
3638
assert.Equal(t, "we had a great ti<strong>m</strong>e too!", p.BodyHTML)
@@ -47,7 +49,7 @@ func TestScrapeForumPosts(t *testing.T) {
4749
tz, err := time.LoadLocation("America/Los_Angeles")
4850
require.NoError(t, err)
4951

50-
posts, err := ScrapeForumPosts(doc, tz)
52+
posts, err := ScrapeForumPosts(doc, poster, tz)
5153
require.Error(t, err)
5254
assert.Equal(t, 0, len(posts))
5355
})

server/forum_post.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,42 @@ import (
77
)
88

99
type ForumPost struct {
10-
Id int `json:"id"`
11-
BodyHTML string `json:"body_html"`
12-
Time time.Time `json:"time"`
13-
Poster string `json:"poster"`
14-
ThreadId int `json:"thread_id"`
15-
ThreadTitle string `json:"thread_title"`
16-
ForumId int `json:"forum_id"`
17-
ForumName string `json:"forum_name"`
10+
Id int `json:"id"`
11+
BodyHTML string `json:"body_html"`
12+
Time time.Time `json:"time"`
13+
Poster string `json:"poster"`
14+
PosterDiscriminator int `json:"poster_discriminator"`
15+
ThreadId int `json:"thread_id"`
16+
ThreadTitle string `json:"thread_title"`
17+
ForumId int `json:"forum_id"`
18+
ForumName string `json:"forum_name"`
1819
}
1920

2021
type forumPostWithHost struct {
21-
Id int `json:"id"`
22-
BodyHTML string `json:"body_html"`
23-
Time time.Time `json:"time"`
24-
Poster string `json:"poster"`
25-
ThreadId int `json:"thread_id"`
26-
ThreadTitle string `json:"thread_title"`
27-
ForumId int `json:"forum_id"`
28-
ForumName string `json:"forum_name"`
29-
Host string `json:"host"`
22+
Id int `json:"id"`
23+
BodyHTML string `json:"body_html"`
24+
Time time.Time `json:"time"`
25+
Poster string `json:"poster"`
26+
PosterDiscriminator int `json:"poster_discriminator"`
27+
ThreadId int `json:"thread_id"`
28+
ThreadTitle string `json:"thread_title"`
29+
ForumId int `json:"forum_id"`
30+
ForumName string `json:"forum_name"`
31+
Host string `json:"host"`
3032
}
3133

3234
func (p ForumPost) MarshalJSON() ([]byte, error) {
3335
return json.Marshal(&forumPostWithHost{
34-
Id: p.Id,
35-
BodyHTML: p.BodyHTML,
36-
Time: p.Time,
37-
Poster: p.Poster,
38-
ThreadId: p.ThreadId,
39-
ThreadTitle: p.ThreadTitle,
40-
ForumId: p.ForumId,
41-
ForumName: p.ForumName,
42-
Host: p.Host(),
36+
Id: p.Id,
37+
BodyHTML: p.BodyHTML,
38+
Time: p.Time,
39+
Poster: p.Poster,
40+
PosterDiscriminator: p.PosterDiscriminator,
41+
ThreadId: p.ThreadId,
42+
ThreadTitle: p.ThreadTitle,
43+
ForumId: p.ForumId,
44+
ForumName: p.ForumName,
45+
Host: p.Host(),
4346
})
4447
}
4548

server/index_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var index = `<!DOCTYPE html><html>
7272
</footer>
7373
</div>
7474
75-
<script src="static/index.js?v7"></script>
75+
<script src="static/index.js?v8"></script>
7676
</body>
7777
</html>`
7878

server/static/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function loadActivity() {
7272

7373
if (type == 'forum_post') {
7474
$tr.append($('<td class="poster">').append($('<a>')
75-
.attr('href', 'https://' + activity.host + '/account/view-profile/' + encodeURIComponent(activity.poster))
75+
.attr('href', 'https://' + activity.host + '/account/view-profile/' + encodeURIComponent(activity.poster) + '-' + String(activity.poster_discriminator || 0).padStart(4, '0'))
7676
.text(activity.poster)
7777
));
7878
} else {

0 commit comments

Comments
 (0)