Skip to content

Commit 16a6f8a

Browse files
Move 'stig' format revives to a single fetch location.
1 parent 9663384 commit 16a6f8a

File tree

2 files changed

+178
-190
lines changed

2 files changed

+178
-190
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,175 @@
1-
"use strict";
2-
3-
const __DEFAULT_REVIVE_REQUEST = {
4-
method: "POST",
5-
relay: true,
6-
silent: true,
7-
succeedOnError: true,
8-
};
9-
10-
function __requestStigFormat(location, vendor) {
11-
return (id, name, country, faction, source) =>
12-
new Promise((resolve, reject) => {
13-
fetchData(location, {
14-
...__DEFAULT_REVIVE_REQUEST,
15-
section: "request",
16-
body: { tornid: id.toString(), username: name, source: source, vendor, type: "revive" },
17-
})
18-
.then((response) => {
19-
if (response.hasOwnProperty("contract")) {
20-
resolve({ response, contract: response["contract"] });
21-
} else {
22-
reject(response);
23-
}
24-
})
25-
.catch((reason) => reject(reason));
26-
});
27-
}
28-
29-
const REVIVE_PROVIDERS = [
30-
{
31-
provider: "nuke",
32-
name: "Nuke",
33-
origin: FETCH_PLATFORMS.nukefamily,
34-
doRequest: (id, name, country, faction, source) =>
35-
new Promise((resolve, reject) => {
36-
fetchData("nukefamily", {
37-
...__DEFAULT_REVIVE_REQUEST,
38-
section: "api/revive-request",
39-
body: {
40-
torn_player_id: id,
41-
torn_player_name: name,
42-
torn_player_country: country,
43-
app_info: source,
44-
},
45-
})
46-
.then((response) => {
47-
if (response.success) resolve({ response });
48-
else reject(response);
49-
})
50-
.catch((reason) => reject(reason));
51-
}),
52-
price: {
53-
money: 1_800_000,
54-
xanax: 2,
55-
},
56-
},
57-
{
58-
provider: "uhc",
59-
name: "UHC",
60-
origin: FETCH_PLATFORMS.uhc,
61-
doRequest: (id, name, country, faction, source) =>
62-
new Promise((resolve, reject) => {
63-
fetchData("uhc", {
64-
...__DEFAULT_REVIVE_REQUEST,
65-
section: "api/request",
66-
body: { userID: id, userName: name, factionName: faction, source },
67-
})
68-
.then((response) => {
69-
if (response.success) resolve({ response });
70-
else reject(response);
71-
})
72-
.catch((reason) => reject(reason));
73-
}),
74-
price: {
75-
money: 1_800_000,
76-
xanax: 2,
77-
},
78-
},
79-
{
80-
provider: "imperium",
81-
name: "Imperium",
82-
origin: FETCH_PLATFORMS.imperium,
83-
doRequest: (id, name, country, faction, source) =>
84-
new Promise((resolve, reject) => {
85-
fetchData("imperium", {
86-
...__DEFAULT_REVIVE_REQUEST,
87-
section: "revive",
88-
body: { userID: id, userName: name, factionName: faction, source },
89-
})
90-
.then((response) => {
91-
if (response.success) resolve({ response });
92-
else reject(response);
93-
})
94-
.catch((reason) => reject(reason));
95-
}),
96-
price: {
97-
money: 1_800_000,
98-
xanax: 2,
99-
},
100-
},
101-
{
102-
provider: "wtf",
103-
name: "WTF",
104-
origin: FETCH_PLATFORMS.wtf,
105-
doRequest: (id, name, country, faction, source) =>
106-
new Promise((resolve, reject) => {
107-
fetchData("wtf", {
108-
...__DEFAULT_REVIVE_REQUEST,
109-
section: "wtfapi/revive",
110-
body: { userID: id, userName: name, Faction: faction, Country: country, requestChannel: source },
111-
})
112-
.then((response) => {
113-
if (response.success) resolve({ response });
114-
else reject(response);
115-
})
116-
.catch((reason) => reject(reason));
117-
}),
118-
price: {
119-
money: 1_800_000,
120-
xanax: 2,
121-
},
122-
},
123-
{
124-
provider: "hela",
125-
name: "HeLa",
126-
origin: FETCH_PLATFORMS.hela,
127-
doRequest: __requestStigFormat("hela", "HeLa"),
128-
price: {
129-
money: 1_800_000,
130-
xanax: 2,
131-
},
132-
},
133-
{
134-
provider: "shadow_healers",
135-
name: "Shadow Healers",
136-
origin: FETCH_PLATFORMS.shadow_healers,
137-
doRequest: __requestStigFormat("shadow_healers", "Shadow Healers"),
138-
price: {
139-
money: 1_800_000,
140-
xanax: 2,
141-
},
142-
},
143-
{
144-
provider: "who",
145-
name: "The Wolverines",
146-
origin: FETCH_PLATFORMS.who,
147-
doRequest: __requestStigFormat("who", "The Wolverines"),
148-
price: {
149-
money: 1_000_000,
150-
xanax: 1,
151-
},
152-
},
153-
];
154-
155-
function doRequestRevive(id, name, country, faction) {
156-
const source = `TornTools v${chrome.runtime.getManifest().version}`;
157-
158-
const providerName = settings.pages.global.reviveProvider || "";
159-
const provider = REVIVE_PROVIDERS.find((p) => p.provider === providerName);
160-
if (!provider) throw new Error(`Revive provider '${providerName}' not found.`);
161-
162-
return provider
163-
.doRequest(id, name, country, faction, source)
164-
.then(({ response, contract }) => ({ response, contract, provider }))
165-
.catch((response) => ({ response, provider }));
166-
}
167-
168-
function calculateRevivePrice({ price }) {
169-
const parts = [];
170-
171-
if (price?.money) parts.push(formatNumber(price.money, { currency: true, shorten: 3 }));
172-
if (price?.xanax) parts.push(`${price.xanax} xan`);
173-
174-
return parts.length > 0 ? parts.join(" or ") : "unknown";
175-
}
1+
"use strict";
2+
3+
const __DEFAULT_REVIVE_REQUEST = {
4+
method: "POST",
5+
relay: true,
6+
silent: true,
7+
succeedOnError: true,
8+
};
9+
10+
function __requestStigFormat(vendor) {
11+
return (id, name, country, faction, source) =>
12+
new Promise((resolve, reject) => {
13+
fetchData("stig", {
14+
...__DEFAULT_REVIVE_REQUEST,
15+
section: "request",
16+
body: { tornid: id.toString(), username: name, source: source, vendor, type: "revive" },
17+
})
18+
.then((response) => {
19+
if (response.hasOwnProperty("contract")) {
20+
resolve({ response, contract: response["contract"] });
21+
} else {
22+
reject(response);
23+
}
24+
})
25+
.catch((reason) => reject(reason));
26+
});
27+
}
28+
29+
const REVIVE_PROVIDERS = [
30+
{
31+
provider: "nuke",
32+
name: "Nuke",
33+
origin: FETCH_PLATFORMS.nukefamily,
34+
doRequest: (id, name, country, faction, source) =>
35+
new Promise((resolve, reject) => {
36+
fetchData("nukefamily", {
37+
...__DEFAULT_REVIVE_REQUEST,
38+
section: "api/revive-request",
39+
body: {
40+
torn_player_id: id,
41+
torn_player_name: name,
42+
torn_player_country: country,
43+
app_info: source,
44+
},
45+
})
46+
.then((response) => {
47+
if (response.success) resolve({ response });
48+
else reject(response);
49+
})
50+
.catch((reason) => reject(reason));
51+
}),
52+
price: {
53+
money: 1_800_000,
54+
xanax: 2,
55+
},
56+
},
57+
{
58+
provider: "uhc",
59+
name: "UHC",
60+
origin: FETCH_PLATFORMS.uhc,
61+
doRequest: (id, name, country, faction, source) =>
62+
new Promise((resolve, reject) => {
63+
fetchData("uhc", {
64+
...__DEFAULT_REVIVE_REQUEST,
65+
section: "api/request",
66+
body: { userID: id, userName: name, factionName: faction, source },
67+
})
68+
.then((response) => {
69+
if (response.success) resolve({ response });
70+
else reject(response);
71+
})
72+
.catch((reason) => reject(reason));
73+
}),
74+
price: {
75+
money: 1_800_000,
76+
xanax: 2,
77+
},
78+
},
79+
{
80+
provider: "imperium",
81+
name: "Imperium",
82+
origin: FETCH_PLATFORMS.imperium,
83+
doRequest: (id, name, country, faction, source) =>
84+
new Promise((resolve, reject) => {
85+
fetchData("imperium", {
86+
...__DEFAULT_REVIVE_REQUEST,
87+
section: "revive",
88+
body: { userID: id, userName: name, factionName: faction, source },
89+
})
90+
.then((response) => {
91+
if (response.success) resolve({ response });
92+
else reject(response);
93+
})
94+
.catch((reason) => reject(reason));
95+
}),
96+
price: {
97+
money: 1_800_000,
98+
xanax: 2,
99+
},
100+
},
101+
{
102+
provider: "wtf",
103+
name: "WTF",
104+
origin: FETCH_PLATFORMS.wtf,
105+
doRequest: (id, name, country, faction, source) =>
106+
new Promise((resolve, reject) => {
107+
fetchData("wtf", {
108+
...__DEFAULT_REVIVE_REQUEST,
109+
section: "wtfapi/revive",
110+
body: { userID: id, userName: name, Faction: faction, Country: country, requestChannel: source },
111+
})
112+
.then((response) => {
113+
if (response.success) resolve({ response });
114+
else reject(response);
115+
})
116+
.catch((reason) => reject(reason));
117+
}),
118+
price: {
119+
money: 1_800_000,
120+
xanax: 2,
121+
},
122+
},
123+
{
124+
provider: "hela",
125+
name: "HeLa",
126+
origin: FETCH_PLATFORMS.stig,
127+
doRequest: __requestStigFormat("HeLa"),
128+
price: {
129+
money: 1_800_000,
130+
xanax: 2,
131+
},
132+
},
133+
{
134+
provider: "shadow_healers",
135+
name: "Shadow Healers",
136+
origin: FETCH_PLATFORMS.stig,
137+
doRequest: __requestStigFormat("Shadow Healers"),
138+
price: {
139+
money: 1_800_000,
140+
xanax: 2,
141+
},
142+
},
143+
{
144+
provider: "who",
145+
name: "The Wolverines",
146+
origin: FETCH_PLATFORMS.stig,
147+
doRequest: __requestStigFormat("The Wolverines"),
148+
price: {
149+
money: 1_000_000,
150+
xanax: 1,
151+
},
152+
},
153+
];
154+
155+
function doRequestRevive(id, name, country, faction) {
156+
const source = `TornTools v${chrome.runtime.getManifest().version}`;
157+
158+
const providerName = settings.pages.global.reviveProvider || "";
159+
const provider = REVIVE_PROVIDERS.find((p) => p.provider === providerName);
160+
if (!provider) throw new Error(`Revive provider '${providerName}' not found.`);
161+
162+
return provider
163+
.doRequest(id, name, country, faction, source)
164+
.then(({ response, contract }) => ({ response, contract, provider }))
165+
.catch((response) => ({ response, provider }));
166+
}
167+
168+
function calculateRevivePrice({ price }) {
169+
const parts = [];
170+
171+
if (price?.money) parts.push(formatNumber(price.money, { currency: true, shorten: 3 }));
172+
if (price?.xanax) parts.push(`${price.xanax} xan`);
173+
174+
return parts.length > 0 ? parts.join(" or ") : "unknown";
175+
}

