Merge remote-tracking branch 'origin/dev-1.x' into dev-1.x

This commit is contained in:
Alex Root Junior 2018-01-23 23:39:59 +02:00
commit f7ef84acbc
19 changed files with 98 additions and 40 deletions

View file

@ -8,7 +8,7 @@
[![Github issues](https://img.shields.io/github/issues/aiogram/aiogram.svg?style=flat-square)](https://github.com/aiogram/aiogram/issues)
[![MIT License](https://img.shields.io/pypi/l/aiogram.svg?style=flat-square)](https://opensource.org/licenses/MIT)
**aiogram** is are pretty simple and fully asynchronously library for [Telegram Bot API](https://core.telegram.org/bots/api) written in Python 3.6 with [asyncio](https://docs.python.org/3/library/asyncio.html) and [aiohttp](https://github.com/aio-libs/aiohttp). It helps to make your bots more faster and simpler.
**aiogram** is a pretty simple and fully asynchronous library for [Telegram Bot API](https://core.telegram.org/bots/api) written in Python 3.6 with [asyncio](https://docs.python.org/3/library/asyncio.html) and [aiohttp](https://github.com/aio-libs/aiohttp). It helps you to make your bots faster and simpler.
You can [read the docs here](http://aiogram.readthedocs.io/en/latest/).

View file

@ -30,7 +30,7 @@ AIOGramBot
:alt: MIT License
**aiogram** is are pretty simple and fully asynchronously library for `Telegram Bot API <https://core.telegram.org/bots/api>`_ written in Python 3.6 with `asyncio <https://docs.python.org/3/library/asyncio.html>`_ and `aiohttp <https://github.com/aio-libs/aiohttp>`_. It helps to make your bots more faster and simpler.
**aiogram** is a pretty simple and fully asynchronous library for `Telegram Bot API <https://core.telegram.org/bots/api>`_ written in Python 3.6 with `asyncio <https://docs.python.org/3/library/asyncio.html>`_ and `aiohttp <https://github.com/aio-libs/aiohttp>`_. It helps you to make your bots faster and simpler.
You can `read the docs here <http://aiogram.readthedocs.io/en/latest/>`_.

View file

@ -4,7 +4,8 @@ try:
from .bot import Bot
except ImportError as e:
if e.name == 'aiohttp':
warnings.warn('Dependencies is not installed!', category=ImportWarning)
warnings.warn('Dependencies are not installed!',
category=ImportWarning)
else:
raise

View file

@ -132,6 +132,32 @@ class RegexpFilter(Filter):
return bool(self.regexp.search(message.text))
class RegexpCommandsFilter(AsyncFilter):
"""
Check commands by regexp in message
"""
def __init__(self, regexp_commands):
self.regexp_commands = [re.compile(command, flags=re.IGNORECASE | re.MULTILINE) for command in regexp_commands]
async def check(self, message):
if not message.is_command():
return False
command = message.text.split()[0][1:]
command, _, mention = command.partition('@')
if mention and mention != (await message.bot.me).username:
return False
for command in self.regexp_commands:
search = command.search(message.text)
if search:
message.conf['regexp_command'] = search
return True
return False
class ContentTypeFilter(Filter):
"""
Check message content type

View file

@ -1,5 +1,5 @@
"""
Need setup task factory:
You need to setup task factory:
>>> from aiogram.utils import context
>>> loop = asyncio.get_event_loop()
>>> loop.set_task_factory(context.task_factory)

View file

@ -51,7 +51,8 @@ def start_pooling(*args, **kwargs):
return start_polling(*args, **kwargs)
def start_polling(dispatcher, *, loop=None, skip_updates=False, on_startup=None, on_shutdown=None):
def start_polling(dispatcher, *, loop=None, skip_updates=False,
on_startup=None, on_shutdown=None):
log.warning('Start bot with long-polling.')
if loop is None:
loop = dispatcher.loop
@ -59,7 +60,7 @@ def start_polling(dispatcher, *, loop=None, skip_updates=False, on_startup=None,
loop.set_task_factory(context.task_factory)
try:
loop.run_until_complete(_startup(dispatcher, skip_updates=skip_updates, callback=on_startup))
loop.run_until_complete(_startup(dispatcher, skip_updates, on_startup))
loop.create_task(dispatcher.start_polling(reset_webhook=True))
loop.run_forever()
except (KeyboardInterrupt, SystemExit):
@ -69,8 +70,8 @@ def start_polling(dispatcher, *, loop=None, skip_updates=False, on_startup=None,
log.warning("Goodbye!")
def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None, on_startup=None, on_shutdown=None,
check_ip=False, **kwargs):
def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None,
on_startup=None, on_shutdown=None, check_ip=False, **kwargs):
log.warning('Start bot with webhook.')
if loop is None:
loop = dispatcher.loop

View file

@ -137,7 +137,8 @@ class Item:
"""
Helper item
If value is not configured it will be generated automatically based on variable name
If a value is not provided,
it will be automatically generated based on a variable's name
"""
def __init__(self, value=None):
@ -156,7 +157,7 @@ class Item:
class ListItem(Item):
"""
This item always is list
This item is always a list
You can use &, | and + operators for that.
"""
@ -179,7 +180,7 @@ class ItemsList(list):
"""
Patch for default list
This class provide +, &, |, +=, &=, |= operators for extending the list
This class provides +, &, |, +=, &=, |= operators for extending the list
"""
def __init__(self, *seq):

View file

@ -18,6 +18,8 @@ HTML_QUOTES_MAP = {
'"': '&quot;'
}
_HQS = HTML_QUOTES_MAP.keys() # HQS for HTML QUOTES SYMBOLS
def _join(*content, sep=' '):
return sep.join(map(str, content))
@ -38,21 +40,22 @@ def quote_html(content):
"""
Quote HTML symbols
All <, > and & symbols that are not a part of a tag or an HTML entity
must be replaced with the corresponding HTML entities (< with &lt;, > with &gt; and & with &amp;).
All <, >, & and " symbols that are not a part of a tag or
an HTML entity must be replaced with the corresponding HTML entities
(< with &lt; > with &gt; & with &amp and " with &quot).
:param content: str
:return: str
"""
new_content = ''
for symbol in content:
new_content += HTML_QUOTES_MAP[symbol] if symbol in '<>&"' else symbol
new_content += HTML_QUOTES_MAP[symbol] if symbol in _HQS else symbol
return new_content
def text(*content, sep=' '):
"""
Join all elements with separator
Join all elements with a separator
:param content:
:param sep:
@ -168,7 +171,7 @@ def hlink(title, url):
:param url:
:return:
"""
return "<a href=\"{0}\">{1}</a>".format(url, quote_html(title))
return '<a href="{0}">{1}</a>'.format(url, quote_html(title))
def escape_md(*content, sep=' '):

View file

@ -9,7 +9,8 @@ from .helper import Helper, HelperMode, Item
class Version:
def __init__(self, major=0, minor=0, maintenance=0, stage='final', build=0):
def __init__(self, major=0, minor=0,
maintenance=0, stage='final', build=0):
self.__raw_version = None
self.__version = None
@ -86,7 +87,8 @@ class Version:
if git_changeset:
sub = '.dev{0}'.format(git_changeset)
elif version[3] != Stage.FINAL:
mapping = {Stage.ALPHA: 'a', Stage.BETA: 'b', Stage.RC: 'rc', Stage.DEV: 'dev'}
mapping = {Stage.ALPHA: 'a', Stage.BETA: 'b',
Stage.RC: 'rc', Stage.DEV: 'dev'}
sub = mapping[version[3]] + str(version[4])
return str(main + sub)

View file

@ -1,7 +1,7 @@
BaseBot
=======
This class is base of bot. In BaseBot implemented only methods for interactions with Telegram Bot API.
This class is the base class for bot. BaseBot implements only methods for interaction with Telegram Bot API.
.. autoclass:: aiogram.bot.base.BaseBot
:members:

View file

@ -1,8 +1,8 @@
Bot object
==========
That is extended (and recommended for usage) bot class based on BaseBot class.
You can use instance of that bot in :obj:`aiogram.dispatcher.Dispatcher`
This is extended (and recommended for use) bot class based on BaseBot class.
You can use an instance of this bot in :obj:`aiogram.dispatcher.Dispatcher`
.. autoclass:: aiogram.bot.bot.Bot
:members:

View file

@ -16,3 +16,10 @@ Redis storage
.. automodule:: aiogram.contrib.fsm_storage.redis
:members:
:show-inheritance:
RethinkDB storage
-----------------
.. automodule:: aiogram.contrib.fsm_storage.rethinkdb
:members:
:show-inheritance:

View file

@ -1,7 +1,7 @@
Filters
-------
In this module stored builtin filters for dispatcher.
This module stores builtin filters for dispatcher.
.. automodule:: aiogram.dispatcher.filters
:members:

View file

@ -1,7 +1,7 @@
Storages
--------
In this module stored base of storage's for finite-state machine.
This module stores storage base for finite-state machine.
.. automodule:: aiogram.dispatcher.storage
:members:

View file

@ -27,7 +27,7 @@ Welcome to aiogram's documentation!
:alt: MIT License
**aiogram** is are pretty simple and fully asynchronously library for `Telegram Bot API <https://core.telegram.org/bots/api>`_ written in Python 3.6 with `asyncio <https://docs.python.org/3/library/asyncio.html>`_ and `aiohttp <https://github.com/aio-libs/aiohttp>`_. It helps to make your bots more faster and simpler.
**aiogram** is a pretty simple and fully asynchronous library for `Telegram Bot API <https://core.telegram.org/bots/api>`_ written in Python 3.6 with `asyncio <https://docs.python.org/3/library/asyncio.html>`_ and `aiohttp <https://github.com/aio-libs/aiohttp>`_. It helps you to make your bots faster and simpler.
Official aiogram resources
@ -45,17 +45,17 @@ Features
--------
- Asynchronous
- Be awesome
- Make things faster
- Have `FSM <https://en.wikipedia.org/wiki/Finite-state_machine>`_
- Can reply into webhook
- Awesome
- Makes things faster
- Has `FSM <https://en.wikipedia.org/wiki/Finite-state_machine>`_
- Can reply into webhook. (In other words `make requests in response to updates <https://core.telegram.org/bots/faq#how-can-i-make-requests-in-response-to-updates>`_)
Contribute
----------
- `Issue Tracker <https://bitbucket.org/illemius/aiogram/issues>`_
- `Source Code <https://bitbucket.org/illemius/aiogram.git>`_
- `Issue Tracker <https://github.com/aiogram/aiogram/issues>`_
- `Source Code <https://github.com/aiogram/aiogram.git>`_
Contents

View file

@ -1,8 +1,8 @@
Installation Guide
==================
From PIP
--------
Using PIP
---------
.. code-block:: bash
$ pip install -U aiogram
@ -11,5 +11,6 @@ From sources
------------
.. code-block:: bash
$ git clone https://bitbucket.org/illemius/aiogram.git
$ git clone https://github.com/aiogram/aiogram.git
$ cd aiogram
$ python setup.py install

View file

@ -4,15 +4,15 @@ Quick start
Simple template
---------------
By first step you need import all modules
At first you have to import all necessary modules
.. code-block:: python3
from aiogram import Bot
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
In next step you you can initialize bot and dispatcher instances.
Then you have to initialize bot and dispatcher instances.
Bot token you can get from `@BotFather <https://t.me/BotFather>`_
@ -21,7 +21,7 @@ Bot token you can get from `@BotFather <https://t.me/BotFather>`_
bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot)
And next: all bots is needed command for starting interaction with bot. Register first command handler:
Next step: interaction with bots starts with one command. Register your first command handler:
.. code-block:: python3
@ -29,7 +29,7 @@ And next: all bots is needed command for starting interaction with bot. Registe
async def send_welcome(message: types.Message):
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
And last step - run long polling.
Last step: run long polling.
.. code-block:: python3
@ -41,7 +41,7 @@ Summary
.. code-block:: python3
from aiogram import Bot
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor

View file

@ -0,0 +1,16 @@
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher, filters
from aiogram.utils import executor
bot = Bot(token='TOKEN')
dp = Dispatcher(bot)
@dp.message_handler(filters.RegexpCommandsFilter(regexp_commands=['item_([0-9]*)']))
async def send_welcome(message: types.Message):
regexp_command = message.conf['regexp_command']
await message.reply("You have requested an item with number: {}".format(regexp_command.group(1)))
if __name__ == '__main__':
executor.start_polling(dp)

View file

@ -44,7 +44,7 @@ setup(
license='MIT',
author='Alex Root Junior',
author_email='jroot.junior@gmail.com',
description='Is are pretty simple and fully asynchronously library for Telegram Bot API',
description='Is a pretty simple and fully asynchronous library for Telegram Bot API',
long_description=get_description(),
classifiers=[
VERSION.pypi_development_status, # Automated change classifier by build stage