RubigramClient 1.3.4__py3-none-any.whl → 1.3.5__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.

Potentially problematic release.


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

rubigram/client.py CHANGED
@@ -2,33 +2,71 @@ from rubigram.types import Update, InlineMessage
2
2
  from rubigram.method import Method
3
3
  from aiohttp import web
4
4
 
5
+
5
6
  class Client(Method):
6
- def __init__(self, token: str):
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
7
12
  self.messages_handler = []
13
+ self.inlines_handler = []
14
+ self.routes = web.RouteTableDef()
15
+ self.api = f"https://botapi.rubika.ir/v3/{self.token}/"
8
16
  super().__init__(token)
9
-
17
+
18
+
10
19
  def on_message(self, *filters):
11
20
  def decorator(func):
12
- async def wrapped(client, update):
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):
13
31
  if all(f(update) for f in filters):
14
32
  await func(client, update)
15
- self.messages_handler.append(wrapped)
33
+ self.inlines_handler.append(wrapper)
16
34
  return func
17
35
  return decorator
18
36
 
19
37
  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)
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"])
44
+ for handler in self.messages_handler:
45
+ await handler(self, event)
23
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
+
24
51
  def run(self):
25
- routes = web.RouteTableDef()
26
- @routes.post("/receiveUpdate")
27
- @routes.post("/receiveInlineMessage")
28
- async def webhook(request):
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):
29
60
  data = await request.json()
30
61
  await self.update(data)
31
62
  return web.json_response({"status": "ok"})
63
+
32
64
  app = web.Application()
33
- app.add_routes(routes)
34
- web.run_app(app, host="0.0.0.0", port=5000)
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)
rubigram/types.py CHANGED
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.3.4
3
+ Version: 1.3.5
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,11 @@
1
+ rubigram/__init__.py,sha256=4JZ6q8ukflz_izRmJNYcndcKZFCsyJdYoYVoAPwN5V0,107
2
+ rubigram/client.py,sha256=F5yEanmYEh2WXMO_Jtwkl1vHa40K1rxHupwFNks7a7E,2635
3
+ rubigram/filters.py,sha256=VU9Nd5ALWQAXafH1mXi19hm-E5H20JgTswTS4usK3ro,1955
4
+ rubigram/method.py,sha256=nm2qfzkanpzDo3yusIXmjYgCYmLzV6nVOyaxPDDqqz4,9074
5
+ rubigram/network.py,sha256=K7vvGikXStvUBqHX2gogy3hJ1eQjLAJ7kdwLbfFuZIg,1399
6
+ rubigram/types.py,sha256=evelh8GGttOHFQjiwXOzwXYFwLXKJSHit60T0T-9VIE,17035
7
+ rubigramclient-1.3.5.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ rubigramclient-1.3.5.dist-info/METADATA,sha256=ZGaxld0O20t7CbavDp6AXPfPJYfib9haVLEuQnMWwBc,1022
9
+ rubigramclient-1.3.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ rubigramclient-1.3.5.dist-info/top_level.txt,sha256=Mhg5HfkL6rLec5sI4ClGmwoqYUANAZUz8sVa1sT_cas,9
11
+ rubigramclient-1.3.5.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- rubigram/__init__.py,sha256=4JZ6q8ukflz_izRmJNYcndcKZFCsyJdYoYVoAPwN5V0,107
2
- rubigram/client.py,sha256=wjSFIoE5s2vniZuNUPpa80TvyYC6dvxbwCfKpJDcLnI,1257
3
- rubigram/filters.py,sha256=VU9Nd5ALWQAXafH1mXi19hm-E5H20JgTswTS4usK3ro,1955
4
- rubigram/method.py,sha256=nm2qfzkanpzDo3yusIXmjYgCYmLzV6nVOyaxPDDqqz4,9074
5
- rubigram/network.py,sha256=K7vvGikXStvUBqHX2gogy3hJ1eQjLAJ7kdwLbfFuZIg,1399
6
- rubigram/types.py,sha256=TidelegJkJ-UT8b9JTmhL_qKBmm-A-nu04pyPYk-ApI,16955
7
- rubigramclient-1.3.4.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- rubigramclient-1.3.4.dist-info/METADATA,sha256=uKmdhwhbiJcdPSGpq3LEUjFUV1U-bRjwZ41kFZs37fo,984
9
- rubigramclient-1.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- rubigramclient-1.3.4.dist-info/top_level.txt,sha256=Mhg5HfkL6rLec5sI4ClGmwoqYUANAZUz8sVa1sT_cas,9
11
- rubigramclient-1.3.4.dist-info/RECORD,,