Rubka 1.7.4__tar.gz → 1.8.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.
- {rubka-1.7.4 → rubka-1.8.6}/PKG-INFO +1 -1
- {rubka-1.7.4 → rubka-1.8.6}/Rubka.egg-info/PKG-INFO +1 -1
- {rubka-1.7.4 → rubka-1.8.6}/rubka/api.py +67 -11
- {rubka-1.7.4 → rubka-1.8.6}/setup.py +1 -1
- {rubka-1.7.4 → rubka-1.8.6}/README.md +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/Rubka.egg-info/SOURCES.txt +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/Rubka.egg-info/dependency_links.txt +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/Rubka.egg-info/requires.txt +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/Rubka.egg-info/top_level.txt +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/__init__.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/config.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/context.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/decorators.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/exceptions.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/jobs.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/keyboards.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/keypad.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/logger.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/rubka/utils.py +0 -0
- {rubka-1.7.4 → rubka-1.8.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Rubka
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.6
|
|
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,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Rubka
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.6
|
|
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
|
|
@@ -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.
|
|
@@ -106,23 +155,30 @@ class Robot:
|
|
|
106
155
|
context = Message(bot=self, chat_id=chat_id, message_id=message_id, sender_id=sender_id, text=text, raw_data=msg)
|
|
107
156
|
self._callback_handler(self, context)
|
|
108
157
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
158
|
def run(self):
|
|
114
159
|
print("Bot started running...")
|
|
160
|
+
if self._offset_id is None:
|
|
161
|
+
try:
|
|
162
|
+
latest = self.get_updates(limit=100)
|
|
163
|
+
if latest and latest.get("data") and latest["data"].get("updates"):
|
|
164
|
+
updates = latest["data"]["updates"]
|
|
165
|
+
last_update = updates[-1]
|
|
166
|
+
self._offset_id = latest["data"].get("next_offset_id")
|
|
167
|
+
print(f"Offset initialized to: {self._offset_id}")
|
|
168
|
+
else:
|
|
169
|
+
print("No updates found.")
|
|
170
|
+
except Exception as e:
|
|
171
|
+
print(f"Failed to fetch latest message: {e}")
|
|
172
|
+
|
|
115
173
|
while True:
|
|
116
174
|
try:
|
|
117
|
-
updates = self.get_updates(offset_id=self._offset_id, limit=
|
|
118
|
-
if updates and updates.get(
|
|
119
|
-
for update in updates[
|
|
175
|
+
updates = self.get_updates(offset_id=self._offset_id, limit=1)
|
|
176
|
+
if updates and updates.get("data"):
|
|
177
|
+
for update in updates["data"].get("updates", []):
|
|
120
178
|
self._process_update(update)
|
|
121
|
-
|
|
179
|
+
self._offset_id = updates["data"].get("next_offset_id", self._offset_id)
|
|
122
180
|
except Exception as e:
|
|
123
181
|
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
182
|
|
|
127
183
|
def send_message(
|
|
128
184
|
self,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|