RubigramClient 1.4.4__tar.gz → 1.4.6__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.

Potentially problematic release.


This version of RubigramClient might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.4.4
3
+ Version: 1.4.6
4
4
  Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
5
5
  Author-email: Javad RZ <Javad.Py1385@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.4.4
3
+ Version: 1.4.6
4
4
  Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
5
5
  Author-email: Javad RZ <Javad.Py1385@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "RubigramClient"
3
- version = "1.4.4"
3
+ version = "1.4.6"
4
4
  description = "A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.7"
@@ -136,6 +136,8 @@ class Client(Method):
136
136
 
137
137
  now = int(datetime.now().timestamp())
138
138
  if message_time >= now or message_time + 2 >= now:
139
+ if isinstance(update, Update):
140
+ update.client = self
139
141
  await self.dispatch_update(update)
140
142
 
141
143
  self.offset_id = get_update.next_offset_id
@@ -143,4 +145,5 @@ class Client(Method):
143
145
  logger.exception(f"Polling error: {e}")
144
146
  await asyncio.sleep(1)
145
147
 
146
- asyncio.run(polling())
148
+ try:asyncio.run(polling())
149
+ except:pass
@@ -10,47 +10,36 @@ class Network:
10
10
  self.token: str = token
11
11
  self.session: Optional[ClientSession] = None
12
12
  self.api: str = f"https://botapi.rubika.ir/v3/{self.token}/"
13
-
14
- async def get_session(self) -> ClientSession:
15
- if self.session is None or self.session.closed:
16
- self.session = ClientSession()
17
- return self.session
18
-
19
- async def close(self) -> None:
20
- if self.session and not self.session.closed:
21
- await self.session.close()
13
+
22
14
 
23
15
  async def request(self, method: str, json: Dict[str, Any]) -> Optional[Dict[str, Any]]:
24
- session = await self.get_session()
25
- async with session.post(self.api + method, json=json) as response:
26
- response.raise_for_status()
27
- data: dict = await response.json()
28
- return data.get("data")
16
+ async with ClientSession() as session:
17
+ async with session.post(self.api + method, json=json) as response:
18
+ response.raise_for_status()
19
+ data: dict = await response.json()
20
+ return data.get("data")
29
21
 
30
22
  async def request_bytes_file(self, url: str) -> bytes:
31
- session = await self.get_session()
32
- async with session.get(url) as response:
33
- response.raise_for_status()
34
- return await response.read()
23
+ async with ClientSession() as session:
24
+ async with session.get(url) as response:
25
+ response.raise_for_status()
26
+ return await response.read()
35
27
 
36
28
  async def request_upload_file(self, upload_url: str, file: Union[str], name: str) -> str:
37
- session = await self.get_session()
38
-
39
29
  if isinstance(file, str) and re.match(r"^https?://", file):
40
30
  file = await self.request_bytes_file(file)
41
-
42
31
  elif isinstance(file, str) and os.path.isfile(file):
43
32
  async with aiofiles.open(file, "rb") as f:
44
33
  file = await f.read()
45
34
 
46
35
  form = FormData()
47
36
  form.add_field("file", file, filename=name, content_type="application/octet-stream")
37
+ async with ClientSession() as session:
38
+ async with session.post(upload_url, data=form) as response:
39
+ response.raise_for_status()
40
+ data = await response.json()
41
+ return data["data"]["file_id"]
48
42
 
49
- async with session.post(upload_url, data=form) as response:
50
- response.raise_for_status()
51
- data = await response.json()
52
- return data["data"]["file_id"]
53
-
54
43
  async def request_download_file(self, url: str, name: str) -> dict[str, Union[str, bool]]:
55
44
  file = await self.request_bytes_file(url)
56
45
  async with aiofiles.open(name, "wb") as f:
@@ -53,7 +53,9 @@ class Dict:
53
53
  return cls(**init_data)
54
54
 
55
55
  def to_json(self):
56
- return json.dumps(self.to_dict(), ensure_ascii=False, indent=4)
56
+ data = self.to_dict().copy()
57
+ data.pop("client", None)
58
+ return json.dumps(data, ensure_ascii=False, indent=4)
57
59
 
58
60
 
59
61
  @dataclass
File without changes
File without changes
File without changes