Added untested Docker example

This commit is contained in:
REDNBLACK 2017-04-14 16:50:54 +03:00
parent 83c9975fbb
commit ecf86d706a
6 changed files with 46 additions and 21 deletions

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM python:3.6.1-slim
ENV CONFIG_PATH "./main.cfg"
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

View File

@ -9,6 +9,7 @@ ImaginaryFriend can:
* reply to random messages in chat groups, * reply to random messages in chat groups,
* reply to replies to its messages / messages mentioning it, * reply to replies to its messages / messages mentioning it,
* send (one!) sticker ("I'm frustrated by all these stickers"), * send (one!) sticker ("I'm frustrated by all these stickers"),
* detect repeating media files and send [:||||||||||||:] to chat,
* do some commands. * do some commands.
### Examples ### Examples
@ -42,7 +43,7 @@ ImaginaryFriend can:
## Commands ## Commands
* `/ping`, * `/ping`: you know the drill,
* `/get_stats`: get information on how many pairs are known by ImaginaryFriend, * `/get_stats`: get information on how many pairs are known by ImaginaryFriend,
* `/chance n`: set the probability that ImaginaryFriend would reply to a random message (must be in range 1-50, default: 5), * `/chance n`: set the probability that ImaginaryFriend would reply to a random message (must be in range 1-50, default: 5),
* `/сhance`: get current probability that ImaginaryFriend would reply to a message, * `/сhance`: get current probability that ImaginaryFriend would reply to a message,
@ -53,14 +54,19 @@ ImaginaryFriend can:
## Installation and Setup ## Installation and Setup
### Dependencies ### Setup using Docker
* `python >= 3.5.2` 1. Install [Docker](https://store.docker.com/search?offering=community&type=edition)
* `python-telegram-bot==5.2.0` 2. Rename `main.cfg.example` to `main.cfg`
* `redis==2.10.5` 3. Talk to [@botfather](https://telegram.me/botfather) and create your own bot.
4. Open `main.cfg` file in text editor and paste your newly created bot token into `bot`.`token` property
5. Execute `docker-compose up`
6. Congrats! You now have ImaginaryFriend of your own!
### Setup ## Setup without Docker
1. Install dependencies with PIP 1. Install [Python >= 3.5.2](https://www.python.org/downloads/)
2. Install `Redis` 2. Install [Redis >= 3.2](https://redis.io/download)
3. Rename `main.cfg.example` to `main.cfg`, set `bot` and `redis` properties 3. Install dependencies with PIP by executing command `pip install -r requirements.txt`
4. (Optionally) Configure `updates` property for websocket support 4. Talk to [@botfather](https://telegram.me/botfather) and create your own bot.
5. Run the `run.py` using python 5. Open `main.cfg` file in text editor and paste your newly created bot token into `bot`.`token` property
6. (Optionally) Configure `updates` property for websocket support
7. Execute the `python run.py`

11
docker-compose.yml Normal file
View File

@ -0,0 +1,11 @@
version: '2.1'
services:
bot:
build: .
command: python run.py
volumes:
- .:/code
depends_on:
- redis
redis:
image: redis:3.2.8-alpine

View File

@ -1,8 +1,7 @@
[bot] [bot]
token= token=
name= name=ImaginaryFriend
anchors= anchors=bot
messages=
purge_interval=43200.0 purge_interval=43200.0
default_chance=5 default_chance=5
spam_stickers=BQADAgADSAIAAkcGQwU-G-9SZUDTWAI spam_stickers=BQADAgADSAIAAkcGQwU-G-9SZUDTWAI
@ -32,6 +31,6 @@ key=
cert= cert=
[redis] [redis]
host= host=redis
port= port=6379
db= db=0

View File

@ -1,2 +1,2 @@
python-telegram-bot python-telegram-bot==5.3.0
redis redis==2.10.5

View File

@ -1,10 +1,11 @@
# Config # Config
import configparser import configparser
import os
encoding = 'utf-8' encoding = 'utf-8'
sections = { sections = {
'bot': ['token', 'name', 'anchors', 'messages', 'purge_interval', 'default_chance', 'spam_stickers'], 'bot': ['token', 'name', 'anchors', 'purge_interval', 'default_chance', 'spam_stickers'],
'grammar': ['chain_length', 'separator', 'stop_word', 'end_sentence', 'all'], 'grammar': ['chain_length', 'separator', 'stop_word', 'end_sentence', 'all'],
'logging': ['level'], 'logging': ['level'],
'updates': ['mode'], 'updates': ['mode'],
@ -18,8 +19,9 @@ def getlist(self, section, option, type=str):
configparser.ConfigParser.getlist = getlist configparser.ConfigParser.getlist = getlist
config_path = os.environ['CONFIG_PATH']
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('./main.cfg', encoding=encoding) config.read(config_path, encoding=encoding)
for section, options in sections.items(): for section, options in sections.items():
if not config.has_section(section): if not config.has_section(section):