Upgraded python-telegram-bot to version 20

ptb-20
Michael DM Dryden 2023-11-05 23:19:47 -05:00
rodzic 325cf33a89
commit 0e4a37072c
5 zmienionych plików z 186 dodań i 129 usunięć

Wyświetl plik

@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_, The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_. and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
----------
Unreleased
----------
Changed
-------
- Upgraded python-telegram-bot to version 20
---------- ----------
`0.7.0`_ - 2023-01-14 `0.7.0`_ - 2023-01-14
---------- ----------

222
poetry.lock wygenerowano
Wyświetl plik

@ -1,5 +1,26 @@
# This file is automatically @generated by Poetry 1.7.0 and should not be changed by hand. # This file is automatically @generated by Poetry 1.7.0 and should not be changed by hand.
[[package]]
name = "anyio"
version = "4.0.0"
description = "High level compatibility layer for multiple asynchronous event loop implementations"
optional = false
python-versions = ">=3.8"
files = [
{file = "anyio-4.0.0-py3-none-any.whl", hash = "sha256:cfdb2b588b9fc25ede96d8db56ed50848b0b649dca3dd1df0b11f683bb9e0b5f"},
{file = "anyio-4.0.0.tar.gz", hash = "sha256:f7ed51751b2c2add651e5747c891b47e26d2a21be5d32d9311dfe9692f3e5d7a"},
]
[package.dependencies]
exceptiongroup = {version = ">=1.0.2", markers = "python_version < \"3.11\""}
idna = ">=2.8"
sniffio = ">=1.1"
[package.extras]
doc = ["Sphinx (>=7)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)"]
test = ["anyio[trio]", "coverage[toml] (>=7)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (>=0.17)"]
trio = ["trio (>=0.22)"]
[[package]] [[package]]
name = "appdirs" name = "appdirs"
version = "1.4.4" version = "1.4.4"
@ -13,30 +34,28 @@ files = [
[[package]] [[package]]
name = "apscheduler" name = "apscheduler"
version = "3.6.3" version = "3.10.4"
description = "In-process task scheduler with Cron-like capabilities" description = "In-process task scheduler with Cron-like capabilities"
optional = false optional = false
python-versions = "*" python-versions = ">=3.6"
files = [ files = [
{file = "APScheduler-3.6.3-py2.py3-none-any.whl", hash = "sha256:e8b1ecdb4c7cb2818913f766d5898183c7cb8936680710a4d3a966e02262e526"}, {file = "APScheduler-3.10.4-py3-none-any.whl", hash = "sha256:fb91e8a768632a4756a585f79ec834e0e27aad5860bac7eaa523d9ccefd87661"},
{file = "APScheduler-3.6.3.tar.gz", hash = "sha256:3bb5229eed6fbbdafc13ce962712ae66e175aa214c69bed35a06bffcf0c5e244"}, {file = "APScheduler-3.10.4.tar.gz", hash = "sha256:e6df071b27d9be898e486bc7940a7be50b4af2e9da7c08f0744a96d4bd4cef4a"},
] ]
[package.dependencies] [package.dependencies]
pytz = "*" pytz = "*"
setuptools = ">=0.7"
six = ">=1.4.0" six = ">=1.4.0"
tzlocal = ">=1.2" tzlocal = ">=2.0,<3.dev0 || >=4.dev0"
[package.extras] [package.extras]
asyncio = ["trollius"]
doc = ["sphinx", "sphinx-rtd-theme"] doc = ["sphinx", "sphinx-rtd-theme"]
gevent = ["gevent"] gevent = ["gevent"]
mongodb = ["pymongo (>=2.8)"] mongodb = ["pymongo (>=3.0)"]
redis = ["redis (>=3.0)"] redis = ["redis (>=3.0)"]
rethinkdb = ["rethinkdb (>=2.4.0)"] rethinkdb = ["rethinkdb (>=2.4.0)"]
sqlalchemy = ["sqlalchemy (>=0.8)"] sqlalchemy = ["sqlalchemy (>=1.4)"]
testing = ["mock", "pytest", "pytest-asyncio", "pytest-asyncio (<0.6)", "pytest-cov", "pytest-tornado5"] testing = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-tornado5"]
tornado = ["tornado (>=4.3)"] tornado = ["tornado (>=4.3)"]
twisted = ["twisted"] twisted = ["twisted"]
zookeeper = ["kazoo"] zookeeper = ["kazoo"]
@ -69,17 +88,6 @@ files = [
[package.extras] [package.extras]
tzdata = ["tzdata"] tzdata = ["tzdata"]
[[package]]
name = "cachetools"
version = "4.2.2"
description = "Extensible memoizing collections and decorators"
optional = false
python-versions = "~=3.5"
files = [
{file = "cachetools-4.2.2-py3-none-any.whl", hash = "sha256:2cc0b89715337ab6dbba85b5b50effe2b0c74e035d83ee8ed637cf52f12ae001"},
{file = "cachetools-4.2.2.tar.gz", hash = "sha256:61b5ed1e22a0924aed1d23b478f37e8d52549ff8a961de2909c69bf950020cff"},
]
[[package]] [[package]]
name = "certifi" name = "certifi"
version = "2023.7.22" version = "2023.7.22"
@ -202,6 +210,20 @@ files = [
docs = ["ipython", "matplotlib", "numpydoc", "sphinx"] docs = ["ipython", "matplotlib", "numpydoc", "sphinx"]
tests = ["pytest", "pytest-cov", "pytest-xdist"] tests = ["pytest", "pytest-cov", "pytest-xdist"]
[[package]]
name = "exceptiongroup"
version = "1.1.3"
description = "Backport of PEP 654 (exception groups)"
optional = false
python-versions = ">=3.7"
files = [
{file = "exceptiongroup-1.1.3-py3-none-any.whl", hash = "sha256:343280667a4585d195ca1cf9cef84a4e178c4b6cf2274caef9859782b567d5e3"},
{file = "exceptiongroup-1.1.3.tar.gz", hash = "sha256:097acd85d473d75af5bb98e41b61ff7fe35efe6675e4f9370ec6ec5126d160e9"},
]
[package.extras]
test = ["pytest (>=6)"]
[[package]] [[package]]
name = "fonttools" name = "fonttools"
version = "4.44.0" version = "4.44.0"
@ -337,6 +359,73 @@ files = [
docs = ["Sphinx"] docs = ["Sphinx"]
test = ["objgraph", "psutil"] test = ["objgraph", "psutil"]
[[package]]
name = "h11"
version = "0.14.0"
description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1"
optional = false
python-versions = ">=3.7"
files = [
{file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"},
{file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"},
]
[[package]]
name = "httpcore"
version = "1.0.1"
description = "A minimal low-level HTTP client."
optional = false
python-versions = ">=3.8"
files = [
{file = "httpcore-1.0.1-py3-none-any.whl", hash = "sha256:c5e97ef177dca2023d0b9aad98e49507ef5423e9f1d94ffe2cfe250aa28e63b0"},
{file = "httpcore-1.0.1.tar.gz", hash = "sha256:fce1ddf9b606cfb98132ab58865c3728c52c8e4c3c46e2aabb3674464a186e92"},
]
[package.dependencies]
certifi = "*"
h11 = ">=0.13,<0.15"
[package.extras]
asyncio = ["anyio (>=4.0,<5.0)"]
http2 = ["h2 (>=3,<5)"]
socks = ["socksio (==1.*)"]
trio = ["trio (>=0.22.0,<0.23.0)"]
[[package]]
name = "httpx"
version = "0.25.1"
description = "The next generation HTTP client."
optional = false
python-versions = ">=3.8"
files = [
{file = "httpx-0.25.1-py3-none-any.whl", hash = "sha256:fec7d6cc5c27c578a391f7e87b9aa7d3d8fbcd034f6399f9f79b45bcc12a866a"},
{file = "httpx-0.25.1.tar.gz", hash = "sha256:ffd96d5cf901e63863d9f1b4b6807861dbea4d301613415d9e6e57ead15fc5d0"},
]
[package.dependencies]
anyio = "*"
certifi = "*"
httpcore = "*"
idna = "*"
sniffio = "*"
[package.extras]
brotli = ["brotli", "brotlicffi"]
cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"]
http2 = ["h2 (>=3,<5)"]
socks = ["socksio (==1.*)"]
[[package]]
name = "idna"
version = "3.4"
description = "Internationalized Domain Names in Applications (IDNA)"
optional = false
python-versions = ">=3.5"
files = [
{file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"},
{file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"},
]
[[package]] [[package]]
name = "importlib-resources" name = "importlib-resources"
version = "6.1.0" version = "6.1.0"
@ -811,26 +900,30 @@ six = ">=1.5"
[[package]] [[package]]
name = "python-telegram-bot" name = "python-telegram-bot"
version = "13.15" version = "20.6"
description = "We have made you a wrapper you can't refuse" description = "We have made you a wrapper you can't refuse"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.8"
files = [ files = [
{file = "python-telegram-bot-13.15.tar.gz", hash = "sha256:b4047606b8081b62bbd6aa361f7ca1efe87fa8f1881ec9d932d35844bf57a154"}, {file = "python-telegram-bot-20.6.tar.gz", hash = "sha256:c6951dc6b9368d80a17b5d0496ced39bca2c9bafab06cbfdae6226493d8b06fe"},
{file = "python_telegram_bot-13.15-py3-none-any.whl", hash = "sha256:06780c258d3f2a3c6c79a7aeb45714f4cd1dd6275941b7dc4628bba64fddd465"}, {file = "python_telegram_bot-20.6-py3-none-any.whl", hash = "sha256:be8ebda350fd0c69c3ebdd7ce87b1e6f8b3fb1d218a193dd821d1d6285b9f649"},
] ]
[package.dependencies] [package.dependencies]
APScheduler = "3.6.3" APScheduler = {version = ">=3.10.4,<3.11.0", optional = true, markers = "extra == \"job-queue\""}
cachetools = "4.2.2" httpx = ">=0.25.0,<0.26.0"
certifi = "*" pytz = {version = ">=2018.6", optional = true, markers = "extra == \"job-queue\""}
pytz = ">=2018.6"
tornado = "6.1"
[package.extras] [package.extras]
json = ["ujson"] all = ["APScheduler (>=3.10.4,<3.11.0)", "aiolimiter (>=1.1.0,<1.2.0)", "cachetools (>=5.3.1,<5.4.0)", "cryptography (>=39.0.1)", "httpx[http2]", "httpx[socks]", "pytz (>=2018.6)", "tornado (>=6.3.3,<6.4.0)"]
passport = ["cryptography (!=3.4,!=3.4.1,!=3.4.2,!=3.4.3)"] callback-data = ["cachetools (>=5.3.1,<5.4.0)"]
socks = ["PySocks"] ext = ["APScheduler (>=3.10.4,<3.11.0)", "aiolimiter (>=1.1.0,<1.2.0)", "cachetools (>=5.3.1,<5.4.0)", "pytz (>=2018.6)", "tornado (>=6.3.3,<6.4.0)"]
http2 = ["httpx[http2]"]
job-queue = ["APScheduler (>=3.10.4,<3.11.0)", "pytz (>=2018.6)"]
passport = ["cryptography (>=39.0.1)"]
rate-limiter = ["aiolimiter (>=1.1.0,<1.2.0)"]
socks = ["httpx[socks]"]
webhooks = ["tornado (>=6.3.3,<6.4.0)"]
[[package]] [[package]]
name = "pytz" name = "pytz"
@ -924,6 +1017,17 @@ files = [
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
] ]
[[package]]
name = "sniffio"
version = "1.3.0"
description = "Sniff out which async library your code is running under"
optional = false
python-versions = ">=3.7"
files = [
{file = "sniffio-1.3.0-py3-none-any.whl", hash = "sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384"},
{file = "sniffio-1.3.0.tar.gz", hash = "sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101"},
]
[[package]] [[package]]
name = "sqlalchemy" name = "sqlalchemy"
version = "1.4.50" version = "1.4.50"
@ -1024,56 +1128,6 @@ files = [
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
] ]
[[package]]
name = "tornado"
version = "6.1"
description = "Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed."
optional = false
python-versions = ">= 3.5"
files = [
{file = "tornado-6.1-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:d371e811d6b156d82aa5f9a4e08b58debf97c302a35714f6f45e35139c332e32"},
{file = "tornado-6.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:0d321a39c36e5f2c4ff12b4ed58d41390460f798422c4504e09eb5678e09998c"},
{file = "tornado-6.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9de9e5188a782be6b1ce866e8a51bc76a0fbaa0e16613823fc38e4fc2556ad05"},
{file = "tornado-6.1-cp35-cp35m-manylinux2010_i686.whl", hash = "sha256:61b32d06ae8a036a6607805e6720ef00a3c98207038444ba7fd3d169cd998910"},
{file = "tornado-6.1-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:3e63498f680547ed24d2c71e6497f24bca791aca2fe116dbc2bd0ac7f191691b"},
{file = "tornado-6.1-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:6c77c9937962577a6a76917845d06af6ab9197702a42e1346d8ae2e76b5e3675"},
{file = "tornado-6.1-cp35-cp35m-win32.whl", hash = "sha256:6286efab1ed6e74b7028327365cf7346b1d777d63ab30e21a0f4d5b275fc17d5"},
{file = "tornado-6.1-cp35-cp35m-win_amd64.whl", hash = "sha256:fa2ba70284fa42c2a5ecb35e322e68823288a4251f9ba9cc77be04ae15eada68"},
{file = "tornado-6.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:0a00ff4561e2929a2c37ce706cb8233b7907e0cdc22eab98888aca5dd3775feb"},
{file = "tornado-6.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:748290bf9112b581c525e6e6d3820621ff020ed95af6f17fedef416b27ed564c"},
{file = "tornado-6.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:e385b637ac3acaae8022e7e47dfa7b83d3620e432e3ecb9a3f7f58f150e50921"},
{file = "tornado-6.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:25ad220258349a12ae87ede08a7b04aca51237721f63b1808d39bdb4b2164558"},
{file = "tornado-6.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:65d98939f1a2e74b58839f8c4dab3b6b3c1ce84972ae712be02845e65391ac7c"},
{file = "tornado-6.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:e519d64089b0876c7b467274468709dadf11e41d65f63bba207e04217f47c085"},
{file = "tornado-6.1-cp36-cp36m-win32.whl", hash = "sha256:b87936fd2c317b6ee08a5741ea06b9d11a6074ef4cc42e031bc6403f82a32575"},
{file = "tornado-6.1-cp36-cp36m-win_amd64.whl", hash = "sha256:cc0ee35043162abbf717b7df924597ade8e5395e7b66d18270116f8745ceb795"},
{file = "tornado-6.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:7250a3fa399f08ec9cb3f7b1b987955d17e044f1ade821b32e5f435130250d7f"},
{file = "tornado-6.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:ed3ad863b1b40cd1d4bd21e7498329ccaece75db5a5bf58cd3c9f130843e7102"},
{file = "tornado-6.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:dcef026f608f678c118779cd6591c8af6e9b4155c44e0d1bc0c87c036fb8c8c4"},
{file = "tornado-6.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:70dec29e8ac485dbf57481baee40781c63e381bebea080991893cd297742b8fd"},
{file = "tornado-6.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:d3f7594930c423fd9f5d1a76bee85a2c36fd8b4b16921cae7e965f22575e9c01"},
{file = "tornado-6.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:3447475585bae2e77ecb832fc0300c3695516a47d46cefa0528181a34c5b9d3d"},
{file = "tornado-6.1-cp37-cp37m-win32.whl", hash = "sha256:e7229e60ac41a1202444497ddde70a48d33909e484f96eb0da9baf8dc68541df"},
{file = "tornado-6.1-cp37-cp37m-win_amd64.whl", hash = "sha256:cb5ec8eead331e3bb4ce8066cf06d2dfef1bfb1b2a73082dfe8a161301b76e37"},
{file = "tornado-6.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:20241b3cb4f425e971cb0a8e4ffc9b0a861530ae3c52f2b0434e6c1b57e9fd95"},
{file = "tornado-6.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:c77da1263aa361938476f04c4b6c8916001b90b2c2fdd92d8d535e1af48fba5a"},
{file = "tornado-6.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:fba85b6cd9c39be262fcd23865652920832b61583de2a2ca907dbd8e8a8c81e5"},
{file = "tornado-6.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:1e8225a1070cd8eec59a996c43229fe8f95689cb16e552d130b9793cb570a288"},
{file = "tornado-6.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:d14d30e7f46a0476efb0deb5b61343b1526f73ebb5ed84f23dc794bdb88f9d9f"},
{file = "tornado-6.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:8f959b26f2634a091bb42241c3ed8d3cedb506e7c27b8dd5c7b9f745318ddbb6"},
{file = "tornado-6.1-cp38-cp38-win32.whl", hash = "sha256:34ca2dac9e4d7afb0bed4677512e36a52f09caa6fded70b4e3e1c89dbd92c326"},
{file = "tornado-6.1-cp38-cp38-win_amd64.whl", hash = "sha256:6196a5c39286cc37c024cd78834fb9345e464525d8991c21e908cc046d1cc02c"},
{file = "tornado-6.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f0ba29bafd8e7e22920567ce0d232c26d4d47c8b5cf4ed7b562b5db39fa199c5"},
{file = "tornado-6.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:33892118b165401f291070100d6d09359ca74addda679b60390b09f8ef325ffe"},
{file = "tornado-6.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:7da13da6f985aab7f6f28debab00c67ff9cbacd588e8477034c0652ac141feea"},
{file = "tornado-6.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:e0791ac58d91ac58f694d8d2957884df8e4e2f6687cdf367ef7eb7497f79eaa2"},
{file = "tornado-6.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:66324e4e1beede9ac79e60f88de548da58b1f8ab4b2f1354d8375774f997e6c0"},
{file = "tornado-6.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:a48900ecea1cbb71b8c71c620dee15b62f85f7c14189bdeee54966fbd9a0c5bd"},
{file = "tornado-6.1-cp39-cp39-win32.whl", hash = "sha256:d3d20ea5782ba63ed13bc2b8c291a053c8d807a8fa927d941bd718468f7b950c"},
{file = "tornado-6.1-cp39-cp39-win_amd64.whl", hash = "sha256:548430be2740e327b3fe0201abe471f314741efcb0067ec4f2d7dcfb4825f3e4"},
{file = "tornado-6.1.tar.gz", hash = "sha256:33c6e81d7bd55b468d2e793517c909b139960b6c790a60b7991b9b6b76fb9791"},
]
[[package]] [[package]]
name = "typer" name = "typer"
version = "0.7.0" version = "0.7.0"
@ -1152,4 +1206,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = ">=3.8,<3.12" python-versions = ">=3.8,<3.12"
content-hash = "9527f6d43423ba2f9377b18d906a753e3973554fa2a635fe690851278876b8da" content-hash = "7c00bec3883665f9a2f73882c80e36dc2fb4003c2650baad8ed2a5076411ffec"

Wyświetl plik

@ -10,7 +10,7 @@ include = ["examples/*", "CHANGELOG.rst"]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = ">=3.8,<3.12" python = ">=3.8,<3.12"
python-telegram-bot = "^13.11" python-telegram-bot = {version = "^20.6", extras = ["job-queue"]}
sqlalchemy = {version = "^1.4", extras = ["postgresql_psycopg2binary"]} sqlalchemy = {version = "^1.4", extras = ["postgresql_psycopg2binary"]}
SQLAlchemy-Utils = "0.37.6" SQLAlchemy-Utils = "0.37.6"
pandas = "^1.0.4" pandas = "^1.0.4"

Wyświetl plik

@ -28,19 +28,21 @@ import os
import telegram import telegram
from telegram.error import BadRequest from telegram.error import BadRequest
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext, JobQueue from telegram.ext import Updater, CommandHandler, MessageHandler, CallbackContext, JobQueue, ContextTypes, Application, \
from telegram.update import Update filters
from telegram import Update
import appdirs import appdirs
from .parse import parse_message from .parse import parse_message
from .log_storage import JSONStore, PostgresStore from .log_storage import JSONStore, PostgresStore
from .stats import StatsRunner, get_parser, HelpException from .stats import StatsRunner, get_parser, HelpException
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO) level=logging.INFO)
logging.getLogger('httpx').setLevel(logging.WARNING) # Mute normal http requests
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
stats = None stats = None
@ -54,7 +56,7 @@ sticker_idx = None
sticker_id = None sticker_id = None
def log_message(update: Update, context: CallbackContext): async def log_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.edited_message: if update.edited_message:
edited_message, user = parse_message(update.effective_message) edited_message, user = parse_message(update.effective_message)
if bak_store: if bak_store:
@ -79,28 +81,25 @@ def log_message(update: Update, context: CallbackContext):
store.append_data('user_events', i) store.append_data('user_events', i)
def get_chatid(update: Update, context: CallbackContext): async def get_chatid(update: Update, context: ContextTypes.DEFAULT_TYPE):
context.bot.send_message(chat_id=update.effective_chat.id, await update.message.reply_text(text=f"Chat id: {update.effective_chat.id}")
text=f"Chat id: {update.effective_chat.id}")
def test_can_read_all_group_messages(context: CallbackContext): async def test_can_read_all_group_messages(context: CallbackContext):
if not context.bot.can_read_all_group_messages: if not context.bot.can_read_all_group_messages:
logger.error("Bot privacy is set to enabled, cannot log messages!!!") logger.error("Bot privacy is set to enabled, cannot log messages!!!")
def update_usernames_wrapper(context: CallbackContext): async def update_usernames(context: ContextTypes.DEFAULT_TYPE): # context.job.context contains the chat_id
context.dispatcher.run_async(update_usernames, context)
def update_usernames(context: CallbackContext): # context.job.context contains the chat_id
user_ids = stats.get_message_user_ids() user_ids = stats.get_message_user_ids()
db_users = stats.get_db_users() db_users = stats.get_db_users()
tg_users = {user_id: None for user_id in user_ids} tg_users = {user_id: None for user_id in user_ids}
to_update = {} to_update = {}
for u_id in tg_users: for u_id in tg_users:
try: try:
user = context.bot.get_chat_member(chat_id=context.job.context, user_id=u_id).user chat_member: telegram.ChatMember = await context.bot.get_chat_member(chat_id=context.job.chat_id,
user_id=u_id)
user = chat_member.user
tg_users[u_id] = user.name, user.full_name tg_users[u_id] = user.name, user.full_name
if tg_users[u_id] != db_users[u_id]: if tg_users[u_id] != db_users[u_id]:
if tg_users[u_id][1] == db_users[u_id][1]: # Flag these so we don't insert new row if tg_users[u_id][1] == db_users[u_id][1]: # Flag these so we don't insert new row
@ -121,7 +120,7 @@ def update_usernames(context: CallbackContext): # context.job.context contains
logger.info("Usernames updated") logger.info("Usernames updated")
def print_stats(update: Update, context: CallbackContext): async def print_stats(update: Update, context: CallbackContext):
if update.effective_user.id not in stats.users: if update.effective_user.id not in stats.users:
return return
@ -132,11 +131,11 @@ def print_stats(update: Update, context: CallbackContext):
ns = stats_parser.parse_args(shlex.split(" ".join(context.args))) ns = stats_parser.parse_args(shlex.split(" ".join(context.args)))
except HelpException as e: except HelpException as e:
text = e.msg text = e.msg
send_help(text, context, update) await send_help(text, context, update)
return return
except argparse.ArgumentError as e: except argparse.ArgumentError as e:
text = str(e) text = str(e)
send_help(text, context, update) await send_help(text, context, update)
return return
else: else:
args = vars(ns) args = vars(ns)
@ -148,7 +147,7 @@ def print_stats(update: Update, context: CallbackContext):
uid = args['user'] uid = args['user']
args['user'] = uid, stats.users[uid][0] args['user'] = uid, stats.users[uid][0]
except KeyError: except KeyError:
send_help("unknown userid", context, update) await send_help("unknown userid", context, update)
return return
except KeyError: except KeyError:
pass pass
@ -164,18 +163,18 @@ def print_stats(update: Update, context: CallbackContext):
text, image = func(**args) text, image = func(**args)
except HelpException as e: except HelpException as e:
text = e.msg text = e.msg
send_help(text, context, update) await send_help(text, context, update)
return return
if text: if text:
context.bot.send_message(chat_id=update.effective_chat.id, await update.message.reply_text(text=text,
text=text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2)
parse_mode=telegram.ParseMode.MARKDOWN_V2)
if image: if image:
context.bot.send_photo(chat_id=update.effective_chat.id, photo=image) await update.message.reply_photo(photo=image)
def send_help(text: str, context: CallbackContext, update: Update): async def send_help(text: str, context: CallbackContext, update: Update):
""" """
Send help text to user. Tries to send a direct message if possible. Send help text to user. Tries to send a direct message if possible.
:param text: text to send :param text: text to send
@ -184,13 +183,12 @@ def send_help(text: str, context: CallbackContext, update: Update):
:return: :return:
""" """
try: try:
context.bot.send_message(chat_id=update.effective_user.id, await context.bot.send_message(chat_id=update.effective_user.id,
text=f"```\n{text}\n```", text=f"```\n{text}\n```",
parse_mode=telegram.ParseMode.MARKDOWN_V2) parse_mode=telegram.constants.ParseMode.MARKDOWN_V2)
except telegram.error.Unauthorized: # If user has never chatted with bot except telegram.error.Forbidden: # If user has never chatted with bot
context.bot.send_message(chat_id=update.effective_chat.id, await update.message.reply_text(text=f"```\n{text}\n```",
text=f"```\n{text}\n```", parse_mode=telegram.constants.ParseMode.MARKDOWN_V2)
parse_mode=telegram.ParseMode.MARKDOWN_V2)
if __name__ == '__main__': if __name__ == '__main__':
@ -206,8 +204,7 @@ if __name__ == '__main__':
default='Etc/UTC') default='Etc/UTC')
args = parser.parse_args() args = parser.parse_args()
updater = Updater(token=args.token, use_context=True) application = Application.builder().token(args.token).build()
dispatcher = updater.dispatcher
if args.json_path: if args.json_path:
path = args.json_path path = args.json_path
@ -221,19 +218,18 @@ if __name__ == '__main__':
store = PostgresStore(args.postgres_url) store = PostgresStore(args.postgres_url)
stats = StatsRunner(store.engine, tz=args.tz) stats = StatsRunner(store.engine, tz=args.tz)
stats_handler = CommandHandler('stats', print_stats, filters=~Filters.update.edited_message, run_async=True) stats_handler = CommandHandler('stats', print_stats)
dispatcher.add_handler(stats_handler) application.add_handler(stats_handler)
chat_id_handler = CommandHandler('chatid', get_chatid, filters=~Filters.update.edited_message) chat_id_handler = CommandHandler('chatid', get_chatid, filters=~filters.UpdateType.EDITED)
dispatcher.add_handler(chat_id_handler) application.add_handler(chat_id_handler)
if args.chat_id != 0: if args.chat_id != 0:
log_handler = MessageHandler(Filters.chat(chat_id=args.chat_id), log_message) log_handler = MessageHandler(filters.Chat(chat_id=args.chat_id), log_message)
dispatcher.add_handler(log_handler) application.add_handler(log_handler)
job_queue: JobQueue = updater.job_queue job_queue = application.job_queue
update_users_job = job_queue.run_repeating(update_usernames_wrapper, interval=3600, first=5, context=args.chat_id) update_users_job = job_queue.run_repeating(update_usernames, interval=3600, first=5, chat_id=args.chat_id)
test_privacy_job = job_queue.run_once(test_can_read_all_group_messages, 0) test_privacy_job = job_queue.run_once(test_can_read_all_group_messages, 0)
updater.start_polling() application.run_polling()
updater.idle()

Wyświetl plik

@ -48,7 +48,7 @@ class MessageDict(TypedDict):
type: str type: str
def parse_message(message: telegram.message.Message) -> Tuple[dict, List[dict]]: def parse_message(message: telegram.Message) -> Tuple[dict, List[dict]]:
message_dict: MessageDict = {'message_id': message.message_id, message_dict: MessageDict = {'message_id': message.message_id,
'date': message.date, 'date': message.date,
'from_user': None, 'from_user': None,