Skip to content

Commit

Permalink
Switched Python to 3.6. Dockerfile was added. Bumped version number t…
Browse files Browse the repository at this point in the history
…o 2.0.0.
  • Loading branch information
quasiyoke committed May 27, 2017
1 parent 0eca74f commit 26d4af7
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ target/

# Bot
conf*.json
*.sh

#Virtualenv
# Virtualenv
bin/
share/
lib64
pip-selfcheck.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python

python:
- "3.5"
- "3.6"

install:
- python setup.py install
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.6
MAINTAINER Pyotr Ermishkin <quasiyoke@gmail.com>

COPY randtalkbot /randtalkbot/
COPY docker-entrypoint.sh /
COPY randtalkbot-runner.py /
COPY README.rst /
COPY setup.py /

VOLUME /configuration

RUN python /setup.py install

CMD ["/docker-entrypoint.sh"]
115 changes: 43 additions & 72 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Rand Talk
.. image:: https://travis-ci.org/quasiyoke/RandTalkBot.svg?branch=dev
:target: https://travis-ci.org/quasiyoke/RandTalkBot

Telegram bot matching you with a random person of desired sex speaking on your language(s). Chat with anonymous strangers `here <https://telegram.me/RandTalkBot>`_. Rand Talk was written on Python 3.5 and `telepot <https://github.com/nickoala/telepot>`_ and uses MySQL to store users' preferences. Rand Talk's interface was translated on several languages. You're able to send any messages except replies and forwarded messages. Rand Talk rewards you with bonuses for people you invite using your individual link. To get this link, use @RandTalkBot as inline bot. The bot collects stats regularly. Rand Talk rewards you with more bonuses for the people of rare sex.
Telegram bot matching you with a random person of desired sex speaking on your language(s). Chat with anonymous strangers `here <https://telegram.me/RandTalkBot>`_. Rand Talk was written on Python 3.6 and `telepot <https://github.com/nickoala/telepot>`_ and uses MySQL to store users' preferences. Rand Talk's interface was translated on several languages. You're able to send any messages except replies and forwarded messages. Rand Talk rewards you with bonuses for people you invite using your individual link. To get this link, use @RandTalkBot as inline bot. The bot collects stats regularly. Rand Talk rewards you with more bonuses for the people of rare sex.

Supported commands
------------------
Expand All @@ -27,118 +27,89 @@ Admins specified at ``admins`` configuration property are able to use the follow
Roadmap
-------

* 1.4 Reports
* 1.5 Replies
* 1.6 Customizable greetings message
* 1.7 /oops command to ask your recent partner to connect together again
* 2.2 Reports
* 2.3 Replies
* 2.4 Customizable greetings message
* 2.5 /oops command to ask your recent partner to connect together again

Deployment
----------

::

$ virtualenv --python=/usr/bin/python3.5 randtalkbotenv
$ source randtalkbotenv/bin/activate
(randtalkbotenv) $ pip install https://github.com/quasiyoke/RandTalkBot/zipball/master

After that write ``randtalkbotenv/configuration.json`` file like that::
$ docker network create \
--subnet=172.28.0.0/16 \
randtalkbot
$ docker run \
--name=randtalkbot-mysql \
--net=randtalkbot \
--ip=172.28.0.50 \
--env="MYSQL_ROOT_PASSWORD=P9u205LLeY8XyRt3fM8t77D8" \
--env="MYSQL_DATABASE=randtalkbot" \
--env="MYSQL_USER=randtalkbot" \
--env="MYSQL_PASSWORD=xwBUr3oobCXjqSvz4t" \
--detach \
mysql:5.7
$ git clone https://github.com/quasiyoke/RandTalkBot.git
$ cd RandTalkBot
$ docker build --tag=randtalkbot .

After that write ``configuration/configuration.json`` file like that::

{
"admins": [31416, 271828],
"database": {
"host": "localhost",
"name": "randtalk",
"host": "172.28.0.50",
"name": "randtalkbot",
"user": "randtalkbot",
"password": "xwBUr3oobCXjqSvz4t"
},
},
"logging": {
"version": 1,
"formatters": {
"simple": {
"class": "logging.Formatter",
"format": "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
}
},
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
"filename": "log.log",
"maxBytes": 10485760,
"backupCount": 10,
"encoding": "utf-8"
},
"email": {
"class": "logging.handlers.SMTPHandler",
"level": "ERROR",
"formatter": "simple",
"mailhost": ["smtp.gmail.com", 587],
"fromaddr": "example1@gmail.com",
"toaddrs": ["example2@gmail.com"],
"subject": "[Rand Talk Error]",
"credentials": ["example1@gmail.com", "RM49p7XFB:Z6x@kCkv"],
"secure": []
}
},
}
},
"loggers": {
"randtalkbot": {
"level": "DEBUG",
"handlers": []
},
},
"peewee": {
"level": "DEBUG",
"handlers": []
}
},
}
},
"root": {
"level": "DEBUG",
"handlers": ["console", "email"]
}
},
}
},
"token": "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
}
}

