pyrobale 0.2.8.2__tar.gz → 0.2.9__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.
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/PKG-INFO +1 -1
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/pyproject.toml +1 -1
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/pyrobale.py +38 -41
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/LICENSE +0 -0
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/README.md +0 -0
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/pyrobale.png +0 -0
- {pyrobale-0.2.8.2 → pyrobale-0.2.9}/pyrobaletext.png +0 -0
@@ -8,26 +8,19 @@ Features:
|
|
8
8
|
- New and Up to date
|
9
9
|
- Internal database management
|
10
10
|
"""
|
11
|
+
from typing import Optional, Dict, Any, List, Union
|
12
|
+
import os
|
11
13
|
import json
|
12
14
|
import time
|
13
|
-
from typing import Optional, Dict, Any, List, Union
|
14
15
|
import threading
|
15
16
|
import traceback
|
16
17
|
import sqlite3
|
17
18
|
import inspect
|
18
|
-
import requests
|
19
19
|
import re
|
20
20
|
import sys
|
21
|
-
import
|
22
|
-
from urllib.parse import urlparse, unquote
|
23
|
-
from io import BytesIO
|
24
|
-
import mimetypes
|
25
|
-
from os import PathLike
|
26
|
-
from pathlib import Path
|
27
|
-
import uuid
|
28
|
-
from typing import Iterator
|
21
|
+
import requests
|
29
22
|
|
30
|
-
__version__ = '0.2.
|
23
|
+
__version__ = '0.2.9'
|
31
24
|
|
32
25
|
|
33
26
|
class ChatActions:
|
@@ -743,6 +736,9 @@ class Chat:
|
|
743
736
|
self.description = result.get('description')
|
744
737
|
self.invite_link = result.get('invite_link')
|
745
738
|
self.photo = result.get('photo')
|
739
|
+
self.is_channel_chat = self.CHANNEL = self.type == "channel"
|
740
|
+
self.is_group_chat = self.GROUP = self.type == "group"
|
741
|
+
self.is_private_chat = self.PRIVATE = self.type == "private"
|
746
742
|
|
747
743
|
def send_photo(self,
|
748
744
|
photo: Union[str,
|
@@ -968,7 +964,7 @@ class Chat:
|
|
968
964
|
"""Send a chat action"""
|
969
965
|
return self.client.send_chat_action(self.id, action, how_many_times)
|
970
966
|
|
971
|
-
def
|
967
|
+
def ban_chat_member(
|
972
968
|
self,
|
973
969
|
user_id: int,
|
974
970
|
until_date: Optional[int] = None) -> bool:
|
@@ -982,7 +978,7 @@ class Chat:
|
|
982
978
|
'POST', 'banChatMember', data=data)
|
983
979
|
return response.get('ok', False)
|
984
980
|
|
985
|
-
def
|
981
|
+
def unban_chat_member(
|
986
982
|
self,
|
987
983
|
user_id: int,
|
988
984
|
only_if_banned: bool = False) -> bool:
|
@@ -996,7 +992,7 @@ class Chat:
|
|
996
992
|
'POST', 'unbanChatMember', data=data)
|
997
993
|
return response.get('ok', False)
|
998
994
|
|
999
|
-
def
|
995
|
+
def promotee_chat_member(
|
1000
996
|
self,
|
1001
997
|
user_id: int,
|
1002
998
|
can_change_info: bool = None,
|
@@ -1022,7 +1018,7 @@ class Chat:
|
|
1022
1018
|
'POST', 'promoteChatMember', data=data)
|
1023
1019
|
return response.get('ok', False)
|
1024
1020
|
|
1025
|
-
def
|
1021
|
+
def set_chat_photo(self, photo: Union[str, bytes, InputFile]) -> bool:
|
1026
1022
|
"""Set a new chat photo"""
|
1027
1023
|
files = None
|
1028
1024
|
data = {'chat_id': self.id}
|
@@ -1038,26 +1034,26 @@ class Chat:
|
|
1038
1034
|
'POST', 'setChatPhoto', data=data, files=files)
|
1039
1035
|
return response.get('ok', False)
|
1040
1036
|
|
1041
|
-
def
|
1037
|
+
def leave_chat(self) -> bool:
|
1042
1038
|
"""Leave the chat"""
|
1043
1039
|
data = {'chat_id': self.id}
|
1044
1040
|
response = self.client._make_request('POST', 'leaveChat', data=data)
|
1045
1041
|
return response.get('ok', False)
|
1046
1042
|
|
1047
|
-
def
|
1043
|
+
def get_chat(self) -> 'Chat':
|
1048
1044
|
"""Get up to date information about the chat"""
|
1049
1045
|
data = {'chat_id': self.id}
|
1050
1046
|
response = self.client._make_request('GET', 'getChat', data=data)
|
1051
1047
|
return Chat(self.client, response)
|
1052
1048
|
|
1053
|
-
def
|
1049
|
+
def get_members_count(self) -> int:
|
1054
1050
|
"""Get the number of members in the chat"""
|
1055
1051
|
data = {'chat_id': self.id}
|
1056
1052
|
response = self.client._make_request(
|
1057
1053
|
'POST', 'getChatMembersCount', data=data)
|
1058
1054
|
return response.get('result', 0)
|
1059
1055
|
|
1060
|
-
def
|
1056
|
+
def pin_message(
|
1061
1057
|
self,
|
1062
1058
|
message_id: int,
|
1063
1059
|
disable_notification: bool = False) -> bool:
|
@@ -1071,7 +1067,7 @@ class Chat:
|
|
1071
1067
|
'POST', 'pinChatMessage', data=data)
|
1072
1068
|
return response.get('ok', False)
|
1073
1069
|
|
1074
|
-
def
|
1070
|
+
def unpin_message(self, message_id: int) -> bool:
|
1075
1071
|
"""Unpin a message in the chat"""
|
1076
1072
|
data = {
|
1077
1073
|
'chat_id': self.id,
|
@@ -1081,14 +1077,14 @@ class Chat:
|
|
1081
1077
|
'POST', 'unpinChatMessage', data=data)
|
1082
1078
|
return response.get('ok', False)
|
1083
1079
|
|
1084
|
-
def
|
1080
|
+
def unpin_all_messages(self) -> bool:
|
1085
1081
|
"""Unpin all messages in the chat"""
|
1086
1082
|
data = {'chat_id': self.id}
|
1087
1083
|
response = self.client._make_request(
|
1088
1084
|
'POST', 'unpinAllChatMessages', data=data)
|
1089
1085
|
return response.get('ok', False)
|
1090
1086
|
|
1091
|
-
def
|
1087
|
+
def set_chat_title(self, title: str) -> bool:
|
1092
1088
|
"""Change the title of the chat"""
|
1093
1089
|
data = {
|
1094
1090
|
'chat_id': self.id,
|
@@ -1097,7 +1093,7 @@ class Chat:
|
|
1097
1093
|
response = self.client._make_request('POST', 'setChatTitle', data=data)
|
1098
1094
|
return response.get('ok', False)
|
1099
1095
|
|
1100
|
-
def
|
1096
|
+
def set_chat_description(self, description: str) -> bool:
|
1101
1097
|
"""Change the description of the chat"""
|
1102
1098
|
data = {
|
1103
1099
|
'chat_id': self.id,
|
@@ -1107,21 +1103,21 @@ class Chat:
|
|
1107
1103
|
'POST', 'setChatDescription', data=data)
|
1108
1104
|
return response.get('ok', False)
|
1109
1105
|
|
1110
|
-
def
|
1106
|
+
def delete_chat_photo(self) -> bool:
|
1111
1107
|
"""Delete the chat photo"""
|
1112
1108
|
data = {'chat_id': self.id}
|
1113
1109
|
response = self.client._make_request(
|
1114
1110
|
'POST', 'deleteChatPhoto', data=data)
|
1115
1111
|
return response.get('ok', False)
|
1116
1112
|
|
1117
|
-
def
|
1113
|
+
def create_invite_link(self) -> str:
|
1118
1114
|
"""Create an invite link for the chat"""
|
1119
1115
|
data = {'chat_id': self.id}
|
1120
1116
|
response = self.client._make_request(
|
1121
1117
|
'POST', 'createChatInviteLink', data=data)
|
1122
1118
|
return response.get('result', {}).get('invite_link')
|
1123
1119
|
|
1124
|
-
def
|
1120
|
+
def revoke_invite_link(self, invite_link: str) -> bool:
|
1125
1121
|
"""Revoke an invite link for the chat"""
|
1126
1122
|
data = {
|
1127
1123
|
'chat_id': self.id,
|
@@ -1131,7 +1127,7 @@ class Chat:
|
|
1131
1127
|
'POST', 'revokeChatInviteLink', data=data)
|
1132
1128
|
return response.get('ok', False)
|
1133
1129
|
|
1134
|
-
def
|
1130
|
+
def export_invite_link(self) -> str:
|
1135
1131
|
"""Generate a new invite link for the chat"""
|
1136
1132
|
data = {'chat_id': self.id}
|
1137
1133
|
response = self.client._make_request(
|
@@ -1670,6 +1666,8 @@ class Client:
|
|
1670
1666
|
self._member_leave_handler = None
|
1671
1667
|
self._member_join_handler = None
|
1672
1668
|
self._threads = []
|
1669
|
+
self._polling = False
|
1670
|
+
self.user = None
|
1673
1671
|
|
1674
1672
|
def set_state(self,
|
1675
1673
|
chat_or_user_id: Union[Chat,
|
@@ -2275,9 +2273,10 @@ class Client:
|
|
2275
2273
|
|
2276
2274
|
def _create_thread(self, handler, *args):
|
2277
2275
|
"""Helper method to create and start a thread"""
|
2278
|
-
|
2279
|
-
|
2280
|
-
|
2276
|
+
if handler:
|
2277
|
+
thread = threading.Thread(target=handler, args=args, daemon=True)
|
2278
|
+
thread.start()
|
2279
|
+
self._threads.append(thread)
|
2281
2280
|
|
2282
2281
|
def _handle_message(self, message, update):
|
2283
2282
|
"""Handle different types of messages"""
|
@@ -2316,7 +2315,7 @@ class Client:
|
|
2316
2315
|
self._create_thread(handler, *args)
|
2317
2316
|
return
|
2318
2317
|
|
2319
|
-
if self
|
2318
|
+
if hasattr(self, '_message_handler'):
|
2320
2319
|
conds = conditions(
|
2321
2320
|
self,
|
2322
2321
|
message.author,
|
@@ -2335,7 +2334,7 @@ class Client:
|
|
2335
2334
|
# Handle message and edited message
|
2336
2335
|
message_types = {
|
2337
2336
|
'message': (Message, self._handle_message),
|
2338
|
-
'edited_message': (Message, self._message_edit_handler)
|
2337
|
+
'edited_message': (Message, lambda m, u: self._create_thread(self._message_edit_handler, m, u) if hasattr(self, '_message_edit_handler') else None)
|
2339
2338
|
}
|
2340
2339
|
|
2341
2340
|
for update_type, (cls, handler) in message_types.items():
|
@@ -2346,7 +2345,7 @@ class Client:
|
|
2346
2345
|
handler(message, update)
|
2347
2346
|
return
|
2348
2347
|
|
2349
|
-
if 'callback_query' in update and self
|
2348
|
+
if 'callback_query' in update and hasattr(self, '_callback_handler'):
|
2350
2349
|
obj = CallbackQuery(
|
2351
2350
|
self, {
|
2352
2351
|
'ok': True, 'result': update['callback_query']})
|
@@ -2364,13 +2363,14 @@ class Client:
|
|
2364
2363
|
info['last_run'] = current_time
|
2365
2364
|
|
2366
2365
|
def run(self, debug=False):
|
2367
|
-
"""Start
|
2366
|
+
"""Start polling for new messages"""
|
2368
2367
|
try:
|
2369
2368
|
self.user = self.get_me()
|
2370
2369
|
except BaseException:
|
2371
2370
|
raise BaleTokenNotFoundError("token not found")
|
2372
2371
|
|
2373
2372
|
self._polling = True
|
2373
|
+
self._threads = []
|
2374
2374
|
offset = 0
|
2375
2375
|
past_updates = set()
|
2376
2376
|
source_file = inspect.getfile(self.__class__)
|
@@ -2391,7 +2391,7 @@ class Client:
|
|
2391
2391
|
python = sys.executable
|
2392
2392
|
os.execl(python, python, *sys.argv)
|
2393
2393
|
|
2394
|
-
updates = self.get_updates(offset=offset
|
2394
|
+
updates = self.get_updates(offset=offset)
|
2395
2395
|
for update in updates:
|
2396
2396
|
update_id = update['update_id']
|
2397
2397
|
if update_id not in past_updates:
|
@@ -2418,11 +2418,8 @@ class Client:
|
|
2418
2418
|
print(f"Error checking file modification time: {e}")
|
2419
2419
|
return False
|
2420
2420
|
|
2421
|
-
def get_updates(self, offset
|
2422
|
-
|
2423
|
-
timeout: Optional[int] = None) -> List[Dict[str, Any]]:
|
2424
|
-
params = {k: v for k, v in locals().items() if k !=
|
2425
|
-
'self' and v is not None}
|
2421
|
+
def get_updates(self, offset=None) -> List[Dict[str, Any]]:
|
2422
|
+
params = {'offset': offset} if offset is not None else {}
|
2426
2423
|
response = self._make_request('GET', 'getUpdates', params=params)
|
2427
2424
|
return response.get('result', [])
|
2428
2425
|
|
@@ -2436,4 +2433,4 @@ class Client:
|
|
2436
2433
|
self._close_handler()
|
2437
2434
|
|
2438
2435
|
def create_ref_link(self, data: str):
|
2439
|
-
return f"https://ble.ir/{self.get_me().username}?start={data}"
|
2436
|
+
return f"https://ble.ir/{self.get_me().username}?start={data}"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|