RubigramClient 1.3.8__tar.gz → 1.4.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.
Potentially problematic release.
This version of RubigramClient might be problematic. Click here for more details.
- rubigramclient-1.4.0/PKG-INFO +70 -0
- rubigramclient-1.4.0/README.md +55 -0
- rubigramclient-1.4.0/RubigramClient.egg-info/PKG-INFO +70 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/pyproject.toml +1 -1
- rubigramclient-1.4.0/rubigram/client.py +90 -0
- rubigramclient-1.4.0/rubigram/filters.py +113 -0
- rubigramclient-1.3.8/PKG-INFO +0 -35
- rubigramclient-1.3.8/README.md +0 -20
- rubigramclient-1.3.8/RubigramClient.egg-info/PKG-INFO +0 -35
- rubigramclient-1.3.8/rubigram/client.py +0 -72
- rubigramclient-1.3.8/rubigram/filters.py +0 -53
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/LICENSE +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/RubigramClient.egg-info/SOURCES.txt +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/RubigramClient.egg-info/dependency_links.txt +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/RubigramClient.egg-info/requires.txt +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/RubigramClient.egg-info/top_level.txt +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/rubigram/__init__.py +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/rubigram/method.py +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/rubigram/network.py +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/rubigram/types.py +0 -0
- {rubigramclient-1.3.8 → rubigramclient-1.4.0}/setup.cfg +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: RubigramClient
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
|
|
5
|
+
Author-email: Javad RZ <Javad.Py1385@gmail.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: aiohttp
|
|
13
|
+
Requires-Dist: aiofiles
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Rubigram
|
|
17
|
+
A lightweight Python library to build Rubika bots easily.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
```bash
|
|
21
|
+
pip install RubigramClient
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Send Message
|
|
25
|
+
```python
|
|
26
|
+
from rubigram import Client, filters
|
|
27
|
+
from rubigram.types import Update
|
|
28
|
+
|
|
29
|
+
bot = Client("your_bot_token", "you_endpoint_url")
|
|
30
|
+
|
|
31
|
+
@bot.on_message(filters.command("start"))
|
|
32
|
+
async def start_handler(client, message: Update):
|
|
33
|
+
await message.reply("Hi, WELCOME TO RUBIGRAM")
|
|
34
|
+
|
|
35
|
+
bot.run()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Send Message & Get receiveInlineMessage
|
|
39
|
+
```python
|
|
40
|
+
from rubigram import Client, filters
|
|
41
|
+
from rubigram.types import Update, Button, Keypad, KeypadRow, InlineMessage
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
bot = Client(token="bot_token", endpoint="endpoint_url")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@bot.on_message(filters.command("start"))
|
|
48
|
+
async def start(_, message: Update):
|
|
49
|
+
inline = Keypad(
|
|
50
|
+
rows=[
|
|
51
|
+
KeypadRow(
|
|
52
|
+
buttons=[
|
|
53
|
+
Button("1", "Simple", "Button 1"),
|
|
54
|
+
Button("2", "Simple", "Button 2")
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
]
|
|
58
|
+
)
|
|
59
|
+
await bot.send_message(message.chat_id, "Hi", inline_keypad=inline)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@bot.on_inline_message(filters.button(["1", "2"]))
|
|
63
|
+
async def button(_, message: InlineMessage):
|
|
64
|
+
if message.aux_data.button_id == "1":
|
|
65
|
+
await bot.send_message(message.chat_id, "You Click Button 1")
|
|
66
|
+
elif message.aux_data.button_id == "2":
|
|
67
|
+
await bot.send_message(message.chat_id, "You Click Button 2")
|
|
68
|
+
|
|
69
|
+
bot.run()
|
|
70
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Rubigram
|
|
2
|
+
A lightweight Python library to build Rubika bots easily.
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
```bash
|
|
6
|
+
pip install RubigramClient
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Send Message
|
|
10
|
+
```python
|
|
11
|
+
from rubigram import Client, filters
|
|
12
|
+
from rubigram.types import Update
|
|
13
|
+
|
|
14
|
+
bot = Client("your_bot_token", "you_endpoint_url")
|
|
15
|
+
|
|
16
|
+
@bot.on_message(filters.command("start"))
|
|
17
|
+
async def start_handler(client, message: Update):
|
|
18
|
+
await message.reply("Hi, WELCOME TO RUBIGRAM")
|
|
19
|
+
|
|
20
|
+
bot.run()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Send Message & Get receiveInlineMessage
|
|
24
|
+
```python
|
|
25
|
+
from rubigram import Client, filters
|
|
26
|
+
from rubigram.types import Update, Button, Keypad, KeypadRow, InlineMessage
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
bot = Client(token="bot_token", endpoint="endpoint_url")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@bot.on_message(filters.command("start"))
|
|
33
|
+
async def start(_, message: Update):
|
|
34
|
+
inline = Keypad(
|
|
35
|
+
rows=[
|
|
36
|
+
KeypadRow(
|
|
37
|
+
buttons=[
|
|
38
|
+
Button("1", "Simple", "Button 1"),
|
|
39
|
+
Button("2", "Simple", "Button 2")
|
|
40
|
+
]
|
|
41
|
+
)
|
|
42
|
+
]
|
|
43
|
+
)
|
|
44
|
+
await bot.send_message(message.chat_id, "Hi", inline_keypad=inline)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@bot.on_inline_message(filters.button(["1", "2"]))
|
|
48
|
+
async def button(_, message: InlineMessage):
|
|
49
|
+
if message.aux_data.button_id == "1":
|
|
50
|
+
await bot.send_message(message.chat_id, "You Click Button 1")
|
|
51
|
+
elif message.aux_data.button_id == "2":
|
|
52
|
+
await bot.send_message(message.chat_id, "You Click Button 2")
|
|
53
|
+
|
|
54
|
+
bot.run()
|
|
55
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: RubigramClient
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
|
|
5
|
+
Author-email: Javad RZ <Javad.Py1385@gmail.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: aiohttp
|
|
13
|
+
Requires-Dist: aiofiles
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Rubigram
|
|
17
|
+
A lightweight Python library to build Rubika bots easily.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
```bash
|
|
21
|
+
pip install RubigramClient
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Send Message
|
|
25
|
+
```python
|
|
26
|
+
from rubigram import Client, filters
|
|
27
|
+
from rubigram.types import Update
|
|
28
|
+
|
|
29
|
+
bot = Client("your_bot_token", "you_endpoint_url")
|
|
30
|
+
|
|
31
|
+
@bot.on_message(filters.command("start"))
|
|
32
|
+
async def start_handler(client, message: Update):
|
|
33
|
+
await message.reply("Hi, WELCOME TO RUBIGRAM")
|
|
34
|
+
|
|
35
|
+
bot.run()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Send Message & Get receiveInlineMessage
|
|
39
|
+
```python
|
|
40
|
+
from rubigram import Client, filters
|
|
41
|
+
from rubigram.types import Update, Button, Keypad, KeypadRow, InlineMessage
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
bot = Client(token="bot_token", endpoint="endpoint_url")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@bot.on_message(filters.command("start"))
|
|
48
|
+
async def start(_, message: Update):
|
|
49
|
+
inline = Keypad(
|
|
50
|
+
rows=[
|
|
51
|
+
KeypadRow(
|
|
52
|
+
buttons=[
|
|
53
|
+
Button("1", "Simple", "Button 1"),
|
|
54
|
+
Button("2", "Simple", "Button 2")
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
]
|
|
58
|
+
)
|
|
59
|
+
await bot.send_message(message.chat_id, "Hi", inline_keypad=inline)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@bot.on_inline_message(filters.button(["1", "2"]))
|
|
63
|
+
async def button(_, message: InlineMessage):
|
|
64
|
+
if message.aux_data.button_id == "1":
|
|
65
|
+
await bot.send_message(message.chat_id, "You Click Button 1")
|
|
66
|
+
elif message.aux_data.button_id == "2":
|
|
67
|
+
await bot.send_message(message.chat_id, "You Click Button 2")
|
|
68
|
+
|
|
69
|
+
bot.run()
|
|
70
|
+
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "RubigramClient"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.4.0"
|
|
4
4
|
description = "A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.7"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Callable, Awaitable, Optional
|
|
3
|
+
from aiohttp import web
|
|
4
|
+
from functools import wraps
|
|
5
|
+
from rubigram.types import Update, InlineMessage
|
|
6
|
+
from rubigram.method import Method
|
|
7
|
+
import asyncio
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Client(Method):
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
token: str,
|
|
17
|
+
endpoint: Optional[str] = None,
|
|
18
|
+
host: str = "0.0.0.0",
|
|
19
|
+
port: int = 8000
|
|
20
|
+
):
|
|
21
|
+
self.token = token
|
|
22
|
+
self.port = port
|
|
23
|
+
self.host = host
|
|
24
|
+
self.endpoint = endpoint
|
|
25
|
+
self.messages_handler: list[Callable[[Client, Update], Awaitable]] = []
|
|
26
|
+
self.inlines_handler: list[Callable[[Client, InlineMessage], Awaitable]] = []
|
|
27
|
+
self.routes = web.RouteTableDef()
|
|
28
|
+
super().__init__(token)
|
|
29
|
+
|
|
30
|
+
def on_message(self, *filters: Callable[[Update], bool]):
|
|
31
|
+
def decorator(func: Callable[[Client, Update], Awaitable]):
|
|
32
|
+
@wraps(func)
|
|
33
|
+
async def wrapper(client: Client, update: Update):
|
|
34
|
+
try:
|
|
35
|
+
if all(f(update) for f in filters):
|
|
36
|
+
await func(client, update)
|
|
37
|
+
except Exception as e:
|
|
38
|
+
logger.exception(f"Error in message handler {func.__name__}: {e}")
|
|
39
|
+
self.messages_handler.append(wrapper)
|
|
40
|
+
return func
|
|
41
|
+
return decorator
|
|
42
|
+
|
|
43
|
+
def on_inline_message(self, *filters: Callable[[InlineMessage], bool]):
|
|
44
|
+
def decorator(func: Callable[[Client, InlineMessage], Awaitable]):
|
|
45
|
+
@wraps(func)
|
|
46
|
+
async def wrapper(client: Client, update: InlineMessage):
|
|
47
|
+
try:
|
|
48
|
+
if all(f(update) for f in filters):
|
|
49
|
+
await func(client, update)
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logger.exception(f"Error in inline handler {func.__name__}: {e}")
|
|
52
|
+
self.inlines_handler.append(wrapper)
|
|
53
|
+
return func
|
|
54
|
+
return decorator
|
|
55
|
+
|
|
56
|
+
async def handle_update(self, data: dict):
|
|
57
|
+
if "inline_message" in data:
|
|
58
|
+
event = InlineMessage.read(data["inline_message"])
|
|
59
|
+
await asyncio.gather(*(h(self, event) for h in self.inlines_handler))
|
|
60
|
+
elif "update" in data:
|
|
61
|
+
event = Update.read(data["update"], self)
|
|
62
|
+
await asyncio.gather(*(h(self, event) for h in self.messages_handler))
|
|
63
|
+
|
|
64
|
+
async def set_endpoints(self):
|
|
65
|
+
if not self.endpoint:
|
|
66
|
+
return
|
|
67
|
+
await self.update_bot_endpoint(f"{self.endpoint}/ReceiveUpdate", "ReceiveUpdate")
|
|
68
|
+
await self.update_bot_endpoint(f"{self.endpoint}/ReceiveInlineMessage", "ReceiveInlineMessage")
|
|
69
|
+
|
|
70
|
+
def run(self):
|
|
71
|
+
@self.routes.post("/ReceiveUpdate")
|
|
72
|
+
async def receive_update(request: web.Request):
|
|
73
|
+
data = await request.json()
|
|
74
|
+
await self.handle_update(data)
|
|
75
|
+
return web.json_response({"status": "OK"})
|
|
76
|
+
|
|
77
|
+
@self.routes.post("/ReceiveInlineMessage")
|
|
78
|
+
async def receive_inline_message(request: web.Request):
|
|
79
|
+
data = await request.json()
|
|
80
|
+
await self.handle_update(data)
|
|
81
|
+
return web.json_response({"status": "OK"})
|
|
82
|
+
|
|
83
|
+
app = web.Application()
|
|
84
|
+
app.add_routes(self.routes)
|
|
85
|
+
|
|
86
|
+
async def on_startup(_):
|
|
87
|
+
await self.set_endpoints()
|
|
88
|
+
|
|
89
|
+
app.on_startup.append(on_startup)
|
|
90
|
+
web.run_app(app, host=self.host, port=self.port)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from rubigram.types import Update, InlineMessage
|
|
2
|
+
# from rubigram.state import state_manager
|
|
3
|
+
from typing import Union
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# def state(states: Union[str, list[str]]):
|
|
8
|
+
# def filter(message: Union[Update, InlineMessage]):
|
|
9
|
+
# user_state = state_manager.get_state(message.chat_id)
|
|
10
|
+
# return user_state in states if isinstance(states, list) else user_state == states
|
|
11
|
+
# return filter
|
|
12
|
+
|
|
13
|
+
def command(commands: Union[str, list[str]], prefix: str = "/"):
|
|
14
|
+
def filter(message: Update):
|
|
15
|
+
if isinstance(message, Update) and message.new_message and message.new_message.text:
|
|
16
|
+
text = message.new_message.text.strip()
|
|
17
|
+
cmds = commands if isinstance(commands, list) else [commands]
|
|
18
|
+
for cmd in cmds:
|
|
19
|
+
if text.lower().startswith(prefix + cmd.lower()):
|
|
20
|
+
return True
|
|
21
|
+
return False
|
|
22
|
+
return filter
|
|
23
|
+
|
|
24
|
+
def button(id: Union[str, list[str]]):
|
|
25
|
+
def filter(message: InlineMessage):
|
|
26
|
+
if isinstance(message, InlineMessage):
|
|
27
|
+
button_id = message.aux_data.button_id
|
|
28
|
+
ID = id if isinstance(id, list) else [id]
|
|
29
|
+
for i in ID:
|
|
30
|
+
if button_id == i:
|
|
31
|
+
return True
|
|
32
|
+
return False
|
|
33
|
+
return filter
|
|
34
|
+
|
|
35
|
+
def chat(chat_id: Union[str, list[str]]):
|
|
36
|
+
def filter(message: Union[Update, InlineMessage]):
|
|
37
|
+
chat_ids = chat_id if isinstance(chat_id, list) else [chat_id]
|
|
38
|
+
if isinstance(message, Update) or isinstance(message, InlineMessage):
|
|
39
|
+
return message.chat_id in chat_ids
|
|
40
|
+
return False
|
|
41
|
+
return filter
|
|
42
|
+
|
|
43
|
+
def regex(pattern: str):
|
|
44
|
+
def filter(message: Union[Update, InlineMessage]):
|
|
45
|
+
if isinstance(message, Update) and message.type == "NewMessage" and message.new_message.text:
|
|
46
|
+
return bool(re.search(pattern, message.new_message.text))
|
|
47
|
+
elif isinstance(message, InlineMessage) and message.text:
|
|
48
|
+
return bool(re.search(pattern, message.text))
|
|
49
|
+
return False
|
|
50
|
+
return filter
|
|
51
|
+
|
|
52
|
+
def text():
|
|
53
|
+
def filter(message: Update):
|
|
54
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
55
|
+
return message.new_message.text is None
|
|
56
|
+
return False
|
|
57
|
+
return filter
|
|
58
|
+
|
|
59
|
+
def file():
|
|
60
|
+
def filter(message: Update):
|
|
61
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
62
|
+
return message.new_message.file is None
|
|
63
|
+
return False
|
|
64
|
+
return filter
|
|
65
|
+
|
|
66
|
+
def private():
|
|
67
|
+
def filter(message: Update):
|
|
68
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
69
|
+
return message.new_message.sender_type in ["User", "Bot"]
|
|
70
|
+
return False
|
|
71
|
+
return filter
|
|
72
|
+
|
|
73
|
+
def forward():
|
|
74
|
+
def filter(message: Update):
|
|
75
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
76
|
+
return message.new_message.forwarded_from is None
|
|
77
|
+
return False
|
|
78
|
+
return filter
|
|
79
|
+
|
|
80
|
+
def location():
|
|
81
|
+
def filter(message: Update):
|
|
82
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
83
|
+
return message.new_message.location is None
|
|
84
|
+
return False
|
|
85
|
+
return filter
|
|
86
|
+
|
|
87
|
+
def sticker():
|
|
88
|
+
def filter(message: Update):
|
|
89
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
90
|
+
return message.new_message.sticker is None
|
|
91
|
+
return False
|
|
92
|
+
return filter
|
|
93
|
+
|
|
94
|
+
def contact():
|
|
95
|
+
def filter(message: Update):
|
|
96
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
97
|
+
return message.new_message.contact_message is None
|
|
98
|
+
return False
|
|
99
|
+
return filter
|
|
100
|
+
|
|
101
|
+
def poll():
|
|
102
|
+
def filter(message: Update):
|
|
103
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
104
|
+
return message.new_message.poll is None
|
|
105
|
+
return False
|
|
106
|
+
return filter
|
|
107
|
+
|
|
108
|
+
def live():
|
|
109
|
+
def filter(message: Update):
|
|
110
|
+
if isinstance(message, Update) and message.type == "NewMessage":
|
|
111
|
+
return message.new_message.live_location is None
|
|
112
|
+
return False
|
|
113
|
+
return filter
|
rubigramclient-1.3.8/PKG-INFO
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: RubigramClient
|
|
3
|
-
Version: 1.3.8
|
|
4
|
-
Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
|
|
5
|
-
Author-email: Javad RZ <Javad.Py1385@gmail.com>
|
|
6
|
-
Classifier: Programming Language :: Python :: 3
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Operating System :: OS Independent
|
|
9
|
-
Requires-Python: >=3.7
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
Requires-Dist: aiohttp
|
|
13
|
-
Requires-Dist: aiofiles
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# Rubigram
|
|
17
|
-
A lightweight Python library to build Rubika bots easily.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
```bash
|
|
21
|
-
pip install RubigramClient
|
|
22
|
-
```
|
|
23
|
-
## Example
|
|
24
|
-
```python
|
|
25
|
-
from rubigram import Client, filters
|
|
26
|
-
from rubigram.types import Update
|
|
27
|
-
|
|
28
|
-
bot = Client("your_bot_token", "you_endpoint_url")
|
|
29
|
-
|
|
30
|
-
@bot.on_message(filters.command("start"))
|
|
31
|
-
async def start_handler(client, message: Update):
|
|
32
|
-
await message.reply("Hi, WELCOME TO RUBIGRAM")
|
|
33
|
-
|
|
34
|
-
bot.run()
|
|
35
|
-
```
|
rubigramclient-1.3.8/README.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Rubigram
|
|
2
|
-
A lightweight Python library to build Rubika bots easily.
|
|
3
|
-
|
|
4
|
-
## Installation
|
|
5
|
-
```bash
|
|
6
|
-
pip install RubigramClient
|
|
7
|
-
```
|
|
8
|
-
## Example
|
|
9
|
-
```python
|
|
10
|
-
from rubigram import Client, filters
|
|
11
|
-
from rubigram.types import Update
|
|
12
|
-
|
|
13
|
-
bot = Client("your_bot_token", "you_endpoint_url")
|
|
14
|
-
|
|
15
|
-
@bot.on_message(filters.command("start"))
|
|
16
|
-
async def start_handler(client, message: Update):
|
|
17
|
-
await message.reply("Hi, WELCOME TO RUBIGRAM")
|
|
18
|
-
|
|
19
|
-
bot.run()
|
|
20
|
-
```
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: RubigramClient
|
|
3
|
-
Version: 1.3.8
|
|
4
|
-
Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
|
|
5
|
-
Author-email: Javad RZ <Javad.Py1385@gmail.com>
|
|
6
|
-
Classifier: Programming Language :: Python :: 3
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Operating System :: OS Independent
|
|
9
|
-
Requires-Python: >=3.7
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
Requires-Dist: aiohttp
|
|
13
|
-
Requires-Dist: aiofiles
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# Rubigram
|
|
17
|
-
A lightweight Python library to build Rubika bots easily.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
```bash
|
|
21
|
-
pip install RubigramClient
|
|
22
|
-
```
|
|
23
|
-
## Example
|
|
24
|
-
```python
|
|
25
|
-
from rubigram import Client, filters
|
|
26
|
-
from rubigram.types import Update
|
|
27
|
-
|
|
28
|
-
bot = Client("your_bot_token", "you_endpoint_url")
|
|
29
|
-
|
|
30
|
-
@bot.on_message(filters.command("start"))
|
|
31
|
-
async def start_handler(client, message: Update):
|
|
32
|
-
await message.reply("Hi, WELCOME TO RUBIGRAM")
|
|
33
|
-
|
|
34
|
-
bot.run()
|
|
35
|
-
```
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
from rubigram.types import Update, InlineMessage
|
|
2
|
-
from rubigram.method import Method
|
|
3
|
-
from aiohttp import web
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Client(Method):
|
|
7
|
-
def __init__(self, token: str, endpoint: str = None, host: str = "0.0.0.0", port: int = 8000):
|
|
8
|
-
self.token = token
|
|
9
|
-
self.port = port
|
|
10
|
-
self.host = host
|
|
11
|
-
self.endpoint = endpoint
|
|
12
|
-
self.messages_handler = []
|
|
13
|
-
self.inlines_handler = []
|
|
14
|
-
self.routes = web.RouteTableDef()
|
|
15
|
-
self.api = f"https://botapi.rubika.ir/v3/{self.token}/"
|
|
16
|
-
super().__init__(token)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def on_message(self, *filters):
|
|
20
|
-
def decorator(func):
|
|
21
|
-
async def wrapper(client, update):
|
|
22
|
-
if all(f(update) for f in filters):
|
|
23
|
-
await func(client, update)
|
|
24
|
-
self.messages_handler.append(wrapper)
|
|
25
|
-
return func
|
|
26
|
-
return decorator
|
|
27
|
-
|
|
28
|
-
def on_inline_message(self, *filters):
|
|
29
|
-
def decorator(func):
|
|
30
|
-
async def wrapper(client, update):
|
|
31
|
-
if all(f(update) for f in filters):
|
|
32
|
-
await func(client, update)
|
|
33
|
-
self.inlines_handler.append(wrapper)
|
|
34
|
-
return func
|
|
35
|
-
return decorator
|
|
36
|
-
|
|
37
|
-
async def update(self, data: dict):
|
|
38
|
-
if "inline_message" in data:
|
|
39
|
-
event = InlineMessage.read(data["inline_message"])
|
|
40
|
-
for handler in self.inlines_handler:
|
|
41
|
-
await handler(self, event)
|
|
42
|
-
else:
|
|
43
|
-
event = Update.read(data["update"], self)
|
|
44
|
-
for handler in self.messages_handler:
|
|
45
|
-
await handler(self, event)
|
|
46
|
-
|
|
47
|
-
async def set_endpoints(self):
|
|
48
|
-
await self.update_bot_endpoint(self.endpoint + "/ReceiveUpdate", "ReceiveUpdate")
|
|
49
|
-
await self.update_bot_endpoint(self.endpoint + "/ReceiveInlineMessage", "ReceiveInlineMessage")
|
|
50
|
-
|
|
51
|
-
def run(self):
|
|
52
|
-
@self.routes.post("/ReceiveUpdate")
|
|
53
|
-
async def receive_update(request):
|
|
54
|
-
data = await request.json()
|
|
55
|
-
await self.update(data)
|
|
56
|
-
return web.json_response({"status": "OK"})
|
|
57
|
-
|
|
58
|
-
@self.routes.post("/ReceiveInlineMessage")
|
|
59
|
-
async def receive_inline_message(request):
|
|
60
|
-
data = await request.json()
|
|
61
|
-
await self.update(data)
|
|
62
|
-
return web.json_response({"status": "ok"})
|
|
63
|
-
|
|
64
|
-
app = web.Application()
|
|
65
|
-
app.add_routes(self.routes)
|
|
66
|
-
|
|
67
|
-
async def on_startup(app):
|
|
68
|
-
if self.endpoint:
|
|
69
|
-
await self.set_endpoints()
|
|
70
|
-
|
|
71
|
-
app.on_startup.append(on_startup)
|
|
72
|
-
web.run_app(app, host = self.host, port = self.port)
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
from rubigram.types import Update, InlineMessage
|
|
2
|
-
from typing import Union
|
|
3
|
-
|
|
4
|
-
def command(commands: Union[str, list[str]], prefixe: str = "/"):
|
|
5
|
-
def filter(message: Update):
|
|
6
|
-
if isinstance(message, Update) and message.type == "NewMessage" and message.new_message.text:
|
|
7
|
-
text = message.new_message.text
|
|
8
|
-
COMMANDS = commands if isinstance(commands, list) else [commands]
|
|
9
|
-
for cmd in COMMANDS:
|
|
10
|
-
if text.lower().startswith(prefixe + cmd):
|
|
11
|
-
return True
|
|
12
|
-
return False
|
|
13
|
-
return filter
|
|
14
|
-
|
|
15
|
-
def button(id: Union[str, list[str]]):
|
|
16
|
-
def filter(message: InlineMessage):
|
|
17
|
-
if isinstance(message, InlineMessage):
|
|
18
|
-
button_id = message.aux_data.button_id
|
|
19
|
-
ID = id if isinstance(id, list) else [id]
|
|
20
|
-
for i in ID:
|
|
21
|
-
if button_id == i:
|
|
22
|
-
return True
|
|
23
|
-
return False
|
|
24
|
-
return filter
|
|
25
|
-
|
|
26
|
-
def chat(chat_id: Union[str, list[str]]):
|
|
27
|
-
def filter(message: Union[Update, InlineMessage]):
|
|
28
|
-
chat_ids = chat_id if isinstance(chat_id, list) else [chat_id]
|
|
29
|
-
if isinstance(message, Update) or isinstance(message, InlineMessage):
|
|
30
|
-
return message.chat_id in chat_ids
|
|
31
|
-
return False
|
|
32
|
-
return filter
|
|
33
|
-
|
|
34
|
-
def text():
|
|
35
|
-
def filter(message: Update):
|
|
36
|
-
if isinstance(message, Update) and message.type == "NewMessage":
|
|
37
|
-
return bool(message.new_message.text)
|
|
38
|
-
return False
|
|
39
|
-
return filter
|
|
40
|
-
|
|
41
|
-
def file():
|
|
42
|
-
def filter(message: Update):
|
|
43
|
-
if isinstance(message, Update) and message.type == "NewMessage":
|
|
44
|
-
return bool(message.new_message.file)
|
|
45
|
-
return False
|
|
46
|
-
return filter
|
|
47
|
-
|
|
48
|
-
def private():
|
|
49
|
-
def filter(message: Update):
|
|
50
|
-
if isinstance(message, Update) and message.type == "NewMessage":
|
|
51
|
-
return message.new_message.sender_type in ["User", "Bot"]
|
|
52
|
-
return False
|
|
53
|
-
return filter
|
|
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
|