Rubka 1.7.4__py3-none-any.whl → 1.8.8__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
|
@@ -5,7 +5,56 @@ from .logger import logger
|
|
|
5
5
|
from typing import Callable
|
|
6
6
|
from .context import Message,InlineMessage
|
|
7
7
|
API_URL = "https://botapi.rubika.ir/v3"
|
|
8
|
-
|
|
8
|
+
import sys
|
|
9
|
+
import subprocess
|
|
10
|
+
import requests
|
|
11
|
+
def install_package(package_name):
|
|
12
|
+
try:
|
|
13
|
+
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
14
|
+
return True
|
|
15
|
+
except Exception:return False
|
|
16
|
+
|
|
17
|
+
def get_importlib_metadata():
|
|
18
|
+
try:
|
|
19
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
20
|
+
return version, PackageNotFoundError
|
|
21
|
+
except ImportError:
|
|
22
|
+
if install_package("importlib-metadata"):
|
|
23
|
+
try:
|
|
24
|
+
from importlib_metadata import version, PackageNotFoundError
|
|
25
|
+
return version, PackageNotFoundError
|
|
26
|
+
except ImportError:
|
|
27
|
+
return None, None
|
|
28
|
+
return None, None
|
|
29
|
+
|
|
30
|
+
version, PackageNotFoundError = get_importlib_metadata()
|
|
31
|
+
def get_installed_version(package_name: str) -> str:
|
|
32
|
+
if version is None:return "unknown"
|
|
33
|
+
try:
|
|
34
|
+
return version(package_name)
|
|
35
|
+
except PackageNotFoundError:
|
|
36
|
+
return None
|
|
37
|
+
def get_latest_version(package_name: str) -> str:
|
|
38
|
+
url = f"https://pypi.org/pypi/{package_name}/json"
|
|
39
|
+
try:
|
|
40
|
+
resp = requests.get(url, timeout=5)
|
|
41
|
+
resp.raise_for_status()
|
|
42
|
+
data = resp.json()
|
|
43
|
+
return data["info"]["version"]
|
|
44
|
+
except Exception:return None
|
|
45
|
+
def check_rubka_version():
|
|
46
|
+
package_name = "rubka"
|
|
47
|
+
installed_version = get_installed_version(package_name)
|
|
48
|
+
if installed_version is None:return
|
|
49
|
+
latest_version = get_latest_version(package_name)
|
|
50
|
+
if latest_version is None:return
|
|
51
|
+
if installed_version != latest_version:
|
|
52
|
+
print(f"\n\n⚠️ WARNING: Your installed version of '{package_name}' is outdated!")
|
|
53
|
+
print(f"Installed version: {installed_version}")
|
|
54
|
+
print(f"Latest version: {latest_version}")
|
|
55
|
+
print(f"Please update it using:\n\npip install --upgrade {package_name}\n")
|
|
56
|
+
|
|
57
|
+
check_rubka_version()
|
|
9
58
|
class Robot:
|
|
10
59
|
"""
|
|
11
60
|
Main class to interact with Rubika Bot API.
|
|
@@ -76,11 +125,13 @@ class Robot:
|
|
|
76
125
|
message_id = msg.get('message_id')
|
|
77
126
|
sender_id = msg.get('sender_id')
|
|
78
127
|
text = msg.get('text')
|
|
79
|
-
|
|
128
|
+
try:
|
|
129
|
+
import time
|
|
130
|
+
if msg.get("time") and (time.time() - float(msg["time"])) > 3:return
|
|
131
|
+
except Exception as e:return
|
|
80
132
|
if self._message_handler:
|
|
81
133
|
handler = self._message_handler
|
|
82
134
|
context = Message(bot=self, chat_id=chat_id, message_id=message_id, sender_id=sender_id, text=text, raw_data=msg)
|
|
83
|
-
|
|
84
135
|
if handler["commands"]:
|
|
85
136
|
if not context.text or not context.text.startswith("/"):
|
|
86
137
|
return
|
|
@@ -95,6 +146,7 @@ class Robot:
|
|
|
95
146
|
return
|
|
96
147
|
|
|
97
148
|
handler["func"](self, context)
|
|
149
|
+
|
|
98
150
|
elif update.get('type') == 'ReceiveQuery':
|
|
99
151
|
msg = update.get("inline_message", {})
|
|
100
152
|
chat_id = msg.get("chat_id")
|
|
@@ -107,22 +159,30 @@ class Robot:
|
|
|
107
159
|
self._callback_handler(self, context)
|
|
108
160
|
|
|
109
161
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
162
|
def run(self):
|
|
114
163
|
print("Bot started running...")
|
|
164
|
+
if self._offset_id is None:
|
|
165
|
+
try:
|
|
166
|
+
latest = self.get_updates(limit=100)
|
|
167
|
+
if latest and latest.get("data") and latest["data"].get("updates"):
|
|
168
|
+
updates = latest["data"]["updates"]
|
|
169
|
+
last_update = updates[-1]
|
|
170
|
+
self._offset_id = latest["data"].get("next_offset_id")
|
|
171
|
+
print(f"Offset initialized to: {self._offset_id}")
|
|
172
|
+
else:
|
|
173
|
+
print("No updates found.")
|
|
174
|
+
except Exception as e:
|
|
175
|
+
print(f"Failed to fetch latest message: {e}")
|
|
176
|
+
|
|
115
177
|
while True:
|
|
116
178
|
try:
|
|
117
|
-
updates = self.get_updates(offset_id=self._offset_id, limit=
|
|
118
|
-
if updates and updates.get(
|
|
119
|
-
for update in updates[
|
|
179
|
+
updates = self.get_updates(offset_id=self._offset_id, limit=1)
|
|
180
|
+
if updates and updates.get("data"):
|
|
181
|
+
for update in updates["data"].get("updates", []):
|
|
120
182
|
self._process_update(update)
|
|
121
|
-
|
|
183
|
+
self._offset_id = updates["data"].get("next_offset_id", self._offset_id)
|
|
122
184
|
except Exception as e:
|
|
123
185
|
print(f"Error in run loop: {e}")
|
|
124
|
-
#logger.error(f"API request failed: {e}")
|
|
125
|
-
raise APIRequestError(f"API request failed: {e}") from e
|
|
126
186
|
|
|
127
187
|
def send_message(
|
|
128
188
|
self,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Rubka
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.8
|
|
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,5 +1,5 @@
|
|
|
1
1
|
rubka/__init__.py,sha256=3f4H6Uj1ylrfBYlTHmTvzZSvaPJsdNhCocyX3Bbvuv0,254
|
|
2
|
-
rubka/api.py,sha256=
|
|
2
|
+
rubka/api.py,sha256=hdY9hQI2-5GAhaIp_IeMYep1LnZTEqGxwmdM55Z9D7w,13168
|
|
3
3
|
rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
|
|
4
4
|
rubka/context.py,sha256=5OMFjcnMWvkn3ZigRgJrjMiFt_tYgMwzHsTS6qXMGj8,12843
|
|
5
5
|
rubka/decorators.py,sha256=hGwUoE4q2ImrunJIGJ_kzGYYxQf1ueE0isadqraKEts,1157
|
|
@@ -9,7 +9,7 @@ rubka/keyboards.py,sha256=7nr-dT2bQJVQnQ6RMWPTSjML6EEk6dsBx-4d8pab8xk,488
|
|
|
9
9
|
rubka/keypad.py,sha256=FHe0xVYhOXMdHZhbGKHsRxtsRB27qZv0DvNfb8NkNwI,1545
|
|
10
10
|
rubka/logger.py,sha256=J2I6NiK1z32lrAzC4H1Et6WPMBXxXGCVUsW4jgcAofs,289
|
|
11
11
|
rubka/utils.py,sha256=XUQUZxQt9J2f0X5hmAH_MH1kibTAfdT1T4AaBkBhBBs,148
|
|
12
|
-
rubka-1.
|
|
13
|
-
rubka-1.
|
|
14
|
-
rubka-1.
|
|
15
|
-
rubka-1.
|
|
12
|
+
rubka-1.8.8.dist-info/METADATA,sha256=KzL_ck3j28Lud7Zw3hVHkMmbqwRf7qVcv1x_NihMj_U,8168
|
|
13
|
+
rubka-1.8.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
rubka-1.8.8.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
|
|
15
|
+
rubka-1.8.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|