RubigramClient 1.3.4__tar.gz → 1.3.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.3.4
3
+ Version: 1.3.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
@@ -9,7 +9,8 @@ Classifier: Operating System :: OS Independent
9
9
  Requires-Python: >=3.7
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
- Requires-Dist: aiohttp>=3.8.0
12
+ Requires-Dist: aiohttp
13
+ Requires-Dist: aiofiles
13
14
  Dynamic: license-file
14
15
 
15
16
  # Rubigram
@@ -24,7 +25,7 @@ pip install RubigramClient
24
25
  from rubigram import Client, filters
25
26
  from rubigram.types import Update
26
27
 
27
- bot = Client("your_bot_token")
28
+ bot = Client("your_bot_token", "you_endpoint_url")
28
29
 
29
30
  @bot.on_message(filters.command("start"))
30
31
  async def start_handler(client, message: Update):
@@ -10,7 +10,7 @@ pip install RubigramClient
10
10
  from rubigram import Client, filters
11
11
  from rubigram.types import Update
12
12
 
13
- bot = Client("your_bot_token")
13
+ bot = Client("your_bot_token", "you_endpoint_url")
14
14
 
15
15
  @bot.on_message(filters.command("start"))
16
16
  async def start_handler(client, message: Update):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.3.4
3
+ Version: 1.3.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
@@ -9,7 +9,8 @@ Classifier: Operating System :: OS Independent
9
9
  Requires-Python: >=3.7
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
- Requires-Dist: aiohttp>=3.8.0
12
+ Requires-Dist: aiohttp
13
+ Requires-Dist: aiofiles
13
14
  Dynamic: license-file
14
15
 
15
16
  # Rubigram
@@ -24,7 +25,7 @@ pip install RubigramClient
24
25
  from rubigram import Client, filters
25
26
  from rubigram.types import Update
26
27
 
27
- bot = Client("your_bot_token")
28
+ bot = Client("your_bot_token", "you_endpoint_url")
28
29
 
29
30
  @bot.on_message(filters.command("start"))
30
31
  async def start_handler(client, message: Update):
@@ -0,0 +1,2 @@
1
+ aiohttp
2
+ aiofiles
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "RubigramClient"
3
- version = "1.3.4"
3
+ version = "1.3.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"
@@ -14,5 +14,6 @@ classifiers = [
14
14
  "Operating System :: OS Independent",
15
15
  ]
16
16
  dependencies = [
17
- "aiohttp>=3.8.0"
17
+ "aiohttp",
18
+ "aiofiles"
18
19
  ]
@@ -0,0 +1,72 @@
1
+ from rubigram.types import Update, InlineMessage
2
+ from rubigram.method import Method
3
+ from aiohttp import web
4
+
5
+
6
+ class Client(Method):
7
+ def __init__(self, token: str, endpoint: str = None, host: str = "0.0.0.0", port: int = 5000):
8
+ self.token = token
9
+ self.port = port
10
+ self.host = host
11
+ self.endpoint = endpoint
12
+ self.messages_handler = []
13
+ self.inlines_handler = []
14
+ self.routes = web.RouteTableDef()
15
+ self.api = f"https://botapi.rubika.ir/v3/{self.token}/"
16
+ super().__init__(token)
17
+
18
+
19
+ def on_message(self, *filters):
20
+ def decorator(func):
21
+ async def wrapper(client, update):
22
+ if all(f(update) for f in filters):
23
+ await func(client, update)
24
+ self.messages_handler.append(wrapper)
25
+ return func
26
+ return decorator
27
+
28
+ def on_inline_message(self, *filters):
29
+ def decorator(func):
30
+ async def wrapper(client, update):
31
+ if all(f(update) for f in filters):
32
+ await func(client, update)
33
+ self.inlines_handler.append(wrapper)
34
+ return func
35
+ return decorator
36
+
37
+ async def update(self, data: dict):
38
+ if "inline_message" in data:
39
+ event = InlineMessage.read(data["inline_message"])
40
+ for handler in self.inlines_handler:
41
+ await handler(self, event)
42
+ else:
43
+ event = Update.read(data["update"], self)
44
+ for handler in self.messages_handler:
45
+ await handler(self, event)
46
+
47
+ async def set_endpoints(self):
48
+ await self.update_bot_endpoint(self.endpoint + "/ReceiveUpdate", "ReceiveUpdate")
49
+ await self.update_bot_endpoint(self.endpoint + "/ReceiveInlineMessage", "ReceiveInlineMessage")
50
+
51
+ def run(self):
52
+ @self.routes.post("/ReceiveUpdate")
53
+ async def receive_update(request):
54
+ data = await request.json()
55
+ await self.update(data)
56
+ return web.json_response({"status": "OK"})
57
+
58
+ @self.routes.post("/receiveInlineMessage")
59
+ async def receive_inline_message(request):
60
+ data = await request.json()
61
+ await self.update(data)
62
+ return web.json_response({"status": "ok"})
63
+
64
+ app = web.Application()
65
+ app.add_routes(self.routes)
66
+
67
+ async def on_startup(app):
68
+ if self.endpoint:
69
+ await self.set_endpoints()
70
+
71
+ app.on_startup.append(on_startup)
72
+ web.run_app(app, host = self.host, port = self.port)
@@ -3,7 +3,6 @@ from typing import Any, Dict, List, Literal, Optional
3
3
  import rubigram
4
4
 
5
5
 
6
-
7
6
  @dataclass
8
7
  class Location:
9
8
  longitude: Optional[str] = None
@@ -62,8 +61,8 @@ class ButtonLocation:
62
61
 
63
62
  def _dict(self) -> Dict:
64
63
  return {
65
- "default_pointer_location": self.default_pointer_location._dict(),
66
- "default_map_location": self.default_map_location._dict(),
64
+ "default_pointer_location": self.default_pointer_location._dict() if self.default_pointer_location else None,
65
+ "default_map_location": self.default_map_location._dict() if self.default_map_location else None,
67
66
  "type": self.type,
68
67
  "title": self.title,
69
68
  "location_image_url": self.location_image_url
@@ -1 +0,0 @@
1
- aiohttp>=3.8.0
@@ -1,34 +0,0 @@
1
- from rubigram.types import Update, InlineMessage
2
- from rubigram.method import Method
3
- from aiohttp import web
4
-
5
- class Client(Method):
6
- def __init__(self, token: str):
7
- self.messages_handler = []
8
- super().__init__(token)
9
-
10
- def on_message(self, *filters):
11
- def decorator(func):
12
- async def wrapped(client, update):
13
- if all(f(update) for f in filters):
14
- await func(client, update)
15
- self.messages_handler.append(wrapped)
16
- return func
17
- return decorator
18
-
19
- async def update(self, data: dict):
20
- event = Update.read(data["update"]) if data.get("update") else InlineMessage.read(data["inline_message"])
21
- for handler in self.messages_handler:
22
- await handler(self, event)
23
-
24
- def run(self):
25
- routes = web.RouteTableDef()
26
- @routes.post("/receiveUpdate")
27
- @routes.post("/receiveInlineMessage")
28
- async def webhook(request):
29
- data = await request.json()
30
- await self.update(data)
31
- return web.json_response({"status": "ok"})
32
- app = web.Application()
33
- app.add_routes(routes)
34
- web.run_app(app, host="0.0.0.0", port=5000)
File without changes
File without changes