Rubka 6.6.2__py3-none-any.whl → 7.1.17__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.
rubka/exceptions.py CHANGED
@@ -1,3 +1,37 @@
1
1
  class APIRequestError(Exception):
2
- """Raised when an API request fails."""
2
+ """Base class for all API request errors."""
3
+ def __init__(self, status: str, dev_message: str = None):
4
+ self.status = status
5
+ self.dev_message = dev_message
6
+ msg = f"{self.__class__.__name__}: {status}"
7
+ if dev_message:
8
+ msg += f" | Message : {dev_message}"
9
+ super().__init__(msg)
10
+
11
+
12
+ class InvalidAccessError(APIRequestError):
13
+ """Raised when access is invalid."""
14
+
15
+ class InvalidTokenError(Exception):
3
16
  pass
17
+
18
+ class InvalidInputError(APIRequestError):
19
+ """Raised when input is invalid."""
20
+
21
+
22
+ class TooRequestError(APIRequestError):
23
+ """Raised when too many requests are made."""
24
+
25
+
26
+ def raise_for_status(response: dict):
27
+ status = response.get("status")
28
+ dev_message = response.get("dev_message")
29
+
30
+ if status == "INVALID_ACCESS":
31
+ raise InvalidAccessError(status, dev_message)
32
+ elif status == "INVALID_INPUT":
33
+ raise InvalidInputError(status, dev_message)
34
+ elif status == "TOO_REQUEST":
35
+ raise TooRequestError(status, dev_message)
36
+ elif status != "OK":
37
+ raise APIRequestError(status, dev_message)
rubka/filters.py CHANGED
@@ -110,6 +110,9 @@ def text_length(min_len: int = 0, max_len: int = None):
110
110
  def text_regex(pattern: str):
111
111
  regex = re.compile(pattern)
112
112
  return Filter(lambda m: getattr(m, "text", "") and regex.search(m.text))
113
+ def regex(pattern: str):
114
+ regex = re.compile(pattern)
115
+ return Filter(lambda m: getattr(m, "text", "") and regex.search(m.text))
113
116
  def text_startswith(prefix: str):
114
117
  return Filter(lambda m: getattr(m, "text", "").startswith(prefix) if getattr(m, "text", None) else False)
115
118
  def text_endswith(suffix: str):
@@ -149,6 +152,19 @@ def sticker_id_is(sid: str):
149
152
  return Filter(lambda m: m.sticker and getattr(m.sticker, "sticker_id", None) == sid)
150
153
  def sticker_emoji_is(emoji: str):
151
154
  return Filter(lambda m: m.sticker and getattr(m.sticker, "emoji", None) == emoji)
155
+ is_bold = Filter(lambda m: getattr(m, "is_bold", False))
156
+ is_italic = Filter(lambda m: getattr(m, "is_italic", False))
157
+ is_strike = Filter(lambda m: getattr(m, "is_strike", False))
158
+ is_underline = Filter(lambda m: getattr(m, "is_underline", False))
159
+ is_quote = Filter(lambda m: getattr(m, "is_quote", False))
160
+ is_spoiler = Filter(lambda m: getattr(m, "is_spoiler", False))
161
+ is_pre = Filter(lambda m: getattr(m, "is_pre", False))
162
+ is_mono = Filter(lambda m: getattr(m, "is_mono", False))
163
+ is_link_meta = Filter(lambda m: getattr(m, "is_link_meta", False))
164
+ has_metadata = Filter(lambda m: getattr(m, "has_metadata", False))
165
+ meta_links_contain = lambda keyword: Filter(lambda m: any(keyword in link for link in getattr(m, "meta_links", [])))
166
+ meta_link_positions_contain = lambda keyword: Filter(lambda m: any(keyword in link.get("url", "") for link in getattr(m, "meta_link_positions", [])))
167
+ meta_types_include = lambda types: Filter(lambda m: any(t in getattr(m, "meta_types", []) for t in types))
152
168
  def poll_question_contains(keyword: str):
153
169
  return Filter(lambda m: m.poll and keyword in getattr(m.poll, "question", ""))
154
170
  def poll_option_count(min_options: int = 1, max_options: int = None):