okakgram 3.0.0__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.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: okakgram
3
+ Version: 3.0.0
4
+ Summary: Official Python SDK for OKAK Messenger
5
+ Home-page: https://messeanger-okak.vercel.app
6
+ Author: Никита (Окак Фаундер)
7
+ Author-email: твой@email.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: okakgram
3
+ Version: 3.0.0
4
+ Summary: Official Python SDK for OKAK Messenger
5
+ Home-page: https://messeanger-okak.vercel.app
6
+ Author: Никита (Окак Фаундер)
7
+ Author-email: твой@email.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
@@ -0,0 +1,6 @@
1
+ okakgram.py
2
+ setup.py
3
+ okakgram.egg-info/PKG-INFO
4
+ okakgram.egg-info/SOURCES.txt
5
+ okakgram.egg-info/dependency_links.txt
6
+ okakgram.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ okakgram
@@ -0,0 +1,140 @@
1
+ """
2
+ OKAKgram v3.0 - Python SDK for OKAK Messenger
3
+ Работает через публичный API (нужен только токен от BotFather)
4
+
5
+ Использование:
6
+ from okakgram import OkakBot
7
+
8
+ bot = OkakBot('okak_live_ВАШ_ТОКЕН')
9
+
10
+ @bot.command('/start')
11
+ def start(message):
12
+ bot.reply(message, 'Привет!')
13
+
14
+ bot.run()
15
+ """
16
+
17
+ import json
18
+ import time
19
+ import logging
20
+ import urllib.request
21
+ import urllib.error
22
+ from typing import List, Optional
23
+ from dataclasses import dataclass
24
+
25
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s [OKAKgram] %(message)s')
26
+ logger = logging.getLogger('okakgram')
27
+
28
+ API_URL = 'https://okak-bridge.vercel.app/api'
29
+
30
+
31
+ @dataclass
32
+ class Chat:
33
+ id: str
34
+ type: str = 'private'
35
+ title: Optional[str] = None
36
+
37
+
38
+ @dataclass
39
+ class User:
40
+ id: str
41
+
42
+
43
+ @dataclass
44
+ class Message:
45
+ message_id: str
46
+ from_user: User
47
+ chat: Chat
48
+ text: Optional[str] = None
49
+
50
+
51
+ class OkakBot:
52
+ def __init__(self, token: str, debug: bool = False):
53
+ self.token = token
54
+ self._handlers = []
55
+ self._processed = set()
56
+ self._running = False
57
+ if debug:
58
+ logger.setLevel(logging.DEBUG)
59
+ logger.info('Bot initialized')
60
+
61
+ def command(self, cmd: str):
62
+ def decorator(func):
63
+ self._handlers.append({'function': func, 'commands': [cmd]})
64
+ return func
65
+ return decorator
66
+
67
+ def message_handler(self, commands: Optional[List[str]] = None):
68
+ def decorator(func):
69
+ self._handlers.append({'function': func, 'commands': commands})
70
+ return func
71
+ return decorator
72
+
73
+ def _api(self, endpoint: str, data: dict = None) -> dict:
74
+ url = f'{API_URL}/{endpoint}'
75
+ body = json.dumps(data or {}).encode('utf-8')
76
+ try:
77
+ req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json'}, method='POST')
78
+ with urllib.request.urlopen(req, timeout=30) as resp:
79
+ return json.loads(resp.read().decode('utf-8'))
80
+ except Exception as e:
81
+ logger.error(f'API error: {e}')
82
+ return {'success': False}
83
+
84
+ def send_message(self, chat_id: str, text: str) -> bool:
85
+ result = self._api('sendMessage', {'token': self.token, 'chatId': chat_id, 'text': text[:4096]})
86
+ if result.get('success'):
87
+ logger.info(f'Sent: {text[:50]}')
88
+ return result.get('success', False)
89
+
90
+ def reply(self, message: Message, text: str) -> bool:
91
+ return self.send_message(message.chat.id, text)
92
+
93
+ def run(self, interval: float = 2.0):
94
+ self._running = True
95
+ logger.info(f'Registered {len(self._handlers)} handler(s)')
96
+ for h in self._handlers:
97
+ logger.info(f' - {h["function"].__name__}: {h.get("commands", "ALL")}')
98
+ logger.info(f'Bot is running! Polling every {interval}s')
99
+ logger.info('Press Ctrl+C to stop\n')
100
+
101
+ while self._running:
102
+ try:
103
+ result = self._api('getUpdates', {'token': self.token})
104
+ if result.get('success'):
105
+ for msg in result.get('messages', []):
106
+ msg_id = msg.get('id', '')
107
+ if msg_id in self._processed:
108
+ continue
109
+ self._processed.add(msg_id)
110
+ if len(self._processed) > 1000:
111
+ self._processed.clear()
112
+ text = msg.get('text', '')
113
+ if not text:
114
+ continue
115
+ message = Message(
116
+ message_id=msg_id,
117
+ from_user=User(id=msg.get('from', '')),
118
+ chat=Chat(id=msg.get('chatId', '')),
119
+ text=text
120
+ )
121
+ for handler in self._handlers:
122
+ commands = handler.get('commands')
123
+ func = handler['function']
124
+ if commands is None:
125
+ func(message)
126
+ else:
127
+ for cmd in commands:
128
+ if text.startswith(cmd):
129
+ func(message)
130
+ break
131
+ except Exception as e:
132
+ logger.error(f'Poll error: {e}')
133
+ time.sleep(interval)
134
+
135
+ def stop(self):
136
+ self._running = False
137
+
138
+
139
+ __all__ = ['OkakBot', 'Message', 'Chat', 'User']
140
+ __version__ = '3.0.0'
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from setuptools import setup
2
+
3
+ setup(
4
+ name='okakgram',
5
+ version='3.0.0',
6
+ py_modules=['okakgram'], # Указываем наш единственный файл
7
+ description='Official Python SDK for OKAK Messenger',
8
+ author='Никита (Окак Фаундер)',
9
+ author_email='твой@email.com',
10
+ url='https://messeanger-okak.vercel.app', # Ссылка на твой мессенджер
11
+ classifiers=[
12
+ 'Programming Language :: Python :: 3',
13
+ 'License :: OSI Approved :: MIT License',
14
+ 'Operating System :: OS Independent',
15
+ ],
16
+ python_requires='>=3.6',
17
+ )