From 4c13dc91e902a8ec6dcf703a03b72c9349b9345c Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90426410+lucmsilva651@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:15:29 -0300 Subject: [PATCH 01/14] Initial commit --- .gitignore | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 28 +++++++++ README.md | 2 + 3 files changed, 192 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82f9275 --- /dev/null +++ b/.gitignore @@ -0,0 +1,162 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..887d4ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2024, Lucas Gabriel + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..927f78f --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# lynx-spamwatch +Lynx integration with the SpamWatch API (WIP) From 8fe6dce44de50cdb24c2cec13d93c5662b0396ec Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Sun, 28 Jul 2024 13:31:24 -0300 Subject: [PATCH 02/14] Added main code + middleware --- Middleware.js | 9 +++++++++ spamwatch.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Middleware.js create mode 100644 spamwatch.js 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 From f0efeb63c414636d5ed523250d007f2b2248c583 Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Sat, 31 Aug 2024 21:20:49 -0300 Subject: [PATCH 03/14] Python blocklist generator + modified .gitignore + WARN string on spamwatch.js Signed-off-by: lucmsilva651 --- .gitignore | 4 ++++ blocklist_gen/main.py | 12 ++++++++++++ blocklist_gen/readme.txt | 3 +++ blocklist_gen/requirements.txt | 2 ++ spamwatch.js | 2 +- 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 blocklist_gen/main.py create mode 100644 blocklist_gen/readme.txt create mode 100644 blocklist_gen/requirements.txt diff --git a/.gitignore b/.gitignore index 82f9275..496c380 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,7 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# Specific to the Python blocklist generator +*.env +sw_blocklist.txt diff --git a/blocklist_gen/main.py b/blocklist_gen/main.py new file mode 100644 index 0000000..370b671 --- /dev/null +++ b/blocklist_gen/main.py @@ -0,0 +1,12 @@ +import os +from dotenv import load_dotenv +import spamwatch + +load_dotenv("config.env") + +client = spamwatch.Client(os.getenv('SW_KEY')) +bans = client.get_bans_min() + +with open('sw_blocklist.txt', 'w') as file: + for ban in bans: + file.write(f'{ban}\n') \ No newline at end of file diff --git a/blocklist_gen/readme.txt b/blocklist_gen/readme.txt new file mode 100644 index 0000000..5edee5c --- /dev/null +++ b/blocklist_gen/readme.txt @@ -0,0 +1,3 @@ +pip install -r requirements.txt +echo SW_KEY=APIKEY >> config.env # put your api key here +python main.py \ No newline at end of file diff --git a/blocklist_gen/requirements.txt b/blocklist_gen/requirements.txt new file mode 100644 index 0000000..989a366 --- /dev/null +++ b/blocklist_gen/requirements.txt @@ -0,0 +1,2 @@ +python-dotenv +spamwatch \ No newline at end of file diff --git a/spamwatch.js b/spamwatch.js index 042f99d..9b7c4d2 100644 --- a/spamwatch.js +++ b/spamwatch.js @@ -11,7 +11,7 @@ const readBlocklist = () => { 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.'); + 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); From 505bf6db3ec38c4a15ef5139e7dcfac9519b4ae6 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sun, 8 Dec 2024 19:46:39 -0300 Subject: [PATCH 04/14] Removed generator to migrate to another branch --- blocklist_gen/main.py | 12 ------------ blocklist_gen/readme.txt | 3 --- blocklist_gen/requirements.txt | 2 -- 3 files changed, 17 deletions(-) delete mode 100644 blocklist_gen/main.py delete mode 100644 blocklist_gen/readme.txt delete mode 100644 blocklist_gen/requirements.txt diff --git a/blocklist_gen/main.py b/blocklist_gen/main.py deleted file mode 100644 index 370b671..0000000 --- a/blocklist_gen/main.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -from dotenv import load_dotenv -import spamwatch - -load_dotenv("config.env") - -client = spamwatch.Client(os.getenv('SW_KEY')) -bans = client.get_bans_min() - -with open('sw_blocklist.txt', 'w') as file: - for ban in bans: - file.write(f'{ban}\n') \ No newline at end of file diff --git a/blocklist_gen/readme.txt b/blocklist_gen/readme.txt deleted file mode 100644 index 5edee5c..0000000 --- a/blocklist_gen/readme.txt +++ /dev/null @@ -1,3 +0,0 @@ -pip install -r requirements.txt -echo SW_KEY=APIKEY >> config.env # put your api key here -python main.py \ No newline at end of file diff --git a/blocklist_gen/requirements.txt b/blocklist_gen/requirements.txt deleted file mode 100644 index 989a366..0000000 --- a/blocklist_gen/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -python-dotenv -spamwatch \ No newline at end of file From 4ee2a82e1d52afcfd3cba956e9c9526a5ede5a64 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sun, 8 Dec 2024 19:48:22 -0300 Subject: [PATCH 05/14] Removed .gitignore from main branch because there is nothing to ignore anymore --- .gitignore | 166 ----------------------------------------------------- 1 file changed, 166 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 496c380..0000000 --- a/.gitignore +++ /dev/null @@ -1,166 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/latest/usage/project/#working-with-version-control -.pdm.toml -.pdm-python -.pdm-build/ - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - -# Specific to the Python blocklist generator -*.env -sw_blocklist.txt From 424d2f13cf68980879add94b9aed1239d91d71c0 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sun, 8 Dec 2024 19:51:49 -0300 Subject: [PATCH 06/14] Push blocklist generator to the branch --- LICENSE | 28 ++++++++++++++++++++++++++++ README.md | 8 ++++++++ config.env.example | 1 + main.py | 12 ++++++++++++ requirements.txt | 2 ++ 5 files changed, 51 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 config.env.example create mode 100644 main.py create mode 100644 requirements.txt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..887d4ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2024, Lucas Gabriel + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e2ea87b --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# SpamWatch blocklist generator +> Put your SpamWatch API key on a config.env file. Use the .example file to see how. + +Then do these commands: +``` +pip install -r requirements.txt +python main.py +``` \ No newline at end of file diff --git a/config.env.example b/config.env.example new file mode 100644 index 0000000..bf7aade --- /dev/null +++ b/config.env.example @@ -0,0 +1 @@ +SW_KEY = "Insert your SpamWatch API key here" \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..370b671 --- /dev/null +++ b/main.py @@ -0,0 +1,12 @@ +import os +from dotenv import load_dotenv +import spamwatch + +load_dotenv("config.env") + +client = spamwatch.Client(os.getenv('SW_KEY')) +bans = client.get_bans_min() + +with open('sw_blocklist.txt', 'w') as file: + for ban in bans: + file.write(f'{ban}\n') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..989a366 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +python-dotenv +spamwatch \ No newline at end of file From 504ab21ad03d31345e6a6b62ee1e89aa03fc27e0 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sun, 8 Dec 2024 20:17:29 -0300 Subject: [PATCH 07/14] Changed branding, Lynx to Kowalski (ty @SKIQQ-flower for the name) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 927f78f..7db7d77 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # lynx-spamwatch -Lynx integration with the SpamWatch API (WIP) +Kowalski integration with the SpamWatch API (WIP) From f81915510c320c3fe2479c8265f5893259698c3d Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sun, 8 Dec 2024 21:51:07 -0300 Subject: [PATCH 08/14] Removed Lynx name from README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7db7d77..16edc68 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# lynx-spamwatch +# TelegramBot-SpamWatch Kowalski integration with the SpamWatch API (WIP) From 8d35b7ec4cffb48df8d1f59485b32e2484ae64e7 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Date: Mon, 9 Dec 2024 22:28:06 -0300 Subject: [PATCH 09/14] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e1a467d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +abocn@protonmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From bb6ead9e5c9d710c22be1ce807fd3b019a5c175c Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Date: Sat, 12 Apr 2025 12:58:04 -0300 Subject: [PATCH 10/14] Update spamwatch.js --- spamwatch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spamwatch.js b/spamwatch.js index 9b7c4d2..031c7a2 100644 --- a/spamwatch.js +++ b/spamwatch.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); -const blocklistPath = path.join(__dirname, '../../props/sw_blocklist.txt'); +const blocklistPath = path.join(__dirname, 'sw_blocklist.txt') || path.join(__dirname, '../../props/sw_blocklist.txt'); let blocklist = []; @@ -25,4 +25,4 @@ const isOnSpamWatch = (userId) => { readBlocklist(); -module.exports = { isOnSpamWatch }; \ No newline at end of file +module.exports = { isOnSpamWatch }; From b71b3b9eab0f172c038674fc6739fce9199ad3e0 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sat, 12 Apr 2025 13:05:19 -0300 Subject: [PATCH 11/14] Add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0617be9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +sw_blocklist.txt \ No newline at end of file From 2f532fdd0d83566c27d22ad7ca2dfbcf4680786d Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Tue, 15 Apr 2025 19:51:47 -0300 Subject: [PATCH 12/14] SW blocklist is local only now --- spamwatch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spamwatch.js b/spamwatch.js index 031c7a2..8428828 100644 --- a/spamwatch.js +++ b/spamwatch.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); -const blocklistPath = path.join(__dirname, 'sw_blocklist.txt') || path.join(__dirname, '../../props/sw_blocklist.txt'); +const blocklistPath = path.join(__dirname, 'sw_blocklist.txt'); let blocklist = []; From cee30dc64217e7ec235635f5bf5066eac56eec87 Mon Sep 17 00:00:00 2001 From: Aidan Date: Tue, 29 Apr 2025 15:52:20 -0400 Subject: [PATCH 13/14] 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 }; From 5e9de56c7e117811f8dba16fb671b65469688144 Mon Sep 17 00:00:00 2001 From: Aidan Date: Mon, 30 Jun 2025 02:04:17 -0400 Subject: [PATCH 14/14] add new functions --- spamwatch.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spamwatch.ts b/spamwatch.ts index 050b006..ec7a054 100644 --- a/spamwatch.ts +++ b/spamwatch.ts @@ -23,6 +23,10 @@ const isOnSpamWatch = (userId: string) => { return blocklist.includes(userId); }; +const isSpamwatchConnected = () => blocklist.length > 0; + +const getSpamwatchBlockedCount = () => blocklist.length; + readBlocklist(); -export { isOnSpamWatch }; +export { isOnSpamWatch, isSpamwatchConnected, getSpamwatchBlockedCount };