extension/scripts/global/functions/api.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ const FETCH_PLATFORMS = {
1818
nukefamily: "https://nuke.family/",
1919
uhc: "https://tornuhc.eu/",
2020
imperium: "https://inq.mavri.dev/",
21-
hela: "https://api.no1irishstig.co.uk/",
22-
shadow_healers: "https://api.no1irishstig.co.uk/",
23-
who: "https://api.no1irishstig.co.uk/",
21+
stig: "https://api.no1irishstig.co.uk/",
2422
prometheus: "https://prombot.co.uk:8443/",
2523
lzpt: "https://api.lzpt.io/",
2624
wtf: "https://what-the-f.de/",
@@ -134,18 +132,8 @@ async function fetchData(location, options = {}) {
134132

135133
path = options.section;
136134
break;
137-
case "hela":
138-
url = FETCH_PLATFORMS.hela;
139-
140-
path = options.section;
141-
break;
142-
case "shadow_healers":
143-
url = FETCH_PLATFORMS.shadow_healers;
144-
145-
path = options.section;
146-
break;
147-
case "who":
148-
url = FETCH_PLATFORMS.who;
135+
case "stig":
136+
url = FETCH_PLATFORMS.stig;
149137

150138
path = options.section;
151139
break;

0 commit comments

Comments
 (0)