Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set up custom ban duration via CAPTCHABOT_BAN_DURATION option #204

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**/.vscode/
**/__pycache__/
**/data/
**/.idea/

**/*.pyc
**/*.pkl
Expand Down
6 changes: 6 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@
int(os_getenv("CAPTCHABOT_MAX_FAIL_BAN_POLL",
SETTINGS["CAPTCHABOT_MAX_FAIL_BAN_POLL"])),

# Duration of ban (in seconds, negative values mean indefinite ban).
# Useful if you want to ban someone temporarily.
"BAN_DURATION":
int(os_getenv("CAPTCHABOT_BAN_DURATION",
SETTINGS["CAPTCHABOT_BAN_DURATION"])),

# Last session restorable RAM data backup file path
"F_SESSION": SCRIPT_PATH + "/session.pkl",

Expand Down
9 changes: 8 additions & 1 deletion src/join_captcha_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
# Collections Data Types Library
from collections import OrderedDict

# Date and Time Library
from datetime import datetime, timedelta, timezone

# JSON Library
from json import dumps as json_dumps

Expand Down Expand Up @@ -873,7 +876,11 @@ async def captcha_fail_member_kick(bot, chat_id, user_id, user_name):
logger.info("[%s] Captcha Fail - Ban - %s (%s)",
chat_id, user_name, user_id)
# Try to ban the user and notify Admins
ban_result = await tlg_ban_user(bot, chat_id, user_id)
if CONST["BAN_DURATION"] >= 0:
ban_until_date = datetime.now(timezone.utc) + timedelta(seconds=CONST["BAN_DURATION"])
else:
ban_until_date = None
ban_result = await tlg_ban_user(bot, chat_id, user_id, until_date=ban_until_date)
if ban_result["error"] == "":
# Ban success
banned = True
Expand Down
6 changes: 5 additions & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,9 @@
# Maximum number of times a user fail to solve a Poll captcha.
# If a user don't solve the captcha after this, it will be ban
# instead kick
"CAPTCHABOT_MAX_FAIL_BAN_POLL": 3
"CAPTCHABOT_MAX_FAIL_BAN_POLL": 3,

# Duration of ban (in seconds, negative values mean indefinite ban).
# Useful if you want to ban someone temporarily.
"CAPTCHABOT_BAN_DURATION": -1,
}
Loading