Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions ban-importer/src/ban-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default class BanFetcher {
case 'battlemetrics':
await this.fetchBattlemetricsBanList(banList);
break;
case 'custom':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pick a different name for this please?

await this.fetchCustomBanList(banList);
break;
default:
throw new Error('Unsupported ban list type.');
}
Expand Down Expand Up @@ -145,4 +148,53 @@ export default class BanFetcher {
}
}
}

async fetchCustomBanList(banList) {
// Fetch ban data.
Logger.verbose(
'BanFetcher',
1,
`Fetching custom ban list data for ban list (ID: ${banList.id})...`
);

try {
const { data } = await axios.get(banList.source);

if (!Array.isArray(data)) {
throw new Error('Custom ban list is not an array');
}

const bans = [];

for (const ban of data) {

// Skip the object if it's missing a steamID or reason.
if (ban.steamID === undefined || !ban.steamID.match(/[0-9]{17}/) || !ban.reason) continue;

// Turn the dates into date objects or null if permanent ban.
const created = ban.created ? new Date(ban.created) : null;
const expires = ban.expires ? new Date(ban.expires) : null;

// Store the new ban.
bans.push({
id: `${banList.id},${ban.steamID},${expires ? expires.getTime() : 'null'}`,

steamUser: ban.steamID,

created: created,
expires: expires,
expired: !(expires === null || expires.getTime() > Date.now()),

reason: classifyBanReason(ban.reason),
rawReason: ban.reason,

banList: banList
});
}

this.storeBanFunc(bans);
} catch (err) {
Logger.verbose('BanFetcher', 1, `Failed to fetch ban list (ID: ${banList.id}): `, err);
}
}
}