-
Notifications
You must be signed in to change notification settings - Fork 4
/
search-options.go
273 lines (226 loc) · 7.81 KB
/
search-options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package godestone
import (
"fmt"
"strings"
)
// CharacterSearchOrder represents the search result ordering of a Lodestone character search.
type CharacterSearchOrder uint8
// Search ordering for character searches.
const (
OrderCharaNameAToZ CharacterSearchOrder = iota + 1
OrderCharaNameZToA
OrderCharaWorldAtoZ
OrderCharaWorldZtoA
OrderCharaLevelDescending
OrderCharaLevelAscending
)
// CharacterOptions defines extra search information that can help to narrow down a search.
type CharacterOptions struct {
Name string
World string
DC string
SearchLang SearchLang
GrandCompany string
Race string
Tribe string
Order CharacterSearchOrder
}
// BuildURI returns a constructed URI for the provided search options.
func (s *CharacterOptions) BuildURI(
scraper *Scraper,
lang string,
) string {
uriFormat := "https://%s.finalfantasyxiv.com/lodestone/character/?q=%s&worldname=%s&classjob=%s&order=%d"
name := strings.Replace(s.Name, " ", "%20", -1)
worldDC := parseWorldDC(s.World, s.DC)
if s.SearchLang == NoneLang || s.SearchLang&SearchJA != 0 {
uriFormat += "&blog_lang=ja"
}
if s.SearchLang == NoneLang || s.SearchLang&SearchEN != 0 {
uriFormat += "&blog_lang=en"
}
if s.SearchLang == NoneLang || s.SearchLang&SearchDE != 0 {
uriFormat += "&blog_lang=de"
}
if s.SearchLang == NoneLang || s.SearchLang&SearchFR != 0 {
uriFormat += "&blog_lang=fr"
}
if s.Tribe != "" || s.Race != "" {
raceTribe := ""
if s.Tribe != "" {
t, err := scraper.dataProvider.Tribe(s.Tribe)
if err == nil {
raceTribe = fmt.Sprintf("tribe_%d", t.ID)
}
} else if s.Race != "" {
r, err := scraper.dataProvider.Race(s.Race)
if err == nil {
raceTribe = fmt.Sprintf("race_%d", r.ID)
}
}
uriFormat += fmt.Sprintf("&race_tribe=%s", raceTribe)
}
if s.GrandCompany != "" {
gc, err := scraper.dataProvider.GrandCompany(s.GrandCompany)
if err == nil {
uriFormat += fmt.Sprintf("&gcid=%d", gc.ID)
}
}
builtURI := fmt.Sprintf(uriFormat, lang, name, worldDC, "", s.Order)
return builtURI
}
// FreeCompanySearchOrder represents the search result ordering of a Lodestone Free Company search.
type FreeCompanySearchOrder uint8
// Search ordering for Free Company searches.
const (
OrderFCNameAToZ FreeCompanySearchOrder = iota + 1
OrderFCNameZToA
OrderFCMembershipHighToLow
OrderFCMembershipLowToHigh
OrderFCDateFoundedDescending
OrderFCDateFoundedAscending
)
// FreeCompanyHousingStatus represents the housing status of a Free Company for the purpose of searches.
type FreeCompanyHousingStatus uint8
// Housing status for Free Company searches.
const (
FCHousingAll FreeCompanyHousingStatus = iota
FCHousingNoEstateOrPlot
FCHousingPlotOnly
FCHousingEstateBuilt
)
// FreeCompanyOptions defines extra search information that can help to narrow down a Free Company search.
type FreeCompanyOptions struct {
Name string
World string
DC string
ActiveTime FreeCompanyActiveState
Recruitment FreeCompanyRecruitingState
Order FreeCompanySearchOrder
HousingStatus FreeCompanyHousingStatus
ActiveMembers ActiveMemberRange
CommunityFinderRecruiting bool
}
// BuildURI returns a constructed URI for the provided search options.
func (s *FreeCompanyOptions) BuildURI(lang string) string {
uriFormat := "https://%s.finalfantasyxiv.com/lodestone/freecompany/?q=%s&worldname=%s&character_count=%s&cf_public=%d&activetime=%s&join=%s&house=%s&order=%d"
name := strings.Replace(s.Name, " ", "%20", -1)
worldDC := parseWorldDC(s.World, s.DC)
cfPublic := 0
if s.CommunityFinderRecruiting {
cfPublic = 1
}
join := ""
if s.Recruitment == FCRecruitmentOpen {
join = "1"
} else if s.Recruitment == FCRecruitmentClosed {
join = "0"
}
active := ""
if s.ActiveTime == FCActiveWeekdaysOnly {
active = "1"
} else if s.ActiveTime == FCActiveWeekendsOnly {
active = "2"
}
housingStatus := ""
if s.HousingStatus != FCHousingAll {
housingStatus = fmt.Sprint(s.HousingStatus)
}
builtURI := fmt.Sprintf(uriFormat, lang, name, worldDC, s.ActiveMembers, cfPublic, active, join, housingStatus, s.Order)
return builtURI
}
// ActiveMemberRange represents the active member range filter of a search.
type ActiveMemberRange string
// Active member range for searches.
const (
OneToTen ActiveMemberRange = "1-10"
ElevenToThirty ActiveMemberRange = "11-30"
ThirtyOneToFifty ActiveMemberRange = "31-50"
FiftyOnePlus ActiveMemberRange = "51-"
)
func parseWorldDC(world string, dc string) string {
worldDC := ""
if len(world) != 0 {
worldDC = strings.ToUpper(string(world[0])) + strings.ToLower(world[1:])
} else {
// DCs have the _dc_ prefix attached to them
if len(dc) != 0 && !strings.HasPrefix(dc, "_dc_") {
worldDC = "_dc_" + strings.ToUpper(string(dc[0])) + strings.ToLower(dc[1:])
}
}
return worldDC
}
// LinkshellSearchOrder represents the search result ordering of a Lodestone CWLS search.
type LinkshellSearchOrder uint8
// Search ordering for linkshell and CWLS searches.
const (
OrderLinkshellNameAToZ LinkshellSearchOrder = iota + 1
OrderLinkshellNameZToA
OrderLinkshellMembershipHighToLow
OrderLinkshellMembershipLowToHigh
)
// LinkshellOptions defines extra search information that can help to narrow down a linkshell search.
type LinkshellOptions struct {
Name string
World string
DC string
Order LinkshellSearchOrder
ActiveMembers ActiveMemberRange
CommunityFinderRecruiting bool
}
// BuildURI returns a constructed URI for the provided search options.
func (s *LinkshellOptions) BuildURI(lang string) string {
uriFormat := "https://%s.finalfantasyxiv.com/lodestone/linkshell/?q=%s&worldname=%s&character_count=%s&cf_public=%d&order=%d"
name := strings.Replace(s.Name, " ", "%20", -1)
worldDC := parseWorldDC(s.World, s.DC)
cfPublic := 0
if s.CommunityFinderRecruiting {
cfPublic = 1
}
builtURI := fmt.Sprintf(uriFormat, lang, name, worldDC, s.ActiveMembers, cfPublic, s.Order)
return builtURI
}
// CWLSOptions defines extra search information that can help to narrow down a CWLS search.
type CWLSOptions struct {
Name string
DC string
Order LinkshellSearchOrder
ActiveMembers ActiveMemberRange
CommunityFinderRecruiting bool
}
// BuildURI returns a constructed URI for the provided search options.
func (s *CWLSOptions) BuildURI(lang string) string {
uriFormat := "https://%s.finalfantasyxiv.com/lodestone/crossworld_linkshell/?q=%s&dcname=%s&character_count=%s&cf_public=%d&order=%d"
name := strings.Replace(s.Name, " ", "%20", -1)
cfPublic := 0
if s.CommunityFinderRecruiting {
cfPublic = 1
}
builtURI := fmt.Sprintf(uriFormat, lang, name, s.DC, s.ActiveMembers, cfPublic, s.Order)
return builtURI
}
// PVPTeamSearchOrder represents the search result ordering of a Lodestone CWLS search.
type PVPTeamSearchOrder uint8
// Search ordering for PVP Team searches.
const (
OrderPVPTeamNameAToZ PVPTeamSearchOrder = iota + 1
OrderPVPTeamNameZToA
)
// PVPTeamOptions defines extra search information that can help to narrow down a PVP team search.
type PVPTeamOptions struct {
Name string
DC string
Order PVPTeamSearchOrder
CommunityFinderRecruiting bool
}
// BuildURI returns a constructed URI for the provided search options.
func (s *PVPTeamOptions) BuildURI(lang string) string {
uriFormat := "https://%s.finalfantasyxiv.com/lodestone/pvpteam/?q=%s&dcname=%s&cf_public=%d&order=%d"
name := strings.Replace(s.Name, " ", "%20", -1)
cfPublic := 0
if s.CommunityFinderRecruiting {
cfPublic = 1
}
builtURI := fmt.Sprintf(uriFormat, lang, name, s.DC, cfPublic, s.Order)
return builtURI
}