RubigramClient 1.5.6__py3-none-any.whl → 1.5.7__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
@@ -7,6 +7,7 @@ from datetime import datetime
7
7
  from aiohttp import web
8
8
  import asyncio
9
9
 
10
+
10
11
  class Client(Method):
11
12
  def __init__(
12
13
  self,
@@ -23,8 +24,7 @@ class Client(Method):
23
24
  self.MESSAGE_HANDLER = []
24
25
  self.INLINE_HANDLER = []
25
26
  self.state = StateManager()
26
- super().__init__(token)
27
-
27
+ super().__init__(token)
28
28
 
29
29
  def create_handler(self, type: Literal["message", "inline"], filters: Optional[Filter] = None):
30
30
  def decorator(func: Callable) -> Callable:
rubigram/filters.py CHANGED
@@ -1,30 +1,110 @@
1
1
  from rubigram.models import Update, InlineMessage
2
- from typing import Union, Callable, Awaitable
2
+ from typing import Union
3
3
  import re
4
4
 
5
5
 
6
6
 
7
-
8
-
9
7
  class Filter:
10
- def __init__(self, func: Callable[[Union[Update, InlineMessage]], Union[bool, Awaitable[bool]]]):
8
+ def __init__(self, func):
11
9
  self.func = func
10
+
11
+ async def __call__(self, update: Union[Update, InlineMessage]):
12
+ return await self.func(update)
13
+
14
+ async def __and__(self, other: "Filter"):
15
+ async def filter(update):
16
+ return await self(update) and await other(update)
17
+ return Filter(filter)
18
+
19
+ async def __or__(self, other: "Filter"):
20
+ async def filter(update):
21
+ return await self(update) or await other(update)
22
+ return Filter(filter)
12
23
 
13
- async def __call__(self, update: Union[Update, InlineMessage]) -> bool:
14
- result = self.func(update)
15
- if isinstance(result, Awaitable):
16
- return await result
17
- return result
18
24
 
19
- def __and__(self, other: "Filter"):
20
- async def combined(update):
21
- return await self(update) and await other(update)
22
- return Filter(combined)
23
25
 
24
- def __or__(self, other: "Filter"):
25
- async def combined(update):
26
- return await self(update) or await other(update)
27
- return Filter(combined)
26
+ async def TEXT(message: Update):
27
+ if isinstance(message, Update):
28
+ return True if message.new_message and message.new_message.text else False
29
+ return False
30
+
31
+ async def FILE(message: Update):
32
+ if isinstance(message, Update):
33
+ return True if message.new_message and message.new_message.file else False
34
+ return False
35
+
36
+ async def LIVE(message: Update):
37
+ if isinstance(message, Update):
38
+ return True if message.new_message and message.new_message.live_location else False
39
+ return False
40
+
41
+ async def POLL(message: Update):
42
+ if isinstance(message, Update):
43
+ return True if message.new_message and message.new_message.poll else False
44
+ return False
45
+
46
+ async def CONTACT(message: Update):
47
+ if isinstance(message, Update):
48
+ return True if message.new_message and message.new_message.contact_message else False
49
+ return False
50
+
51
+ async def STICKER(message: Update):
52
+ if isinstance(message, Update):
53
+ return True if message.new_message and message.new_message.sticker else False
54
+ return False
55
+
56
+ async def LOCATION(message: Update):
57
+ if isinstance(message, Update):
58
+ return True if message.new_message and message.new_message.location else False
59
+ return False
60
+
61
+ async def FORWARD(message: Update):
62
+ if isinstance(message, Update):
63
+ return True if message.new_message and message.new_message.forwarded_from else False
64
+ return False
65
+
66
+ async def EDITED(message: Update):
67
+ if isinstance(message, Update):
68
+ return True if message.updated_message else False
69
+ return False
70
+
71
+ async def PRIVATE(message: Union[Update, InlineMessage]):
72
+ return True if message.chat_id.startswith("b0") else False
73
+
74
+ async def GROUP(message: Union[Update, InlineMessage]):
75
+ return True if message.chat_id.startswith("g0") else False
76
+
77
+ async def CHANNEL(message: Union[Update, InlineMessage]):
78
+ return True if message.chat_id.startswith("c0") else False
79
+
80
+ async def FORWARD_BOT(message: Update):
81
+ if isinstance(message, Update) and message.new_message:
82
+ return True if message.new_message.forwarded_from and message.new_message.forwarded_from.type_from == "Bot" else False
83
+
84
+ async def FORWARD_USER(message: Update):
85
+ if isinstance(message, Update) and message.new_message:
86
+ return True if message.new_message.forwarded_from and message.new_message.forwarded_from.type_from == "User" else False
87
+
88
+ async def FORWARD_CHANNEL(message: Update):
89
+ if isinstance(message, Update) and message.new_message:
90
+ return True if message.new_message.forwarded_from and message.new_message.forwarded_from.type_from == "Channel" else False
91
+
92
+
93
+ text = Filter(TEXT)
94
+ file = Filter(FILE)
95
+ live = Filter(LIVE)
96
+ poll = Filter(POLL)
97
+ contact = Filter(CONTACT)
98
+ sticker = Filter(STICKER)
99
+ location = Filter(LOCATION)
100
+ forward = Filter(FORWARD)
101
+ edited = Filter(EDITED)
102
+ private = Filter(PRIVATE)
103
+ group = Filter(GROUP)
104
+ channel = Filter(CHANNEL)
105
+ forward_bot = Filter(FORWARD_BOT)
106
+ forward_user = Filter(FORWARD_USER)
107
+ forward_channel = Filter(FORWARD_CHANNEL)
28
108
 
29
109
 
30
110
  class state(Filter):
@@ -32,12 +112,10 @@ class state(Filter):
32
112
  self.states = states
33
113
  super().__init__(self.filter)
34
114
 
35
- async def filter(self, update: Update):
115
+ async def filter(self, update: Union[Update, InlineMessage]):
36
116
  states = self.states if isinstance(self.states, list) else [self.states]
37
- if isinstance(update, Update):
38
- user = await update.client.state.get_state(update.chat_id)
39
- return user.lower() in states if user else False
40
- return False
117
+ user = await update.client.state.get_state(update.chat_id)
118
+ return user.lower() in states if user else False
41
119
 
42
120
 
43
121
  class command(Filter):
@@ -46,7 +124,7 @@ class command(Filter):
46
124
  self.prefix = prefix
47
125
  super().__init__(self.filter)
48
126
 
49
- def filter(self, update: Update):
127
+ async def filter(self, update: Update):
50
128
  commands = self.cmd if isinstance(self.cmd, list) else [self.cmd]
51
129
  text = ""
52
130
  if isinstance(update, Update):
@@ -66,7 +144,7 @@ class regex(Filter):
66
144
  self.pattern = pattern
67
145
  super().__init__(self.filter)
68
146
 
69
- def filter(self, update: Union[Update, InlineMessage]):
147
+ async def filter(self, update: Union[Update, InlineMessage]):
70
148
  text = ""
71
149
  if isinstance(update, Update):
72
150
  if update.type == "NewMessage":
@@ -86,7 +164,7 @@ class chat(Filter):
86
164
  self.chat_id = chat_id
87
165
  super().__init__(self.filter)
88
166
 
89
- def filter(self, update: Union[Update, InlineMessage]):
167
+ async def filter(self, update: Union[Update, InlineMessage]):
90
168
  chat_ids = self.chat_id if isinstance(self.chat_id, list) else [self.chat_id]
91
169
  return update.chat_id in chat_ids
92
170
 
@@ -96,97 +174,7 @@ class button(Filter):
96
174
  self.button_id = button_id
97
175
  super().__init__(self.filter)
98
176
 
99
- def filter(self, update: InlineMessage):
177
+ async def filter(self, update: InlineMessage):
100
178
  if isinstance(update, InlineMessage):
101
179
  button_ids = self.button_id if isinstance(self.button_id, list) else [self.button_id]
102
- return update.aux_data.button_id in button_ids
103
-
104
-
105
-
106
- def TEXT(update: Update):
107
- return bool(update.new_message and getattr(update.new_message, "text", None))
108
-
109
-
110
- def FILE(update: Update):
111
- return bool(update.new_message and getattr(update.new_message, "file", None))
112
-
113
-
114
- def LIVE(update: Update):
115
- return bool(update.new_message and getattr(update.new_message, "live_location", None))
116
-
117
-
118
- def POLL(update: Update):
119
- return bool(update.new_message and getattr(update.new_message, "poll", None))
120
-
121
-
122
- def CONTACT(update: Update):
123
- return bool(update.new_message and getattr(update.new_message, "contact_message", None))
124
-
125
-
126
- def STICKER(update: Update):
127
- return bool(update.new_message and getattr(update.new_message, "sticker", None))
128
-
129
-
130
- def LOCATION(update: Update):
131
- return bool(update.new_message and getattr(update.new_message, "location", None))
132
-
133
-
134
- def FORWARD(update: Update):
135
- return bool(update.new_message and getattr(update.new_message, "forwarded_from", None))
136
-
137
-
138
- def EDITED(update: Update):
139
- if isinstance(update, Update) and update.type == "UpdatedMessage":
140
- return update.updated_message.is_edited
141
-
142
-
143
- def PRIVATE(update: Update):
144
- if isinstance(update, Update) and update.type == "NewMessage":
145
- return update.new_message.sender_type in ["User", "Bot"]
146
- return False
147
-
148
-
149
- def FORWARD_BOT(update: Update):
150
- if isinstance(update, Update) and update.type == "NewMessage" and update.new_message.forwarded_from:
151
- return update.new_message.forwarded_from.type_from == "Bot"
152
- return False
153
-
154
-
155
- def FORWARD_USER(update: Update):
156
- if isinstance(update, Update) and update.type == "NewMessage" and update.new_message.forwarded_from:
157
- return update.new_message.forwarded_from.type_from == "User"
158
- return False
159
-
160
-
161
- def FORWARD_CHANNEL(update: Update):
162
- if isinstance(update, Update) and update.type == "NewMessage" and update.new_message.forwarded_from:
163
- return update.new_message.forwarded_from.type_from == "Channel"
164
- return False
165
-
166
- def GROUP(update: Update):
167
- if isinstance(update, Update):
168
- return update.chat_id.startswith("g0")
169
- return False
170
-
171
-
172
- def CHANNEL(update: Update):
173
- if isinstance(update, Update):
174
- return update.chat_id.startswith("c0")
175
- return False
176
-
177
-
178
- text = Filter(TEXT)
179
- file = Filter(FILE)
180
- live = Filter(LIVE)
181
- poll = Filter(POLL)
182
- group = Filter(GROUP)
183
- channel = Filter(CHANNEL)
184
- edited = Filter(EDITED)
185
- contact = Filter(CONTACT)
186
- sticker = Filter(STICKER)
187
- location = Filter(LOCATION)
188
- forward = Filter(FORWARD)
189
- private = Filter(PRIVATE)
190
- forward_bot = Filter(FORWARD_BOT)
191
- forward_user = Filter(FORWARD_USER)
192
- forward_channel = Filter(FORWARD_CHANNEL)
180
+ return update.aux_data.button_id in button_ids
rubigram/method.py CHANGED
@@ -3,12 +3,10 @@ from typing import Literal, Optional
3
3
  from rubigram.models import Bot, Chat, Keypad, MessageId, Updates
4
4
 
5
5
 
6
-
7
6
  class Method(Network):
8
7
  def __init__(self, token: str):
9
8
  super().__init__(token)
10
9
 
11
-
12
10
  async def get_me(self) -> "Bot":
13
11
  response = await self.request("getMe", {})
14
12
  return Bot.from_dict(response["bot"])
rubigram/network.py CHANGED
@@ -3,7 +3,6 @@ from typing import Any, Optional
3
3
  import aiofiles, re, os
4
4
 
5
5
 
6
-
7
6
  class Network:
8
7
  def __init__(self, token: str) -> None:
9
8
  self.token: str = token
rubigram/state.py CHANGED
@@ -62,7 +62,6 @@ class ManageDB:
62
62
  data = await cursor.fetchall()
63
63
  return {k: v for k, v in data} if data else {}
64
64
 
65
-
66
65
 
67
66
  async def remove_data(self, user_id: str, key: str = None):
68
67
  await self.connect()
@@ -71,8 +70,7 @@ class ManageDB:
71
70
  else:
72
71
  await self.connection.execute("DELETE FROM user_data WHERE user_id = ?", (user_id,))
73
72
  await self.connection.commit()
74
-
75
-
73
+
76
74
 
77
75
  class StateManager:
78
76
  def __init__(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.5.6
3
+ Version: 1.5.7
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
@@ -27,7 +27,7 @@ pip install RubigramClient
27
27
  from rubigram import Client, filters
28
28
  from rubigram.models import Update
29
29
 
30
- bot = Client("your_bot_token", "you_endpoint_url")
30
+ bot = Client("your_bot_token")
31
31
 
32
32
  @bot.on_message(filters.command("start") & filters.private)
33
33
  async def start_handler(client, message: Update):
@@ -0,0 +1,12 @@
1
+ rubigram/__init__.py,sha256=IWNCN7oDaIBzaP54cGiA-4Sa31ehGBlqj0SuqhNQVgU,162
2
+ rubigram/client.py,sha256=ET5L9Lzj0qbUO4IYZ647q_sXrLeFpLqH-ySU2zUISN0,4466
3
+ rubigram/filters.py,sha256=T1As4tVr4EsZAun4wJBf3tgpQ-1lbuF8QwRsLryFKOo,6430
4
+ rubigram/method.py,sha256=VfhxOoYQmNZjvAodXWqnSIin1vpc6478bj5_3IAxZP0,10609
5
+ rubigram/models.py,sha256=42WK68VPKqgKCy14jrRyoP_XRsZ-04S5rUbdpO_UfaQ,13831
6
+ rubigram/network.py,sha256=6_kLFg9Uw_MHwxoDff53HYtPD-PSTqqWC3qtgbZbmfY,2362
7
+ rubigram/state.py,sha256=jpr0ovuBk9Cnvj5JsPbE2tgv0KrEkrrv-_THHTxlYYw,4065
8
+ rubigramclient-1.5.7.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ rubigramclient-1.5.7.dist-info/METADATA,sha256=CfJ5mlhnpH32vh37EKhldGekqQVoIPGVhv2p7VR57e8,2280
10
+ rubigramclient-1.5.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ rubigramclient-1.5.7.dist-info/top_level.txt,sha256=Mhg5HfkL6rLec5sI4ClGmwoqYUANAZUz8sVa1sT_cas,9
12
+ rubigramclient-1.5.7.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- rubigram/__init__.py,sha256=IWNCN7oDaIBzaP54cGiA-4Sa31ehGBlqj0SuqhNQVgU,162
2
- rubigram/client.py,sha256=AGb7PaXBdFIoUTB3mTWHgdCQAO0anAjgoAuY2tPph0U,4469
3
- rubigram/filters.py,sha256=LWc_qCLExsQqqucFCeNKi_3okfyIx6yAVQHMAzAskc8,6224
4
- rubigram/method.py,sha256=PUP9DTX6XpWVbersiLv12GdlwOFaXzrgx582nJd4i_I,10613
5
- rubigram/models.py,sha256=42WK68VPKqgKCy14jrRyoP_XRsZ-04S5rUbdpO_UfaQ,13831
6
- rubigram/network.py,sha256=ErrGwtKpMHN1Dq4IvPHSrMOcDN-TFjUk1CfU-2EuPAY,2364
7
- rubigram/state.py,sha256=oRk5xXuO4k-cK0qRI2Rz2mdoivJkANlo20zQAkdqFSY,4081
8
- rubigramclient-1.5.6.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- rubigramclient-1.5.6.dist-info/METADATA,sha256=eoRk-VQNt67olSWe9IsX36MnlKHSQDMuCjay_8NeYws,2300
10
- rubigramclient-1.5.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- rubigramclient-1.5.6.dist-info/top_level.txt,sha256=Mhg5HfkL6rLec5sI4ClGmwoqYUANAZUz8sVa1sT_cas,9
12
- rubigramclient-1.5.6.dist-info/RECORD,,