Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 filter rewrite #5

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c6eff42
filter_rewrite: Streamlined it a bit.
luckydonald Jun 25, 2020
884ea0e
filter_rewrite: Allow empty username for now.
luckydonald Jun 25, 2020
82a36fc
filter_rewrite: added __str__ and __repr__ to the filters.
luckydonald Jun 25, 2020
147c347
filter_rewrite: Migrated the `@on_update` to be using `Filter`s now.
luckydonald Jun 25, 2020
3cb6511
filter_rewrite: Trying to provide the decorator in the class.
luckydonald Jun 28, 2020
15a631d
filter_rewrite: Adapted the message decorator.
luckydonald Jun 28, 2020
4ef55bb
filter_rewrite: With that we can integrate MessagesMixin into the Upd…
luckydonald Jun 28, 2020
370262a
filter_rewrite: Copy paste message decorator to the CommandFilter.
luckydonald Jun 28, 2020
87c8d2b
filter_rewrite: Updated CommandFilter's decorator.
luckydonald Jun 28, 2020
2ef5136
filter_rewrite: Multiline __init__ arguments for readability.
luckydonald Jun 28, 2020
8510a22
filter_rewrite: Killed old BotCommandsMixin; migrated classes into Up…
luckydonald Jun 28, 2020
899f68e
filter_rewrite: Trying to get the unittest working, by fixing the imp…
luckydonald Jun 28, 2020
ff41a22
filter_rewrite: Trying to get the unittest working, by removing the d…
luckydonald Jun 28, 2020
09d94e8
filter_rewrite: Make sure the abstracts are imported.
luckydonald Jun 28, 2020
a156f05
filter_rewrite: Trying to get the unittest working (2)
luckydonald Jun 28, 2020
51fa751
filter_rewrite: Migrated RegisterBlueprintsMixin, StartupMixin and Up…
luckydonald Jun 28, 2020
3a15568
filter_rewrite: Removed TeleflaskMixinBase, we don't need those any l…
luckydonald Jun 28, 2020
6552dc0
filter_rewrite: Changed Teleflask to BotServer, and TeleflaskBase to …
luckydonald Jun 28, 2020
9e8f651
filter_rewrite: Missing imports.
luckydonald Jun 29, 2020
19c0e82
filter_rewrite: Moved some bot stuff up to the new parent.
luckydonald Jun 29, 2020
2883df0
filter_rewrite: Changed TBlueprint.teleflask to be TBlueprint.server …
luckydonald Jun 29, 2020
1266c21
filter_rewrite: Fixed do_startup getting lost somehow.
luckydonald Jun 29, 2020
c5f813d
filter_rewrite: Renamed BotServer to TeleServe.
luckydonald Jun 29, 2020
d63ed5c
filter_rewrite: Renamed TeleServe to Teleserver.
luckydonald Jun 29, 2020
3cacda2
filter_rewrite: Fixed imports.
luckydonald Jun 29, 2020
50292e9
filter_rewrite: Import that one in the main file.
luckydonald Jun 29, 2020
89a498d
filter_rewrite: Moved `Teleserver` to `.core`.
luckydonald Jun 29, 2020
2d2192a
filter_rewrite: Woops.
luckydonald Jun 29, 2020
3d1166a
filter_rewrite: Make the main package import the server one too.
luckydonald Jun 29, 2020
0eb0ebf
filter_rewrite: Moved `Teleflask` to `.extras.flask`.
luckydonald Jun 29, 2020
95ec3f2
filter_rewrite: Tried a lazy import for Teleserver, Teleflask as with…
luckydonald Jun 29, 2020
c277ad3
filter_rewrite: Fixed a few import bugs.
luckydonald Jun 29, 2020
3717653
filter_rewrite: Moved the VERSION and __version__ object to the maste…
luckydonald Jun 29, 2020
e6a1f59
filter_rewrite: Renamed Teleserver to Teleprocessor, to have the new …
luckydonald Jun 29, 2020
b25f3b8
filter_rewrite: Extracted calculate_webhook_url to be an helper funct…
luckydonald Jun 29, 2020
c5e5188
filter_rewrite: Fixed/imporved some imports.
luckydonald Jun 29, 2020
876acb8
filter_rewrite: Removed some imports, you'll need to go the full path…
luckydonald Jun 29, 2020
73d6bdb
filter_rewrite: Speaking of top level import.
luckydonald Jun 29, 2020
cfecae4
filter_rewrite: Don't import inside of the functions.
luckydonald Jun 29, 2020
05b4a8d
filter_rewrite: Bring back the http://ipinfo.io check within Teleflask.
luckydonald Jun 29, 2020
3440293
filter_rewrite: Fixed import path of PollingTeleflask in one example.
luckydonald Jun 29, 2020
6a4101d
filter_rewrite: Improved docstrings.
luckydonald Jun 29, 2020
2194cb2
filter_rewrite: Trying to get a sync polling version set up.
luckydonald Jun 29, 2020
6127e73
filter_rewrite: Example for the sync polling version.
luckydonald Jun 29, 2020
3c2ac6f
filter_rewrite: Fixed subclassing the server instead of just the proc…
luckydonald Jun 30, 2020
b5843f1
filter_rewrite: Be verbose with the process_update type assertion.
luckydonald Jun 30, 2020
f067dcc
filter_rewrite: Streamlined the requirements to now have a [sync], [a…
luckydonald Jun 30, 2020
5ce8b3d
filter_rewrite: Fixed some errors.
luckydonald Jun 30, 2020
2566112
filter_rewrite: Some type hints.
luckydonald Jul 4, 2020
660d68c
filter_rewrite: Don't provide the teleflask object.
luckydonald Jul 4, 2020
b858c43
filter_rewrite: Added on message example.
luckydonald Jul 4, 2020
74c1d3a
filter_rewrite: Added missing parameters.
luckydonald Jul 4, 2020
2bbef1b
filter_rewrite: Added HelpfulCommandFilter, to later automatically ge…
luckydonald Jul 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/example2/bot_stuff2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from flask import Flask

from teleflask.server.extras import PollingTeleflask
from teleflask.server.extras.flask import PollingTeleflask

from somewhere import API_KEY

Expand Down Expand Up @@ -33,4 +33,4 @@ def test2(update):
# end def


app.run(HOST, PORT, debug=True)
app.run(HOST, PORT, debug=True)
36 changes: 36 additions & 0 deletions examples/example2/sync_poll_bot_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from luckydonaldUtils.logger import logging
from teleflask.server.extras.polling.sync import Telepoll

from somewhere import API_KEY

__author__ = 'luckydonald'

logger = logging.getLogger(__name__)
if __name__ == '__main__':
logging.add_colored_handler(level=logging.DEBUG)
# end if


bot = Telepoll(api_key=API_KEY)


@bot.command("test")
def test(update, text):
return "You tested with {arg!r}".format(arg=text)
# end def


@bot.on_message()
def test32(update):
bot.bot.forward_message(10717954, update.message.chat.id, update.message.message_id)


@bot.on_update()
def test2(update):
pass
# end def


bot.run_forever()
42 changes: 31 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@

long_description = """A Python module that connects to the Telegram bot api, allowing to interact with Telegram users or groups."""


SYNC_REQUIREMENTS = [
'pytgbot[sync]',
'requests', "requests[security]", # connect with the internet in general
]
ASYNC_REQUIREMENTS = [
'pytgbot[async]',
'httpx', # connect with the internet in general
]


setup(
name='teleflask', version="2.0.0.dev21",
description='Easily create Telegram bots with pytgbot and flask. Webhooks made easy.',
name='teleflask', version="3.0.0.dev1",
description='Easily create Telegram bots with decorators functions, running a webserver of your choice. Webhooks made easy, but you don\'t even have to use \'em.',
long_description=long_description,
# The project's main homepage.
url='https://github.com/luckydonald/teleflask',
# Author details
author='luckydonald',
author_email='[email protected]',
author_email='teleflask+[email protected]',
# Choose your license
license='GPLv3+',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 2 - Pre-Alpha', # 2 - Pre-Alpha, 3 - Alpha, 4 - Beta, 5 - Production/Stable
'Development Status :: 4 - Beta', # 2 - Pre-Alpha, 3 - Alpha, 4 - Beta, 5 - Production/Stable
# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Communications',
Expand All @@ -36,16 +47,18 @@
# that you indicate whether you support Python 2, Python 3 or both.
# 'Programming Language :: Python :: 2',
# 'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
# 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
# 'Programming Language :: Python :: 3.2',
# 'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.7',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Unix',
],
# What does your project relate to?
keywords='pytgbot flask webhook telegram bot api python message send receive python secure fast answer reply image voice picture location contacts typing multi messanger inline quick reply gif image video mp4 mpeg4',
keywords='pytgbot flask webhook telegram bot api python message send receive python secure fast answer reply image voice picture location contacts typing multi messanger inline quick reply gif image video mp4 mpeg4 webserver decorators',
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=['teleflask', 'teleflask.server'],
Expand All @@ -55,20 +68,27 @@
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=[
"flask", # have flask
"pytgbot>=4.0", # connect to telegram
'pprint',
"DictObject", "luckydonald-utils>=0.70", # general utils
"python-magic", "backoff>=1.4.1", # messages messages
# backoff >=1.4.1 because of a bug with the flask development server
# see https://github.com/litl/backoff/issues/30
"requests", "requests[security]", # connect with the internet in general
'pytgbot>=4.0" # connect to telegram'
],
# List additional groups of dependencies here (e.g. development dependencies).
# You can install these using the following syntax, for example:
# $ pip install -e .[dev,test]
extras_require = {
'dev': ['bump2version'],
# 'test': ['coverage'],
'dev': ['bump2version'],
'sync': SYNC_REQUIREMENTS,
'async': ASYNC_REQUIREMENTS,
'flask': [
'flask',
] + SYNC_REQUIREMENTS,
'quart': [
'quart',
] + ASYNC_REQUIREMENTS,
# 'test': ['coverage'],
},
# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
Expand Down
40 changes: 39 additions & 1 deletion teleflask/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
# -*- coding: utf-8 -*-
__author__ = 'luckydonald'

import sys as _sys

VERSION = "2.0.0.dev21"
__version__ = VERSION

from .server import Teleflask
__all__ = [
'VERSION', '__version__',
# the ones we provide for easy toplevel access:
'Teleprocessor', 'Teleserver',
'TBlueprint', 'abort_processing',
# special modules:
'Teleflask',
# submodules:
'server', 'exceptions', 'messages', 'new_messages', 'proxy',
]

from .server.core import Teleprocessor, Teleserver

if _sys.version_info.major >= 3 and _sys.version_info.minor >= 6:
IMPORTS = {'Teleflask': '.server.extras.flask', 'SyncTelepoll': '.server.extras.polling.sync'}
try:
# we try to serve them as lazy imports
import importlib as _importlib

_module = _importlib.import_module('.sever', __name__)

def __getattr__(name):
if name not in IMPORTS:
raise AttributeError(f'module {_module.__spec__.parent!r} has no attribute {name!r} ({IMPORTS[name]!r}')
# end if
imported = _importlib.import_module(IMPORTS[name], _module.__spec__.parent)
return imported
# end def
except Exception:
# for some reason it failed, go back to importing it directly
from .server.extras.flask import Teleflask
# end if
else:
# older python, go back to importing it directly
from .server.extras.flask import Teleflask
# end if

from .server.blueprints import TBlueprint
from .server.utilities import abort_processing
3 changes: 0 additions & 3 deletions teleflask/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# -*- coding: utf-8 -*-
from .extras import Teleflask

__author__ = 'luckydonald'

9 changes: 7 additions & 2 deletions teleflask/server/abstact.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ def on_update(self, *required_keywords):
# end def

@abstractmethod
def add_update_listener(self, function, required_keywords=None):
def register_handler(self, handler):
pass
# end def

@abstractmethod
def remove_update_listener(self, func):
def remove_handler(self, handler):
pass
# end def

@abstractmethod
def remove_handled_func(self, func):
pass
# end def
# end class
Expand Down
Loading