Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Isabella Skořepová
travian
Commits
7c529842
Unverified
Commit
7c529842
authored
Sep 17, 2017
by
Isabella Skořepová
Browse files
Add option to specify chromium opts and move timeout to index
🔦
parent
bf14f266
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/bot.js
View file @
7c529842
...
...
@@ -32,6 +32,5 @@ async function bot(travian) {
.
join
(
'
\n
'
)}
`
,
)
}
await
timeout
(
1000
)
}
module
.
exports
.
bot
=
bot
src/index.js
View file @
7c529842
...
...
@@ -8,6 +8,15 @@ async function readCredentials() {
return
JSON
.
parse
(
await
promisify
(
fs
.
readFile
)(
'
creds.json
'
,
'
utf-8
'
))
}
async
function
readChromiumOpts
()
{
try
{
const
data
=
await
promisify
(
fs
.
readFile
)(
'
chromium-opts.json
'
,
'
uft-8
'
)
return
JSON
.
parse
(
data
)
}
catch
(
e
)
{
return
undefined
}
}
function
timeout
(
ms
)
{
return
new
Promise
(
res
=>
setTimeout
(
res
,
ms
))
}
...
...
@@ -17,6 +26,7 @@ console.log('starting')
const
args
=
await
Travian
.
generateArgs
({
headless
:
true
,
server
:
'
https://ts5.travian.cz/
'
,
opts
:
await
readChromiumOpts
(),
})
const
impl
=
Travian
.
travianImpl
const
travian
=
impl
(...
args
)
...
...
@@ -29,6 +39,7 @@ console.log('starting')
try
{
// eslint-disable-next-line global-require
await
require
(
'
./bot
'
).
bot
(
require
(
'
./travian
'
).
travianImpl
(...
args
))
await
timeout
(
1000
)
}
catch
(
e
)
{
console
.
error
(
'
Detected problem while running bot...
'
)
console
.
error
(
e
)
...
...
src/travian.js
View file @
7c529842
...
...
@@ -143,7 +143,10 @@ const generateArgs = async _opts => {
...
_opts
,
}
if
(
!
opts
.
server
)
throw
new
Error
(
'
You have to specify server
'
)
const
browser
=
await
puppeteer
.
launch
({
headless
:
opts
.
headless
})
const
browser
=
await
puppeteer
.
launch
({
headless
:
opts
.
headless
,
opts
:
opts
.
opts
,
})
try
{
const
page
=
await
browser
.
newPage
()
const
state
=
{}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment