Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
srvpro
Commits
f0753262
Commit
f0753262
authored
May 28, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'mc'
parents
c6fbc00f
86fffcae
Pipeline
#13261
passed with stages
in 13 minutes and 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
28 deletions
+20
-28
ygopro-tournament.js
ygopro-tournament.js
+20
-28
No files found.
ygopro-tournament.js
View file @
f0753262
...
...
@@ -16,6 +16,7 @@ const _ = require('underscore');
_
.
str
=
require
(
'
underscore.string
'
);
_
.
mixin
(
_
.
str
.
exports
());
const
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
const
axios
=
require
(
'
axios
'
);
const
auth
=
require
(
'
./ygopro-auth.js
'
);
...
...
@@ -24,10 +25,6 @@ config = settings.modules.tournament_mode;
challonge_config
=
settings
.
modules
.
challonge
;
ssl_config
=
settings
.
modules
.
http
.
ssl
;
let
challonge
;
if
(
challonge_config
.
enabled
)
{
challonge
=
require
(
'
challonge
'
).
createClient
(
challonge_config
.
options
);
}
const
_async
=
require
(
"
async
"
);
const
os
=
require
(
"
os
"
);
const
PROCESS_COUNT
=
os
.
cpus
().
length
;
...
...
@@ -138,8 +135,8 @@ const clearDecks = function (callback) {
},
callback
);
}
const
UploadToChallonge
=
function
()
{
if
(
!
challonge
)
{
const
UploadToChallonge
=
async
function
()
{
if
(
!
challonge
_config
.
enabled
)
{
sendResponse
(
"
未开启Challonge模式。
"
);
return
false
;
}
...
...
@@ -157,30 +154,25 @@ const UploadToChallonge = function () {
return
false
;
}
sendResponse
(
"
读取玩家列表完毕,共有
"
+
player_list
.
length
+
"
名玩家。
"
);
sendResponse
(
"
开始上传玩家列表至Challonge。
"
);
_async
.
each
(
player_list
,
(
player_name
,
done
)
=>
{
sendResponse
(
"
正在上传玩家
"
+
player_name
+
"
至Challonge。
"
);
challonge
.
participants
.
create
({
id
:
challonge_config
.
tournament_id
,
participant
:
{
name
:
player_name
},
callback
:
(
err
,
data
)
=>
{
if
(
err
)
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传失败:
"
+
err
.
text
);
}
else
{
if
(
data
.
participant
)
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传完毕,其Challonge ID是
"
+
data
.
participant
.
id
+
"
。
"
);
}
else
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传完毕。
"
);
}
}
done
();
try
{
sendResponse
(
"
开始清空 Challonge 玩家列表。
"
);
await
axios
.
delete
(
`https://api.challonge.com/v1/tournaments/
${
challonge_config
.
tournament_id
}
/participants/clear.json`
,
{
params
:
{
api_key
:
challonge_config
.
options
.
apiKey
}
});
},
(
err
)
=>
{
sendResponse
(
"
开始上传玩家列表至 Challonge。
"
);
for
(
const
chunk
of
_
.
chunk
(
player_list
,
10
))
{
sendResponse
(
`开始上传玩家
${
chunk
.
join
(
'
,
'
)}
至 Challonge。`
);
await
axios
.
post
(
`https://api.challonge.com/v1/tournaments/
${
challonge_config
.
tournament_id
}
/participants/bulk_add.json`
,
{
api_key
:
challonge_config
.
options
.
apiKey
,
participants
:
chunk
.
map
(
name
=>
({
name
})),
},
axiosPostConfig
);
}
sendResponse
(
"
玩家列表上传完成。
"
);
});
}
catch
(
e
)
{
sendResponse
(
"
Challonge 上传失败:
"
+
e
.
message
);
}
return
true
;
}
...
...
@@ -338,7 +330,7 @@ async function requestListener(req, res) {
return
;
}
res
.
writeHead
(
200
);
const
result
=
UploadToChallonge
();
const
result
=
await
UploadToChallonge
();
res
.
end
(
u
.
query
.
callback
+
'
("操作完成。");
'
);
}
else
{
...
...
Write
Preview
Markdown
is supported
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