RubigramClient 1.5.5__tar.gz → 1.5.7__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.5.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", "you_endpoint_url")
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", "Simple", "Button 1"),
55
- Button("2", "Simple", "Button 2")
54
+ Button("1", "Button 1"),
55
+ Button("2", "Button 2")
56
56
  ]
57
57
  )
58
58
  ]
@@ -11,7 +11,7 @@ pip install RubigramClient
11
11
  from rubigram import Client, filters
12
12
  from rubigram.models import Update
13
13
 
14
- bot = Client("your_bot_token", "you_endpoint_url")
14
+ bot = Client("your_bot_token")
15
15
 
16
16
  @bot.on_message(filters.command("start") & filters.private)
17
17
  async def start_handler(client, message: Update):
@@ -35,8 +35,8 @@ async def start(_, message: Update):
35
35
  rows=[
36
36
  KeypadRow(
37
37
  buttons=[
38
- Button("1", "Simple", "Button 1"),
39
- Button("2", "Simple", "Button 2")
38
+ Button("1", "Button 1"),
39
+ Button("2", "Button 2")
40
40
  ]
41
41
  )
42
42
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RubigramClient
3
- Version: 1.5.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", "you_endpoint_url")
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", "Simple", "Button 1"),
55
- Button("2", "Simple", "Button 2")
54
+ Button("1", "Button 1"),
55
+ Button("2", "Button 2")
56
56
  ]
57
57
  )
58
58
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "RubigramClient"
3
- version = "1.5.5"
3
+ version = "1.5.7"
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,115 @@
1
+ from typing import Optional, Callable, Literal, Union
2
+ from rubigram.models import Update, InlineMessage
3
+ from rubigram.method import Method
4
+ from rubigram.filters import Filter
5
+ from rubigram.state import StateManager
6
+ from datetime import datetime
7
+ from aiohttp import web
8
+ import asyncio
9
+
10
+
11
+ class Client(Method):
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
+ self.token = token
20
+ self.endpoint = endpoint
21
+ self.host = host
22
+ self.port = port
23
+ self.offset_id = None
24
+ self.MESSAGE_HANDLER = []
25
+ self.INLINE_HANDLER = []
26
+ self.state = StateManager()
27
+ super().__init__(token)
28
+
29
+ def create_handler(self, type: Literal["message", "inline"], filters: Optional[Filter] = None):
30
+ def decorator(func: Callable) -> Callable:
31
+ async def wrapper(client: Client, update: Update):
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)
37
+ return func
38
+ return decorator
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
48
+ for handler in handlers:
49
+ matched = await handler(self, update)
50
+ if matched:
51
+ return
52
+
53
+ async def updater(self, data: dict):
54
+ if "inline_message" in data:
55
+ event = InlineMessage.from_dict(data["inline_message"])
56
+ type = "inline"
57
+ elif "update" in data:
58
+ event = Update.from_dict(data["update"])
59
+ type = "message"
60
+ else: return
61
+ event.client = self
62
+ await self.dispatch(event, type)
63
+
64
+ async def set_endpoints(self):
65
+ endpoint_type = ["ReceiveUpdate", "ReceiveInlineMessage"]
66
+ if self.endpoint:
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
+
106
+ def run(self):
107
+ if self.endpoint:
108
+ app = web.Application()
109
+ app.router.add_post("/ReceiveUpdate", self.create_request_handler())
110
+ app.router.add_post("/ReceiveInlineMessage", self.create_request_handler())
111
+ web.run_app(app, host=self.host, port=self.port)
112
+ else:
113
+ try:
114
+ asyncio.run(self.runner())
115
+ except:pass
@@ -0,0 +1,180 @@
1
+ from rubigram.models import Update, InlineMessage
2
+ from typing import Union
3
+ import re
4
+
5
+
6
+
7
+ class Filter:
8
+ def __init__(self, func):
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)
23
+
24
+
25
+
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)
108
+
109
+
110
+ class state(Filter):
111
+ def __init__(self, states: Union[str, list[str]]):
112
+ self.states = states
113
+ super().__init__(self.filter)
114
+
115
+ async def filter(self, update: Union[Update, InlineMessage]):
116
+ states = self.states if isinstance(self.states, list) else [self.states]
117
+ user = await update.client.state.get_state(update.chat_id)
118
+ return user.lower() in states if user else False
119
+
120
+
121
+ class command(Filter):
122
+ def __init__(self, cmd: Union[str, list[str]], prefix: str = "/"):
123
+ self.cmd = cmd
124
+ self.prefix = prefix
125
+ super().__init__(self.filter)
126
+
127
+ async def filter(self, update: Update):
128
+ commands = self.cmd if isinstance(self.cmd, list) else [self.cmd]
129
+ text = ""
130
+ if isinstance(update, Update):
131
+ if update.type == "NewMessage":
132
+ text = update.new_message.text
133
+ elif update.type == "UpdatedMessage":
134
+ text = update.updated_message.text
135
+ if text:
136
+ for cmd in commands:
137
+ if text.lower().startswith(self.prefix + cmd.lower()):
138
+ return True
139
+ return False
140
+
141
+
142
+ class regex(Filter):
143
+ def __init__(self, pattern: str):
144
+ self.pattern = pattern
145
+ super().__init__(self.filter)
146
+
147
+ async def filter(self, update: Union[Update, InlineMessage]):
148
+ text = ""
149
+ if isinstance(update, Update):
150
+ if update.type == "NewMessage":
151
+ text = getattr(update.new_message, "text", "")
152
+ elif update.type == "UpdatedMessage":
153
+ text = getattr(update.updated_message, "text", "")
154
+ elif isinstance(update, InlineMessage):
155
+ text = getattr(update, "text", "")
156
+
157
+ if text:
158
+ return bool(re.search(self.pattern, text))
159
+ return False
160
+
161
+
162
+ class chat(Filter):
163
+ def __init__(self, chat_id: Union[str, list[str]]):
164
+ self.chat_id = chat_id
165
+ super().__init__(self.filter)
166
+
167
+ async def filter(self, update: Union[Update, InlineMessage]):
168
+ chat_ids = self.chat_id if isinstance(self.chat_id, list) else [self.chat_id]
169
+ return update.chat_id in chat_ids
170
+
171
+
172
+ class button(Filter):
173
+ def __init__(self, button_id: Union[str, list[str]]):
174
+ self.button_id = button_id
175
+ super().__init__(self.filter)
176
+
177
+ async def filter(self, update: InlineMessage):
178
+ if isinstance(update, InlineMessage):
179
+ button_ids = self.button_id if isinstance(self.button_id, list) else [self.button_id]
180
+ return update.aux_data.button_id in button_ids
@@ -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"])
@@ -3,7 +3,6 @@ from typing import Any, Optional
3
3
  import aiofiles, re, os
