From cee30dc64217e7ec235635f5bf5066eac56eec87 Mon Sep 17 00:00:00 2001 From: Aidan Date: Tue, 29 Apr 2025 15:52:20 -0400 Subject: [PATCH] Migrate to TypeScript (#1) * rf: js -> ts * [m] docs: add badges, lint --- Middleware.js => Middleware.ts | 2 +- README.md | 4 ++++ spamwatch.js => spamwatch.ts | 12 ++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) rename Middleware.js => Middleware.ts (84%) rename spamwatch.js => spamwatch.ts (76%) diff --git a/Middleware.js b/Middleware.ts similarity index 84% rename from Middleware.js rename to Middleware.ts index 5e22c04..9586d52 100644 --- a/Middleware.js +++ b/Middleware.ts @@ -1,4 +1,4 @@ -module.exports = (isOnSpamWatch) => { +export default (isOnSpamWatch) => { return async (ctx, next) => { if (await isOnSpamWatch(ctx.from.id)) { console.log(`User ${ctx.from.id} is banned on SpamWatch. Blocking command.`); diff --git a/README.md b/README.md index 16edc68..4931cf1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # TelegramBot-SpamWatch + +[![GitHub License](https://img.shields.io/github/license/abocn/TelegramBot)](https://github.com/abocn/TelegramBot/blob/main/LICENSE) +[![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=fff)](https://www.typescriptlang.org) + Kowalski integration with the SpamWatch API (WIP) diff --git a/spamwatch.js b/spamwatch.ts similarity index 76% rename from spamwatch.js rename to spamwatch.ts index 8428828..050b006 100644 --- a/spamwatch.js +++ b/spamwatch.ts @@ -1,9 +1,9 @@ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; const blocklistPath = path.join(__dirname, 'sw_blocklist.txt'); -let blocklist = []; +let blocklist: string[] = []; const readBlocklist = () => { try { @@ -19,10 +19,10 @@ const readBlocklist = () => { } }; -const isOnSpamWatch = (userId) => { - return blocklist.includes(String(userId)); +const isOnSpamWatch = (userId: string) => { + return blocklist.includes(userId); }; readBlocklist(); -module.exports = { isOnSpamWatch }; +export { isOnSpamWatch };