pysoroush 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. pysoroush-0.1.0/LICENSE +22 -0
  2. pysoroush-0.1.0/MANIFEST.in +21 -0
  3. pysoroush-0.1.0/PKG-INFO +199 -0
  4. pysoroush-0.1.0/README.md +173 -0
  5. pysoroush-0.1.0/pyproject.toml +41 -0
  6. pysoroush-0.1.0/pysoroush/__init__.py +30 -0
  7. pysoroush-0.1.0/pysoroush/account/__init__.py +15 -0
  8. pysoroush-0.1.0/pysoroush/account/async_client.py +696 -0
  9. pysoroush-0.1.0/pysoroush/account/client.py +162 -0
  10. pysoroush-0.1.0/pysoroush/account/exceptions.py +15 -0
  11. pysoroush-0.1.0/pysoroush/bot/__init__.py +21 -0
  12. pysoroush-0.1.0/pysoroush/bot/async_bot.py +111 -0
  13. pysoroush-0.1.0/pysoroush/bot/async_client.py +350 -0
  14. pysoroush-0.1.0/pysoroush/bot/base_client.py +105 -0
  15. pysoroush-0.1.0/pysoroush/bot/bot.py +112 -0
  16. pysoroush-0.1.0/pysoroush/bot/client.py +331 -0
  17. pysoroush-0.1.0/pysoroush/bot/constants.py +58 -0
  18. pysoroush-0.1.0/pysoroush/bot/exceptions.py +220 -0
  19. pysoroush-0.1.0/pysoroush/bot/filters/__init__.py +13 -0
  20. pysoroush-0.1.0/pysoroush/bot/filters/filters.py +124 -0
  21. pysoroush-0.1.0/pysoroush/bot/fsm/__init__.py +7 -0
  22. pysoroush-0.1.0/pysoroush/bot/fsm/memory.py +62 -0
  23. pysoroush-0.1.0/pysoroush/bot/types/__init__.py +41 -0
  24. pysoroush-0.1.0/pysoroush/bot/types/_base.py +109 -0
  25. pysoroush-0.1.0/pysoroush/bot/types/chat.py +43 -0
  26. pysoroush-0.1.0/pysoroush/bot/types/commands.py +32 -0
  27. pysoroush-0.1.0/pysoroush/bot/types/file.py +18 -0
  28. pysoroush-0.1.0/pysoroush/bot/types/input_file.py +55 -0
  29. pysoroush-0.1.0/pysoroush/bot/types/input_media.py +59 -0
  30. pysoroush-0.1.0/pysoroush/bot/types/keyboard.py +122 -0
  31. pysoroush-0.1.0/pysoroush/bot/types/media.py +125 -0
  32. pysoroush-0.1.0/pysoroush/bot/types/message.py +90 -0
  33. pysoroush-0.1.0/pysoroush/bot/types/update.py +63 -0
  34. pysoroush-0.1.0/pysoroush/bot/types/user.py +30 -0
  35. pysoroush-0.1.0/pysoroush/bot/webapp/__init__.py +7 -0
  36. pysoroush-0.1.0/pysoroush/bot/webapp/validator.py +56 -0
  37. pysoroush-0.1.0/pysoroush.egg-info/PKG-INFO +199 -0
  38. pysoroush-0.1.0/pysoroush.egg-info/SOURCES.txt +40 -0
  39. pysoroush-0.1.0/pysoroush.egg-info/dependency_links.txt +1 -0
  40. pysoroush-0.1.0/pysoroush.egg-info/requires.txt +7 -0
  41. pysoroush-0.1.0/pysoroush.egg-info/top_level.txt +1 -0
  42. pysoroush-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ali VEX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+ PYEOF
