msmbale 0.1__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.
Files changed (38) hide show
  1. msmbale-0.1/PKG-INFO +10 -0
  2. msmbale-0.1/README.md +6 -0
  3. msmbale-0.1/msmbale/__init__.py +1 -0
  4. msmbale-0.1/msmbale/bot_client.py +22 -0
  5. msmbale-0.1/msmbale/client.py +22 -0
  6. msmbale-0.1/msmbale/config.py +0 -0
  7. msmbale-0.1/msmbale/connection.py +25 -0
  8. msmbale-0.1/msmbale/crypto.py +0 -0
  9. msmbale-0.1/msmbale/dispatcher.py +25 -0
  10. msmbale-0.1/msmbale/events.py +0 -0
  11. msmbale-0.1/msmbale/filters.py +11 -0
  12. msmbale-0.1/msmbale/methods/__init__.py +0 -0
  13. msmbale-0.1/msmbale/methods/base.py +5 -0
  14. msmbale-0.1/msmbale/methods/callback_query.py +7 -0
  15. msmbale-0.1/msmbale/methods/send_message.py +7 -0
  16. msmbale-0.1/msmbale/methods/start_phone_auth.py +7 -0
  17. msmbale-0.1/msmbale/methods/validate_code.py +7 -0
  18. msmbale-0.1/msmbale/methods/validate_password.py +7 -0
  19. msmbale-0.1/msmbale/msmbale/__init__.py +0 -0
  20. msmbale-0.1/msmbale/msmbale/bot_client.py +0 -0
  21. msmbale-0.1/msmbale/msmbale/methods/__init__.py +0 -0
  22. msmbale-0.1/msmbale/msmbale/methods/base.py +0 -0
  23. msmbale-0.1/msmbale/msmbale/methods/send_message.py +0 -0
  24. msmbale-0.1/msmbale/msmbale/self_client.py +0 -0
  25. msmbale-0.1/msmbale/self_client.py +30 -0
  26. msmbale-0.1/msmbale/session.py +0 -0
  27. msmbale-0.1/msmbale/setup.py +0 -0
  28. msmbale-0.1/msmbale/test_bot.py +0 -0
  29. msmbale-0.1/msmbale/test_self.py +0 -0
  30. msmbale-0.1/msmbale/types.py +49 -0
  31. msmbale-0.1/msmbale/websocket.py +0 -0
  32. msmbale-0.1/msmbale.egg-info/PKG-INFO +10 -0
  33. msmbale-0.1/msmbale.egg-info/SOURCES.txt +36 -0
  34. msmbale-0.1/msmbale.egg-info/dependency_links.txt +1 -0
  35. msmbale-0.1/msmbale.egg-info/requires.txt +2 -0
  36. msmbale-0.1/msmbale.egg-info/top_level.txt +1 -0
  37. msmbale-0.1/setup.cfg +4 -0
  38. msmbale-0.1/setup.py +10 -0
