balenova 0.3.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.
- balenova-0.3.0/.gitignore +15 -0
- balenova-0.3.0/LICENSE +22 -0
- balenova-0.3.0/NOTICE +5 -0
- balenova-0.3.0/PKG-INFO +161 -0
- balenova-0.3.0/README.md +126 -0
- balenova-0.3.0/docs/USAGE.md +151 -0
- balenova-0.3.0/examples/README.md +35 -0
- balenova-0.3.0/examples/calls.py +13 -0
- balenova-0.3.0/examples/commands.py +13 -0
- balenova-0.3.0/examples/dialogs.py +16 -0
- balenova-0.3.0/examples/echo.py +13 -0
- balenova-0.3.0/examples/files.py +13 -0
- balenova-0.3.0/examples/gifts.py +13 -0
- balenova-0.3.0/examples/groups.py +16 -0
- balenova-0.3.0/examples/json_output.py +13 -0
- balenova-0.3.0/examples/login.py +14 -0
- balenova-0.3.0/examples/messages.py +14 -0
- balenova-0.3.0/examples/updates.py +14 -0
- balenova-0.3.0/pyproject.toml +67 -0
- balenova-0.3.0/scripts/generate_proto.py +67 -0
- balenova-0.3.0/src/bale/__init__.py +75 -0
- balenova-0.3.0/src/bale/client.py +3617 -0
- balenova-0.3.0/src/bale/dispatcher.py +143 -0
- balenova-0.3.0/src/bale/errors.py +33 -0
- balenova-0.3.0/src/bale/events.py +134 -0
- balenova-0.3.0/src/bale/filters.py +268 -0
- balenova-0.3.0/src/bale/models.py +596 -0
- balenova-0.3.0/src/bale/proto/__init__.py +5 -0
- balenova-0.3.0/src/bale/proto/codec.py +87 -0
- balenova-0.3.0/src/bale/proto/request.proto +659 -0
- balenova-0.3.0/src/bale/proto/request_pb2.py +281 -0
- balenova-0.3.0/src/bale/proto/response.proto +359 -0
- balenova-0.3.0/src/bale/proto/response_pb2.py +175 -0
- balenova-0.3.0/src/bale/proto/struct.proto +728 -0
- balenova-0.3.0/src/bale/proto/struct_pb2.py +254 -0
- balenova-0.3.0/src/bale/protocol.py +252 -0
- balenova-0.3.0/src/bale/py.typed +1 -0
- balenova-0.3.0/src/bale/session.py +71 -0
- balenova-0.3.0/src/bale/transports/__init__.py +6 -0
- balenova-0.3.0/src/bale/transports/grpc.py +242 -0
- balenova-0.3.0/src/bale/transports/websocket.py +315 -0
- balenova-0.3.0/src/balenova/__init__.py +70 -0
- balenova-0.3.0/src/balenova/client.py +5 -0
- balenova-0.3.0/src/balenova/errors.py +5 -0
- balenova-0.3.0/src/balenova/events.py +5 -0
- balenova-0.3.0/src/balenova/filters.py +3 -0
- balenova-0.3.0/src/balenova/models.py +3 -0
- balenova-0.3.0/tests/test_client.py +1089 -0
- balenova-0.3.0/tests/test_events.py +75 -0
- balenova-0.3.0/tests/test_examples.py +41 -0
- balenova-0.3.0/tests/test_grpc_transport.py +104 -0
- balenova-0.3.0/tests/test_models.py +47 -0
- balenova-0.3.0/tests/test_proto.py +211 -0
- balenova-0.3.0/tests/test_session.py +35 -0
- balenova-0.3.0/tests/test_web_bale.py +35 -0
- balenova-0.3.0/tests/test_websocket_transport.py +161 -0
balenova-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bale Async contributors
|
|
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
|
+
|
balenova-0.3.0/NOTICE
ADDED
balenova-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: balenova
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A friendly Python client for Bale accounts
|
|
5
|
+
Project-URL: Homepage, https://github.com/iliasync/balenova
|
|
6
|
+
Project-URL: Documentation, https://github.com/iliasync/balenova#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/iliasync/balenova
|
|
8
|
+
Project-URL: Issues, https://github.com/iliasync/balenova/issues
|
|
9
|
+
Author: iliasync
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: asyncio,bale,client,messaging
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Framework :: AsyncIO
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: httpx<1,>=0.27
|
|
25
|
+
Requires-Dist: protobuf<8,>=7.35.1
|
|
26
|
+
Requires-Dist: websockets<17,>=13
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: grpcio-tools<2,>=1.83; extra == 'dev'
|
|
29
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
|
33
|
+
Requires-Dist: types-protobuf>=6.30; extra == 'dev'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# BaleNova
|
|
37
|
+
|
|
38
|
+
کار با حساب بله در Python، با یک API ساده و قابلفهم.
|
|
39
|
+
|
|
40
|
+
## نصب
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install balenova
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Python 3.10 یا جدیدتر لازم است.
|
|
47
|
+
|
|
48
|
+
## شروع در کمتر از یک دقیقه
|
|
49
|
+
|
|
50
|
+
یک فایل به نام `main.py` بسازید:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from balenova import Client, events, filters
|
|
54
|
+
|
|
55
|
+
app = Client("my_account")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@app.on(events.NewMessage, filters.command("start"))
|
|
59
|
+
async def start(event):
|
|
60
|
+
await event.reply("سلام! من آمادهام 🌱")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
app.run_forever()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
سپس اجرا کنید:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python main.py
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
بار اول شماره، کد ورود و در صورت نیاز رمز دومرحلهای پرسیده میشود. دفعات بعد
|
|
73
|
+
ورود ذخیرهشده استفاده خواهد شد.
|
|
74
|
+
|
|
75
|
+
## پیامها
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
@app.on(events.NewMessage, filters.private & filters.text)
|
|
79
|
+
async def new_message(event):
|
|
80
|
+
print(event.text)
|
|
81
|
+
print(event.sender_id)
|
|
82
|
+
print(event.chat.id)
|
|
83
|
+
|
|
84
|
+
await event.answer("پیامت رسید")
|
|
85
|
+
await event.reply("این پیام بهصورت پاسخ ارسال شد")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
فیلترها را میتوان با `&`، `|` و `~` ترکیب کرد:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
only_commands = filters.incoming & filters.private & filters.command("help")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## همهٔ بهروزرسانیها بهصورت کلاس
|
|
95
|
+
|
|
96
|
+
هر بهروزرسانی یک شیء مشخص است:
|
|
97
|
+
|
|
98
|
+
- `events.NewMessage` برای پیام تازه
|
|
99
|
+
- `events.MessageSent` برای تأیید ارسال
|
|
100
|
+
- `events.RawUpdate` برای موارد دیگری که دادهٔ آنها دریافت شده است
|
|
101
|
+
- `events.Update` پایهٔ مشترک همهٔ موارد
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
@app.on_update
|
|
105
|
+
async def every_update(update):
|
|
106
|
+
print(update.name)
|
|
107
|
+
print(update.to_json())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
برای گرفتن فقط یک نوع:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
@app.on(events.MessageSent)
|
|
114
|
+
async def sent(update):
|
|
115
|
+
print(update.to_dict())
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## تبدیل نتیجهها به JSON
|
|
119
|
+
|
|
120
|
+
مدلهایی مانند پیام، کاربر، گفتوگو و بهروزرسانی مستقیماً قابل تبدیلاند:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
print(event.to_dict())
|
|
124
|
+
print(event.to_json())
|
|
125
|
+
|
|
126
|
+
me = await client.get_me()
|
|
127
|
+
print(me.to_json())
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## میانبرهای کاربردی
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
await client.send("12345|1", "سلام")
|
|
134
|
+
chat = await client.get_entity("username")
|
|
135
|
+
|
|
136
|
+
async for message in client.iter_messages("12345|1", limit=100):
|
|
137
|
+
print(message.text)
|
|
138
|
+
|
|
139
|
+
limits = await client.get_upload_limits()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
روی خود پیام نیز میانبرهای آماده وجود دارد:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
await event.message.respond("سلام")
|
|
146
|
+
await event.message.edit_text("متن جدید")
|
|
147
|
+
await event.message.delete()
|
|
148
|
+
await event.message.react("❤")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
نمونههای بیشتر در پوشهٔ [`examples`](examples) و راهنمای ساده در
|
|
152
|
+
[`docs/USAGE.md`](docs/USAGE.md) قرار دارند.
|
|
153
|
+
|
|
154
|
+
## نکتهٔ مهم
|
|
155
|
+
|
|
156
|
+
این پروژه رسمیِ بله نیست. از حساب آزمایشی شروع کنید، اطلاعات ورود و فایلهای
|
|
157
|
+
session را منتشر نکنید و مسئولیت استفاده از حساب بر عهدهٔ خود شماست.
|
|
158
|
+
|
|
159
|
+
## مجوز
|
|
160
|
+
|
|
161
|
+
MIT — جزئیات حقوقی لازم در فایل [`NOTICE`](NOTICE) نگهداری میشود.
|
balenova-0.3.0/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# BaleNova
|
|
2
|
+
|
|
3
|
+
کار با حساب بله در Python، با یک API ساده و قابلفهم.
|
|
4
|
+
|
|
5
|
+
## نصب
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install balenova
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Python 3.10 یا جدیدتر لازم است.
|
|
12
|
+
|
|
13
|
+
## شروع در کمتر از یک دقیقه
|
|
14
|
+
|
|
15
|
+
یک فایل به نام `main.py` بسازید:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from balenova import Client, events, filters
|
|
19
|
+
|
|
20
|
+
app = Client("my_account")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@app.on(events.NewMessage, filters.command("start"))
|
|
24
|
+
async def start(event):
|
|
25
|
+
await event.reply("سلام! من آمادهام 🌱")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
app.run_forever()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
سپس اجرا کنید:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python main.py
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
بار اول شماره، کد ورود و در صورت نیاز رمز دومرحلهای پرسیده میشود. دفعات بعد
|
|
38
|
+
ورود ذخیرهشده استفاده خواهد شد.
|
|
39
|
+
|
|
40
|
+
## پیامها
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
@app.on(events.NewMessage, filters.private & filters.text)
|
|
44
|
+
async def new_message(event):
|
|
45
|
+
print(event.text)
|
|
46
|
+
print(event.sender_id)
|
|
47
|
+
print(event.chat.id)
|
|
48
|
+
|
|
49
|
+
await event.answer("پیامت رسید")
|
|
50
|
+
await event.reply("این پیام بهصورت پاسخ ارسال شد")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
فیلترها را میتوان با `&`، `|` و `~` ترکیب کرد:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
only_commands = filters.incoming & filters.private & filters.command("help")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## همهٔ بهروزرسانیها بهصورت کلاس
|
|
60
|
+
|
|
61
|
+
هر بهروزرسانی یک شیء مشخص است:
|
|
62
|
+
|
|
63
|
+
- `events.NewMessage` برای پیام تازه
|
|
64
|
+
- `events.MessageSent` برای تأیید ارسال
|
|
65
|
+
- `events.RawUpdate` برای موارد دیگری که دادهٔ آنها دریافت شده است
|
|
66
|
+
- `events.Update` پایهٔ مشترک همهٔ موارد
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
@app.on_update
|
|
70
|
+
async def every_update(update):
|
|
71
|
+
print(update.name)
|
|
72
|
+
print(update.to_json())
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
برای گرفتن فقط یک نوع:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
@app.on(events.MessageSent)
|
|
79
|
+
async def sent(update):
|
|
80
|
+
print(update.to_dict())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## تبدیل نتیجهها به JSON
|
|
84
|
+
|
|
85
|
+
مدلهایی مانند پیام، کاربر، گفتوگو و بهروزرسانی مستقیماً قابل تبدیلاند:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
print(event.to_dict())
|
|
89
|
+
print(event.to_json())
|
|
90
|
+
|
|
91
|
+
me = await client.get_me()
|
|
92
|
+
print(me.to_json())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## میانبرهای کاربردی
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
await client.send("12345|1", "سلام")
|
|
99
|
+
chat = await client.get_entity("username")
|
|
100
|
+
|
|
101
|
+
async for message in client.iter_messages("12345|1", limit=100):
|
|
102
|
+
print(message.text)
|
|
103
|
+
|
|
104
|
+
limits = await client.get_upload_limits()
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
روی خود پیام نیز میانبرهای آماده وجود دارد:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
await event.message.respond("سلام")
|
|
111
|
+
await event.message.edit_text("متن جدید")
|
|
112
|
+
await event.message.delete()
|
|
113
|
+
await event.message.react("❤")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
نمونههای بیشتر در پوشهٔ [`examples`](examples) و راهنمای ساده در
|
|
117
|
+
[`docs/USAGE.md`](docs/USAGE.md) قرار دارند.
|
|
118
|
+
|
|
119
|
+
## نکتهٔ مهم
|
|
120
|
+
|
|
121
|
+
این پروژه رسمیِ بله نیست. از حساب آزمایشی شروع کنید، اطلاعات ورود و فایلهای
|
|
122
|
+
session را منتشر نکنید و مسئولیت استفاده از حساب بر عهدهٔ خود شماست.
|
|
123
|
+
|
|
124
|
+
## مجوز
|
|
125
|
+
|
|
126
|
+
MIT — جزئیات حقوقی لازم در فایل [`NOTICE`](NOTICE) نگهداری میشود.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# راهنمای سادهٔ BaleNova
|
|
2
|
+
|
|
3
|
+
## نصب و ورود
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install balenova
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from balenova import Client
|
|
11
|
+
|
|
12
|
+
app = Client("personal")
|
|
13
|
+
app.run_forever()
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
برنامه در اولین اجرا اطلاعات ورود را میپرسد. پوشهٔ `sessions` را هیچوقت در
|
|
17
|
+
GitHub قرار ندهید.
|
|
18
|
+
|
|
19
|
+
## پاسخ به پیام
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from balenova import Client, events, filters
|
|
23
|
+
|
|
24
|
+
app = Client("personal")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@app.on(events.NewMessage, filters.incoming & filters.private)
|
|
28
|
+
async def reply(event):
|
|
29
|
+
await event.reply("سلام 👋")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
app.run_forever()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## ساخت دستور
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
@app.on(events.NewMessage, filters.command("ping"))
|
|
39
|
+
async def ping(event):
|
|
40
|
+
await event.reply("pong")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
دستوری که کاربر میفرستد `/ping` است.
|
|
44
|
+
|
|
45
|
+
## فیلترهای پرکاربرد
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
filters.incoming # پیام دریافتی
|
|
49
|
+
filters.outgoing # پیام ارسالی خودتان
|
|
50
|
+
filters.private # گفتوگوی خصوصی
|
|
51
|
+
filters.group # گروه
|
|
52
|
+
filters.channel # کانال
|
|
53
|
+
filters.text # متن
|
|
54
|
+
filters.photo # عکس
|
|
55
|
+
filters.video # ویدیو
|
|
56
|
+
filters.document # فایل
|
|
57
|
+
filters.reply # پیام پاسخدار
|
|
58
|
+
filters.sender(12345) # فرستندهٔ مشخص
|
|
59
|
+
filters.regex(r"سلام")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
نمونهٔ ترکیب:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
photos_from_groups = filters.incoming & filters.group & filters.photo
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## ارسال پیام
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
await client.send("12345|1", "سلام")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
شناسهٔ گفتوگو را میتوانید از `event.chat.id` بگیرید.
|
|
75
|
+
|
|
76
|
+
## اطلاعات پیام
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
print(event.text)
|
|
80
|
+
print(event.sender)
|
|
81
|
+
print(event.sender_id)
|
|
82
|
+
print(event.chat)
|
|
83
|
+
print(event.message.id)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## کارهای آماده روی پیام
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
await event.answer("پیام عادی")
|
|
90
|
+
await event.reply("پاسخ به همین پیام")
|
|
91
|
+
await event.delete()
|
|
92
|
+
await event.message.edit_text("ویرایش شد")
|
|
93
|
+
await event.message.seen()
|
|
94
|
+
await event.message.forward("67890|1")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## کاربر و گفتوگو
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
me = await client.get_me()
|
|
101
|
+
chat = await client.get_entity("username")
|
|
102
|
+
|
|
103
|
+
print(me.full_name)
|
|
104
|
+
print(chat.to_json() if chat else "پیدا نشد")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## تاریخچه بدون صفحهبندی دستی
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
async for message in client.iter_messages("12345|1", limit=100):
|
|
111
|
+
print(message.content)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## JSON
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
data = event.to_dict()
|
|
118
|
+
text = event.to_json()
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
همین دو متد روی `Message`، `User` و `Chat` هم وجود دارد.
|
|
122
|
+
|
|
123
|
+
## همهٔ رویدادها
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
@app.on_update
|
|
127
|
+
async def inspect(update):
|
|
128
|
+
print(update.name)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
یا فقط یک کلاس مشخص:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
@app.on(events.NewMessage)
|
|
135
|
+
async def messages(event):
|
|
136
|
+
print(event.text)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## اجرای مثالهای آماده
|
|
140
|
+
|
|
141
|
+
پس از دریافت سورس پروژه:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pip install -e .
|
|
145
|
+
python examples/login.py
|
|
146
|
+
python examples/echo.py
|
|
147
|
+
python examples/commands.py
|
|
148
|
+
python examples/dialogs.py
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
برای دیدن گزینههای هر مثال، `--help` بزنید.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# مثالهای BaleNova
|
|
2
|
+
|
|
3
|
+
همهٔ مثالها کوتاه و مستقلاند. ابتدا کتابخانه را نصب کنید:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install -e .
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
سپس یکی را اجرا کنید:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python examples/login.py
|
|
13
|
+
python examples/echo.py
|
|
14
|
+
python examples/commands.py
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
در اولین اجرا اطلاعات ورود پرسیده میشود و دفعات بعد از فایل ذخیرهشده در
|
|
18
|
+
`sessions/my_account.session` استفاده خواهد شد.
|
|
19
|
+
|
|
20
|
+
در مثالهایی که `CHAT_ID` یا `GROUP_ID` دارند، مقدار نمونه را با شناسهٔ واقعی
|
|
21
|
+
خودتان جایگزین کنید.
|
|
22
|
+
|
|
23
|
+
| فایل | کاربرد |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `login.py` | ورود و نمایش حساب |
|
|
26
|
+
| `echo.py` | پاسخ خودکار |
|
|
27
|
+
| `commands.py` | دستور `/start` |
|
|
28
|
+
| `messages.py` | ارسال پیام |
|
|
29
|
+
| `dialogs.py` | نمایش گفتوگوها |
|
|
30
|
+
| `json_output.py` | خروجی JSON |
|
|
31
|
+
| `updates.py` | مشاهدهٔ رویدادها |
|
|
32
|
+
| `files.py` | ظرفیت آپلود |
|
|
33
|
+
| `groups.py` | اطلاعات گروه |
|
|
34
|
+
| `gifts.py` | اطلاعات کیف پول |
|
|
35
|
+
| `calls.py` | تماسهای اخیر |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""ساخت دستور /start."""
|
|
2
|
+
|
|
3
|
+
from balenova import Client, events, filters
|
|
4
|
+
|
|
5
|
+
app = Client("my_account")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.on(events.NewMessage, filters.command("start"))
|
|
9
|
+
async def start(event):
|
|
10
|
+
await event.reply("سلام! آمادهام 🌱")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
app.run_forever()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""نمایش گفتوگوهای حساب."""
|
|
2
|
+
|
|
3
|
+
from balenova import Client
|
|
4
|
+
|
|
5
|
+
app = Client("my_account")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def main(client):
|
|
9
|
+
dialogs = await client.get_all_dialogs_by_type()
|
|
10
|
+
for kind, chats in dialogs.items():
|
|
11
|
+
print(f"{kind}: {len(chats)}")
|
|
12
|
+
for chat in chats[:5]:
|
|
13
|
+
print(" -", chat.full_name, chat.id)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
app.run_task(main)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""پاسخ خودکار به پیامهای خصوصی."""
|
|
2
|
+
|
|
3
|
+
from balenova import Client, events, filters
|
|
4
|
+
|
|
5
|
+
app = Client("my_account")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.on(events.NewMessage, filters.incoming & filters.private & filters.text)
|
|
9
|
+
async def echo(event):
|
|
10
|
+
await event.reply(f"گفتی: {event.text}")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
app.run_forever()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""نمایش اطلاعات و اعضای یک گروه."""
|
|
2
|
+
|
|
3
|
+
from balenova import Client
|
|
4
|
+
|
|
5
|
+
app = Client("my_account")
|
|
6
|
+
GROUP_ID = "12345|2" # شناسهٔ گروه خودتان
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def main(client):
|
|
10
|
+
group = await client.get_entity(GROUP_ID)
|
|
11
|
+
members = await client.load_members(GROUP_ID, limit=20)
|
|
12
|
+
print(group.to_json() if group else "گروه پیدا نشد")
|
|
13
|
+
print(members["members"])
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
app.run_task(main)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""ارسال یک پیام."""
|
|
2
|
+
|
|
3
|
+
from balenova import Client
|
|
4
|
+
|
|
5
|
+
app = Client("my_account")
|
|
6
|
+
CHAT_ID = "12345|1" # شناسهٔ گفتوگوی خودتان
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def main(client):
|
|
10
|
+
message = await client.send(CHAT_ID, "سلام از BaleNova")
|
|
11
|
+
print(message.id)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
app.run_task(main)
|