Skip to content

Commit

Permalink
fix(all): fix 'logs' & 'users.json'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey-Voko committed Mar 31, 2023
1 parent 586447d commit ff34b06
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ env_dist

# user
logs
users
LICENSE
Procfile
README.md
brief.txt
runtime.txt
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ fabric.properties
# user
output/
tmpl/
logs/
users/
tmpl.*
*.env
brief.*
*.env
logs/
users/
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COPY requirements.txt .
RUN pip install --no-cache-dir -r ./requirements.txt

COPY captcha_bot ./captcha_bot
COPY users ./users

CMD ["python", "-m", "captcha_bot"]

Expand Down
1 change: 0 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
worker: python -m captcha_bot

53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# CaptchaBot

telegram-bot (python, [aiogram](https://aiogram.dev/))
Telegram-bot (python, [aiogram](https://aiogram.dev/))

captcha for incoming telegram chats users
Captcha for incoming telegram chats users.

### Launching in Docker

Create and start container:

```bash
$ export BOT_TOKEN=<BOT_TOKEN>
$ export CHAT_ID_1=<CHAT_ID_1>
$ export CHAT_ID_2=<CHAT_ID_2>
$ export CHAT_ID_3=<CHAT_ID_3>
$ export CHAT_ID_4=<CHAT_ID_4>
$ docker-compose up -d
```

Stop lifted containers:

```bash
$ docker-compose stop
```

Start stopped containers:

```bash
$ docker-compose start
```

Stop and delete containers and network:

```bash
$ docker-compose down
```

Remove image:

```bash
$ docker rmi captcha_bot
```

Clear logs:

```bash
$ sudo rm -rf logs/*
```

Execute a command in a running container:

```bash
$ docker exec -it CaptchaBot bash
```
12 changes: 7 additions & 5 deletions captcha_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
for i in range(MAX_CHATS_NUMBER):
chat_id = os.getenv(f'CHAT_ID_{str(i)}')
if chat_id:
WORKS_CHATS[int(chat_id)] = 'chat_id_' + str(i)
WORKS_CHATS[int(chat_id)] = f'chat_id_{str(i)}'

USERS_DATA_FILE = 'logs/users.json'
USERS_DATA_FILE = 'users/users.json'

BAN_TIME = 30 # minutes
TIME_FOR_TEST = 30 # seconds
Expand All @@ -33,7 +33,7 @@
'3': 'ТРИ',
'4': 'ЧЕТЫРЕ',
'5': 'ПЯТЬ',
'0': 'НОЛЬ'
'0': 'НОЛЬ',
}

for BUTTON in range(BUTTONS_NUMBER):
Expand All @@ -57,7 +57,9 @@
'not right': 'Неправильно, я тебя баню!',
'greeting with riddle': (
lambda name, number:
f'Привет, {name}! Это анти-спам проверка. Если ты не бот, '
+ f'нажми в течение {TIME_FOR_TEST} сек. кнопку c цифрой {number}'
(f'Привет, {name}! '
'Это анти-спам проверка. '
f'Если ты не бот, нажми в течение {TIME_FOR_TEST} '
f'сек. кнопку c цифрой {number}')
)
}
2 changes: 0 additions & 2 deletions captcha_bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@


def main():
Path(USERS_DATA_FILE).parent.mkdir(parents=True, exist_ok=True)

log_name = f'logs/{datetime.now().strftime("%Y-%m-%d")}.log'
Path(log_name).parent.mkdir(parents=True, exist_ok=True)

Expand Down
2 changes: 1 addition & 1 deletion captcha_bot/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def handler_check_message(message):
return

if message.from_user.id in doubtful_users:
forwarded = bool(getattr(message, "forward_date"))
forwarded = bool(getattr(message, 'forward_date'))
with_links = False

for entity in message.entities:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ volumes:
# -------------------------------
# Clear logs & users:
# $ sudo rm -rf logs/*
# $ sudo rm -rf users/*
4 changes: 0 additions & 4 deletions env_dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# This is your bot's token. Go to https://t.me/botfather to register your own bot. It's free!
BOT_TOKEN = 12345:AaBbCcDdEeFfGgHhIiJjKk

RAILWAY_APP_NAME = RaIlWaY_ApP_NaMe

PORT = 8000

# ID of bot's main group, where messages are checked
CHAT_ID_1 = -100987654321
CHAT_ID_2 = -100987654321
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiogram~=2.25.1
aiogram==2.25.1
pytz==2023.3
python-dotenv==1.0.0
asynctest==0.13.0

0 comments on commit ff34b06

Please sign in to comment.