Skip to content

Commit 8b2cf38

Browse files
committed
Support api 0.8.3 for callback class
1 parent 74ecd45 commit 8b2cf38

File tree

2 files changed

+109
-4
lines changed

2 files changed

+109
-4
lines changed

bot/classes/CallbackQuery.lua

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,119 @@ function callback:new(ctx)
1515
local obj = {}
1616

1717
obj.update_id = ctx.update_id
18-
obj.message = Message(ctx.callback_query.message, { direct = true })
1918

19+
local t_message = Message(ctx.callback_query.message, { direct = true })
20+
21+
obj.message = t_message.message
2022
obj.callback_query = ctx.callback_query
2123
obj.is_callback_query = true
2224

2325
return setmetatable(obj, self)
2426
end
2527

28+
-- START DEPRECATED BLOCK
29+
--
30+
-- Этот блок, стоило бы не делать, так как -
31+
-- Но оставим ради поддержки старой версии библиотеки.
32+
--
33+
--- Gets the chat from the associated message.
34+
-- @return (number) The chat.
35+
function callback:getChat()
36+
if self.message and self.message.chat then
37+
return self.message.chat
38+
end
39+
end
40+
41+
--- Gets the chat ID from the associated message.
42+
-- @return (number) The chat ID.
43+
function callback:getChatId()
44+
if self.message and self.message.chat then
45+
return self.message.chat.id
46+
end
47+
end
48+
49+
--- Gets the chat type from the associated message.
50+
-- @return (string) The chat type.
51+
function callback:getChatType()
52+
if self.message and self.message.chat then
53+
return self.message.chat.type
54+
end
55+
end
56+
57+
--- Gets the text from the associated message.
58+
-- @return (string) The message text.
59+
function callback:getText()
60+
if self.message and self.message.text then
61+
return self.message.text
62+
end
63+
end
64+
65+
--- Gets the message ID from the associated message.
66+
-- @return (number) The message ID.
67+
function callback:getMessageId()
68+
if self.message and self.message.message_id then
69+
return self.message.message_id
70+
end
71+
end
72+
73+
--- Gets the user data from the associated message.
74+
-- @return (table) The user data.
75+
function callback:getUserMessageFrom()
76+
if self.message and self.message.from then
77+
return self.message.from
78+
end
79+
end
80+
81+
--- Gets the user who replied to the associated message.
82+
-- @return (table) The user data of the reply.
83+
function callback:getUserReply()
84+
if self.message and self.message.reply_to_message then
85+
return self.message.reply_to_message.from
86+
end
87+
end
88+
89+
--- get reply to message
90+
-- @return (table)
91+
function callback:getReplyToMessage()
92+
if self.message and self.message.reply_to_message then
93+
return self.message.reply_to_message
94+
end
95+
end
96+
97+
--- Checks if the user who sent the callback query is the same as the one who replied to the associated message.
98+
-- @return (boolean) True if it's the same user, false otherwise.
99+
function callback:isSameUser()
100+
if self.callback_query and self.callback_query.from and
101+
self.message and self.message.reply_to_message
102+
then
103+
return self.callback_query.from.id == self.message.reply_to_message.from.id
104+
end
105+
end
106+
107+
--- Gets the inline keyboard
108+
-- @return (table) inline keyboard object
109+
function callback:getInlineKeyboard()
110+
if self.message
111+
and self.message.reply_markup
112+
and self.message.reply_markup.inline_keyboard
113+
then
114+
return self.message.reply_markup.inline_keyboard
115+
end
116+
end
117+
118+
--- Gets the sender chat
119+
-- @return (table) Sender chat object
120+
function callback:getSenderChat()
121+
if self.message
122+
and self.message.reply_to_message
123+
and self.message.reply_to_message.sender_chat
124+
then
125+
return self.message.reply_to_message.sender_chat
126+
end
127+
end
128+
--
129+
-- END DEPRECATED BLOCK
130+
26131
--- Gets the update ID
27132
-- @return (number) The update ID
28133
function callback:getUpdateId()

bot/classes/Message.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ function message:getUpdateId()
4646
end
4747
end
4848

49-
--- Gets the message data
50-
-- @return (table) The message data
49+
--- Gets the self data
50+
-- @return (table) The self data
5151
function message:getMessage()
52-
return self.message
52+
return self
5353
end
5454

5555
--- Gets the arguments from the message text.

0 commit comments

Comments
 (0)