Rubka 1.5.0__py3-none-any.whl → 1.6.0__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/api.py CHANGED
@@ -3,7 +3,7 @@ from typing import List, Optional, Dict, Any, Literal
3
3
  from .exceptions import APIRequestError
4
4
  from .logger import logger
5
5
  from typing import Callable
6
- from .context import MessageContext
6
+ from .context import Message
7
7
  API_URL = "https://botapi.rubika.ir/v3"
8
8
 
9
9
  class Robot:
@@ -34,8 +34,8 @@ class Robot:
34
34
  def get_me(self) -> Dict[str, Any]:
35
35
  """Get info about the bot itself."""
36
36
  return self._post("getMe", {})
37
- def on_message(self, filters: Optional[Callable[[MessageContext], bool]] = None, commands: Optional[List[str]] = None):
38
- def decorator(func: Callable[[Any, MessageContext], None]):
37
+ def on_message(self, filters: Optional[Callable[[Message], bool]] = None, commands: Optional[List[str]] = None):
38
+ def decorator(func: Callable[[Any, Message], None]):
39
39
  self._message_handler = {
40
40
  "func": func,
41
41
  "filters": filters,
@@ -57,7 +57,8 @@ class Robot:
57
57
 
58
58
  if self._message_handler:
59
59
  handler = self._message_handler
60
- context = MessageContext(self, chat_id, message_id, sender_id, text)
60
+ context = Message(bot=self,chat_id=chat_id,message_id=message_id,sender_id=sender_id,text=text,raw_data=msg)
61
+
61
62
 
62
63
 
63
64
  if handler["commands"]:
rubka/context.py CHANGED
@@ -1,14 +1,209 @@
1
- from typing import Any, Dict, List
1
+ from typing import Any, Dict, List,Optional
2
2
 
3
+ class File:
4
+ def __init__(self, data: dict):
5
+ self.file_id: str = data.get("file_id")
6
+ self.file_name: str = data.get("file_name")
7
+ self.size: str = data.get("size")
3
8
 
9
+
10
+ class Sticker:
11
+ def __init__(self, data: dict):
12
+ self.sticker_id: str = data.get("sticker_id")
13
+ self.emoji_character: str = data.get("emoji_character")
14
+ self.file = File(data.get("file", {}))
15
+
16
+
17
+ # =========================
18
+ # Poll
19
+ # =========================
20
+ class PollStatus:
21
+ def __init__(self, data: dict):
22
+ self.state: str = data.get("state")
23
+ self.selection_index: int = data.get("selection_index")
24
+ self.percent_vote_options: List[int] = data.get("percent_vote_options", [])
25
+ self.total_vote: int = data.get("total_vote")
26
+ self.show_total_votes: bool = data.get("show_total_votes")
27
+
28
+
29
+ class Poll:
30
+ def __init__(self, data: dict):
31
+ self.question: str = data.get("question")
32
+ self.options: List[str] = data.get("options", [])
33
+ self.poll_status = PollStatus(data.get("poll_status", {}))
34
+
35
+
36
+ # =========================
37
+ # Location & Contact & ForwardedFrom
38
+ # =========================
39
+ class Location:
40
+ def __init__(self, data: dict):
41
+ self.latitude: str = data.get("latitude")
42
+ self.longitude: str = data.get("longitude")
43
+
44
+
45
+ class LiveLocation:
46
+ def __init__(self, data: dict):
47
+ self.start_time: str = data.get("start_time")
48
+ self.live_period: int = data.get("live_period")
49
+ self.current_location = Location(data.get("current_location", {}))
50
+ self.user_id: str = data.get("user_id")
51
+ self.status: str = data.get("status")
52
+ self.last_update_time: str = data.get("last_update_time")
53
+
54
+
55
+ class ContactMessage:
56
+ def __init__(self, data: dict):
57
+ self.phone_number: str = data.get("phone_number")
58
+ self.first_name: str = data.get("first_name")
59
+ self.last_name: str = data.get("last_name")
60
+
61
+
62
+ class ForwardedFrom:
63
+ def __init__(self, data: dict):
64
+ self.type_from: str = data.get("type_from")
65
+ self.message_id: str = data.get("message_id")
66
+ self.from_chat_id: str = data.get("from_chat_id")
67
+ self.from_sender_id: str = data.get("from_sender_id")
68
+
69
+
70
+ # =========================
71
+ # AuxData
72
+ # =========================
73
+ class AuxData:
74
+ def __init__(self, data: dict):
75
+ self.start_id: str = data.get("start_id")
76
+ self.button_id: str = data.get("button_id")
77
+
78
+
79
+ # =========================
80
+ # Button Models
81
+ # =========================
82
+ class ButtonTextbox:
83
+ def __init__(self, data: dict):
84
+ self.type_line: str = data.get("type_line")
85
+ self.type_keypad: str = data.get("type_keypad")
86
+ self.place_holder: Optional[str] = data.get("place_holder")
87
+ self.title: Optional[str] = data.get("title")
88
+ self.default_value: Optional[str] = data.get("default_value")
89
+
90
+
91
+ class ButtonNumberPicker:
92
+ def __init__(self, data: dict):
93
+ self.min_value: str = data.get("min_value")
94
+ self.max_value: str = data.get("max_value")
95
+ self.default_value: Optional[str] = data.get("default_value")
96
+ self.title: str = data.get("title")
97
+
98
+
99
+ class ButtonStringPicker:
100
+ def __init__(self, data: dict):
101
+ self.items: List[str] = data.get("items", [])
102
+ self.default_value: Optional[str] = data.get("default_value")
103
+ self.title: Optional[str] = data.get("title")
104
+
105
+
106
+ class ButtonCalendar:
107
+ def __init__(self, data: dict):
108
+ self.default_value: Optional[str] = data.get("default_value")
109
+ self.type: str = data.get("type")
110
+ self.min_year: str = data.get("min_year")
111
+ self.max_year: str = data.get("max_year")
112
+ self.title: str = data.get("title")
113
+
114
+
115
+ class ButtonLocation:
116
+ def __init__(self, data: dict):
117
+ self.default_pointer_location = Location(data.get("default_pointer_location", {}))
118
+ self.default_map_location = Location(data.get("default_map_location", {}))
119
+ self.type: str = data.get("type")
120
+ self.title: Optional[str] = data.get("title")
121
+ self.location_image_url: str = data.get("location_image_url")
122
+
123
+
124
+ class ButtonSelectionItem:
125
+ def __init__(self, data: dict):
126
+ self.text: str = data.get("text")
127
+ self.image_url: str = data.get("image_url")
128
+ self.type: str = data.get("type")
129
+
130
+
131
+ class ButtonSelection:
132
+ def __init__(self, data: dict):
133
+ self.selection_id: str = data.get("selection_id")
134
+ self.search_type: str = data.get("search_type")
135
+ self.get_type: str = data.get("get_type")
136
+ self.items: List[ButtonSelectionItem] = [ButtonSelectionItem(i) for i in data.get("items", [])]
137
+ self.is_multi_selection: bool = data.get("is_multi_selection")
138
+ self.columns_count: str = data.get("columns_count")
139
+ self.title: str = data.get("title")
140
+
141
+
142
+ class Button:
143
+ def __init__(self, data: dict):
144
+ self.id: str = data.get("id")
145
+ self.type: str = data.get("type")
146
+ self.button_text: str = data.get("button_text")
147
+ self.button_selection = ButtonSelection(data.get("button_selection", {})) if "button_selection" in data else None
148
+ self.button_calendar = ButtonCalendar(data.get("button_calendar", {})) if "button_calendar" in data else None
149
+ self.button_number_picker = ButtonNumberPicker(data.get("button_number_picker", {})) if "button_number_picker" in data else None
150
+ self.button_string_picker = ButtonStringPicker(data.get("button_string_picker", {})) if "button_string_picker" in data else None
151
+ self.button_location = ButtonLocation(data.get("button_location", {})) if "button_location" in data else None
152
+ self.button_textbox = ButtonTextbox(data.get("button_textbox", {})) if "button_textbox" in data else None
153
+
154
+
155
+ class KeypadRow:
156
+ def __init__(self, data: dict):
157
+ self.buttons: List[Button] = [Button(btn) for btn in data.get("buttons", [])]
158
+
159
+
160
+ class Keypad:
161
+ def __init__(self, data: dict):
162
+ self.rows: List[KeypadRow] = [KeypadRow(r) for r in data.get("rows", [])]
163
+ self.resize_keyboard: bool = data.get("resize_keyboard", False)
164
+ self.on_time_keyboard: bool = data.get("on_time_keyboard", False)
165
+
166
+
167
+ class Chat:
168
+ def __init__(self, data: dict):
169
+ self.chat_id: str = data.get("chat_id")
170
+ self.chat_type: str = data.get("chat_type")
171
+ self.user_id: str = data.get("user_id")
172
+ self.first_name: str = data.get("first_name")
173
+ self.last_name: str = data.get("last_name")
174
+ self.title: str = data.get("title")
175
+ self.username: str = data.get("username")
176
+
177
+
178
+ class Bot:
179
+ def __init__(self, data: dict):
180
+ self.bot_id: str = data.get("bot_id")
181
+ self.bot_title: str = data.get("bot_title")
182
+ self.avatar = File(data.get("avatar", {}))
183
+ self.description: str = data.get("description")
184
+ self.username: str = data.get("username")
185
+ self.start_message: str = data.get("start_message")
186
+ self.share_url: str = data.get("share_url")
4
187
  class Message:
5
- def __init__(self, bot, chat_id, message_id, sender_id, text):
188
+ def __init__(self, bot, chat_id, message_id, sender_id, text, raw_data=None):
6
189
  self.bot = bot
7
190
  self.chat_id = chat_id
8
191
  self.message_id = message_id
9
192
  self.sender_id = sender_id
10
193
  self.text = text
11
194
  self.args = []
195
+ self.raw_data = raw_data or {}
196
+
197
+ self.reply_to_message_id: Optional[str] = self.raw_data.get("reply_to_message_id")
198
+ self.forwarded_from = ForwardedFrom(self.raw_data["forwarded_from"]) if "forwarded_from" in self.raw_data else None
199
+ self.file = File(self.raw_data["file"]) if "file" in self.raw_data else None
200
+ self.sticker = Sticker(self.raw_data["sticker"]) if "sticker" in self.raw_data else None
201
+ self.contact_message = ContactMessage(self.raw_data["contact_message"]) if "contact_message" in self.raw_data else None
202
+ self.poll = Poll(self.raw_data["poll"]) if "poll" in self.raw_data else None
203
+ self.location = Location(self.raw_data["location"]) if "location" in self.raw_data else None
204
+ self.live_location = LiveLocation(self.raw_data["live_location"]) if "live_location" in self.raw_data else None
205
+ self.aux_data = AuxData(self.raw_data["aux_data"]) if "aux_data" in self.raw_data else None
206
+
12
207
  @property
13
208
  def session(self):
14
209
  if self.chat_id not in self.bot.sessions:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Rubka
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: A Python library for interacting with Rubika Bot API.
5
5
  Home-page: https://github.com/Mahdy-Ahmadi/Rubka
6
6
  Download-URL: https://github.com/Mahdy-Ahmadi/Rubka/archive/refs/tags/v0.1.0.tar.gz
@@ -1,7 +1,7 @@
1
1
  rubka/__init__.py,sha256=3f4H6Uj1ylrfBYlTHmTvzZSvaPJsdNhCocyX3Bbvuv0,254
2
- rubka/api.py,sha256=ye9xvT6BSluqko_nwez6MSALHHgxa6mYhz9fRQ8fmPM,9195
2
+ rubka/api.py,sha256=-68MTjIHuQ--1LBHW1-mnGVdz6XUOhHsR7F4J2jGo2k,9216
3
3
  rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
4
- rubka/context.py,sha256=piCAj7HamMOmXajtISC1OGELJvV08B7YtaawUYOPDR8,3344
4
+ rubka/context.py,sha256=dv7EJz3xu6N9ktbZnzMlmtgxAB6oCwkGKbs57hTWx64,11526
5
5
  rubka/decorators.py,sha256=hGwUoE4q2ImrunJIGJ_kzGYYxQf1ueE0isadqraKEts,1157
6
6
  rubka/exceptions.py,sha256=tujZt1XrhWaw-lmdeVadVceUptpw4XzNgE44sAAY0gs,90
7
7
  rubka/jobs.py,sha256=GvLMLsVhcSEzRTgkvnPISPEBN71suW2xXI0hUaUZPTo,378
@@ -9,7 +9,7 @@ rubka/keyboards.py,sha256=7nr-dT2bQJVQnQ6RMWPTSjML6EEk6dsBx-4d8pab8xk,488
9
9
  rubka/keypad.py,sha256=uJ9ocsTR2lPPJDER48h0p-9dU1Cv9FD4Qcm_--u6H1M,428
10
10
  rubka/logger.py,sha256=VhxaryxN_SqUmCX39nym2A6JiEPI-jEG22htPBP88Y4,289
11
11
  rubka/utils.py,sha256=XUQUZxQt9J2f0X5hmAH_MH1kibTAfdT1T4AaBkBhBBs,148
12
- rubka-1.5.0.dist-info/METADATA,sha256=sTd954TkrVUslP6jkyYAwLH7VENTm1MA2i1O7PVtTDI,8168
13
- rubka-1.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- rubka-1.5.0.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
15
- rubka-1.5.0.dist-info/RECORD,,
12
+ rubka-1.6.0.dist-info/METADATA,sha256=C0N9aXmICglQiazwyq9PgvxETjCbemeLvSBBW7VtkJk,8168
13
+ rubka-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ rubka-1.6.0.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
15
+ rubka-1.6.0.dist-info/RECORD,,
File without changes