gitbin-bot 1.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.
- gitbin_bot-1.0.0/LICENSE +9 -0
- gitbin_bot-1.0.0/PKG-INFO +58 -0
- gitbin_bot-1.0.0/README.md +38 -0
- gitbin_bot-1.0.0/gitbin/__init__.py +20 -0
- gitbin_bot-1.0.0/gitbin/client.py +72 -0
- gitbin_bot-1.0.0/gitbin/errors.py +61 -0
- gitbin_bot-1.0.0/gitbin/methods.py +185 -0
- gitbin_bot-1.0.0/gitbin/types.py +126 -0
- gitbin_bot-1.0.0/gitbin_bot.egg-info/PKG-INFO +58 -0
- gitbin_bot-1.0.0/gitbin_bot.egg-info/SOURCES.txt +14 -0
- gitbin_bot-1.0.0/gitbin_bot.egg-info/dependency_links.txt +1 -0
- gitbin_bot-1.0.0/gitbin_bot.egg-info/requires.txt +1 -0
- gitbin_bot-1.0.0/gitbin_bot.egg-info/top_level.txt +1 -0
- gitbin_bot-1.0.0/pyproject.toml +28 -0
- gitbin_bot-1.0.0/setup.cfg +4 -0
- gitbin_bot-1.0.0/tests/test_basic.py +20 -0
gitbin_bot-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 MMD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitbin-bot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: کتابخانه پایتون برای GitBin Bot API
|
|
5
|
+
Author-email: MMD <ammmd219@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MMD-C0DE/gitbin-bot
|
|
8
|
+
Project-URL: Documentation, https://github.com/MMD-C0DE/gitbin-bot#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/MMD-C0DE/gitbin-bot/issues
|
|
10
|
+
Keywords: gitbin,bot,api,telegram,messenger
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Communications :: Chat
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: requests>=2.28
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# gitbin-bot
|
|
22
|
+
|
|
23
|
+
کتابخانه پایتون برای GitBin Bot API.
|
|
24
|
+
|
|
25
|
+
## نصب
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install gitbin-bot
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## استفاده
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from gitbin import Bot
|
|
35
|
+
|
|
36
|
+
bot = Bot(token="YOUR_TOKEN")
|
|
37
|
+
|
|
38
|
+
# اطلاعات ربات
|
|
39
|
+
me = bot.get_me()
|
|
40
|
+
print(me["first_name"])
|
|
41
|
+
|
|
42
|
+
# ارسال پیام
|
|
43
|
+
bot.send_message(chat_id=123, text="سلام 👋")
|
|
44
|
+
|
|
45
|
+
# موجودی استارز
|
|
46
|
+
bal = bot.get_my_star_balance()
|
|
47
|
+
print(f"{bal['amount']:,} استارز")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## متدهای موجود
|
|
51
|
+
|
|
52
|
+
getMe, getUpdates, sendMessage, sendPhoto, sendDocument, sendVideo, sendAudio, sendVoice, sendAnimation, sendVideoNote, sendSticker, sendDice, sendLocation, sendVenue, sendContact, editMessageText, deleteMessage, answerCallbackQuery, banChatMember, unbanChatMember, restrictChatMember, promoteChatMember, pinChatMessage, unpinChatMessage, getChatAdministrators, getChatMember, setMyCommands, getMyCommands, setChatMenuButton, getChatMenuButton, getFile, setWebhook, deleteWebhook, getWebhookInfo, getMyStarBalance, transferStars, sendGift, giftPremiumSubscription, getAvailableGifts, refundStarPayment, sendInvoice, answerPreCheckoutQuery, answerShippingQuery, answerWebAppQuery, savePreparedInlineMessage, setUserEmojiStatus
|
|
53
|
+
|
|
54
|
+
**جمعاً ۴۵ متد.**
|
|
55
|
+
|
|
56
|
+
## لایسنس
|
|
57
|
+
|
|
58
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# gitbin-bot
|
|
2
|
+
|
|
3
|
+
کتابخانه پایتون برای GitBin Bot API.
|
|
4
|
+
|
|
5
|
+
## نصب
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install gitbin-bot
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## استفاده
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from gitbin import Bot
|
|
15
|
+
|
|
16
|
+
bot = Bot(token="YOUR_TOKEN")
|
|
17
|
+
|
|
18
|
+
# اطلاعات ربات
|
|
19
|
+
me = bot.get_me()
|
|
20
|
+
print(me["first_name"])
|
|
21
|
+
|
|
22
|
+
# ارسال پیام
|
|
23
|
+
bot.send_message(chat_id=123, text="سلام 👋")
|
|
24
|
+
|
|
25
|
+
# موجودی استارز
|
|
26
|
+
bal = bot.get_my_star_balance()
|
|
27
|
+
print(f"{bal['amount']:,} استارز")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## متدهای موجود
|
|
31
|
+
|
|
32
|
+
getMe, getUpdates, sendMessage, sendPhoto, sendDocument, sendVideo, sendAudio, sendVoice, sendAnimation, sendVideoNote, sendSticker, sendDice, sendLocation, sendVenue, sendContact, editMessageText, deleteMessage, answerCallbackQuery, banChatMember, unbanChatMember, restrictChatMember, promoteChatMember, pinChatMessage, unpinChatMessage, getChatAdministrators, getChatMember, setMyCommands, getMyCommands, setChatMenuButton, getChatMenuButton, getFile, setWebhook, deleteWebhook, getWebhookInfo, getMyStarBalance, transferStars, sendGift, giftPremiumSubscription, getAvailableGifts, refundStarPayment, sendInvoice, answerPreCheckoutQuery, answerShippingQuery, answerWebAppQuery, savePreparedInlineMessage, setUserEmojiStatus
|
|
33
|
+
|
|
34
|
+
**جمعاً ۴۵ متد.**
|
|
35
|
+
|
|
36
|
+
## لایسنس
|
|
37
|
+
|
|
38
|
+
MIT
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""کتابخانه گیتبین — Bot API"""
|
|
2
|
+
from .client import GitbinClient
|
|
3
|
+
from .methods import BotMethods
|
|
4
|
+
from .errors import GitbinError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Bot(GitbinClient, BotMethods):
|
|
8
|
+
"""
|
|
9
|
+
کلاس اصلی — همه ۴۵ متد + ارتباط با API
|
|
10
|
+
|
|
11
|
+
مثال:
|
|
12
|
+
from gitbin import Bot
|
|
13
|
+
bot = Bot(token="1780243415:K0WZ...")
|
|
14
|
+
bot.send_message(chat_id=123, text="سلام")
|
|
15
|
+
"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
__all__ = ["Bot", "GitbinError"]
|
|
20
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""کلاینت پایه — ارتباط با سرور گیتبین"""
|
|
2
|
+
import json
|
|
3
|
+
import requests
|
|
4
|
+
from .errors import raise_from_response, GitbinError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GitbinClient:
|
|
8
|
+
def __init__(self, token: str, base_url: str = "https://api.gitbin.site", timeout: int = 40):
|
|
9
|
+
"""
|
|
10
|
+
token: توکن ربات (مثل 1780243415:K0WZ...)
|
|
11
|
+
base_url: آدرس سرور (پیشفرض api.gitbin.site)
|
|
12
|
+
timeout: ثانیه صبر برای پاسخ
|
|
13
|
+
"""
|
|
14
|
+
self.token = token
|
|
15
|
+
self.base_url = base_url.rstrip("/")
|
|
16
|
+
self.timeout = timeout
|
|
17
|
+
self.session = requests.Session()
|
|
18
|
+
|
|
19
|
+
# ─────────────────────────────────────────
|
|
20
|
+
# هسته: ارسال درخواست
|
|
21
|
+
# ─────────────────────────────────────────
|
|
22
|
+
def _call(self, method: str, **params):
|
|
23
|
+
"""
|
|
24
|
+
متد رو صدا بزن. params میتونه هر پارامتری باشه.
|
|
25
|
+
برمیگردونه: result (بدون ok)
|
|
26
|
+
خطا: GitbinError raise میکنه
|
|
27
|
+
"""
|
|
28
|
+
url = f"{self.base_url}/bot{self.token}/{method}"
|
|
29
|
+
|
|
30
|
+
# پاکسازی: حذف Noneها و تبدیل bool/dict/list به رشته
|
|
31
|
+
clean = {}
|
|
32
|
+
for k, v in params.items():
|
|
33
|
+
if v is None:
|
|
34
|
+
continue
|
|
35
|
+
if isinstance(v, bool):
|
|
36
|
+
clean[k] = "true" if v else "false"
|
|
37
|
+
elif isinstance(v, (dict, list)):
|
|
38
|
+
clean[k] = json.dumps(v, ensure_ascii=False)
|
|
39
|
+
else:
|
|
40
|
+
clean[k] = v
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
r = self.session.post(url, data=clean, timeout=self.timeout)
|
|
44
|
+
except requests.RequestException as exc:
|
|
45
|
+
raise GitbinError(0, f"CONNECTION_ERROR: {exc}", method)
|
|
46
|
+
|
|
47
|
+
# پاسخ JSON
|
|
48
|
+
try:
|
|
49
|
+
data = r.json()
|
|
50
|
+
except ValueError:
|
|
51
|
+
raise GitbinError(r.status_code, f"BAD_JSON: {r.text[:200]}", method)
|
|
52
|
+
|
|
53
|
+
# خطای API
|
|
54
|
+
if not data.get("ok"):
|
|
55
|
+
raise_from_response(data, method)
|
|
56
|
+
|
|
57
|
+
return data.get("result")
|
|
58
|
+
|
|
59
|
+
# ─────────────────────────────────────────
|
|
60
|
+
# میانبر برای GET (بعضی متدها فقط GET قبول میکنن)
|
|
61
|
+
# ─────────────────────────────────────────
|
|
62
|
+
def _call_get(self, method: str, **params):
|
|
63
|
+
url = f"{self.base_url}/bot{self.token}/{method}"
|
|
64
|
+
clean = {k: v for k, v in params.items() if v is not None}
|
|
65
|
+
try:
|
|
66
|
+
r = self.session.get(url, params=clean, timeout=self.timeout)
|
|
67
|
+
data = r.json()
|
|
68
|
+
except Exception as exc:
|
|
69
|
+
raise GitbinError(0, str(exc), method)
|
|
70
|
+
if not data.get("ok"):
|
|
71
|
+
raise_from_response(data, method)
|
|
72
|
+
return data.get("result")
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""خطاهای API گیتبین"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GitbinError(Exception):
|
|
5
|
+
"""خطای پایه همه خطاهای گیتبین"""
|
|
6
|
+
def __init__(self, code: int, description: str, method: str = ""):
|
|
7
|
+
self.code = code
|
|
8
|
+
self.description = description
|
|
9
|
+
self.method = method
|
|
10
|
+
msg = f"[{code}] {description}"
|
|
11
|
+
if method:
|
|
12
|
+
msg += f" (در متد {method})"
|
|
13
|
+
super().__init__(msg)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# نقشه: description → اسم کلاس Exception
|
|
17
|
+
_ERROR_NAMES = {
|
|
18
|
+
# احراز هویت
|
|
19
|
+
"ACCESS_TOKEN_INVALID": "AccessTokenInvalid",
|
|
20
|
+
|
|
21
|
+
# پارامترهای نامعتبر
|
|
22
|
+
"CHAT_ID_INVALID": "ChatIdInvalid",
|
|
23
|
+
"USER_ID_INVALID": "UserIdInvalid",
|
|
24
|
+
"FILE_ID_INVALID": "FileIdInvalid",
|
|
25
|
+
"GIFT_ID_INVALID": "GiftIdInvalid",
|
|
26
|
+
"QUERY_ID_INVALID": "QueryIdInvalid",
|
|
27
|
+
"BUTTON_INVALID": "ButtonInvalid",
|
|
28
|
+
"BOT_COMMAND_INVALID": "BotCommandInvalid",
|
|
29
|
+
"WEBHOOK_URL_INVALID": "WebhookUrlInvalid",
|
|
30
|
+
"EMOTICON_INVALID": "EmoticonInvalid",
|
|
31
|
+
"BOT_INVALID": "BotInvalid",
|
|
32
|
+
|
|
33
|
+
# محدودیتها
|
|
34
|
+
"EPHEMERAL_TARGET_REQUIRED": "EphemeralTargetRequired",
|
|
35
|
+
"FILE_TOO_BIG": "FileTooBig",
|
|
36
|
+
|
|
37
|
+
# استارز
|
|
38
|
+
"STARS_AMOUNT_INVALID": "StarsAmountInvalid",
|
|
39
|
+
"BALANCE_TOO_LOW": "BalanceTooLow",
|
|
40
|
+
"USER_NOT_FOUND": "UserNotFound",
|
|
41
|
+
"USER_IS_BOT": "UserIsBot",
|
|
42
|
+
|
|
43
|
+
# عمومی
|
|
44
|
+
"METHOD_NOT_FOUND": "MethodNotFound",
|
|
45
|
+
"CONFLICT": "ConflictError",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# ساخت پویا کلاسها
|
|
49
|
+
import sys as _sys
|
|
50
|
+
_module = _sys.modules[__name__]
|
|
51
|
+
for _desc, _cls_name in _ERROR_NAMES.items():
|
|
52
|
+
globals()[_cls_name] = type(_cls_name, (GitbinError,), {})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def raise_from_response(data: dict, method: str = ""):
|
|
56
|
+
"""از پاسخ خطای API، Exception مناسب بساز و raise کن"""
|
|
57
|
+
desc = data.get("description", "UNKNOWN_ERROR")
|
|
58
|
+
code = data.get("error_code", 0)
|
|
59
|
+
cls_name = _ERROR_NAMES.get(desc, "GitbinError")
|
|
60
|
+
cls = globals().get(cls_name, GitbinError)
|
|
61
|
+
raise cls(code, desc, method)
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""همه متدهای API گیتبین — ۴۵ متد"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BotMethods:
|
|
5
|
+
# ═══════════════ هویت و آپدیت ═══════════════
|
|
6
|
+
|
|
7
|
+
def get_me(self):
|
|
8
|
+
"""اطلاعات ربات"""
|
|
9
|
+
return self._call("getMe")
|
|
10
|
+
|
|
11
|
+
def get_updates(self, offset=None, limit=None, timeout=None, allowed_updates=None):
|
|
12
|
+
"""دریافت آپدیتها (long polling)"""
|
|
13
|
+
return self._call("getUpdates", offset=offset, limit=limit,
|
|
14
|
+
timeout=timeout, allowed_updates=allowed_updates)
|
|
15
|
+
|
|
16
|
+
def set_webhook(self, url, **kwargs):
|
|
17
|
+
return self._call("setWebhook", url=url, **kwargs)
|
|
18
|
+
|
|
19
|
+
def delete_webhook(self, **kwargs):
|
|
20
|
+
return self._call("deleteWebhook", **kwargs)
|
|
21
|
+
|
|
22
|
+
def get_webhook_info(self):
|
|
23
|
+
return self._call("getWebhookInfo")
|
|
24
|
+
|
|
25
|
+
def get_file(self, file_id):
|
|
26
|
+
return self._call("getFile", file_id=file_id)
|
|
27
|
+
|
|
28
|
+
# ═══════════════ دستورات و منو ═══════════════
|
|
29
|
+
|
|
30
|
+
def set_my_commands(self, commands, **kwargs):
|
|
31
|
+
"""commands: [{"command": "start", "description": "شروع"}]"""
|
|
32
|
+
return self._call("setMyCommands", commands=commands, **kwargs)
|
|
33
|
+
|
|
34
|
+
def get_my_commands(self, **kwargs):
|
|
35
|
+
return self._call("getMyCommands", **kwargs)
|
|
36
|
+
|
|
37
|
+
def set_chat_menu_button(self, **kwargs):
|
|
38
|
+
return self._call("setChatMenuButton", **kwargs)
|
|
39
|
+
|
|
40
|
+
def get_chat_menu_button(self, **kwargs):
|
|
41
|
+
return self._call("getChatMenuButton", **kwargs)
|
|
42
|
+
|
|
43
|
+
def set_user_emoji_status(self, user_id, emoji_status_custom_emoji_id=None, **kwargs):
|
|
44
|
+
return self._call("setUserEmojiStatus", user_id=user_id,
|
|
45
|
+
emoji_status_custom_emoji_id=emoji_status_custom_emoji_id, **kwargs)
|
|
46
|
+
|
|
47
|
+
# ═══════════════ ارسال پیام ═══════════════
|
|
48
|
+
|
|
49
|
+
def send_message(self, chat_id, text, **kwargs):
|
|
50
|
+
return self._call("sendMessage", chat_id=chat_id, text=text, **kwargs)
|
|
51
|
+
|
|
52
|
+
def send_photo(self, chat_id, photo, **kwargs):
|
|
53
|
+
return self._call("sendPhoto", chat_id=chat_id, photo=photo, **kwargs)
|
|
54
|
+
|
|
55
|
+
def send_audio(self, chat_id, audio, **kwargs):
|
|
56
|
+
return self._call("sendAudio", chat_id=chat_id, audio=audio, **kwargs)
|
|
57
|
+
|
|
58
|
+
def send_document(self, chat_id, document, **kwargs):
|
|
59
|
+
return self._call("sendDocument", chat_id=chat_id, document=document, **kwargs)
|
|
60
|
+
|
|
61
|
+
def send_video(self, chat_id, video, **kwargs):
|
|
62
|
+
return self._call("sendVideo", chat_id=chat_id, video=video, **kwargs)
|
|
63
|
+
|
|
64
|
+
def send_animation(self, chat_id, animation, **kwargs):
|
|
65
|
+
return self._call("sendAnimation", chat_id=chat_id, animation=animation, **kwargs)
|
|
66
|
+
|
|
67
|
+
def send_voice(self, chat_id, voice, **kwargs):
|
|
68
|
+
return self._call("sendVoice", chat_id=chat_id, voice=voice, **kwargs)
|
|
69
|
+
|
|
70
|
+
def send_video_note(self, chat_id, video_note, **kwargs):
|
|
71
|
+
return self._call("sendVideoNote", chat_id=chat_id, video_note=video_note, **kwargs)
|
|
72
|
+
|
|
73
|
+
def send_sticker(self, chat_id, sticker, **kwargs):
|
|
74
|
+
return self._call("sendSticker", chat_id=chat_id, sticker=sticker, **kwargs)
|
|
75
|
+
|
|
76
|
+
def send_dice(self, chat_id, emoji=None, **kwargs):
|
|
77
|
+
"""تاس/بسکتبال/فوتبال/... — emoji: 🎲 🎯 🎳 🏀 ⚽ 🎰"""
|
|
78
|
+
return self._call("sendDice", chat_id=chat_id, emoji=emoji, **kwargs)
|
|
79
|
+
|
|
80
|
+
# ─── سه متد ویژه: بهجای chat_id، receiver_user_id لازم دارن ───
|
|
81
|
+
def send_location(self, chat_id, receiver_user_id, latitude, longitude, **kwargs):
|
|
82
|
+
return self._call("sendLocation", chat_id=chat_id, receiver_user_id=receiver_user_id,
|
|
83
|
+
latitude=latitude, longitude=longitude, **kwargs)
|
|
84
|
+
|
|
85
|
+
def send_venue(self, chat_id, receiver_user_id, latitude, longitude, title, address, **kwargs):
|
|
86
|
+
return self._call("sendVenue", chat_id=chat_id, receiver_user_id=receiver_user_id,
|
|
87
|
+
latitude=latitude, longitude=longitude,
|
|
88
|
+
title=title, address=address, **kwargs)
|
|
89
|
+
|
|
90
|
+
def send_contact(self, chat_id, receiver_user_id, phone_number, first_name, **kwargs):
|
|
91
|
+
return self._call("sendContact", chat_id=chat_id, receiver_user_id=receiver_user_id,
|
|
92
|
+
phone_number=phone_number, first_name=first_name, **kwargs)
|
|
93
|
+
|
|
94
|
+
# ═══════════════ ویرایش و حذف ═══════════════
|
|
95
|
+
|
|
96
|
+
def edit_message_text(self, chat_id, message_id, text, **kwargs):
|
|
97
|
+
return self._call("editMessageText", chat_id=chat_id,
|
|
98
|
+
message_id=message_id, text=text, **kwargs)
|
|
99
|
+
|
|
100
|
+
def delete_message(self, chat_id, message_id):
|
|
101
|
+
return self._call("deleteMessage", chat_id=chat_id, message_id=message_id)
|
|
102
|
+
|
|
103
|
+
def answer_callback_query(self, callback_query_id, text=None, show_alert=None, **kwargs):
|
|
104
|
+
return self._call("answerCallbackQuery", callback_query_id=callback_query_id,
|
|
105
|
+
text=text, show_alert=show_alert, **kwargs)
|
|
106
|
+
|
|
107
|
+
# ═══════════════ مدیریت چت ═══════════════
|
|
108
|
+
|
|
109
|
+
def ban_chat_member(self, chat_id, user_id, **kwargs):
|
|
110
|
+
return self._call("banChatMember", chat_id=chat_id, user_id=user_id, **kwargs)
|
|
111
|
+
|
|
112
|
+
def unban_chat_member(self, chat_id, user_id, **kwargs):
|
|
113
|
+
return self._call("unbanChatMember", chat_id=chat_id, user_id=user_id, **kwargs)
|
|
114
|
+
|
|
115
|
+
def restrict_chat_member(self, chat_id, user_id, permissions=None, **kwargs):
|
|
116
|
+
"""permissions: dict مثل {"can_send_messages": False}"""
|
|
117
|
+
return self._call("restrictChatMember", chat_id=chat_id, user_id=user_id,
|
|
118
|
+
permissions=permissions, **kwargs)
|
|
119
|
+
|
|
120
|
+
def promote_chat_member(self, chat_id, user_id, **kwargs):
|
|
121
|
+
return self._call("promoteChatMember", chat_id=chat_id, user_id=user_id, **kwargs)
|
|
122
|
+
|
|
123
|
+
def pin_chat_message(self, chat_id, message_id, **kwargs):
|
|
124
|
+
return self._call("pinChatMessage", chat_id=chat_id, message_id=message_id, **kwargs)
|
|
125
|
+
|
|
126
|
+
def unpin_chat_message(self, chat_id, message_id=None, **kwargs):
|
|
127
|
+
return self._call("unpinChatMessage", chat_id=chat_id, message_id=message_id, **kwargs)
|
|
128
|
+
|
|
129
|
+
def get_chat_administrators(self, chat_id):
|
|
130
|
+
return self._call("getChatAdministrators", chat_id=chat_id)
|
|
131
|
+
|
|
132
|
+
def get_chat_member(self, chat_id, user_id):
|
|
133
|
+
return self._call("getChatMember", chat_id=chat_id, user_id=user_id)
|
|
134
|
+
|
|
135
|
+
# ═══════════════ استارز (قابلیت ویژه گیتبین) ═══════════════
|
|
136
|
+
|
|
137
|
+
def get_my_star_balance(self):
|
|
138
|
+
"""موجودی استارز ربات"""
|
|
139
|
+
return self._call("getMyStarBalance")
|
|
140
|
+
|
|
141
|
+
def get_available_gifts(self):
|
|
142
|
+
return self._call("getAvailableGifts")
|
|
143
|
+
|
|
144
|
+
def send_gift(self, gift_id, **kwargs):
|
|
145
|
+
return self._call("sendGift", gift_id=gift_id, **kwargs)
|
|
146
|
+
|
|
147
|
+
def gift_premium_subscription(self, user_id, **kwargs):
|
|
148
|
+
return self._call("giftPremiumSubscription", user_id=user_id, **kwargs)
|
|
149
|
+
|
|
150
|
+
def refund_star_payment(self, user_id, telegram_payment_charge_id, **kwargs):
|
|
151
|
+
return self._call("refundStarPayment", user_id=user_id,
|
|
152
|
+
telegram_payment_charge_id=telegram_payment_charge_id, **kwargs)
|
|
153
|
+
|
|
154
|
+
def transfer_stars(self, user_id, amount, **kwargs):
|
|
155
|
+
"""انتقال استارز از کیف پول ربات به یک کاربر"""
|
|
156
|
+
return self._call("transferStars", user_id=user_id, amount=amount, **kwargs)
|
|
157
|
+
|
|
158
|
+
# ═══════════════ پرداخت ═══════════════
|
|
159
|
+
|
|
160
|
+
def send_invoice(self, chat_id, title, description, payload,
|
|
161
|
+
provider_token, currency, prices, **kwargs):
|
|
162
|
+
return self._call("sendInvoice", chat_id=chat_id, title=title,
|
|
163
|
+
description=description, payload=payload,
|
|
164
|
+
provider_token=provider_token, currency=currency,
|
|
165
|
+
prices=prices, **kwargs)
|
|
166
|
+
|
|
167
|
+
def answer_pre_checkout_query(self, pre_checkout_query_id, ok, **kwargs):
|
|
168
|
+
return self._call("answerPreCheckoutQuery",
|
|
169
|
+
pre_checkout_query_id=pre_checkout_query_id,
|
|
170
|
+
ok=ok, **kwargs)
|
|
171
|
+
|
|
172
|
+
def answer_shipping_query(self, shipping_query_id, ok, **kwargs):
|
|
173
|
+
"""⚠️ در اسکن 404 داد — با احتیاط استفاده کن"""
|
|
174
|
+
return self._call("answerShippingQuery",
|
|
175
|
+
shipping_query_id=shipping_query_id, ok=ok, **kwargs)
|
|
176
|
+
|
|
177
|
+
# ═══════════════ WebApp ═══════════════
|
|
178
|
+
|
|
179
|
+
def answer_web_app_query(self, web_app_query_id, result, **kwargs):
|
|
180
|
+
return self._call("answerWebAppQuery",
|
|
181
|
+
web_app_query_id=web_app_query_id, result=result, **kwargs)
|
|
182
|
+
|
|
183
|
+
def save_prepared_inline_message(self, user_id, result, **kwargs):
|
|
184
|
+
return self._call("savePreparedInlineMessage",
|
|
185
|
+
user_id=user_id, result=result, **kwargs)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""انواع داده API گیتبین — بر اساس مستندات"""
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import Optional, List, Dict, Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class User:
|
|
8
|
+
id: int
|
|
9
|
+
is_bot: bool = False
|
|
10
|
+
first_name: str = ""
|
|
11
|
+
last_name: Optional[str] = None
|
|
12
|
+
username: Optional[str] = None
|
|
13
|
+
language_code: Optional[str] = None
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def from_dict(cls, d: dict) -> "User":
|
|
17
|
+
return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__})
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class Chat:
|
|
22
|
+
id: int
|
|
23
|
+
type: str = "private" # private | group | supergroup | channel
|
|
24
|
+
title: Optional[str] = None
|
|
25
|
+
username: Optional[str] = None
|
|
26
|
+
first_name: Optional[str] = None
|
|
27
|
+
last_name: Optional[str] = None
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def from_dict(cls, d: dict) -> "Chat":
|
|
31
|
+
return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__})
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class Dice:
|
|
36
|
+
emoji: str = "🎲"
|
|
37
|
+
value: int = 0
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_dict(cls, d: dict) -> "Dice":
|
|
41
|
+
return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__})
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class Message:
|
|
46
|
+
message_id: int
|
|
47
|
+
date: int = 0
|
|
48
|
+
text: Optional[str] = None
|
|
49
|
+
caption: Optional[str] = None
|
|
50
|
+
from_user: Optional[User] = None # فیلد اصلی API: from
|
|
51
|
+
chat: Optional[Chat] = None
|
|
52
|
+
dice: Optional[Dice] = None
|
|
53
|
+
photo: Optional[List[Dict[str, Any]]] = None
|
|
54
|
+
document: Optional[Dict[str, Any]] = None
|
|
55
|
+
video: Optional[Dict[str, Any]] = None
|
|
56
|
+
audio: Optional[Dict[str, Any]] = None
|
|
57
|
+
voice: Optional[Dict[str, Any]] = None
|
|
58
|
+
sticker: Optional[Dict[str, Any]] = None
|
|
59
|
+
animation: Optional[Dict[str, Any]] = None
|
|
60
|
+
reply_to_message: Optional["Message"] = None
|
|
61
|
+
successful_payment: Optional[Dict[str, Any]] = None
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def from_dict(cls, d: dict) -> "Message":
|
|
65
|
+
d = dict(d)
|
|
66
|
+
if "from" in d:
|
|
67
|
+
d["from_user"] = d.pop("from")
|
|
68
|
+
if d.get("from_user"):
|
|
69
|
+
d["from_user"] = User.from_dict(d["from_user"])
|
|
70
|
+
if d.get("chat"):
|
|
71
|
+
d["chat"] = Chat.from_dict(d["chat"])
|
|
72
|
+
if d.get("dice"):
|
|
73
|
+
d["dice"] = Dice.from_dict(d["dice"])
|
|
74
|
+
if d.get("reply_to_message"):
|
|
75
|
+
d["reply_to_message"] = Message.from_dict(d["reply_to_message"])
|
|
76
|
+
allowed = {k: v for k, v in d.items() if k in cls.__dataclass_fields__}
|
|
77
|
+
return cls(**allowed)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass
|
|
81
|
+
class CallbackQuery:
|
|
82
|
+
id: str
|
|
83
|
+
from_user: Optional[User] = None
|
|
84
|
+
message: Optional[Message] = None
|
|
85
|
+
data: Optional[str] = None
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def from_dict(cls, d: dict) -> "CallbackQuery":
|
|
89
|
+
d = dict(d)
|
|
90
|
+
if "from" in d:
|
|
91
|
+
d["from_user"] = d.pop("from")
|
|
92
|
+
if d.get("from_user"):
|
|
93
|
+
d["from_user"] = User.from_dict(d["from_user"])
|
|
94
|
+
if d.get("message"):
|
|
95
|
+
d["message"] = Message.from_dict(d["message"])
|
|
96
|
+
allowed = {k: v for k, v in d.items() if k in cls.__dataclass_fields__}
|
|
97
|
+
return cls(**allowed)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass
|
|
101
|
+
class Update:
|
|
102
|
+
update_id: int
|
|
103
|
+
message: Optional[Message] = None
|
|
104
|
+
edited_message: Optional[Message] = None
|
|
105
|
+
callback_query: Optional[CallbackQuery] = None
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def from_dict(cls, d: dict) -> "Update":
|
|
109
|
+
d = dict(d)
|
|
110
|
+
if d.get("message"):
|
|
111
|
+
d["message"] = Message.from_dict(d["message"])
|
|
112
|
+
if d.get("edited_message"):
|
|
113
|
+
d["edited_message"] = Message.from_dict(d["edited_message"])
|
|
114
|
+
if d.get("callback_query"):
|
|
115
|
+
d["callback_query"] = CallbackQuery.from_dict(d["callback_query"])
|
|
116
|
+
return cls(**d)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@dataclass
|
|
120
|
+
class StarBalance:
|
|
121
|
+
amount: int = 0
|
|
122
|
+
nanostar_amount: int = 0
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def from_dict(cls, d: dict) -> "StarBalance":
|
|
126
|
+
return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitbin-bot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: کتابخانه پایتون برای GitBin Bot API
|
|
5
|
+
Author-email: MMD <ammmd219@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MMD-C0DE/gitbin-bot
|
|
8
|
+
Project-URL: Documentation, https://github.com/MMD-C0DE/gitbin-bot#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/MMD-C0DE/gitbin-bot/issues
|
|
10
|
+
Keywords: gitbin,bot,api,telegram,messenger
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Communications :: Chat
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: requests>=2.28
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# gitbin-bot
|
|
22
|
+
|
|
23
|
+
کتابخانه پایتون برای GitBin Bot API.
|
|
24
|
+
|
|
25
|
+
## نصب
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install gitbin-bot
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## استفاده
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from gitbin import Bot
|
|
35
|
+
|
|
36
|
+
bot = Bot(token="YOUR_TOKEN")
|
|
37
|
+
|
|
38
|
+
# اطلاعات ربات
|
|
39
|
+
me = bot.get_me()
|
|
40
|
+
print(me["first_name"])
|
|
41
|
+
|
|
42
|
+
# ارسال پیام
|
|
43
|
+
bot.send_message(chat_id=123, text="سلام 👋")
|
|
44
|
+
|
|
45
|
+
# موجودی استارز
|
|
46
|
+
bal = bot.get_my_star_balance()
|
|
47
|
+
print(f"{bal['amount']:,} استارز")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## متدهای موجود
|
|
51
|
+
|
|
52
|
+
getMe, getUpdates, sendMessage, sendPhoto, sendDocument, sendVideo, sendAudio, sendVoice, sendAnimation, sendVideoNote, sendSticker, sendDice, sendLocation, sendVenue, sendContact, editMessageText, deleteMessage, answerCallbackQuery, banChatMember, unbanChatMember, restrictChatMember, promoteChatMember, pinChatMessage, unpinChatMessage, getChatAdministrators, getChatMember, setMyCommands, getMyCommands, setChatMenuButton, getChatMenuButton, getFile, setWebhook, deleteWebhook, getWebhookInfo, getMyStarBalance, transferStars, sendGift, giftPremiumSubscription, getAvailableGifts, refundStarPayment, sendInvoice, answerPreCheckoutQuery, answerShippingQuery, answerWebAppQuery, savePreparedInlineMessage, setUserEmojiStatus
|
|
53
|
+
|
|
54
|
+
**جمعاً ۴۵ متد.**
|
|
55
|
+
|
|
56
|
+
## لایسنس
|
|
57
|
+
|
|
58
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
gitbin/__init__.py
|
|
5
|
+
gitbin/client.py
|
|
6
|
+
gitbin/errors.py
|
|
7
|
+
gitbin/methods.py
|
|
8
|
+
gitbin/types.py
|
|
9
|
+
gitbin_bot.egg-info/PKG-INFO
|
|
10
|
+
gitbin_bot.egg-info/SOURCES.txt
|
|
11
|
+
gitbin_bot.egg-info/dependency_links.txt
|
|
12
|
+
gitbin_bot.egg-info/requires.txt
|
|
13
|
+
gitbin_bot.egg-info/top_level.txt
|
|
14
|
+
tests/test_basic.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gitbin
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gitbin-bot"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "کتابخانه پایتون برای GitBin Bot API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "MMD", email = "ammmd219@gmail.com" }]
|
|
13
|
+
keywords = ["gitbin", "bot", "api", "telegram", "messenger"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Communications :: Chat",
|
|
19
|
+
]
|
|
20
|
+
dependencies = ["requests>=2.28"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/MMD-C0DE/gitbin-bot"
|
|
24
|
+
Documentation = "https://github.com/MMD-C0DE/gitbin-bot#readme"
|
|
25
|
+
Issues = "https://github.com/MMD-C0DE/gitbin-bot/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
include = ["gitbin*"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""تست ساده کتابخانه"""
|
|
2
|
+
import os
|
|
3
|
+
from gitbin import Bot
|
|
4
|
+
|
|
5
|
+
TOKEN = os.environ.get("GITBIN_TOKEN", "")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_import():
|
|
9
|
+
"""کتابخانه نصب شده"""
|
|
10
|
+
from gitbin import Bot
|
|
11
|
+
assert Bot is not None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_get_me():
|
|
15
|
+
"""اتصال به API"""
|
|
16
|
+
if not TOKEN:
|
|
17
|
+
return # اگه توکن نداری، رد شو
|
|
18
|
+
bot = Bot(token=TOKEN)
|
|
19
|
+
me = bot.get_me()
|
|
20
|
+
assert me["is_bot"] is True
|