-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (112 loc) · 4.02 KB
/
index.js
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
const yargs = require('yargs/yargs')
const {hideBin} = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
const SheepApi = require("./lib/sheep-api");
const {sleep} = require("./lib/utils");
const fs = require('fs').promises;
const prompts = require('prompts');
let defaultConfig = {
"showProfileInfo": true,
"unlockChest": true,
"watchChestAd": true,
"openChest": true,
"showGame": true,
"loopGame": false,
"proxy": null,
};
const ratingMode = async (accounts, builds) => {
for (const account of accounts) {
let config = account.config || {};
let build = builds[account.build || 0];
account.api = new SheepApi(account.params, {...defaultConfig, loopGame: true, ...config});
await account.api.init();
account.api.game.setBuild(build);
await account.api.changeDeck(build.cards);
let url, _id = null;
if (account.api.profile.lobby) {
url = account.api.profile.lobby.url;
_id = account.api.profile.lobby._id || null;
}
if (!url) {
url = await account.api.getWaitRoom();
}
account.api.game.connect(url, _id);
await sleep(200);
}
}
const lobbyMode = async (accounts, builds) => {
let [account, twink] = accounts;
account.api = new SheepApi(account.params, {...defaultConfig, ...account.config});
twink.api = new SheepApi(twink.params, {...defaultConfig, ...twink.config});
await account.api.init();
await twink.api.init();
account.api.game.setBuild(builds[account.build || 0]);
twink.api.game.setBuild(builds[twink.build || 0]);
//
let url, _id = null;
if (twink.api.profile.lobby) {
url = twink.api.profile.lobby.url;
_id = twink.api.profile.lobby._id || null;
}
if (!url) {
let lobby = await twink.api.createLobby();
url = lobby.url;
_id = lobby._id || null;
}
console.log(`Created lobby: https://vk.com/app51491054#lobby${url}:${_id}`);
twink.api.game.connect(url, _id);
await sleep(2000);
account.api.game.connect(url, _id);
}
const infoMode = async (accounts) => {
for (const account of accounts) {
let config = account.config || {};
account.api = new SheepApi(account.params, {...defaultConfig, loopGame: true, ...config});
await account.api.init();
await sleep(200);
}
}
(async () => {
const response = argv.mode ? {mode: argv.mode} : await prompts([
{
type: 'select',
name: 'mode',
message: 'Pick a mode',
choices: [
{title: 'Rating', description: 'Starts rating matchmaking', value: 'rating'},
{title: 'Lobby', description: 'Creates lobby and join from another account', value: 'lobby'},
{title: 'Info', description: 'Just display account(s) info', value: 'info'},
],
}
]);
let builds = JSON.parse((await fs.readFile("./builds.json")).toString());
let accounts = JSON.parse((await fs.readFile("./accounts.json")).toString());
accounts = accounts.filter(({disabled = false})=> (!disabled));
switch (response.mode) {
case "rating":
await ratingMode(accounts, builds)
break;
case "lobby":
const accountsChoices = (accounts || []).map(((a) => ({
title: `@id${a.id}`,
description: `${a.params}`,
value: a
})))
const lobbySettings = await prompts([
{
type: 'multiselect',
name: 'lobbyAccounts',
message: 'Select acc',
choices: accountsChoices,
max: 2,
min: 2,
hint: '- Space to select. Return to submit. Max: 2'
},
]);
await lobbyMode(lobbySettings.lobbyAccounts, builds)
break;
case "info":
await infoMode(accounts)
break;
}
})()