Skip to content

Commit a35bee2

Browse files
authored
Fix parsing issue when guild description contains founded string (#151)
* add check if length is more than zero * using HasPrefix at some more places resolves #150
1 parent 51fb8ea commit a35bee2

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/TibiaGuildsGuildV3.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type GuildResponse struct {
7474

7575
var (
7676
GuildLogoRegex = regexp.MustCompile(`.*img src="(.*)" width=.*`)
77-
GuildWorldAndFoundationRegex = regexp.MustCompile(`The guild was founded on (.*) on (.*).<br/>`)
77+
GuildWorldAndFoundationRegex = regexp.MustCompile(`^The guild was founded on (.*) on (.*).<br/>`)
7878
GuildHomepageRegex = regexp.MustCompile(`<a href="(.*)" target=.*>`)
7979
GuildhallRegex = regexp.MustCompile(` is (.*). The rent is paid until (.*).<br/>`)
8080
GuildDisbaneRegex = regexp.MustCompile(`<b>It will be disbanded on (.*.[0-9]+.[0-9]+) (.*)\.<\/b>.*`)
@@ -132,7 +132,7 @@ func TibiaGuildsGuildV3Impl(guild string, BoxContentHTML string) GuildResponse {
132132
}
133133

134134
}
135-
135+
136136
if GuildDescriptionFinished || strings.HasPrefix(line, "The guild was founded on ") {
137137
// The rest of the Guild information
138138

@@ -141,32 +141,34 @@ func TibiaGuildsGuildV3Impl(guild string, BoxContentHTML string) GuildResponse {
141141
GuildDescriptionFinished = true
142142
}
143143

144-
if strings.Contains(line, "The guild was founded on") {
144+
if strings.HasPrefix(line, "The guild was founded on") {
145145
// Regex to get GuildWorld and GuildFounded
146146
subma1b := GuildWorldAndFoundationRegex.FindAllStringSubmatch(line, -1)
147-
GuildWorld = subma1b[0][1]
148-
GuildFounded = TibiaDataDateV3(subma1b[0][2])
147+
if len(subma1b) != 0 {
148+
GuildWorld = subma1b[0][1]
149+
GuildFounded = TibiaDataDateV3(subma1b[0][2])
150+
}
149151
}
150152

151153
// If to get GuildActive
152-
if strings.Contains(line, "It is currently active") {
154+
if strings.HasPrefix(line, "It is currently active") {
153155
GuildActive = true
154156
}
155157

156158
// If open for applications
157-
if strings.Contains(line, "Guild is opened for applications.") {
159+
if strings.HasPrefix(line, "Guild is opened for applications.") {
158160
GuildApplications = true
159-
} else if strings.Contains(line, "Guild is closed for applications during war.") {
161+
} else if strings.HasPrefix(line, "Guild is closed for applications during war.") {
160162
GuildInWar = true
161163
}
162164

163-
if strings.Contains(line, "The official homepage is") {
165+
if strings.HasPrefix(line, "The official homepage is") {
164166
subma1c := GuildHomepageRegex.FindAllStringSubmatch(line, -1)
165167
GuildHomepage = subma1c[0][1]
166168
}
167169

168170
// If guildhall
169-
if strings.Contains(line, "Their home on "+GuildWorld) {
171+
if strings.HasPrefix(line, "Their home on "+GuildWorld) {
170172
subma1b := GuildhallRegex.FindAllStringSubmatch(line, -1)
171173

172174
GuildGuildhallData = append(GuildGuildhallData, Guildhall{
@@ -177,7 +179,7 @@ func TibiaGuildsGuildV3Impl(guild string, BoxContentHTML string) GuildResponse {
177179
}
178180

179181
// If disbanded
180-
if strings.Contains(line, "<b>It will be disbanded on ") {
182+
if strings.HasPrefix(line, "<b>It will be disbanded on ") {
181183
subma1c := GuildDisbaneRegex.FindAllStringSubmatch(line, -1)
182184
if len(subma1c) > 0 {
183185
GuildDisbandedDate = subma1c[0][1]

0 commit comments

Comments
 (0)