-
Notifications
You must be signed in to change notification settings - Fork 0
/
flappy_chiko_upload.js
80 lines (74 loc) · 1.98 KB
/
flappy_chiko_upload.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
let showNotification = true;
let token = null;
function surgeNotify(subtitle = '', message = '') {
$notification.post('Chiko 上傳', subtitle, message, {
'url': ''
});
};
function handleError(error) {
if (Array.isArray(error)) {
console.log(`❌ ${error[0]} ${error[1]}`);
if (showNotification) {
surgeNotify(error[0], error[1]);
}
} else {
console.log(`❌ ${error}`);
if (showNotification) {
surgeNotify(error);
}
}
}
async function preCheck() {
return new Promise((resolve, reject) => {
const chikoToken = $persistentStore.read('ChikoToken');
if (!chikoToken || chikoToken.length === 0) {
return reject(['檢查失敗 ‼️', '找不到 token']);
}
token = chikoToken;
return resolve();
});
}
async function upload() {
return new Promise((resolve, reject) => {
try {
const request = {
url: 'https://chikoroko.games/api/' + token + '/',
headers: {
'referer': 'https://chikoroko.games/game/?id=' + token,
},
body: 'new_score=75'
};
$httpClient.post(request, function (error, response, data) {
if (error) {
return reject(['上傳失敗 ‼️', '連線錯誤']);
} else {
if (response.status === 200) {
const obj = JSON.parse(data);
if (obj.score >= 0) {
return resolve(obj.score);
} else {
return reject(['上傳失敗 ‼️', 'Error: ' + obj]);
}
} else {
return reject(['上傳失敗 ‼️', response.status]);
}
}
});
} catch (error) {
return reject(['上傳失敗 ‼️', error]);
}
});
}
(async () => {
console.log('ℹ️ Chiko 自動上傳成績 v20230128.1');
try {
await preCheck();
console.log('✅ 檢查成功');
await upload();
console.log('✅ 上傳成功');
surgeNotify('上傳成功 ✅', '');
} catch (error) {
handleError(error);
}
$done();
})();