msmbale-0.1/PKG-INFO ADDED
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: msmbale
3
+ Version: 0.1
4
+ Summary: Full Bale client based on aiobale + extra features
5
+ Author: Saleh
6
+ Requires-Dist: aiohttp
7
+ Requires-Dist: aiobale
8
+ Dynamic: author
9
+ Dynamic: requires-dist
10
+ Dynamic: summary
msmbale-0.1/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # msmbale
2
+ کتابخانه کامل برای ربات‌های پیام‌رسان بله با پشتیبانی از تمام متدهای API
3
+
4
+ ## نصب
5
+ ```bash
6
+ pip install .
@@ -0,0 +1 @@
1
+ from .client import MSMClient
@@ -0,0 +1,22 @@
1
+ import aiohttp
2
+
3
+ class BotClient:
4
+ def __init__(self, token: str):
5
+ self.token = token
6
+ self.session = None
7
+ self.base_url = f"https://tapi.bale.ai/bot{token}"
8
+
9
+ async def connect(self):
10
+ if self.session is None:
11
+ self.session = aiohttp.ClientSession()
12
+
13
+ async def call(self, method_obj):
14
+ await self.connect()
15
+ url = f"{self.base_url}/{method_obj.method}"
16
+ async with self.session.post(url, json=method_obj.data) as resp:
17
+ return await resp.json()
18
+
19
+ async def close(self):
20
+ if self.session:
21
+ await self.session.close()
22
+ self.session = None
@@ -0,0 +1,22 @@
1
+ from aiobale import Client
2
+ from .dispatcher import MSMDispatcher
3
+
4
+ class MSMClient(Client):
5
+ def __init__(self):
6
+ self.dispatcher = MSMDispatcher()
7
+ super().__init__(dispatcher=self.dispatcher)
8
+
9
+ async def click(self, message, button):
10
+ try:
11
+ await message.click(button)
12
+ except:
13
+ pass
14
+
15
+ async def delete_my_messages(self, chat_id, count):
16
+ history = await self.load_history(chat_id, limit=count)
17
+ for msg in history:
18
+ if msg.out:
19
+ try:
20
+ await msg.delete()
21
+ except:
22
+ pass
File without changes
@@ -0,0 +1,25 @@
1
+ import uuid
2
+ import time
3
+
4
+ class BaleConnection:
5
+ def __init__(self):
6
+ self.device_id = str(uuid.uuid4())
7
+ self.session_key = None
8
+ self.api_url = "https://tapi.bale.ai/api/v1"
9
+ self.headers = {
10
+ "X-Device-Id": self.device_id,
11
+ "X-Client-Version": "5.0.0",
12
+ "X-Platform": "android"
13
+ }
14
+
15
+ def build_payload(self, method: str, data: dict):
16
+ return {
17
+ "method": method,
18
+ "input": data,
19
+ "client": {
20
+ "device_id": self.device_id,
21
+ "platform": "android",
22
+ "version": "5.0.0"
23
+ },
24
+ "timestamp": int(time.time())
25
+ }
File without changes
@@ -0,0 +1,25 @@
1
+ from aiobale import Dispatcher
2
+ import re
3
+
4
+ class MSMDispatcher(Dispatcher):
5
+ async def feed_update(self, update, client):
6
+ message = getattr(update, "message", None)
7
+ if message:
8
+ await self.handle_message(message, client)
9
+
10
+ async def handle_message(self, message, client):
11
+ # پاکسازی پیام‌های خودم
12
+ match = re.match(r"پاکسازی\[(\d+)\]", message.text or "")
13
+ if match:
14
+ count = int(match.group(1))
15
+ await client.delete_my_messages(message.chat.id, count)
16
+
17
+ # کلیک خودکار روی دکمه شیشه‌ای
18
+ rm = getattr(message, "reply_markup", None)
19
+ if rm and rm.inline_keyboard:
20
+ first_row = rm.inline_keyboard[0]
21
+ btn = first_row[0]
22
+ await client.click(message, btn)
23
+
24
+ # هندلرهای معمولی aiobale
25
+ await super().handle_message(message, client)
File without changes
@@ -0,0 +1,11 @@
1
+ from .types import Message
2
+
3
+ def command(cmd: str):
4
+ def filter_func(message: Message) -> bool:
5
+ return message.text and message.text.startswith('/' + cmd)
6
+ return filter_func
7
+
8
+ def text_contains(word: str):
9
+ def filter_func(message: Message) -> bool:
10
+ return message.text and word in message.text
11
+ return filter_func
File without changes
@@ -0,0 +1,5 @@
1
+ class BaseMethod:
2
+ method: str = None
3
+
4
+ def __init__(self, **kwargs):
5
+ self.data = kwargs
@@ -0,0 +1,7 @@
1
+ from .base import BaseMethod
2
+
3
+ class AnswerCallbackQuery(BaseMethod):
4
+ method = "answerCallbackQuery"
5
+
6
+ def __init__(self, callback_query_id: str):
7
+ super().__init__(callback_query_id=callback_query_id)
@@ -0,0 +1,7 @@
1
+ from .base import BaseMethod
2
+
3
+ class SendMessage(BaseMethod):
4
+ method = "sendMessage"
5
+
6
+ def __init__(self, chat_id: int, text: str):
7
+ super().__init__(chat_id=chat_id, text=text)
@@ -0,0 +1,7 @@
1
+ from .base import BaseMethod
2
+
3
+ class StartPhoneAuth(BaseMethod):
4
+ method = "StartPhoneAuth"
5
+
6
+ def __init__(self, phone: str):
7
+ super().__init__(phone=phone)
@@ -0,0 +1,7 @@
1
+ from .base import BaseMethod
2
+
3
+ class ValidateCode(BaseMethod):
4
+ method = "ValidateCode"
5
+
6
+ def __init__(self, phone: str, code: str):
7
+ super().__init__(phone=phone, code=code)
@@ -0,0 +1,7 @@
1
+ from .base import BaseMethod
2
+
3
+ class ValidatePassword(BaseMethod):
4
+ method = "ValidatePassword"
5
+
6
+ def __init__(self, phone: str, password: str):
7
+ super().__init__(phone=phone, password=password)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,30 @@
1
+ import aiohttp
2
+ from .connection import BaleConnection
3
+
4
+ class SelfClient:
5
+ def __init__(self, phone_number: str):
6
+ self.phone = phone_number
7
+ self.session = None
8
+ self.conn = BaleConnection()
9
+
10
+ async def connect(self):
11
+ if self.session is None:
12
+ self.session = aiohttp.ClientSession()
13
+
14
+ async def call(self, method_obj):
15
+ await self.connect()
16
+
17
+ # ساخت پیام داخلی بله
18
+ payload = self.conn.build_payload(method_obj.method, method_obj.data)
19
+
20
+ async with self.session.post(
21
+ self.conn.api_url,
22
+ json=payload,
23
+ headers=self.conn.headers
24
+ ) as resp:
25
+ return await resp.json()
26
+
27
+ async def close(self):
28
+ if self.session:
29
+ await self.session.close()
30
+ self.session = None
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,49 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional, List, Any
3
+
4
+ @dataclass
5
+ class User:
6
+ id: int
7
+ first_name: str
8
+ last_name: Optional[str] = None
9
+ username: Optional[str] = None
10
+ phone_number: Optional[str] = None
11
+
12
+ @dataclass
13
+ class Message:
14
+ message_id: int
15
+ from_user: Optional[User] = None
16
+ chat_id: Optional[int] = None
17
+ text: Optional[str] = None
18
+ date: Optional[int] = None
19
+ # می‌تونی فیلدهای دیگه مثل photo, document و ... رو اضافه کنی
20
+
21
+ @classmethod
22
+ def from_dict(cls, data: dict):
23
+ user_data = data.get('from', {})
24
+ user = User(
25
+ id=user_data.get('id'),
26
+ first_name=user_data.get('first_name', ''),
27
+ last_name=user_data.get('last_name'),
28
+ username=user_data.get('username')
29
+ ) if user_data else None
30
+ return cls(
31
+ message_id=data.get('message_id'),
32
+ from_user=user,
33
+ chat_id=data.get('chat', {}).get('id'),
34
+ text=data.get('text'),
35
+ date=data.get('date')
36
+ )
37
+
38
+ @dataclass
39
+ class Dialog:
40
+ id: int
41
+ title: str
42
+ # فیلدهای دیگه
43
+
44
+ @dataclass
45
+ class Group:
46
+ id: int
47
+ title: str
48
+ members_count: int
49
+ # ...
File without changes
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: msmbale
3
+ Version: 0.1
4
+ Summary: Full Bale client based on aiobale + extra features
5
+ Author: Saleh
6
+ Requires-Dist: aiohttp
7
+ Requires-Dist: aiobale
8
+ Dynamic: author
9
+ Dynamic: requires-dist
10
+ Dynamic: summary
@@ -0,0 +1,36 @@
1
+ README.md
2
+ setup.py
3
+ msmbale/__init__.py
4
+ msmbale/bot_client.py
5
+ msmbale/client.py
6
+ msmbale/config.py
7
+ msmbale/connection.py
8
+ msmbale/crypto.py
9
+ msmbale/dispatcher.py
10
+ msmbale/events.py
11
+ msmbale/filters.py
12
+ msmbale/self_client.py
13
+ msmbale/session.py
14
+ msmbale/setup.py
15
+ msmbale/test_bot.py
16
+ msmbale/test_self.py
17
+ msmbale/types.py
18
+ msmbale/websocket.py
19
+ msmbale.egg-info/PKG-INFO
20
+ msmbale.egg-info/SOURCES.txt
21
+ msmbale.egg-info/dependency_links.txt
22
+ msmbale.egg-info/requires.txt
23
+ msmbale.egg-info/top_level.txt
24
+ msmbale/methods/__init__.py
25
+ msmbale/methods/base.py
26
+ msmbale/methods/callback_query.py
27
+ msmbale/methods/send_message.py
28
+ msmbale/methods/start_phone_auth.py
29
+ msmbale/methods/validate_code.py
30
+ msmbale/methods/validate_password.py
31
+ msmbale/msmbale/__init__.py
32
+ msmbale/msmbale/bot_client.py
33
+ msmbale/msmbale/self_client.py
34
+ msmbale/msmbale/methods/__init__.py
35
+ msmbale/msmbale/methods/base.py
36
+ msmbale/msmbale/methods/send_message.py
@@ -0,0 +1,2 @@
1
+ aiohttp
2
+ aiobale
@@ -0,0 +1 @@
1
+ msmbale
msmbale-0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
msmbale-0.1/setup.py ADDED
@@ -0,0 +1,10 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="msmbale",
5
+ version="0.1",
6
+ packages=find_packages(),
7
+ install_requires=["aiohttp", "aiobale"],
8
+ description="Full Bale client based on aiobale + extra features",
9
+ author="Saleh",
10
+ )