RubigramClient 1.5.5__py3-none-any.whl → 1.5.7__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.
Potentially problematic release.
This version of RubigramClient might be problematic. Click here for more details.
- rubigram/client.py +85 -129
- rubigram/filters.py +106 -115
- rubigram/method.py +0 -2
- rubigram/network.py +0 -1
- rubigram/state.py +1 -3
- {rubigramclient-1.5.5.dist-info → rubigramclient-1.5.7.dist-info}/METADATA +4 -4
- rubigramclient-1.5.7.dist-info/RECORD +12 -0
- rubigramclient-1.5.5.dist-info/RECORD +0 -12
- {rubigramclient-1.5.5.dist-info → rubigramclient-1.5.7.dist-info}/WHEEL +0 -0
- {rubigramclient-1.5.5.dist-info → rubigramclient-1.5.7.dist-info}/licenses/LICENSE +0 -0
- {rubigramclient-1.5.5.dist-info → rubigramclient-1.5.7.dist-info}/top_level.txt +0 -0
rubigram/client.py
CHANGED
|
@@ -1,159 +1,115 @@
|
|
|
1
|
-
from
|
|
2
|
-
from typing import Optional, Callable, Literal
|
|
3
|
-
from aiohttp import web
|
|
4
|
-
from functools import wraps
|
|
1
|
+
from typing import Optional, Callable, Literal, Union
|
|
5
2
|
from rubigram.models import Update, InlineMessage
|
|
6
3
|
from rubigram.method import Method
|
|
7
4
|
from rubigram.filters import Filter
|
|
8
5
|
from rubigram.state import StateManager
|
|
9
6
|
from datetime import datetime
|
|
7
|
+
from aiohttp import web
|
|
10
8
|
import asyncio
|
|
11
|
-
import logging
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
logger = logging.getLogger(__name__)
|
|
15
9
|
|
|
16
10
|
|
|
17
11
|
class Client(Method):
|
|
18
|
-
def __init__(
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
token: str,
|
|
15
|
+
endpoint: Optional[str] = None,
|
|
16
|
+
host: str = "0.0.0.0",
|
|
17
|
+
port: int = 8000
|
|
18
|
+
):
|
|
19
19
|
self.token = token
|
|
20
20
|
self.endpoint = endpoint
|
|
21
21
|
self.host = host
|
|
22
22
|
self.port = port
|
|
23
23
|
self.offset_id = None
|
|
24
|
+
self.MESSAGE_HANDLER = []
|
|
25
|
+
self.INLINE_HANDLER = []
|
|
24
26
|
self.state = StateManager()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
super().__init__(token)
|
|
29
|
-
|
|
30
|
-
def on_message(self, *filters: Filter):
|
|
27
|
+
super().__init__(token)
|
|
28
|
+
|
|
29
|
+
def create_handler(self, type: Literal["message", "inline"], filters: Optional[Filter] = None):
|
|
31
30
|
def decorator(func: Callable) -> Callable:
|
|
32
|
-
@wraps(func)
|
|
33
31
|
async def wrapper(client: Client, update: Update):
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if combined_filter is None or await combined_filter(update):
|
|
40
|
-
await func(client, update)
|
|
41
|
-
return True
|
|
42
|
-
return False
|
|
43
|
-
except Exception as error:
|
|
44
|
-
logger.exception("Error {}: {}".format(func.__name__, error))
|
|
45
|
-
|
|
46
|
-
self.message_handlers.append(wrapper)
|
|
32
|
+
if filters is None or await filters(update):
|
|
33
|
+
await func(client, update)
|
|
34
|
+
return True
|
|
35
|
+
return False
|
|
36
|
+
self.MESSAGE_HANDLER.append(wrapper) if type == "message" else self.INLINE_HANDLER.append(wrapper)
|
|
47
37
|
return func
|
|
48
38
|
return decorator
|
|
49
|
-
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if combined_filter is None or await combined_filter(update):
|
|
60
|
-
await func(client, update)
|
|
61
|
-
return True
|
|
62
|
-
return False
|
|
63
|
-
except Exception as error:
|
|
64
|
-
logger.exception("Error {}: {}".format(func.__name__, error))
|
|
65
|
-
|
|
66
|
-
self.inline_handlers.append(wrapper)
|
|
67
|
-
return func
|
|
68
|
-
return decorator
|
|
69
|
-
|
|
70
|
-
async def dispatch(self, update: Update, type: Literal["update", "inline_message"] = "update"):
|
|
71
|
-
handlers = self.message_handlers if type == "update" else self.inline_handlers
|
|
39
|
+
|
|
40
|
+
def on_message(self, filters: Optional[Filter] = None):
|
|
41
|
+
return self.create_handler("message", filters)
|
|
42
|
+
|
|
43
|
+
def on_inline_message(self, filters: Optional[Filter] = None):
|
|
44
|
+
return self.create_handler("inline", filters)
|
|
45
|
+
|
|
46
|
+
async def dispatch(self, update: Union[Update, InlineMessage], type: Literal["message", "inline"]):
|
|
47
|
+
handlers = self.MESSAGE_HANDLER if type == "message" else self.INLINE_HANDLER
|
|
72
48
|
for handler in handlers:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
except Exception as error:
|
|
78
|
-
logger.exception(f"Dispatch Error in handler [ {handler.__name__} ] : {error}")
|
|
49
|
+
matched = await handler(self, update)
|
|
50
|
+
if matched:
|
|
51
|
+
return
|
|
79
52
|
|
|
80
53
|
async def updater(self, data: dict):
|
|
81
54
|
if "inline_message" in data:
|
|
82
|
-
event = InlineMessage.from_dict(data
|
|
83
|
-
|
|
84
|
-
await self.dispatch(event, "inline_message")
|
|
55
|
+
event = InlineMessage.from_dict(data["inline_message"])
|
|
56
|
+
type = "inline"
|
|
85
57
|
elif "update" in data:
|
|
86
|
-
event = Update.from_dict(data
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
58
|
+
event = Update.from_dict(data["update"])
|
|
59
|
+
type = "message"
|
|
60
|
+
else: return
|
|
61
|
+
event.client = self
|
|
62
|
+
await self.dispatch(event, type)
|
|
63
|
+
|
|
92
64
|
async def set_endpoints(self):
|
|
65
|
+
endpoint_type = ["ReceiveUpdate", "ReceiveInlineMessage"]
|
|
93
66
|
if self.endpoint:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
67
|
+
for i in endpoint_type:
|
|
68
|
+
await self.update_bot_endpoint(f"{self.endpoint}/{i}", i)
|
|
69
|
+
|
|
70
|
+
async def on_startup(self, app):
|
|
71
|
+
await self.set_endpoints()
|
|
72
|
+
await self.state.start()
|
|
73
|
+
await self.start()
|
|
74
|
+
|
|
75
|
+
async def on_cleanup(self, app):
|
|
76
|
+
await self.state.stop()
|
|
77
|
+
await self.stop()
|
|
78
|
+
|
|
79
|
+
def create_request_handler(self):
|
|
80
|
+
async def wrapper(request: web.Request):
|
|
81
|
+
data = await request.json()
|
|
82
|
+
await self.updater(data)
|
|
83
|
+
return web.json_response({"status": "OK"})
|
|
84
|
+
return wrapper
|
|
85
|
+
|
|
86
|
+
async def runner(self):
|
|
87
|
+
try:
|
|
88
|
+
await self.state.start()
|
|
89
|
+
while True:
|
|
90
|
+
get_updates = await self.get_update(100, self.offset_id)
|
|
91
|
+
if get_updates.updates:
|
|
92
|
+
updates = get_updates.updates
|
|
93
|
+
for update in updates:
|
|
94
|
+
time = int(update.new_message.time) if update.type == "NewMessage" else int(update.updated_message.time) if update.type == "UpdatedMessage" else None
|
|
95
|
+
now = int(datetime.now().timestamp())
|
|
96
|
+
if time and time >= now or time + 2 >= now:
|
|
97
|
+
update.client = self
|
|
98
|
+
await self.dispatch(update, "message")
|
|
99
|
+
self.offset_id = get_updates.next_offset_id
|
|
100
|
+
except Exception as error:
|
|
101
|
+
print(f"ERROR : {error}")
|
|
102
|
+
finally:
|
|
103
|
+
await self.state.stop()
|
|
104
|
+
await self.stop()
|
|
105
|
+
|
|
97
106
|
def run(self):
|
|
98
107
|
if self.endpoint:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
await self.updater(data)
|
|
103
|
-
return web.json_response({"status": "OK"})
|
|
104
|
-
|
|
105
|
-
@self.routes.post("/ReceiveInlineMessage")
|
|
106
|
-
async def receive_inline_message(request: web.Request):
|
|
107
|
-
data = await request.json()
|
|
108
|
-
await self.updater(data)
|
|
109
|
-
return web.json_response({"status": "OK"})
|
|
110
|
-
|
|
111
|
-
app = web.Application()
|
|
112
|
-
app.add_routes(self.routes)
|
|
113
|
-
|
|
114
|
-
async def on_startup(app):
|
|
115
|
-
await self.set_endpoints()
|
|
116
|
-
await self.state.start()
|
|
117
|
-
await self.start()
|
|
118
|
-
|
|
119
|
-
async def on_cleanup(app):
|
|
120
|
-
await self.state.stop()
|
|
121
|
-
await self.stop()
|
|
122
|
-
|
|
123
|
-
app.on_startup.append(on_startup)
|
|
124
|
-
app.on_cleanup.append(on_cleanup)
|
|
108
|
+
app = web.Application()
|
|
109
|
+
app.router.add_post("/ReceiveUpdate", self.create_request_handler())
|
|
110
|
+
app.router.add_post("/ReceiveInlineMessage", self.create_request_handler())
|
|
125
111
|
web.run_app(app, host=self.host, port=self.port)
|
|
126
|
-
|
|
127
112
|
else:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
while True:
|
|
132
|
-
try:
|
|
133
|
-
get_update = await self.get_update(100, self.offset_id)
|
|
134
|
-
if get_update.updates:
|
|
135
|
-
updates = get_update.updates
|
|
136
|
-
for update in updates:
|
|
137
|
-
if update.type == "NewMessage":
|
|
138
|
-
message_time = int(update.new_message.time)
|
|
139
|
-
elif update.type == "UpdatedMessage":
|
|
140
|
-
message_time = int(update.updated_message.time)
|
|
141
|
-
else:continue
|
|
142
|
-
|
|
143
|
-
now = int(datetime.now().timestamp())
|
|
144
|
-
if message_time >= now or message_time + 2 >= now:
|
|
145
|
-
if isinstance(update, Update):
|
|
146
|
-
update.client = self
|
|
147
|
-
await self.dispatch(update)
|
|
148
|
-
|
|
149
|
-
self.offset_id = get_update.next_offset_id
|
|
150
|
-
except Exception as error:
|
|
151
|
-
logger.exception("Polling Error : {}".format(error))
|
|
152
|
-
await asyncio.sleep(1)
|
|
153
|
-
|
|
154
|
-
except:
|
|
155
|
-
pass
|
|
156
|
-
finally:
|
|
157
|
-
await self.state.stop()
|
|
158
|
-
await self.stop()
|
|
159
|
-
asyncio.run(polling())
|
|
113
|
+
try:
|
|
114
|
+
asyncio.run(self.runner())
|
|
115
|
+
except:pass
|
rubigram/filters.py
CHANGED
|
@@ -1,27 +1,110 @@
|
|
|
1
1
|
from rubigram.models import Update, InlineMessage
|
|
2
|
-
from typing import Union
|
|
2
|
+
from typing import Union
|
|
3
3
|
import re
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
class Filter:
|
|
7
|
-
def __init__(self, func
|
|
8
|
+
def __init__(self, func):
|
|
8
9
|
self.func = func
|
|
10
|
+
|
|
11
|
+
async def __call__(self, update: Union[Update, InlineMessage]):
|
|
12
|
+
return await self.func(update)
|
|
13
|
+
|
|
14
|
+
async def __and__(self, other: "Filter"):
|
|
15
|
+
async def filter(update):
|
|
16
|
+
return await self(update) and await other(update)
|
|
17
|
+
return Filter(filter)
|
|
18
|
+
|
|
19
|
+
async def __or__(self, other: "Filter"):
|
|
20
|
+
async def filter(update):
|
|
21
|
+
return await self(update) or await other(update)
|
|
22
|
+
return Filter(filter)
|
|
9
23
|
|
|
10
|
-
async def __call__(self, update: Union[Update, InlineMessage]) -> bool:
|
|
11
|
-
result = self.func(update)
|
|
12
|
-
if isinstance(result, Awaitable):
|
|
13
|
-
return await result
|
|
14
|
-
return result
|
|
15
24
|
|
|
16
|
-
def __and__(self, other: "Filter"):
|
|
17
|
-
async def combined(update):
|
|
18
|
-
return await self(update) and await other(update)
|
|
19
|
-
return Filter(combined)
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
async def TEXT(message: Update):
|
|
27
|
+
if isinstance(message, Update):
|
|
28
|
+
return True if message.new_message and message.new_message.text else False
|
|
29
|
+
return False
|
|
30
|
+
|
|
31
|
+
async def FILE(message: Update):
|
|
32
|
+
if isinstance(message, Update):
|
|
33
|
+
return True if message.new_message and message.new_message.file else False
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
async def LIVE(message: Update):
|
|
37
|
+
if isinstance(message, Update):
|
|
38
|
+
return True if message.new_message and message.new_message.live_location else False
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
async def POLL(message: Update):
|
|
42
|
+
if isinstance(message, Update):
|
|
43
|
+
return True if message.new_message and message.new_message.poll else False
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
async def CONTACT(message: Update):
|
|
47
|
+
if isinstance(message, Update):
|
|
48
|
+
return True if message.new_message and message.new_message.contact_message else False
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
async def STICKER(message: Update):
|
|
52
|
+
if isinstance(message, Update):
|
|
53
|
+
return True if message.new_message and message.new_message.sticker else False
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
async def LOCATION(message: Update):
|
|
57
|
+
if isinstance(message, Update):
|
|
58
|
+
return True if message.new_message and message.new_message.location else False
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
async def FORWARD(message: Update):
|
|
62
|
+
if isinstance(message, Update):
|
|
63
|
+
return True if message.new_message and message.new_message.forwarded_from else False
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
async def EDITED(message: Update):
|
|
67
|
+
if isinstance(message, Update):
|
|
68
|
+
return True if message.updated_message else False
|
|
69
|
+
return False
|
|
70
|
+
|
|
71
|
+
async def PRIVATE(message: Union[Update, InlineMessage]):
|
|
72
|
+
return True if message.chat_id.startswith("b0") else False
|
|
73
|
+
|
|
74
|
+
async def GROUP(message: Union[Update, InlineMessage]):
|
|
75
|
+
return True if message.chat_id.startswith("g0") else False
|
|
76
|
+
|
|
77
|
+
async def CHANNEL(message: Union[Update, InlineMessage]):
|
|
78
|
+
return True if message.chat_id.startswith("c0") else False
|
|
79
|
+
|
|
80
|
+
async def FORWARD_BOT(message: Update):
|
|
81
|
+
if isinstance(message, Update) and message.new_message:
|
|
82
|
+
return True if message.new_message.forwarded_from and message.new_message.forwarded_from.type_from == "Bot" else False
|
|
83
|
+
|
|
84
|
+
async def FORWARD_USER(message: Update):
|
|
85
|
+
if isinstance(message, Update) and message.new_message:
|
|
86
|
+
return True if message.new_message.forwarded_from and message.new_message.forwarded_from.type_from == "User" else False
|
|
87
|
+
|
|
88
|
+
async def FORWARD_CHANNEL(message: Update):
|
|
89
|
+
if isinstance(message, Update) and message.new_message:
|
|
90
|
+
return True if message.new_message.forwarded_from and message.new_message.forwarded_from.type_from == "Channel" else False
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
text = Filter(TEXT)
|
|
94
|
+
file = Filter(FILE)
|
|
95
|
+
live = Filter(LIVE)
|
|
96
|
+
poll = Filter(POLL)
|
|
97
|
+
contact = Filter(CONTACT)
|
|
98
|
+
sticker = Filter(STICKER)
|
|
99
|
+
location = Filter(LOCATION)
|
|
100
|
+
forward = Filter(FORWARD)
|
|
101
|
+
edited = Filter(EDITED)
|
|
102
|
+
private = Filter(PRIVATE)
|
|
103
|
+
group = Filter(GROUP)
|
|
104
|
+
channel = Filter(CHANNEL)
|
|
105
|
+
forward_bot = Filter(FORWARD_BOT)
|
|
106
|
+
forward_user = Filter(FORWARD_USER)
|
|
107
|
+
forward_channel = Filter(FORWARD_CHANNEL)
|
|
25
108
|
|
|
26
109
|
|
|
27
110
|
class state(Filter):
|
|
@@ -29,12 +112,10 @@ class state(Filter):
|
|
|
29
112
|
self.states = states
|
|
30
113
|
super().__init__(self.filter)
|
|
31
114
|
|
|
32
|
-
async def filter(self, update: Update):
|
|
115
|
+
async def filter(self, update: Union[Update, InlineMessage]):
|
|
33
116
|
states = self.states if isinstance(self.states, list) else [self.states]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return user.lower() in states if user else False
|
|
37
|
-
return False
|
|
117
|
+
user = await update.client.state.get_state(update.chat_id)
|
|
118
|
+
return user.lower() in states if user else False
|
|
38
119
|
|
|
39
120
|
|
|
40
121
|
class command(Filter):
|
|
@@ -43,7 +124,7 @@ class command(Filter):
|
|
|
43
124
|
self.prefix = prefix
|
|
44
125
|
super().__init__(self.filter)
|
|
45
126
|
|
|
46
|
-
def filter(self, update: Update):
|
|
127
|
+
async def filter(self, update: Update):
|
|
47
128
|
commands = self.cmd if isinstance(self.cmd, list) else [self.cmd]
|
|
48
129
|
text = ""
|
|
49
130
|
if isinstance(update, Update):
|
|
@@ -63,7 +144,7 @@ class regex(Filter):
|
|
|
63
144
|
self.pattern = pattern
|
|
64
145
|
super().__init__(self.filter)
|
|
65
146
|
|
|
66
|
-
def filter(self, update: Union[Update, InlineMessage]):
|
|
147
|
+
async def filter(self, update: Union[Update, InlineMessage]):
|
|
67
148
|
text = ""
|
|
68
149
|
if isinstance(update, Update):
|
|
69
150
|
if update.type == "NewMessage":
|
|
@@ -83,7 +164,7 @@ class chat(Filter):
|
|
|
83
164
|
self.chat_id = chat_id
|
|
84
165
|
super().__init__(self.filter)
|
|
85
166
|
|
|
86
|
-
def filter(self, update: Union[Update, InlineMessage]):
|
|
167
|
+
async def filter(self, update: Union[Update, InlineMessage]):
|
|
87
168
|
chat_ids = self.chat_id if isinstance(self.chat_id, list) else [self.chat_id]
|
|
88
169
|
return update.chat_id in chat_ids
|
|
89
170
|
|
|
@@ -93,97 +174,7 @@ class button(Filter):
|
|
|
93
174
|
self.button_id = button_id
|
|
94
175
|
super().__init__(self.filter)
|
|
95
176
|
|
|
96
|
-
def filter(self, update: InlineMessage):
|
|
177
|
+
async def filter(self, update: InlineMessage):
|
|
97
178
|
if isinstance(update, InlineMessage):
|
|
98
179
|
button_ids = self.button_id if isinstance(self.button_id, list) else [self.button_id]
|
|
99
|
-
return update.aux_data.button_id in button_ids
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def TEXT(update: Update):
|
|
104
|
-
return bool(update.new_message and getattr(update.new_message, "text", None))
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def FILE(update: Update):
|
|
108
|
-
return bool(update.new_message and getattr(update.new_message, "file", None))
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def LIVE(update: Update):
|
|
112
|
-
return bool(update.new_message and getattr(update.new_message, "live_location", None))
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def POLL(update: Update):
|
|
116
|
-
return bool(update.new_message and getattr(update.new_message, "poll", None))
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def CONTACT(update: Update):
|
|
120
|
-
return bool(update.new_message and getattr(update.new_message, "contact_message", None))
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def STICKER(update: Update):
|
|
124
|
-
return bool(update.new_message and getattr(update.new_message, "sticker", None))
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def LOCATION(update: Update):
|
|
128
|
-
return bool(update.new_message and getattr(update.new_message, "location", None))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def FORWARD(update: Update):
|
|
132
|
-
return bool(update.new_message and getattr(update.new_message, "forwarded_from", None))
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def EDITED(update: Update):
|
|
136
|
-
if isinstance(update, Update) and update.type == "UpdatedMessage":
|
|
137
|
-
return update.updated_message.is_edited
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def PRIVATE(update: Update):
|
|
141
|
-
if isinstance(update, Update) and update.type == "NewMessage":
|
|
142
|
-
return update.new_message.sender_type in ["User", "Bot"]
|
|
143
|
-
return False
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def FORWARD_BOT(update: Update):
|
|
147
|
-
if isinstance(update, Update) and update.type == "NewMessage" and update.new_message.forwarded_from:
|
|
148
|
-
return update.new_message.forwarded_from.type_from == "Bot"
|
|
149
|
-
return False
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def FORWARD_USER(update: Update):
|
|
153
|
-
if isinstance(update, Update) and update.type == "NewMessage" and update.new_message.forwarded_from:
|
|
154
|
-
return update.new_message.forwarded_from.type_from == "User"
|
|
155
|
-
return False
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def FORWARD_CHANNEL(update: Update):
|
|
159
|
-
if isinstance(update, Update) and update.type == "NewMessage" and update.new_message.forwarded_from:
|
|
160
|
-
return update.new_message.forwarded_from.type_from == "Channel"
|
|
161
|
-
return False
|
|
162
|
-
|
|
163
|
-
def GROUP(update: Update):
|
|
164
|
-
if isinstance(update, Update):
|
|
165
|
-
return update.chat_id.startswith("g0")
|
|
166
|
-
return False
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
def CHANNEL(update: Update):
|
|
170
|
-
if isinstance(update, Update):
|
|
171
|
-
return update.chat_id.startswith("c0")
|
|
172
|
-
return False
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
text = Filter(TEXT)
|
|
176
|
-
file = Filter(FILE)
|
|
177
|
-
live = Filter(LIVE)
|
|
178
|
-
poll = Filter(POLL)
|
|
179
|
-
group = Filter(GROUP)
|
|
180
|
-
channel = Filter(CHANNEL)
|
|
181
|
-
edited = Filter(EDITED)
|
|
182
|
-
contact = Filter(CONTACT)
|
|
183
|
-
sticker = Filter(STICKER)
|
|
184
|
-
location = Filter(LOCATION)
|
|
185
|
-
forward = Filter(FORWARD)
|
|
186
|
-
private = Filter(PRIVATE)
|
|
187
|
-
forward_bot = Filter(FORWARD_BOT)
|
|
188
|
-
forward_user = Filter(FORWARD_USER)
|
|
189
|
-
forward_channel = Filter(FORWARD_CHANNEL)
|
|
180
|
+
return update.aux_data.button_id in button_ids
|
rubigram/method.py
CHANGED
|
@@ -3,12 +3,10 @@ from typing import Literal, Optional
|
|
|
3
3
|
from rubigram.models import Bot, Chat, Keypad, MessageId, Updates
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
class Method(Network):
|
|
8
7
|
def __init__(self, token: str):
|
|
9
8
|
super().__init__(token)
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
async def get_me(self) -> "Bot":
|
|
13
11
|
response = await self.request("getMe", {})
|
|
14
12
|
return Bot.from_dict(response["bot"])
|
rubigram/network.py
CHANGED
rubigram/state.py
CHANGED
|
@@ -62,7 +62,6 @@ class ManageDB:
|
|
|
62
62
|
data = await cursor.fetchall()
|
|
63
63
|
return {k: v for k, v in data} if data else {}
|
|
64
64
|
|
|
65
|
-
|
|
66
65
|
|
|
67
66
|
async def remove_data(self, user_id: str, key: str = None):
|
|
68
67
|
await self.connect()
|
|
@@ -71,8 +70,7 @@ class ManageDB:
|
|
|
71
70
|
else:
|
|
72
71
|
await self.connection.execute("DELETE FROM user_data WHERE user_id = ?", (user_id,))
|
|
73
72
|
await self.connection.commit()
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
|
|
76
74
|
|
|
77
75
|
class StateManager:
|
|
78
76
|
def __init__(self):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: RubigramClient
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.7
|
|
4
4
|
Summary: A simple and flexible Python library for building advanced Rubika bots with powerful message handling, inline buttons, and custom filters.
|
|
5
5
|
Author-email: Javad RZ <Javad.Py1385@gmail.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -27,7 +27,7 @@ pip install RubigramClient
|
|
|
27
27
|
from rubigram import Client, filters
|
|
28
28
|
from rubigram.models import Update
|
|
29
29
|
|
|
30
|
-
bot = Client("your_bot_token"
|
|
30
|
+
bot = Client("your_bot_token")
|
|
31
31
|
|
|
32
32
|
@bot.on_message(filters.command("start") & filters.private)
|
|
33
33
|
async def start_handler(client, message: Update):
|
|
@@ -51,8 +51,8 @@ async def start(_, message: Update):
|
|
|
51
51
|
rows=[
|
|
52
52
|
KeypadRow(
|
|
53
53
|
buttons=[
|
|
54
|
-
Button("1", "
|
|
55
|
-
Button("2", "
|
|
54
|
+
Button("1", "Button 1"),
|
|
55
|
+
Button("2", "Button 2")
|
|
56
56
|
]
|
|
57
57
|
)
|
|
58
58
|
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
rubigram/__init__.py,sha256=IWNCN7oDaIBzaP54cGiA-4Sa31ehGBlqj0SuqhNQVgU,162
|
|
2
|
+
rubigram/client.py,sha256=ET5L9Lzj0qbUO4IYZ647q_sXrLeFpLqH-ySU2zUISN0,4466
|
|
3
|
+
rubigram/filters.py,sha256=T1As4tVr4EsZAun4wJBf3tgpQ-1lbuF8QwRsLryFKOo,6430
|
|
4
|
+
rubigram/method.py,sha256=VfhxOoYQmNZjvAodXWqnSIin1vpc6478bj5_3IAxZP0,10609
|
|
5
|
+
rubigram/models.py,sha256=42WK68VPKqgKCy14jrRyoP_XRsZ-04S5rUbdpO_UfaQ,13831
|
|
6
|
+
rubigram/network.py,sha256=6_kLFg9Uw_MHwxoDff53HYtPD-PSTqqWC3qtgbZbmfY,2362
|
|
7
|
+
rubigram/state.py,sha256=jpr0ovuBk9Cnvj5JsPbE2tgv0KrEkrrv-_THHTxlYYw,4065
|
|
8
|
+
rubigramclient-1.5.7.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
rubigramclient-1.5.7.dist-info/METADATA,sha256=CfJ5mlhnpH32vh37EKhldGekqQVoIPGVhv2p7VR57e8,2280
|
|
10
|
+
rubigramclient-1.5.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
rubigramclient-1.5.7.dist-info/top_level.txt,sha256=Mhg5HfkL6rLec5sI4ClGmwoqYUANAZUz8sVa1sT_cas,9
|
|
12
|
+
rubigramclient-1.5.7.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
rubigram/__init__.py,sha256=IWNCN7oDaIBzaP54cGiA-4Sa31ehGBlqj0SuqhNQVgU,162
|
|
2
|
-
rubigram/client.py,sha256=GDdlGzCeSwBAzEP3Truat1g2il5l3nPWbmFw2hRhYoc,6511
|
|
3
|
-
rubigram/filters.py,sha256=EyrcKbEIwqDwf18lucusUoZYP0KIkaKkZc7PnaA0GcU,6218
|
|
4
|
-
rubigram/method.py,sha256=PUP9DTX6XpWVbersiLv12GdlwOFaXzrgx582nJd4i_I,10613
|
|
5
|
-
rubigram/models.py,sha256=42WK68VPKqgKCy14jrRyoP_XRsZ-04S5rUbdpO_UfaQ,13831
|
|
6
|
-
rubigram/network.py,sha256=ErrGwtKpMHN1Dq4IvPHSrMOcDN-TFjUk1CfU-2EuPAY,2364
|
|
7
|
-
rubigram/state.py,sha256=oRk5xXuO4k-cK0qRI2Rz2mdoivJkANlo20zQAkdqFSY,4081
|
|
8
|
-
rubigramclient-1.5.5.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
rubigramclient-1.5.5.dist-info/METADATA,sha256=Abido_4uhjv1iK3kIoUv49ulhGE8DmKfgzfRPoVcED8,2320
|
|
10
|
-
rubigramclient-1.5.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
-
rubigramclient-1.5.5.dist-info/top_level.txt,sha256=Mhg5HfkL6rLec5sI4ClGmwoqYUANAZUz8sVa1sT_cas,9
|
|
12
|
-
rubigramclient-1.5.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|