Skip to content

Commit

Permalink
backroll: ASF reverted back to old struc. (JustArchiNET/ArchiSteamFar…
Browse files Browse the repository at this point in the history
  • Loading branch information
zerox003 committed Jan 25, 2025
1 parent f4dfb25 commit 6fbbd6a
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ const BotVersion = "v2.1.1";
const ASF_ICON = "https://raw.githubusercontent.com/JustArchiNET/ArchiSteamFarm/refs/heads/main/resources/ASF_184x184.png";

const translations = {
EPurchaseResultDetail: {},
EResult: {},
ECurrencyCode: {},
PurchaseResultDetail: {},
Result: {},
Currency: {},
HealthStatus: {}
}
}

const schemaMapping = {
"SteamKit2.EPurchaseResultDetail": "PurchaseResultDetail",
"SteamKit2.EResult": "Result",
"SteamKit2.ECurrencyCode": "Currency",
"Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus": "HealthStatus"
};

const rpcStat = {
pinging: "ASF | pinging...",
Expand Down Expand Up @@ -365,7 +372,7 @@ async function heartbeat() {
});
client.user.setStatus("online");

if (Object.keys(translations.EPurchaseResultDetail).length === 0) {
if (Object.keys(translations.PurchaseResultDetail).length === 0) {
fetchTranslations().then(() => {
basicCLog(`Translations loaded`);
basicCLog(`[${client.user.username}] Ready!`);
Expand Down Expand Up @@ -505,12 +512,10 @@ async function fetchBots() {
};
};

//TODO: rework to new strucutal changes
//TODO: rework to new strucutal changes (waiting for crutial error to be fixed (https://github.com/JustArchiNET/ArchiSteamFarm/issues/3376))
async function fetchTranslations() {
try {

const translationKeys = Object.keys(translations);

const response = await fetch(
`${config.security.SSL_STAT}:${config.security.IP}/swagger/ASF/swagger.json`
);
Expand All @@ -519,19 +524,19 @@ async function fetchTranslations() {

const data = await response.json();

for (const key of translationKeys) {
const schema = data.components.schemas[key];
for (const [schemaName, translationKey] of Object.entries(schemaMapping)) {
const schema = data.components.schemas[schemaName];

if (schema && schema["x-definition"]) {
const xDefinition = schema["x-definition"];

for (const [code, translation] of Object.entries(xDefinition)) {
translations[key][code] = translation;
translations[translationKey][code] = translation;
};
}

else {
console.error(`Expected structure not found in the JSON response for ${key}`);
console.error(`Expected structure not found in the JSON response for ${schemaName}`);
}
};
}
Expand Down Expand Up @@ -621,7 +626,7 @@ async function responseBodyStat(bot) {
iconURL: `https://avatars.cloudflare.steamstatic.com/${body.Result[bot].AvatarHash}.jpg`,
url: `https://steamcommunity.com/profiles/${body.Result[bot].s_SteamID}/`
})
.setDescription((`**Steam ID:** [${body.Result[bot].s_SteamID}](https://steamid.xyz/${body.Result[bot].s_SteamID})\n**Wallet:** ${body.Result[bot].WalletBalance} ${await getTranslation("ECurrencyCode", body.Result[bot].WalletCurrency)}`))
.setDescription((`**Steam ID:** [${body.Result[bot].s_SteamID}](https://steamid.xyz/${body.Result[bot].s_SteamID})\n**Wallet:** ${body.Result[bot].WalletBalance} ${await getTranslation("Currency", body.Result[bot].WalletCurrency)}`))
.setTimestamp(Date.now())
.setFooter({
text: `ASF-Bot ${BotVersion}`,
Expand Down Expand Up @@ -803,9 +808,9 @@ async function responseBodyAL(data, bot) {
let appDetail = apps[id];
let packageDetail = packages[id];

output += `<${botName}> Apps ID: ${id} | Status: ${await getTranslation("EResult", appDetail.Result)} | Status Detail: ${await getTranslation("EPurchaseResultDetail", appDetail.PurchaseResultDetail)}\n`;
output += `<${botName}> Apps ID: ${id} | Status: ${await getTranslation("Result", appDetail.Result)} | Status Detail: ${await getTranslation("PurchaseResultDetail", appDetail.PurchaseResultDetail)}\n`;

output += `<${botName}> Packages ID: ${id} | Status: ${await getTranslation("EResult", packageDetail.Result)} | Status Detail: ${await getTranslation("EPurchaseResultDetail", packageDetail.PurchaseResultDetail)}\n`;
output += `<${botName}> Packages ID: ${id} | Status: ${await getTranslation("Result", packageDetail.Result)} | Status Detail: ${await getTranslation("PurchaseResultDetail", packageDetail.PurchaseResultDetail)}\n`;

output += "\n";
};
Expand Down Expand Up @@ -874,7 +879,7 @@ async function responseBodyRP(IDs, bot) {
botGroups[botName].push({
id,
status: message,
statusDetail: await getTranslation("EResult", statusDetail),
statusDetail: await getTranslation("Result", statusDetail),
});
};
};
Expand Down

0 comments on commit 6fbbd6a

Please sign in to comment.