pyrobale 0.3.5__py3-none-any.whl → 0.3.8__py3-none-any.whl
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.
- pyrobale/StateMachine/__init__.py +66 -0
- pyrobale/__init__.py +122 -0
- pyrobale/client/__init__.py +679 -35
- pyrobale/exceptions/__init__.py +1 -0
- pyrobale/exceptions/common.py +6 -0
- pyrobale/filters/__init__.py +2 -0
- pyrobale/filters/enum_filters.py +12 -0
- pyrobale/filters/func_filters.py +17 -0
- pyrobale/objects/__init__.py +3 -0
- pyrobale/objects/callbackquery.py +19 -24
- pyrobale/objects/chatmember.py +5 -4
- pyrobale/objects/enums.py +8 -0
- pyrobale/objects/inlinekeyboardmarkup.py +11 -4
- pyrobale/objects/message.py +33 -16
- pyrobale/objects/user.py +11 -9
- pyrobale/objects/utils.py +23 -3
- pyrobale-0.3.8.dist-info/METADATA +152 -0
- {pyrobale-0.3.5.dist-info → pyrobale-0.3.8.dist-info}/RECORD +20 -16
- {pyrobale-0.3.5.dist-info → pyrobale-0.3.8.dist-info}/licenses/LICENSE +2 -2
- pyrobale-0.3.5.dist-info/METADATA +0 -176
- {pyrobale-0.3.5.dist-info → pyrobale-0.3.8.dist-info}/WHEEL +0 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
from typing import Union, TYPE_CHECKING
|
2
|
+
|
3
|
+
if TYPE_CHECKING:
|
4
|
+
from ..objects import User
|
5
|
+
from ..client import Client
|
6
|
+
|
7
|
+
|
8
|
+
class StateMachine:
|
9
|
+
def __init__(self):
|
10
|
+
self.__states = {}
|
11
|
+
|
12
|
+
def set_state(self, user_id: Union[str, int], state: str):
|
13
|
+
"""Sets or updates state of a user
|
14
|
+
|
15
|
+
Args:
|
16
|
+
user_id (string OR integer): unique id of user for setting the state
|
17
|
+
state (string): state of user (it can be anything)
|
18
|
+
"""
|
19
|
+
self.__states[user_id] = state
|
20
|
+
|
21
|
+
def get_state(self, user_id: Union[str, int]) -> str:
|
22
|
+
"""Gets state of a specified user
|
23
|
+
|
24
|
+
Args:
|
25
|
+
user_id (string OR integer): unique id of user for getting the state
|
26
|
+
|
27
|
+
Returns:
|
28
|
+
Str: the state of user
|
29
|
+
"""
|
30
|
+
|
31
|
+
if user_id in self.__states:
|
32
|
+
return self.__states[user_id]
|
33
|
+
else:
|
34
|
+
raise KeyError
|
35
|
+
|
36
|
+
def del_state(self, user_id: Union[str, int]):
|
37
|
+
"""Deletes the saved state of user
|
38
|
+
|
39
|
+
Args:
|
40
|
+
user_id (string OR integer): unique if of user to delete its state
|
41
|
+
"""
|
42
|
+
if user_id in self.__states:
|
43
|
+
del self.__states[user_id]
|
44
|
+
else:
|
45
|
+
raise KeyError
|
46
|
+
|
47
|
+
def save_local(self, file_name: str):
|
48
|
+
"""Saves the state of all users to a file
|
49
|
+
|
50
|
+
Args:
|
51
|
+
file_name (string): name of file to save the state of users
|
52
|
+
"""
|
53
|
+
with open(file_name, "w") as f:
|
54
|
+
for user_id, state in self.__states.items():
|
55
|
+
f.write(f"{user_id} {state}\n")
|
56
|
+
|
57
|
+
def load_local(self, file_name: str):
|
58
|
+
"""Loads the state of all users from a file
|
59
|
+
|
60
|
+
Args:
|
61
|
+
file_name (string): name of file to load the state of users
|
62
|
+
"""
|
63
|
+
with open(file_name, "r") as f:
|
64
|
+
for line in f:
|
65
|
+
user_id, state = line.split()
|
66
|
+
self.__states[user_id] = state
|
pyrobale/__init__.py
CHANGED
@@ -1,3 +1,125 @@
|
|
1
|
+
"""
|
2
|
+

|
3
|
+
|
4
|
+
# Bale Bot API Python Library
|
5
|
+
|
6
|
+
A modern, easy-to-use Python wrapper for the Bale Bot API that makes building Bale bots simple and intuitive.
|
7
|
+
|
8
|
+
## Features
|
9
|
+
|
10
|
+
- 🚀 **Simple & Intuitive** - Clean, Pythonic API design
|
11
|
+
- 📨 **Full Message Support** - Text, photos, videos, documents, and more
|
12
|
+
- ⌨️ **Interactive Elements** - Inline keyboards, reply keyboards, and buttons
|
13
|
+
- 🔄 **Real-time Updates** - Webhook and polling support
|
14
|
+
- 📁 **File Handling** - Easy upload and download of media files
|
15
|
+
- 🛡️ **Error Handling** - Comprehensive exception handling
|
16
|
+
- 📖 **Type Hints** - Full typing support for better development experience
|
17
|
+
- ⚡ **Async Support** - Both synchronous and asynchronous operations
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
```bash
|
22
|
+
pip install pyrobale
|
23
|
+
```
|
24
|
+
|
25
|
+
## Quick Start
|
26
|
+
|
27
|
+
```python
|
28
|
+
from pyrobale.client import Client
|
29
|
+
from pyrobale.objects import Message, UpdatesTypes
|
30
|
+
|
31
|
+
bot = Client("YOUR_BOT_TOKEN")
|
32
|
+
|
33
|
+
@bot.on_message()
|
34
|
+
async def message_handler(message: Message):
|
35
|
+
await message.reply("Hello, world!")
|
36
|
+
|
37
|
+
bot.run()
|
38
|
+
```
|
39
|
+
|
40
|
+
## Examples
|
41
|
+
|
42
|
+
### Conversation Bot
|
43
|
+
```python
|
44
|
+
from pyrobale.objects import *
|
45
|
+
from pyrobale.client import Client, Message, UpdatesTypes
|
46
|
+
import asyncio
|
47
|
+
|
48
|
+
client = Client("YOUR_BOT_TOKEN")
|
49
|
+
|
50
|
+
async def handle_message(message: Message):
|
51
|
+
if message.text == "/start":
|
52
|
+
await message.reply("سلام! من یک ربات PyRoBale هستم!")
|
53
|
+
await client.wait_for(UpdatesTypes.MESSAGE)
|
54
|
+
await message.reply("Okay! wait_for Test Compeleted")
|
55
|
+
|
56
|
+
client.add_handler(UpdatesTypes.MESSAGE, handle_message)
|
57
|
+
|
58
|
+
client.run()
|
59
|
+
```
|
60
|
+
|
61
|
+
### Echo Bot
|
62
|
+
```python
|
63
|
+
from pyrobale.client import Client
|
64
|
+
from pyrobale.objects import Message, UpdatesTypes
|
65
|
+
|
66
|
+
bot = Client("YOUR_BOT_TOKEN")
|
67
|
+
|
68
|
+
@bot.on_message()
|
69
|
+
async def message_handler(message: Message):
|
70
|
+
await message.reply(message.text)
|
71
|
+
|
72
|
+
bot.run()
|
73
|
+
```
|
74
|
+
|
75
|
+
### Inline Keyboard
|
76
|
+
```python
|
77
|
+
from pyrobale.client import Client
|
78
|
+
from pyrobale.objects import Message, UpdatesTypes, InlineKeyboardButton, InlineKeyboardMarkup, CopyTextButton
|
79
|
+
|
80
|
+
bot = Client("YOUR_BOT_TOKEN")
|
81
|
+
async def message_handler(message: Message):
|
82
|
+
buttons = InlineKeyboardMarkup()
|
83
|
+
buttons.add_button("URL", url="https://google.com")
|
84
|
+
buttons.add_button("Callback", callback_data="callback")
|
85
|
+
buttons.add_row()
|
86
|
+
buttons.add_button("WebApp", web_app="https://daradege.ir")
|
87
|
+
buttons.add_button("Copy", copy_text_button=CopyTextButton("TEXT"))
|
88
|
+
await message.reply("Hello, world!", reply_markup=buttons)
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
## Core Abilities
|
93
|
+
|
94
|
+
- **Message Handling** - Process text, commands, and media messages
|
95
|
+
- **Callback Queries** - Handle inline keyboard interactions
|
96
|
+
- **File Operations** - Send and receive photos, videos, documents
|
97
|
+
- **Chat Management** - Get chat info, member management
|
98
|
+
- **Custom Keyboards** - Create interactive user interfaces
|
99
|
+
- **Webhook Support** - Production-ready webhook handling
|
100
|
+
- **Middleware Support** - Add custom processing layers
|
101
|
+
|
102
|
+
## Documentation
|
103
|
+
|
104
|
+
For detailed documentation and advanced usage, visit our [documentation site](https://pyrobale.readthedocs.io).
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
113
|
+
|
114
|
+
## Support
|
115
|
+
|
116
|
+
- 📖 [Documentation](https://pyrobale.readthedocs.io)
|
117
|
+
- 🐛 [Issue Tracker](https://github.com/pyrobale/pyrobale/issues)
|
118
|
+
- 💬 [Discussions](https://github.com/pyrobale/pyrobale/discussions)
|
119
|
+
|
120
|
+
"""
|
121
|
+
|
1
122
|
from .objects.utils import *
|
2
123
|
from .exceptions import *
|
3
124
|
from .objects import *
|
125
|
+
from .client import Client
|