Migrate to TypeScript (#1)

* rf: js -> ts

* [m] docs: add badges, lint
This commit is contained in:
Aidan 2025-04-29 15:52:20 -04:00 committed by GitHub
parent 2f532fdd0d
commit cee30dc642
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

28
spamwatch.ts Normal file
View file

@ -0,0 +1,28 @@
import fs from 'fs';
import path from 'path';
const blocklistPath = path.join(__dirname, 'sw_blocklist.txt');
let blocklist: string[] = [];
const readBlocklist = () => {
try {
const data = fs.readFileSync(blocklistPath, 'utf8');
blocklist = data.split('\n').map(id => id.trim()).filter(id => id !== '');
} catch (error) {
if (error.code === 'ENOENT') {
console.log('WARN: SpamWatch blocklist file not found. Creating a new, blank one.\nUse your own SpamWatch API key and our generator to push the blocklist to the file.');
fs.writeFileSync(blocklistPath, '');
} else {
console.error('WARN: Error reading SpamWatch blocklist:', error);
}
}
};
const isOnSpamWatch = (userId: string) => {
return blocklist.includes(userId);
};
readBlocklist();
export { isOnSpamWatch };