MCPcopy Create free account
hub / github.com/FSGModding/FSG_Mod_Assistant / #botRunner

Method #botRunner

lib/modCheckLib.js:140–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

138 }
139
140 #botRunner() {
141 const thisRun = Date.now()
142 if ( thisRun > this.#botLastRun + this.#botMinInterval ) {
143 this.#log.info('fsg-bot-poll', 'Updating FSG Bot Information')
144 if ( this.#botRequestList.size === 0 ) {
145 this.#log.debug('fsg-bot-poll', 'Bot request list empty, stopping interval')
146 if ( this.#botInterval !== null ) {
147 clearInterval(this.#botInterval)
148 this.#botInterval = null
149 }
150 return
151 }
152
153 this.#botLastRun = thisRun
154
155 const { net } = require('electron')
156
157 if ( net.isOnline() ) {
158 const thisURL = `https://www.farmsimgame.com/ma/${[...this.#botRequestList].join('-')}`
159 const request = net.request(thisURL)
160
161 request.setHeader('pragma', 'no-cache')
162
163 request.on('response', (response) => {
164 this.#log.debug('fsg-bot-poll', 'Got FSG Bot response', response.statusCode)
165 let responseData = ''
166
167 response.on('error', (err) => {
168 this.#log.info('fsg-bot-poll', 'Network error', err)
169 })
170 response.on('abort', () => {
171 this.#log.info('fsg-bot-poll', 'Network abort')
172 })
173
174 response.on('data', (chunk) => { responseData = responseData + chunk.toString() })
175 response.on('end', () => {
176 try {
177 const responseObj = JSON.parse(responseData)
178 this.#botResponse = {}
179 for ( const thisIDObj of responseObj ) {
180 this.#botResponse[thisIDObj.id] = thisIDObj
181 }
182 } catch (err) {
183 this.#log.info('fsg-bot-poll', 'File error', err.message)
184 }
185
186 })
187 })
188 request.on('abort', () => {
189 this.#log.info('fsg-bot-poll', 'Network abort')
190 })
191 request.on('error', (err) => {
192 this.#log.info('fsg-bot-poll', 'Network error', err)
193 })
194 request.end()
195 }
196 }
197 }

Callers 1

startBotIntervalMethod · 0.95

Calls 4

infoMethod · 0.80
debugMethod · 0.80
endMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected