diff --git a/Middleware.js b/Middleware.js new file mode 100644 index 0000000..5e22c04 --- /dev/null +++ b/Middleware.js @@ -0,0 +1,9 @@ +module.exports = (isOnSpamWatch) => { + return async (ctx, next) => { + if (await isOnSpamWatch(ctx.from.id)) { + console.log(`User ${ctx.from.id} is banned on SpamWatch. Blocking command.`); + return; + } + await next(); + }; +}; \ No newline at end of file diff --git a/spamwatch.js b/spamwatch.js new file mode 100644 index 0000000..042f99d --- /dev/null +++ b/spamwatch.js @@ -0,0 +1,28 @@ +const fs = require('fs'); +const path = require('path'); + +const blocklistPath = path.join(__dirname, '../../props/sw_blocklist.txt'); + +let blocklist = []; + +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 API key to push the blocklist to the file.'); + fs.writeFileSync(blocklistPath, ''); + } else { + console.error('WARN: Error reading SpamWatch blocklist:', error); + } + } +}; + +const isOnSpamWatch = (userId) => { + return blocklist.includes(String(userId)); +}; + +readBlocklist(); + +module.exports = { isOnSpamWatch }; \ No newline at end of file