vipzenoxnet 0.1.0__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.
- vipzenoxnet/__init__.py +1 -0
- vipzenoxnet/bot.py +56 -0
- vipzenoxnet/context.py +10 -0
- vipzenoxnet-0.1.0.dist-info/METADATA +13 -0
- vipzenoxnet-0.1.0.dist-info/RECORD +8 -0
- vipzenoxnet-0.1.0.dist-info/WHEEL +5 -0
- vipzenoxnet-0.1.0.dist-info/licenses/LICENSE +3 -0
- vipzenoxnet-0.1.0.dist-info/top_level.txt +1 -0
vipzenoxnet/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__ = ["bot", "context"]
|
vipzenoxnet/bot.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import requests, threading, time
|
|
2
|
+
from .context import Message
|
|
3
|
+
|
|
4
|
+
class Bot:
|
|
5
|
+
def __init__(self, token, polling_interval=2.0):
|
|
6
|
+
self.token = token
|
|
7
|
+
self.base_url = "https://botapi.rubika.ir/v3"
|
|
8
|
+
self.polling_interval = polling_interval
|
|
9
|
+
self._on_start = None
|
|
10
|
+
self._running = False
|
|
11
|
+
|
|
12
|
+
def on_start(self, func):
|
|
13
|
+
self._on_start = func
|
|
14
|
+
return func
|
|
15
|
+
|
|
16
|
+
def _call(self, method, data=None):
|
|
17
|
+
url = f"{self.base_url}/{self.token}/{method}"
|
|
18
|
+
r = requests.post(url, json=data or {}, timeout=15)
|
|
19
|
+
r.raise_for_status()
|
|
20
|
+
return r.json()
|
|
21
|
+
|
|
22
|
+
def send_message(self, chat_id, text):
|
|
23
|
+
return self._call("sendMessage", {"chat_id": chat_id, "text": text})
|
|
24
|
+
|
|
25
|
+
def get_updates(self, offset=None):
|
|
26
|
+
data = {"limit": 10}
|
|
27
|
+
if offset:
|
|
28
|
+
data["offset"] = offset
|
|
29
|
+
return self._call("getUpdates", data)
|
|
30
|
+
|
|
31
|
+
def _dispatch(self, update):
|
|
32
|
+
msg = update.get("message")
|
|
33
|
+
if not msg:
|
|
34
|
+
return
|
|
35
|
+
text = msg.get("text", "")
|
|
36
|
+
chat_id = msg["chat"]["chat_id"]
|
|
37
|
+
message_id = msg["message_id"]
|
|
38
|
+
sender_id = msg["author_object_guid"]
|
|
39
|
+
message = Message(self, chat_id, message_id, sender_id, text)
|
|
40
|
+
|
|
41
|
+
if text.startswith("/start") and self._on_start:
|
|
42
|
+
self._on_start(self, message)
|
|
43
|
+
|
|
44
|
+
def run_polling(self):
|
|
45
|
+
offset = None
|
|
46
|
+
self._running = True
|
|
47
|
+
print("✅ Bot started (polling)...")
|
|
48
|
+
while self._running:
|
|
49
|
+
try:
|
|
50
|
+
updates = self.get_updates(offset)
|
|
51
|
+
for upd in updates.get("data", []):
|
|
52
|
+
offset = upd.get("update_id")
|
|
53
|
+
self._dispatch(upd)
|
|
54
|
+
except Exception as e:
|
|
55
|
+
print("polling error:", e)
|
|
56
|
+
time.sleep(self.polling_interval)
|
vipzenoxnet/context.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class Message:
|
|
2
|
+
def __init__(self, bot, chat_id, message_id, sender_id, text):
|
|
3
|
+
self.bot = bot
|
|
4
|
+
self.chat_id = chat_id
|
|
5
|
+
self.message_id = message_id
|
|
6
|
+
self.sender_id = sender_id
|
|
7
|
+
self.text = text
|
|
8
|
+
|
|
9
|
+
def reply(self, text):
|
|
10
|
+
return self.bot.send_message(self.chat_id, text)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vipzenoxnet
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: VIP Zenox Net - simple Rubika bot framework
|
|
5
|
+
Author: Generated by ChatGPT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: requests>=2.25.0
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
Dynamic: requires-dist
|
|
12
|
+
Dynamic: requires-python
|
|
13
|
+
Dynamic: summary
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
vipzenoxnet/__init__.py,sha256=p8nbkyw8MLvRRADfUifGnqOhUQ87PEtR1RAMgVjl8xY,29
|
|
2
|
+
vipzenoxnet/bot.py,sha256=tCjk9rtUygZ5ZP5FgcpP9bUMSXHkXKIFDKE-wZBk5fE,1827
|
|
3
|
+
vipzenoxnet/context.py,sha256=QglRqsp1f3oScLciJHjiIZaKap5XF2wtxMDbCpO7Ow8,318
|
|
4
|
+
vipzenoxnet-0.1.0.dist-info/licenses/LICENSE,sha256=xhtRcYl-h0QPjZB46NX1eCp12GGDeLqxmEBiRs2G2Ws,27
|
|
5
|
+
vipzenoxnet-0.1.0.dist-info/METADATA,sha256=qpG-PeWSZNSZLZHoes3xjUwfYoHP1bY8z1vY_8DcYCs,330
|
|
6
|
+
vipzenoxnet-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
vipzenoxnet-0.1.0.dist-info/top_level.txt,sha256=Hy9comBeA8mHZrT6NWmp4aYK7nr2g3I1PUQKi2mzIKg,12
|
|
8
|
+
vipzenoxnet-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vipzenoxnet
|