4
4
 
5
5
 
6
-
7
6
  class Network:
8
7
  def __init__(self, token: str) -> None:
9
8
  self.token: str = token
@@ -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,159 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Optional, Callable, Literal
3
- from aiohttp import web
4
- from functools import wraps
5
- from rubigram.models import Update, InlineMessage
6
- from rubigram.method import Method
7
- from rubigram.filters import Filter
8
- from rubigram.state import StateManager
9
- from datetime import datetime
10
- import asyncio
11
- import logging
12
-
13
-
14
- logger = logging.getLogger(__name__)
15
-
16
-
17
- class Client(Method):
18
- def __init__(self, token: str, endpoint: Optional[str] = None, host: str = "0.0.0.0", port: int = 8000):
19
- self.token = token
20
- self.endpoint = endpoint
21
- self.host = host
22
- self.port = port
23
- self.offset_id = None
24
- self.state = StateManager()
25
- self.routes = web.RouteTableDef()
26
- self.message_handlers = []
27
- self.inline_handlers = []
28
- super().__init__(token)
29
-
30
- def on_message(self, *filters: Filter):
31
- def decorator(func: Callable) -> Callable:
32
- @wraps(func)
33
- async def wrapper(client: Client, update: Update):
34
- try:
35
- combined_filter = filters[0] if filters else None
36
- for filter in filters[1:]:
37
- combined_filter = combined_filter & filter
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)
47
- return func
48
- return decorator
49
-
50
- def on_inline_message(self, *filters: Filter):
51
- def decorator(func: Callable) -> Callable:
52
- @wraps(func)
53
- async def wrapper(client: Client, update: InlineMessage):
54
- try:
55
- combined_filter = filters[0] if filters else None
56
- for filter in filters[1:]:
57
- combined_filter = combined_filter & filter
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
72
- for handler in handlers:
73
- try:
74
- matched = await handler(self, update)
75
- if matched:
76
- return
77
- except Exception as error:
78
- logger.exception(f"Dispatch Error in handler [ {handler.__name__} ] : {error}")
79
-
80
- async def updater(self, data: dict):
81
- if "inline_message" in data:
82
- event = InlineMessage.from_dict(data.get("inline_message", {}))
83
- event.client = self
84
- await self.dispatch(event, "inline_message")
85
- elif "update" in data:
86
- event = Update.from_dict(data.get("update", {}))
87
- event.client = self
88
- await self.dispatch(event)
89
- else:
90
- return
91
-
92
- async def set_endpoints(self):
93
- if self.endpoint:
94
- await self.update_bot_endpoint(f"{self.endpoint}/ReceiveUpdate", "ReceiveUpdate")
95
- await self.update_bot_endpoint(f"{self.endpoint}/ReceiveInlineMessage", "ReceiveInlineMessage")
96
-
97
- def run(self):
98
- if self.endpoint:
99
- @self.routes.post("/ReceiveUpdate")
100
- async def receive_update(request: web.Request):
101
- data = await request.json()
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)
125
- web.run_app(app, host=self.host, port=self.port)
126
-
127
- else:
128
- async def polling():
129
- try:
130
- await self.state.start()
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())
@@ -1,189 +0,0 @@
1
- from rubigram.models import Update, InlineMessage
2
- from typing import Union, Callable, Awaitable
3
- import re
4
-
5
-
6
- class Filter:
7
- def __init__(self, func: Callable[[Union[Update, InlineMessage]], Union[bool, Awaitable[bool]]]):
8
- self.func = func
9
-
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
-
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
-
21
- def __or__(self, other: "Filter"):
22
- async def combined(update):
23
- return await self(update) or await other(update)
24
- return Filter(combined)
25
-
26
-
27
- class state(Filter):
28
- def __init__(self, states: Union[str, list[str]]):
29
- self.states = states
30
- super().__init__(self.filter)
31
-
32
- async def filter(self, update: Update):
33
- states = self.states if isinstance(self.states, list) else [self.states]
34
- if isinstance(update, Update):
35
- user = await update.client.state.get_state(update.chat_id)
36
- return user.lower() in states if user else False
37
- return False
38
-
39
-
40
- class command(Filter):
41
- def __init__(self, cmd: Union[str, list[str]], prefix: str = "/"):
42
- self.cmd = cmd
43
- self.prefix = prefix
44
- super().__init__(self.filter)
45
-
46
- def filter(self, update: Update):
47
- commands = self.cmd if isinstance(self.cmd, list) else [self.cmd]
48
- text = ""
49
- if isinstance(update, Update):
50
- if update.type == "NewMessage":
51
- text = update.new_message.text
52
- elif update.type == "UpdatedMessage":
53
- text = update.updated_message.text
54
- if text:
55
- for cmd in commands:
56
- if text.lower().startswith(self.prefix + cmd.lower()):
57
- return True
58
- return False
59
-
60
-
61
- class regex(Filter):
62
- def __init__(self, pattern: str):
63
- self.pattern = pattern
64
- super().__init__(self.filter)
65
-
66
- def filter(self, update: Union[Update, InlineMessage]):
67
- text = ""
68
- if isinstance(update, Update):
69
- if update.type == "NewMessage":
70
- text = getattr(update.new_message, "text", "")
71
- elif update.type == "UpdatedMessage":
72
- text = getattr(update.updated_message, "text", "")
73
- elif isinstance(update, InlineMessage):
74
- text = getattr(update, "text", "")
75
-
76
- if text:
77
- return bool(re.search(self.pattern, text))
78
- return False
79
-
80
-
81
- class chat(Filter):
82
- def __init__(self, chat_id: Union[str, list[str]]):
83
- self.chat_id = chat_id
84
- super().__init__(self.filter)
85
-
86
- def filter(self, update: Union[Update, InlineMessage]):
87
- chat_ids = self.chat_id if isinstance(self.chat_id, list) else [self.chat_id]
88
- return update.chat_id in chat_ids
89
-
90
-
91
- class button(Filter):
92
- def __init__(self, button_id: Union[str, list[str]]):
93
- self.button_id = button_id
94
- super().__init__(self.filter)
95
-
96
- def filter(self, update: InlineMessage):
97
- if isinstance(update, InlineMessage):
98
- 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)
File without changes
File without changes