@@ -0,0 +1,21 @@
1
+ # Include only what is needed for the package
2
+ include README.md
3
+ include LICENSE
4
+ include pyproject.toml
5
+
6
+ # Include only the package's Python files
7
+ recursive-include pysoroush *.py
8
+
9
+ # Explicitly exclude anything sensitive or unnecessary
10
+ global-exclude *.py[cod]
11
+ global-exclude __pycache__
12
+ global-exclude *.session
13
+ global-exclude *.session-journal
14
+ global-exclude *.log
15
+ global-exclude *.db
16
+ global-exclude *.sqlite
17
+ global-exclude .env
18
+ global-exclude *.pem
19
+ global-exclude *.key
20
+ global-exclude example*.py
21
+ global-exclude test_*.py
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: pysoroush
3
+ Version: 0.1.0
4
+ Summary: A modern, simple, and powerful Python library for the Soroush Plus messenger.
5
+ Author-email: Ali VEX <lyrdaadhrpyk802@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/lyrdaadhrpyk802-ux/pysoroush
8
+ Project-URL: Repository, https://github.com/lyrdaadhrpyk802-ux/pysoroush
9
+ Keywords: soroush,soroush-plus,bot,api,userbot,messenger
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.28.0
20
+ Requires-Dist: aiohttp>=3.8.0
21
+ Requires-Dist: splusthon>=1.1.4
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
24
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # PySoroush
28
+
29
+ A modern, simple, and powerful Python library for the Soroush Plus messenger.
30
+
31
+ Designed with an intuitive API so that even beginners can build bots and user-automation scripts with just a few lines of code.
32
+
33
+ [![PyPI version](https://img.shields.io/pypi/v/pysoroush.svg)](https://pypi.org/project/pysoroush/)
34
+ [![Python versions](https://img.shields.io/pypi/pyversions/pysoroush.svg)](https://pypi.org/project/pysoroush/)
35
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
36
+
37
+ ---
38
+
39
+ ## Features
40
+
41
+ ### Bot API (Synchronous & Asynchronous)
42
+ - Full support for the official Soroush Plus Bot API
43
+ - Both Sync (requests) and Async (aiohttp) clients
44
+ - Auto-Retry with exponential backoff on network failures
45
+ - Rate Limit handling (automatic sleeping when hitting 429)
46
+ - Fluent Keyboard Builder for building complex keyboards easily
47
+ - Filters for routing messages (Text, Photo, Private, StateFilter, etc.)
48
+ - FSM (Finite State Machine) for multi-step conversations
49
+ - Media support (photos, videos, documents, audio, media groups)
50
+ - WebApp data validation (HMAC-SHA-256)
51
+
52
+ ### Account API (Self / Userbot)
53
+ - Login with phone number + OTP
54
+ - Two-Step Verification support
55
+ - Send and receive messages as your own user
56
+ - Send media (photos, files, etc.)
57
+ - Read message history, edit, delete, forward
58
+ - Download media
59
+ - Get dialogs and participants
60
+ - Event handlers (on_message, on_callback, on_edited_message, etc.)
61
+ - Raw TL API access for advanced use cases
62
+ - Sync and Async interfaces
63
+
64
+ ---
65
+
66
+ ## Installation
67
+
68
+ pip install pysoroush
69
+ ---
70
+
71
+ Quick Start
72
+
73
+ 1. Bot API (Simple Polling)
74
+
75
+ from pysoroush.bot import Bot
76
+
77
+ bot = Bot("YOUR_BOT_TOKEN")
78
+
79
+ @bot.command("start")
80
+ def start_handler(msg):
81
+ return bot.reply(msg, "Hello! I am a bot.")
82
+
83
+ @bot.on_message()
84
+ def echo_handler(msg):
85
+ bot.reply(msg, f"You said: {msg.text}")
86
+ return True
87
+
88
+ bot.run() # Start polling
89
+ 2. Bot API with Inline Keyboards
90
+
91
+ from pysoroush.bot import Bot
92
+ from pysoroush.bot.types import InlineKeyboardMarkup, InlineKeyboardButton
93
+
94
+ bot = Bot("YOUR_BOT_TOKEN")
95
+
96
+ @bot.command("menu")
97
+ def menu_handler(msg):
98
+ kb = InlineKeyboardMarkup().row(
99
+ InlineKeyboardButton(text="Option 1", callback_data="opt1"),
100
+ InlineKeyboardButton(text="Open Website", url="https://splus.ir")
101
+ )
102
+ bot.reply(msg, "Choose an option:", reply_markup=kb)
103
+ return True
104
+
105
+ @bot.on_callback()
106
+ def handle_callback(callback):
107
+ bot.answer_callback_query(callback.id, text=f"You clicked: {callback.data}")
108
+ return True
109
+
110
+ bot.run()
111
+ 3. Async Bot
112
+
113
+ import asyncio
114
+ from pysoroush.bot import AsyncBot
115
+
116
+ bot = AsyncBot("YOUR_BOT_TOKEN")
117
+
118
+ @bot.command("start")
119
+ async def start_handler(msg):
120
+ await bot.reply(msg, "Hello async world!")
121
+ return True
122
+
123
+ async def main():
124
+ await bot.run()
125
+
126
+ asyncio.run(main())
127
+ 4. Account API (Userbot)
128
+
129
+ import asyncio
130
+ from pysoroush.account import AsyncClient
131
+
132
+ async def main():
133
+ # The first run will prompt for phone number and OTP
134
+ async with AsyncClient(session_file="my_account") as client:
135
+ if not await client.is_authorized():
136
+ phone = input("Phone number (e.g., 989123456789): ")
137
+ await client.start(phone=phone, code_callback=lambda: input("OTP: "))
138
+
139
+ me = await client.get_me()
140
+ print(f"Logged in as {me.first_name}")
141
+
142
+ await client.send_message("me", "Hello from my own account!")
143
+ await client.send_photo("me", "/path/to/photo.jpg", caption="Check this out!")
144
+
145
+ dialogs = await client.get_dialogs(limit=10)
146
+ for dialog in dialogs:
147
+ print(f"- {dialog.name}")
148
+
149
+ asyncio.run(main())
150
+ 5. Account API with Event Handlers
151
+
152
+ import asyncio
153
+ from pysoroush.account import AsyncClient
154
+
155
+ async def main():
156
+ async with AsyncClient(session_file="my_account") as client:
157
+ if not await client.is_authorized():
158
+ phone = input("Phone: ")
159
+ await client.start(phone=phone, code_callback=lambda: input("OTP: "))
160
+
161
+ @client.on_message()
162
+ async def auto_reply(message):
163
+ if message.text == "ping":
164
+ await message.reply("pong!")
165
+
166
+ print("Listening for messages...")
167
+ await client.run_until_disconnected()
168
+
169
+ asyncio.run(main())
170
+ ---
171
+
172
+ Security Notes
173
+
174
+ · Never commit your *.session files to GitHub. These files contain your authentication tokens.
175
+ · Use environment variables to store bot tokens in production.
176
+ · The Account API is based on the MTProto protocol and is provided for automation purposes only. Please respect Soroush Plus's Terms of Service.
177
+
178
+ ---
179
+
180
+ Contributing
181
+
182
+ Contributions, issues, and feature requests are welcome!
183
+ Feel free to check the issues page.
184
+
185
+ ---
186
+
187
+ License
188
+
189
+ This project is licensed under the MIT License.
190
+ See the LICENSE file for details.
191
+
192
+ ---
193
+
194
+ Author
195
+
196
+ Ali VEX
197
+
198
+ · GitHub: @lyrdaadhrpyk802-ux
199
+ · Email: lyrdaadhrpyk802@gmail.com
@@ -0,0 +1,173 @@
1
+ # PySoroush
2
+
3
+ A modern, simple, and powerful Python library for the Soroush Plus messenger.
4
+
5
+ Designed with an intuitive API so that even beginners can build bots and user-automation scripts with just a few lines of code.
6
+
7
+ [![PyPI version](https://img.shields.io/pypi/v/pysoroush.svg)](https://pypi.org/project/pysoroush/)
8
+ [![Python versions](https://img.shields.io/pypi/pyversions/pysoroush.svg)](https://pypi.org/project/pysoroush/)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ ### Bot API (Synchronous & Asynchronous)
16
+ - Full support for the official Soroush Plus Bot API
17
+ - Both Sync (requests) and Async (aiohttp) clients
18
+ - Auto-Retry with exponential backoff on network failures
19
+ - Rate Limit handling (automatic sleeping when hitting 429)
20
+ - Fluent Keyboard Builder for building complex keyboards easily
21
+ - Filters for routing messages (Text, Photo, Private, StateFilter, etc.)
22
+ - FSM (Finite State Machine) for multi-step conversations
23
+ - Media support (photos, videos, documents, audio, media groups)
24
+ - WebApp data validation (HMAC-SHA-256)
25
+
26
+ ### Account API (Self / Userbot)
27
+ - Login with phone number + OTP
28
+ - Two-Step Verification support
29
+ - Send and receive messages as your own user
30
+ - Send media (photos, files, etc.)
31
+ - Read message history, edit, delete, forward
32
+ - Download media
33
+ - Get dialogs and participants
34
+ - Event handlers (on_message, on_callback, on_edited_message, etc.)
35
+ - Raw TL API access for advanced use cases
36
+ - Sync and Async interfaces
37
+
38
+ ---
39
+
40
+ ## Installation
41
+
42
+ pip install pysoroush
43
+ ---
44
+
45
+ Quick Start
46
+
47
+ 1. Bot API (Simple Polling)
48
+
49
+ from pysoroush.bot import Bot
50
+
51
+ bot = Bot("YOUR_BOT_TOKEN")
52
+
53
+ @bot.command("start")
54
+ def start_handler(msg):
55
+ return bot.reply(msg, "Hello! I am a bot.")
56
+
57
+ @bot.on_message()
58
+ def echo_handler(msg):
59
+ bot.reply(msg, f"You said: {msg.text}")
60
+ return True
61
+
62
+ bot.run() # Start polling
63
+ 2. Bot API with Inline Keyboards
64
+
65
+ from pysoroush.bot import Bot
66
+ from pysoroush.bot.types import InlineKeyboardMarkup, InlineKeyboardButton
67
+
68
+ bot = Bot("YOUR_BOT_TOKEN")
69
+
70
+ @bot.command("menu")
71
+ def menu_handler(msg):
72
+ kb = InlineKeyboardMarkup().row(
73
+ InlineKeyboardButton(text="Option 1", callback_data="opt1"),
74
+ InlineKeyboardButton(text="Open Website", url="https://splus.ir")
75
+ )
76
+ bot.reply(msg, "Choose an option:", reply_markup=kb)
77
+ return True
78
+
79
+ @bot.on_callback()
80
+ def handle_callback(callback):
81
+ bot.answer_callback_query(callback.id, text=f"You clicked: {callback.data}")
82
+ return True
83
+
84
+ bot.run()
85
+ 3. Async Bot
86
+
87
+ import asyncio
88
+ from pysoroush.bot import AsyncBot
89
+
90
+ bot = AsyncBot("YOUR_BOT_TOKEN")
91
+
92
+ @bot.command("start")
93
+ async def start_handler(msg):
94
+ await bot.reply(msg, "Hello async world!")
95
+ return True
96
+
97
+ async def main():
98
+ await bot.run()
99
+
100
+ asyncio.run(main())
101
+ 4. Account API (Userbot)
102
+
103
+ import asyncio
104
+ from pysoroush.account import AsyncClient
105
+
106
+ async def main():
107
+ # The first run will prompt for phone number and OTP
108
+ async with AsyncClient(session_file="my_account") as client:
109
+ if not await client.is_authorized():
110
+ phone = input("Phone number (e.g., 989123456789): ")
111
+ await client.start(phone=phone, code_callback=lambda: input("OTP: "))
112
+
113
+ me = await client.get_me()
114
+ print(f"Logged in as {me.first_name}")
115
+
116
+ await client.send_message("me", "Hello from my own account!")
117
+ await client.send_photo("me", "/path/to/photo.jpg", caption="Check this out!")
118
+
119
+ dialogs = await client.get_dialogs(limit=10)
120
+ for dialog in dialogs:
121
+ print(f"- {dialog.name}")
122
+
123
+ asyncio.run(main())
124
+ 5. Account API with Event Handlers
125
+
126
+ import asyncio
127
+ from pysoroush.account import AsyncClient
128
+
129
+ async def main():
130
+ async with AsyncClient(session_file="my_account") as client:
131
+ if not await client.is_authorized():
132
+ phone = input("Phone: ")
133
+ await client.start(phone=phone, code_callback=lambda: input("OTP: "))
134
+
135
+ @client.on_message()
136
+ async def auto_reply(message):
137
+ if message.text == "ping":
138
+ await message.reply("pong!")
139
+
140
+ print("Listening for messages...")
141
+ await client.run_until_disconnected()
142
+
143
+ asyncio.run(main())
144
+ ---
145
+
146
+ Security Notes
147
+
148
+ · Never commit your *.session files to GitHub. These files contain your authentication tokens.
149
+ · Use environment variables to store bot tokens in production.
150
+ · The Account API is based on the MTProto protocol and is provided for automation purposes only. Please respect Soroush Plus's Terms of Service.
151
+
152
+ ---
153
+
154
+ Contributing
155
+
156
+ Contributions, issues, and feature requests are welcome!
157
+ Feel free to check the issues page.
158
+
159
+ ---
160
+
161
+ License
162
+
163
+ This project is licensed under the MIT License.
164
+ See the LICENSE file for details.
165
+
166
+ ---
167
+
168
+ Author
169
+
170
+ Ali VEX
171
+
172
+ · GitHub: @lyrdaadhrpyk802-ux
173
+ · Email: lyrdaadhrpyk802@gmail.com
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pysoroush"
7
+ version = "0.1.0"
8
+ description = "A modern, simple, and powerful Python library for the Soroush Plus messenger."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "Ali VEX", email = "lyrdaadhrpyk802@gmail.com" }
14
+ ]
15
+ keywords = ["soroush", "soroush-plus", "bot", "api", "userbot", "messenger"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Development Status :: 4 - Beta",
21
+ "Intended Audience :: Developers",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ ]
24
+ dependencies = [
25
+ "requests>=2.28.0",
26
+ "aiohttp>=3.8.0",
27
+ "splusthon>=1.1.4",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "pytest>=7.0.0",
33
+ "pytest-asyncio>=0.21.0",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/lyrdaadhrpyk802-ux/pysoroush"
38
+ Repository = "https://github.com/lyrdaadhrpyk802-ux/pysoroush"
39
+
40
+ [tool.setuptools.packages.find]
41
+ include = ["pysoroush*"]
@@ -0,0 +1,30 @@
1
+ """
2
+ PySoroush - A modern Python library for the Soroush Plus messenger.
3
+
4
+ This package contains two independent sub-packages:
5
+
6
+ * ``pysoroush.bot`` - Bot API client (sync & async).
7
+ * ``pysoroush.account`` - User account (Self) API client (async).
8
+
9
+ Example usage for bots::
10
+
11
+ from pysoroush.bot import Bot
12
+
13
+ Example usage for accounts::
14
+
15
+ from pysoroush.account import AsyncClient
16
+ """
17
+
18
+ __version__ = "0.1.0"
19
+ __author__ = "Ali VEX"
20
+ __author_email__ = "lyrdaadhrpyk802@gmail.com"
21
+ __url__ = "https://github.com/lyrdaadhrpyk802-ux/pysoroush"
22
+ __license__ = "MIT"
23
+
24
+ __all__ = [
25
+ "__version__",
26
+ "__author__",
27
+ "__author_email__",
28
+ "__url__",
29
+ "__license__",
30
+ ]
@@ -0,0 +1,15 @@
1
+ """
2
+ pysoroush.account - Soroush Plus User Account (Self) API client.
3
+ """
4
+
5
+ from .client import Client
6
+ from .async_client import AsyncClient
7
+ from .exceptions import SoroushAccountError, AuthError, PasswordRequiredError
8
+
9
+ __all__ = [
10
+ "Client",
11
+ "AsyncClient",
12
+ "SoroushAccountError",
13
+ "AuthError",
14
+ "PasswordRequiredError",
15
+ ]