Where:

* ``admins`` — list of admins' Telegram IDs. Admins are able to use extended list of bot commands. Optional. Default is ``[]``.
* ``logging`` — logging setup as described in `this howto <https://docs.python.org/3/howto/logging.html>`_.

Create MySQL DB::

CREATE DATABASE IF NOT EXISTS randtalk CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER randtalkbot@localhost IDENTIFIED BY 'xwBUr3oobCXjqSvz4t';
GRANT ALL ON randtalk.* TO randtalkbot@localhost;

Create necessary DB tables::

(randtalkbotenv) $ randtalkbot install randtalkbotenv/configuration.json

Now you may run ``randtalkbot``::

(randtalkbotenv) $ randtalkbot randtalkbotenv/configuration.json

Updating using SSH
^^^^^^^^^^^^^^^^^^

I'm using such shell script for semi-automatic deployment::

#!/bin/bash
cd path/to/randtalkbotenv/
source bin/activate
echo "y" | pip uninstall randtalkbot
pip install https://github.com/quasiyoke/RandTalkBot/zipball/master
killall randtalkbot
nohup randtalkbot configuration.json &

Just launch::
Now you may run Rand Talk::

$ ssh john_doe@8.8.8.8 "bash -s" < deploy.sh
$ docker run \
--name=randtalkbot \
--net=randtalkbot \
--volume=`pwd`/configuration:/configuration \
--detach \
randtalkbot

Contributing
------------
Expand Down
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

/randtalkbot-runner.py install /configuration/configuration.json
/randtalkbot-runner.py /configuration/configuration.json
14 changes: 9 additions & 5 deletions randtalkbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .admin_handler import AdminHandler
from .stranger_handler import StrangerHandler
from telepot.delegate import per_from_id_in, per_from_id_except
from telepot.aio.delegate import create_open
from telepot.aio.delegate import create_open, pave_event_space

LOGGER = logging.getLogger('randtalkbot.bot')

Expand All @@ -23,16 +23,20 @@ def __init__(self, configuration):
[
# If the bot isn't chatting with an admin, skip, so for this
# chat will be used another handler, not AdminHandler.
(per_from_id_in(self._admins_telegram_ids), create_open(
pave_event_space()(
per_from_id_in(self._admins_telegram_ids),
create_open,
AdminHandler,
timeout=60,
)),
),
# If the bot is chatting with an admin, skip, so for this chat
# will be used another handler, not StrangerHandler.
(per_from_id_except(self._admins_telegram_ids), create_open(
pave_event_space()(
per_from_id_except(self._admins_telegram_ids),
create_open,
StrangerHandler,
timeout=60,
)),
),
],
)

Expand Down
2 changes: 1 addition & 1 deletion randtalkbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

from os import path

__version__ = '1.3.8'
__version__ = '2.0.0'
RANDTALKBOT_DIR = path.abspath(path.dirname(__file__))
LOCALE_DIR = path.join(RANDTALKBOT_DIR, 'locale')
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ def run_tests(self):
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU Affero General Public License v3',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Communications :: Chat',
],
install_requires=[
'docopt>=0.6.2,<0.7',
'peewee>=2.7.4,<3.0',
'pycountry>=1.19,<2.0',
'pymysql>=0.6.7,<0.7',
'telepot>=8.2,<8.3',
'telepot>=12.0,<13.0',
],
tests_require=[
'asynctest>=0.6,<0.7',
Expand Down
1 change: 1 addition & 0 deletions tests/test_admin_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setUp(self, stranger_sender_service):
self.sender.send_notification = CoroutineMock()
self.admin_handler = AdminHandler(
(Mock(), self.initial_msg, 31416),
event_space=None,
timeout=1,
)
self.stranger_sender_service = stranger_sender_service
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stranger_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def setUp(self, stranger_sender_service, StrangerSetupWizard):
self.sender.send_notification = CoroutineMock()
self.stranger_handler = StrangerHandler(
(Mock(), self.initial_msg, 31416),
event_space=None,
timeout=1,
)
self.stranger_sender_service = stranger_sender_service
Expand All @@ -60,6 +61,7 @@ def test_init__ok(self, StrangerSetupWizard):
stranger_service.get_or_create_stranger.return_value = self.stranger
self.stranger_handler = StrangerHandler(
(Mock(), self.initial_msg, 31416),
event_space=None,
timeout=1,
)
self.assertEqual(self.stranger_handler._from_id, 31416)
Expand All @@ -79,6 +81,7 @@ def test_init__stranger_service_error(self):
with self.assertRaises(SystemExit):
self.stranger_handler = StrangerHandler(
(Mock(), self.initial_msg, 31416),
event_space=None,
timeout=1,
)
self.assertEqual(self.stranger_handler._from_id, 31416)
Expand Down

0 comments on commit 26d4af7

Please sign in to comment.