Skip to content

Commit 41aa156

Browse files
committed
Add docker support
1 parent 41f2a6d commit 41aa156

11 files changed

+50
-17
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Project
2+
install.sh
3+
README.md
4+
data/*
5+
6+
# Cache
7+
__pycache__
8+
.vscode
9+
10+
# Docker
11+
Dockerfile

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:buster
2+
WORKDIR /app
3+
RUN mkdir data
4+
COPY . .
5+
RUN pip3 install -r requirements.txt
6+
ENTRYPOINT ["python"]
7+
CMD ["main.py"]

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# rude_bot
22
Karmabot for telegram chat [@rude_chat](https://t.me/rude_chat)
3+
![Waterfall](data/media/cat.jpg)
34

45
## Install
56

@@ -12,16 +13,24 @@ Use next environment variables:
1213
* `RUDEBOT_FLOOD_TIMEOUT=10` - cooldown to allow +- karma per chat, default 30 seconds
1314
* `RUDEBOT_DELETE_TIMEOUT=30` - time before bot messages being deleted
1415
* `RUDEBOT_DATABASE_FILENAME=rudebot_db.json` - stored database name
15-
* `RUDEBOT_ALLOWED_CHATS=-10010101,-10000101010` - whitelist chats. If it empty, whitelist mode will be turned off.
16+
* `RUDEBOT_ALLOWED_CHATS=-10010101,-10000101010` - whitelist chats. If it empty or not added to envs, whitelist mode will be turned off.
1617

1718
**Python:** Add to system environment that variables.
1819

20+
**Docker compose:** create `.env` file and fill it with that variables.
21+
1922
## Run
2023

24+
25+
### Docker compose
26+
27+
```
28+
docker-compose up -d
29+
```
30+
2131
### Python
2232

2333
```
24-
cd app/
2534
pip3 install -r requirements.txt
2635
python main.py
2736
```

data/media/cat.jpg

52.9 KB
Loading
File renamed without changes.

media/sh.MOV data/media/sh.MOV

File renamed without changes.
File renamed without changes.
File renamed without changes.

docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "3.3"
2+
services:
3+
karmabot:
4+
build: .
5+
image: rudebot
6+
volumes:
7+
- ./data:/app/data
8+
env_file:
9+
- .env
10+
container_name: rudebot-container

main.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
bot_token = os.getenv('RUDEBOT_TELEGRAM_TOKEN')
2222
flood_timeout = int(os.getenv('RUDEBOT_FLOOD_TIMEOUT', '10'))
2323
destruction_timeout = int(os.getenv('RUDEBOT_DELETE_TIMEOUT', '30'))
24-
database_filename = (os.getenv('RUDEBOT_DATABASE_FILENAME', 'db.json'))
24+
database_filename = 'data/' + (os.getenv('RUDEBOT_DATABASE_FILENAME', 'db.json'))
2525
whitelist_chats = os.getenv('RUDEBOT_ALLOWED_CHATS', '')
2626

2727
whitelist_chats: list = None if whitelist_chats == '' else [int(chat) for chat in whitelist_chats.split(',')]
@@ -93,16 +93,13 @@ def add_or_update_user(user_id: int, username: str, mats_count: int):
9393

9494
def get_karma(user_id : int):
9595
def size(id: int):
96-
result = hashlib.md5(id.to_bytes(8, 'big', signed=True)).hexdigest()
97-
size = int(result, 16)
98-
size = size % 15 + 7
99-
return size
96+
return (id+6) % 15 + 7
10097

10198
def orientation(id: int):
10299
result = hashlib.md5(id.to_bytes(8, 'big', signed=True)).hexdigest()
103100
_orientation = int(result, 16)
104-
_orientation_1 = _orientation % 1
105-
_orientation_2 = _orientation % 5 % 1
101+
_orientation_1 = _orientation % 3
102+
_orientation_2 = _orientation % 5 % 2
106103
return _orientation_1, _orientation_2
107104

108105
user = users[user_id]
@@ -128,12 +125,10 @@ def orientation(id: int):
128125
replytext += f"Довжина: `{user_size}` сантиметрів, ну і гігант...\n"
129126

130127
user_values = orientation(user_id)
131-
orientation_type = ['Латентний', ''][user_values[0]]
128+
orientation_type = ['Латентний', 'Гендерфлюід', ''][user_values[0]]
132129
orientation_name = ['Android', 'Apple'][user_values[0]]
133130
replytext += f"Орієнтація: `{orientation_type} {orientation_name}` користувач"
134131

135-
replytext = replytext.replace('_', '\\_')
136-
137132
return replytext
138133

139134

@@ -235,7 +230,7 @@ def read_users():
235230
with open(database_filename, 'r', encoding= 'utf-8') as f:
236231
users = eval(f.read())
237232
else:
238-
print ("File not exist")
233+
print("File not exist")
239234

240235

241236
@dp.callback_query_handler(lambda call: call.data == "refresh_top")
@@ -284,7 +279,7 @@ async def add_group(message: types.Message):
284279

285280

286281
message_text = f"Вітаємо {message.from_user.mention} у нашому чаті! Ми не чат, а дружня, толерантна IT спільнота, яка поважає думку кожного, приєднавшись, ти згоджуєшся стати чемною частиною спільноти (та полюбити епл). I якшо не важко, пліз тут анкета на 8 питань https://forms.gle/pY6EjJhNRosUbd9P9"
287-
msg = await bot.send_animation(chat_id = message.chat.id, reply_to_message_id = message.message_id, animation = open("media/welcome.mp4", 'rb'), caption = message_text, reply_markup = keyboard)
282+
msg = await bot.send_animation(chat_id = message.chat.id, reply_to_message_id = message.message_id, animation = open("data/media/welcome.mp4", 'rb'), caption = message_text, reply_markup = keyboard)
288283
await autodelete_message(msg.chat.id, msg.message_id, destruction_timeout * 5)
289284

290285

@@ -355,21 +350,21 @@ async def zrada(message: types.Message):
355350
@dp.message_handler(white_list_chats(), ignore_old_messages(), regexp='xiaomi|сяоми|ксиоми|ксяоми')
356351
@update_user
357352
async def xiaomi(message: types.Message):
358-
msg = await bot.send_photo(message.chat.id, reply_to_message_id=message.message_id, photo=open('media/xiaomi.jpg', 'rb'))
353+
msg = await bot.send_photo(message.chat.id, reply_to_message_id=message.message_id, photo=open('data/media/xiaomi.jpg', 'rb'))
359354
await autodelete_message(msg.chat.id, msg.message_id, destruction_timeout)
360355

361356

362357
@dp.message_handler(white_list_chats(), ignore_old_messages(), regexp='iphone|айфон|іфон|епл|еппл|apple|ipad|айпад|macbook|макбук')
363358
@update_user
364359
async def iphone(message: types.Message):
365-
msg = await bot.send_photo(message.chat.id, reply_to_message_id=message.message_id, photo=open('media/iphon.jpg', 'rb'))
360+
msg = await bot.send_photo(message.chat.id, reply_to_message_id=message.message_id, photo=open('data/media/iphon.jpg', 'rb'))
366361
await autodelete_message(msg.chat.id, msg.message_id, destruction_timeout)
367362

368363

369364
@dp.message_handler(white_list_chats(), ignore_old_messages(), regexp='шарий|шарій')
370365
@update_user
371366
async def сockman(message: types.Message):
372-
msg = await bot.send_video(message.chat.id, video=open('media/sh.MOV', mode='rb'))
367+
msg = await bot.send_video(message.chat.id, video=open('data/media/sh.MOV', mode='rb'))
373368
await autodelete_message(msg.chat.id, msg.message_id, destruction_timeout)
374369

375370

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
aiogram==2.14.2
2+
requests

0 commit comments

Comments
 (0)