Rubka 3.3.4__py3-none-any.whl → 4.4.4__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.
rubka/api.py
CHANGED
|
@@ -73,6 +73,8 @@ class Robot:
|
|
|
73
73
|
self._callback_handler = None
|
|
74
74
|
self._message_handler = None
|
|
75
75
|
self._inline_query_handler = None
|
|
76
|
+
self._callback_handlers = None
|
|
77
|
+
self._callback_handlers = [] # ✅ این خط مهمه
|
|
76
78
|
|
|
77
79
|
|
|
78
80
|
logger.info(f"Initialized RubikaBot with token: {token[:8]}***")
|
|
@@ -108,7 +110,16 @@ class Robot:
|
|
|
108
110
|
return func
|
|
109
111
|
return decorator
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
def on_callback(self, button_id: Optional[str] = None):
|
|
114
|
+
def decorator(func: Callable[[Any, Message], None]):
|
|
115
|
+
if not hasattr(self, "_callback_handlers"):
|
|
116
|
+
self._callback_handlers = []
|
|
117
|
+
self._callback_handlers.append({
|
|
118
|
+
"func": func,
|
|
119
|
+
"button_id": button_id
|
|
120
|
+
})
|
|
121
|
+
return func
|
|
122
|
+
return decorator
|
|
112
123
|
def on_inline_query(self):
|
|
113
124
|
def decorator(func: Callable[[Any, InlineMessage], None]):
|
|
114
125
|
self._inline_query_handler = func
|
|
@@ -116,12 +127,14 @@ class Robot:
|
|
|
116
127
|
return decorator
|
|
117
128
|
|
|
118
129
|
def _process_update(self, update: Dict[str, Any]):
|
|
119
|
-
import threading
|
|
130
|
+
import threading, time
|
|
131
|
+
|
|
120
132
|
if update.get('type') == 'ReceiveQuery':
|
|
121
133
|
msg = update.get("inline_message", {})
|
|
122
134
|
if self._inline_query_handler:
|
|
123
135
|
context = InlineMessage(bot=self, raw_data=msg)
|
|
124
136
|
threading.Thread(target=self._inline_query_handler, args=(self, context), daemon=True).start()
|
|
137
|
+
return # اگر inline بود ادامه نده
|
|
125
138
|
|
|
126
139
|
if update.get('type') == 'NewMessage':
|
|
127
140
|
msg = update.get('new_message', {})
|
|
@@ -129,16 +142,27 @@ class Robot:
|
|
|
129
142
|
message_id = msg.get('message_id')
|
|
130
143
|
sender_id = msg.get('sender_id')
|
|
131
144
|
text = msg.get('text')
|
|
145
|
+
|
|
146
|
+
# فیلتر زمان قدیمی
|
|
132
147
|
try:
|
|
133
|
-
import time
|
|
134
148
|
if msg.get("time") and (time.time() - float(msg["time"])) > 20:
|
|
135
149
|
return
|
|
136
150
|
except Exception:
|
|
137
151
|
return
|
|
138
152
|
|
|
153
|
+
# ساخت context یکجا
|
|
154
|
+
context = Message(bot=self, chat_id=chat_id, message_id=message_id, sender_id=sender_id, text=text, raw_data=msg)
|
|
155
|
+
|
|
156
|
+
# 💠 اول بررسی دکمهها (callback)
|
|
157
|
+
if context.aux_data and hasattr(self, "_callback_handlers"):
|
|
158
|
+
for handler in self._callback_handlers:
|
|
159
|
+
if not handler["button_id"] or context.aux_data.button_id == handler["button_id"]:
|
|
160
|
+
threading.Thread(target=handler["func"], args=(self, context), daemon=True).start()
|
|
161
|
+
return # فقط اولین callback اجرا شود
|
|
162
|
+
|
|
163
|
+
# 💠 بعد بررسی پیامهای متنی معمولی
|
|
139
164
|
if self._message_handler:
|
|
140
165
|
handler = self._message_handler
|
|
141
|
-
context = Message(bot=self, chat_id=chat_id, message_id=message_id, sender_id=sender_id, text=text, raw_data=msg)
|
|
142
166
|
|
|
143
167
|
if handler["commands"]:
|
|
144
168
|
if not context.text or not context.text.startswith("/"):
|
|
@@ -149,22 +173,11 @@ class Robot:
|
|
|
149
173
|
return
|
|
150
174
|
context.args = parts[1:]
|
|
151
175
|
|
|
152
|
-
if handler["filters"]:
|
|
153
|
-
|
|
154
|
-
return
|
|
176
|
+
if handler["filters"] and not handler["filters"](context):
|
|
177
|
+
return
|
|
155
178
|
|
|
156
179
|
threading.Thread(target=handler["func"], args=(self, context), daemon=True).start()
|
|
157
180
|
|
|
158
|
-
elif update.get('type') == 'ReceiveQuery':
|
|
159
|
-
msg = update.get("inline_message", {})
|
|
160
|
-
chat_id = msg.get("chat_id")
|
|
161
|
-
message_id = msg.get("message_id")
|
|
162
|
-
sender_id = msg.get("sender_id")
|
|
163
|
-
text = msg.get("text")
|
|
164
|
-
|
|
165
|
-
if hasattr(self, "_callback_handler"):
|
|
166
|
-
context = Message(bot=self, chat_id=chat_id, message_id=message_id, sender_id=sender_id, text=text, raw_data=msg)
|
|
167
|
-
threading.Thread(target=self._callback_handler, args=(self, context), daemon=True).start()
|
|
168
181
|
|
|
169
182
|
|
|
170
183
|
|
|
@@ -225,7 +238,9 @@ class Robot:
|
|
|
225
238
|
def _get_client(self):
|
|
226
239
|
return Client_get(show_last_six_words(self.token))
|
|
227
240
|
|
|
228
|
-
|
|
241
|
+
from typing import Union
|
|
242
|
+
|
|
243
|
+
def check_join(self, channel_guid: str, chat_id: str = None) -> Union[bool, list[str]]:
|
|
229
244
|
client = self._get_client()
|
|
230
245
|
|
|
231
246
|
if chat_id:
|
rubka/context.py
CHANGED
|
@@ -195,7 +195,6 @@ class Message:
|
|
|
195
195
|
self.time: str = self.raw_data.get("time")
|
|
196
196
|
self.is_edited: bool = self.raw_data.get("is_edited", False)
|
|
197
197
|
self.sender_type: str = self.raw_data.get("sender_type")
|
|
198
|
-
|
|
199
198
|
self.args = []
|
|
200
199
|
self.reply_to_message_id: Optional[str] = self.raw_data.get("reply_to_message_id")
|
|
201
200
|
self.forwarded_from = ForwardedFrom(self.raw_data["forwarded_from"]) if "forwarded_from" in self.raw_data else None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Rubka
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.4.4
|
|
4
4
|
Summary: A Python library for interacting with Rubika Bot API.
|
|
5
5
|
Home-page: https://github.com/Mahdy-Ahmadi/Rubka
|
|
6
6
|
Download-URL: https://github.com/Mahdy-Ahmadi/Rubka/archive/refs/tags/v0.1.0.tar.gz
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
rubka/__init__.py,sha256=3f4H6Uj1ylrfBYlTHmTvzZSvaPJsdNhCocyX3Bbvuv0,254
|
|
2
|
-
rubka/api.py,sha256=
|
|
2
|
+
rubka/api.py,sha256=ltEMTWP0YbsOeRmIdgCxKhDMjdldl4hr5FJxa7ThP_k,16142
|
|
3
3
|
rubka/button.py,sha256=4fMSZR7vUADxSmw1R3_pZ4dw5uMLZX5sOkwPPyNTBDE,8437
|
|
4
4
|
rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
|
|
5
|
-
rubka/context.py,sha256=
|
|
5
|
+
rubka/context.py,sha256=BSb_O1PiB0QEPeY_u2F97oIVxg-3J9Re2iV1HWywz4M,12841
|
|
6
6
|
rubka/decorators.py,sha256=hGwUoE4q2ImrunJIGJ_kzGYYxQf1ueE0isadqraKEts,1157
|
|
7
7
|
rubka/exceptions.py,sha256=tujZt1XrhWaw-lmdeVadVceUptpw4XzNgE44sAAY0gs,90
|
|
8
8
|
rubka/jobs.py,sha256=GvLMLsVhcSEzRTgkvnPISPEBN71suW2xXI0hUaUZPTo,378
|
|
@@ -31,7 +31,7 @@ rubka/adaptorrubka/types/socket/message.py,sha256=0WgLMZh4eow8Zn7AiSX4C3GZjQTkIg
|
|
|
31
31
|
rubka/adaptorrubka/utils/__init__.py,sha256=OgCFkXdNFh379quNwIVOAWY2NP5cIOxU5gDRRALTk4o,54
|
|
32
32
|
rubka/adaptorrubka/utils/configs.py,sha256=nMUEOJh1NqDJsf9W9PurkN_DLYjO6kKPMm923i4Jj_A,492
|
|
33
33
|
rubka/adaptorrubka/utils/utils.py,sha256=5-LioLNYX_TIbQGDeT50j7Sg9nAWH2LJUUs-iEXpsUY,8816
|
|
34
|
-
rubka-
|
|
35
|
-
rubka-
|
|
36
|
-
rubka-
|
|
37
|
-
rubka-
|
|
34
|
+
rubka-4.4.4.dist-info/METADATA,sha256=UhBp299rDrFsmyEw42UnzBNhencqkvUqOgWSfTi5CEc,8168
|
|
35
|
+
rubka-4.4.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
36
|
+
rubka-4.4.4.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
|
|
37
|
+
rubka-4.4.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|