gruubY 0.2.1 → 0.2.3

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +11 -6
  4. data/Rakefile +51 -51
  5. data/config/config.rb +1 -1
  6. data/example/bot.rb +122 -2
  7. data/example/generate_user_session.rb +81 -81
  8. data/example/tdlib.rb +77 -77
  9. data/example/userbot.rb +133 -133
  10. data/lib/gruubY/api.rb +540 -363
  11. data/lib/gruubY/async.rb +13 -13
  12. data/lib/gruubY/bot.rb +104 -90
  13. data/lib/gruubY/bound.rb +14 -14
  14. data/lib/gruubY/client.rb +310 -296
  15. data/lib/gruubY/context.rb +296 -242
  16. data/lib/gruubY/dispatcher.rb +60 -60
  17. data/lib/gruubY/enums.rb +57 -62
  18. data/lib/gruubY/exception.rb +5 -5
  19. data/lib/gruubY/file_stream.rb +17 -17
  20. data/lib/gruubY/filters.rb +292 -292
  21. data/lib/gruubY/group_manager.rb +213 -213
  22. data/lib/gruubY/handlers.rb +225 -170
  23. data/lib/gruubY/keyboard.rb +49 -49
  24. data/lib/gruubY/media.rb +38 -38
  25. data/lib/gruubY/middleware.rb +18 -18
  26. data/lib/gruubY/plugin.rb +27 -14
  27. data/lib/gruubY/raw.rb +25 -25
  28. data/lib/gruubY/retry.rb +14 -14
  29. data/lib/gruubY/server.rb +18 -18
  30. data/lib/gruubY/session.rb +30 -30
  31. data/lib/gruubY/tdlib/client.rb +565 -565
  32. data/lib/gruubY/tdlib/client_manager.rb +37 -37
  33. data/lib/gruubY/tdlib/decorators.rb +17 -17
  34. data/lib/gruubY/tdlib/errors.rb +6 -6
  35. data/lib/gruubY/tdlib/group_manager.rb +58 -58
  36. data/lib/gruubY/tdlib/native.rb +72 -72
  37. data/lib/gruubY/tdlib/schema_builder.rb +237 -237
  38. data/lib/gruubY/tdlib/tdjson.rb +49 -49
  39. data/lib/gruubY/tdlib/user_session.rb +69 -69
  40. data/lib/gruubY/types/base_object.rb +72 -72
  41. data/lib/gruubY/types/bound_entities.rb +289 -245
  42. data/lib/gruubY/types/chat.rb +93 -93
  43. data/lib/gruubY/types/chat_info.rb +32 -31
  44. data/lib/gruubY/types/extra.rb +289 -251
  45. data/lib/gruubY/types/message.rb +301 -295
  46. data/lib/gruubY/types/message_entity.rb +14 -14
  47. data/lib/gruubY/types/registry.rb +86 -67
  48. data/lib/gruubY/types/user.rb +47 -31
  49. data/lib/gruubY/webapp.rb +22 -22
  50. data/lib/gruubY.rb +39 -41
  51. data/plugins/logger.rb +7 -7
  52. metadata +3 -9
  53. data/example/ntgcalls.rb +0 -80
  54. data/lib/gruubY/ntgcalls/native.rb +0 -100
  55. data/lib/gruubY/ntgcalls.rb +0 -478
  56. data/lib/gruubY/raw_types.rb +0 -57
  57. data/plugins/media_tools.rb +0 -13
@@ -1,251 +1,289 @@
1
- require_relative "base_object"
2
- require_relative "chat"
3
- require_relative "user"
4
- require_relative "message_entity"
5
-
6
- module GrubY
7
- class MessageId < BaseObject
8
- fields :message_id
9
- end
10
-
11
- class InaccessibleMessage < BaseObject
12
- fields :chat, :message_id, :date
13
-
14
- def initialize(data)
15
- super(data)
16
- @chat = Chat.new(@chat) if @chat.is_a?(Hash)
17
- end
18
- end
19
-
20
- class MaybeInaccessibleMessage < BaseObject
21
- fields :raw
22
-
23
- def initialize(data)
24
- super({ raw: data })
25
- end
26
-
27
- def inaccessible?
28
- @raw.is_a?(Hash) && @raw["date"].to_i.zero?
29
- end
30
-
31
- def as_inaccessible
32
- return nil unless inaccessible?
33
-
34
- InaccessibleMessage.new(@raw)
35
- end
36
- end
37
-
38
- class TextQuote < BaseObject
39
- fields :text, :entities, :position, :is_manual
40
-
41
- def initialize(data)
42
- super(data)
43
- @entities = Array(@entities).map { |e| MessageEntity.new(e) }
44
- end
45
- end
46
-
47
- class ExternalReplyInfo < BaseObject
48
- fields :origin, :chat, :message_id, :link_preview_options, :animation, :audio,
49
- :document, :paid_media, :photo, :sticker, :story, :video, :video_note,
50
- :voice, :has_media_spoiler, :checklist, :contact, :dice, :game,
51
- :giveaway, :giveaway_winners, :invoice, :location, :poll, :venue
52
-
53
- def initialize(data)
54
- super(data)
55
- @chat = Chat.new(@chat) if @chat.is_a?(Hash)
56
- end
57
- end
58
-
59
- class MessageOrigin < BaseObject
60
- fields :type, :date
61
- end
62
-
63
- class MessageOriginUser < MessageOrigin
64
- fields :sender_user
65
-
66
- def initialize(data)
67
- super(data)
68
- @sender_user = User.new(@sender_user) if @sender_user.is_a?(Hash)
69
- end
70
- end
71
-
72
- class MessageOriginHiddenUser < MessageOrigin
73
- fields :sender_user_name
74
- end
75
-
76
- class MessageOriginChat < MessageOrigin
77
- fields :sender_chat, :author_signature
78
-
79
- def initialize(data)
80
- super(data)
81
- @sender_chat = Chat.new(@sender_chat) if @sender_chat.is_a?(Hash)
82
- end
83
- end
84
-
85
- class MessageOriginChannel < MessageOrigin
86
- fields :chat, :message_id, :author_signature
87
-
88
- def initialize(data)
89
- super(data)
90
- @chat = Chat.new(@chat) if @chat.is_a?(Hash)
91
- end
92
- end
93
-
94
- class PhotoSize < BaseObject
95
- fields :file_id, :file_unique_id, :width, :height, :file_size
96
- end
97
-
98
- class Animation < BaseObject
99
- fields :file_id, :file_unique_id, :width, :height, :duration, :thumbnail,
100
- :file_name, :mime_type, :file_size
101
-
102
- def initialize(data)
103
- super(data)
104
- @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
105
- end
106
- end
107
-
108
- class Audio < BaseObject
109
- fields :file_id, :file_unique_id, :duration, :performer, :title, :file_name,
110
- :mime_type, :file_size, :thumbnail
111
-
112
- def initialize(data)
113
- super(data)
114
- @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
115
- end
116
- end
117
-
118
- class Document < BaseObject
119
- fields :file_id, :file_unique_id, :thumbnail, :file_name, :mime_type,
120
- :file_size
121
-
122
- def initialize(data)
123
- super(data)
124
- @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
125
- end
126
- end
127
-
128
- class Story < BaseObject
129
- fields :chat, :id
130
-
131
- def initialize(data)
132
- super(data)
133
- @chat = Chat.new(@chat) if @chat.is_a?(Hash)
134
- end
135
- end
136
-
137
- class VideoQuality < BaseObject
138
- fields :file_id, :file_unique_id, :width, :height, :codec, :file_size
139
- end
140
-
141
- class Video < BaseObject
142
- fields :file_id, :file_unique_id, :width, :height, :duration, :thumbnail,
143
- :cover, :start_timestamp, :qualities, :file_name, :mime_type, :file_size
144
-
145
- def initialize(data)
146
- super(data)
147
- @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
148
- @cover = Array(@cover).map { |c| PhotoSize.new(c) }
149
- @qualities = Array(@qualities).map { |q| VideoQuality.new(q) }
150
- end
151
- end
152
-
153
- class VideoNote < BaseObject
154
- fields :file_id, :file_unique_id, :length, :duration, :thumbnail, :file_size
155
-
156
- def initialize(data)
157
- super(data)
158
- @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
159
- end
160
- end
161
-
162
- class Voice < BaseObject
163
- fields :file_id, :file_unique_id, :duration, :mime_type, :file_size
164
- end
165
-
166
- class PaidMediaInfo < BaseObject
167
- fields :star_count, :paid_media
168
- end
169
-
170
- class PaidMedia < BaseObject
171
- fields :type
172
- end
173
-
174
- class PaidMediaPreview < PaidMedia
175
- fields :width, :height, :duration
176
- end
177
-
178
- class PaidMediaPhoto < PaidMedia
179
- fields :photo
180
-
181
- def initialize(data)
182
- super(data)
183
- @photo = Array(@photo).map { |p| PhotoSize.new(p) }
184
- end
185
- end
186
-
187
- class PaidMediaVideo < PaidMedia
188
- fields :video
189
-
190
- def initialize(data)
191
- super(data)
192
- @video = Video.new(@video) if @video.is_a?(Hash)
193
- end
194
- end
195
-
196
- class Contact < BaseObject
197
- fields :phone_number, :first_name, :last_name, :user_id, :vcard
198
- end
199
-
200
- class Dice < BaseObject
201
- fields :emoji, :value
202
- end
203
-
204
- class PollOption < BaseObject
205
- fields :persistent_id, :text, :text_entities, :voter_count, :added_by_user,
206
- :added_by_chat, :addition_date
207
-
208
- def initialize(data)
209
- super(data)
210
- @text_entities = Array(@text_entities).map { |e| MessageEntity.new(e) }
211
- @added_by_user = User.new(@added_by_user) if @added_by_user.is_a?(Hash)
212
- @added_by_chat = Chat.new(@added_by_chat) if @added_by_chat.is_a?(Hash)
213
- end
214
- end
215
-
216
- class InputPollOption < BaseObject
217
- fields :text, :text_parse_mode, :text_entities
218
- end
219
-
220
- class PollAnswer < BaseObject
221
- fields :poll_id, :voter_chat, :user, :option_ids, :option_persistent_ids
222
-
223
- def initialize(data)
224
- super(data)
225
- @voter_chat = Chat.new(@voter_chat) if @voter_chat.is_a?(Hash)
226
- @user = User.new(@user) if @user.is_a?(Hash)
227
- end
228
- end
229
-
230
- class Poll < BaseObject
231
- fields :id, :question, :question_entities, :options, :total_voter_count,
232
- :is_closed, :is_anonymous, :type, :allows_multiple_answers,
233
- :allows_revoting, :correct_option_ids, :explanation,
234
- :explanation_entities, :open_period, :close_date, :description,
235
- :description_entities
236
-
237
- def initialize(data)
238
- super(data)
239
- @question_entities = Array(@question_entities).map { |e| MessageEntity.new(e) }
240
- @options = Array(@options).map { |o| PollOption.new(o) }
241
- @explanation_entities = Array(@explanation_entities).map { |e| MessageEntity.new(e) }
242
- @description_entities = Array(@description_entities).map { |e| MessageEntity.new(e) }
243
- end
244
- end
245
-
246
- class ReplyParameters < BaseObject
247
- fields :message_id, :chat_id, :allow_sending_without_reply, :quote,
248
- :quote_parse_mode, :quote_entities, :quote_position, :checklist_task_id,
249
- :poll_option_id
250
- end
251
- end
1
+ require_relative "base_object"
2
+ require_relative "chat"
3
+ require_relative "user"
4
+ require_relative "message_entity"
5
+
6
+ module GrubY
7
+ class MessageId < BaseObject
8
+ fields :message_id
9
+ end
10
+
11
+ class InaccessibleMessage < BaseObject
12
+ fields :chat, :message_id, :date
13
+
14
+ def initialize(data)
15
+ super(data)
16
+ @chat = Chat.new(@chat) if @chat.is_a?(Hash)
17
+ end
18
+ end
19
+
20
+ class MaybeInaccessibleMessage < BaseObject
21
+ fields :raw
22
+
23
+ def initialize(data)
24
+ super({ raw: data })
25
+ end
26
+
27
+ def inaccessible?
28
+ @raw.is_a?(Hash) && @raw["date"].to_i.zero?
29
+ end
30
+
31
+ def as_inaccessible
32
+ return nil unless inaccessible?
33
+
34
+ InaccessibleMessage.new(@raw)
35
+ end
36
+ end
37
+
38
+ class TextQuote < BaseObject
39
+ fields :text, :entities, :position, :is_manual, :rich_texts,
40
+ :quote_rich_texts
41
+
42
+ def initialize(data)
43
+ super(data)
44
+ @entities = Array(@entities).map { |e| MessageEntity.new(e) }
45
+ end
46
+ end
47
+
48
+ class ExternalReplyInfo < BaseObject
49
+ fields :origin, :chat, :message_id, :link_preview_options, :animation, :audio,
50
+ :document, :paid_media, :photo, :sticker, :story, :video, :video_note,
51
+ :voice, :has_media_spoiler, :checklist, :contact, :dice, :game,
52
+ :giveaway, :giveaway_winners, :invoice, :location, :poll, :venue,
53
+ :widget
54
+
55
+ def initialize(data)
56
+ super(data)
57
+ @chat = Chat.new(@chat) if @chat.is_a?(Hash)
58
+ end
59
+ end
60
+
61
+ class MessageOrigin < BaseObject
62
+ fields :type, :date
63
+ end
64
+
65
+ class MessageOriginUser < MessageOrigin
66
+ fields :sender_user
67
+
68
+ def initialize(data)
69
+ super(data)
70
+ @sender_user = User.new(@sender_user) if @sender_user.is_a?(Hash)
71
+ end
72
+ end
73
+
74
+ class MessageOriginHiddenUser < MessageOrigin
75
+ fields :sender_user_name
76
+ end
77
+
78
+ class MessageOriginChat < MessageOrigin
79
+ fields :sender_chat, :author_signature
80
+
81
+ def initialize(data)
82
+ super(data)
83
+ @sender_chat = Chat.new(@sender_chat) if @sender_chat.is_a?(Hash)
84
+ end
85
+ end
86
+
87
+ class MessageOriginChannel < MessageOrigin
88
+ fields :chat, :message_id, :author_signature
89
+
90
+ def initialize(data)
91
+ super(data)
92
+ @chat = Chat.new(@chat) if @chat.is_a?(Hash)
93
+ end
94
+ end
95
+
96
+ class PhotoSize < BaseObject
97
+ fields :file_id, :file_unique_id, :width, :height, :file_size
98
+ end
99
+
100
+ class Animation < BaseObject
101
+ fields :file_id, :file_unique_id, :width, :height, :duration, :thumbnail,
102
+ :file_name, :mime_type, :file_size
103
+
104
+ def initialize(data)
105
+ super(data)
106
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
107
+ end
108
+ end
109
+
110
+ class Audio < BaseObject
111
+ fields :file_id, :file_unique_id, :duration, :performer, :title, :file_name,
112
+ :mime_type, :file_size, :thumbnail
113
+
114
+ def initialize(data)
115
+ super(data)
116
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
117
+ end
118
+ end
119
+
120
+ class Document < BaseObject
121
+ fields :file_id, :file_unique_id, :thumbnail, :file_name, :mime_type,
122
+ :file_size
123
+
124
+ def initialize(data)
125
+ super(data)
126
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
127
+ end
128
+ end
129
+
130
+ class Story < BaseObject
131
+ fields :chat, :id
132
+
133
+ def initialize(data)
134
+ super(data)
135
+ @chat = Chat.new(@chat) if @chat.is_a?(Hash)
136
+ end
137
+ end
138
+
139
+ class VideoQuality < BaseObject
140
+ fields :file_id, :file_unique_id, :width, :height, :codec, :file_size
141
+ end
142
+
143
+ class Video < BaseObject
144
+ fields :file_id, :file_unique_id, :width, :height, :duration, :thumbnail,
145
+ :cover, :start_timestamp, :qualities, :file_name, :mime_type, :file_size
146
+
147
+ def initialize(data)
148
+ super(data)
149
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
150
+ @cover = Array(@cover).map { |c| PhotoSize.new(c) }
151
+ @qualities = Array(@qualities).map { |q| VideoQuality.new(q) }
152
+ end
153
+ end
154
+
155
+ class VideoNote < BaseObject
156
+ fields :file_id, :file_unique_id, :length, :duration, :thumbnail, :file_size
157
+
158
+ def initialize(data)
159
+ super(data)
160
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
161
+ end
162
+ end
163
+
164
+ class Voice < BaseObject
165
+ fields :file_id, :file_unique_id, :duration, :mime_type, :file_size
166
+ end
167
+
168
+ class Sticker < BaseObject
169
+ fields :file_id, :file_unique_id, :type, :width, :height, :is_animated,
170
+ :is_video, :thumbnail, :emoji, :set_name, :premium_animation,
171
+ :mask_position, :custom_emoji_id, :needs_repainting, :file_size
172
+
173
+ def initialize(data)
174
+ super(data)
175
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
176
+ @mask_position = MaskPosition.new(@mask_position) if @mask_position.is_a?(Hash)
177
+ end
178
+ end
179
+
180
+ class StickerSet < BaseObject
181
+ fields :name, :title, :sticker_type, :stickers, :thumbnail,
182
+ :premium_animation, :custom_emoji_ids
183
+
184
+ def initialize(data)
185
+ super(data)
186
+ @stickers = Array(@stickers).map { |sticker| Sticker.new(sticker) }
187
+ @thumbnail = PhotoSize.new(@thumbnail) if @thumbnail.is_a?(Hash)
188
+ end
189
+ end
190
+
191
+ class MaskPosition < BaseObject
192
+ fields :point, :x_shift, :y_shift, :scale
193
+ end
194
+
195
+ class InputSticker < BaseObject
196
+ fields :sticker, :emoji_list, :mask_position, :keywords
197
+
198
+ def initialize(data)
199
+ super(data)
200
+ @mask_position = MaskPosition.new(@mask_position) if @mask_position.is_a?(Hash)
201
+ end
202
+ end
203
+
204
+ class PaidMediaInfo < BaseObject
205
+ fields :star_count, :paid_media
206
+ end
207
+
208
+ class PaidMedia < BaseObject
209
+ fields :type
210
+ end
211
+
212
+ class PaidMediaPreview < PaidMedia
213
+ fields :width, :height, :duration
214
+ end
215
+
216
+ class PaidMediaPhoto < PaidMedia
217
+ fields :photo
218
+
219
+ def initialize(data)
220
+ super(data)
221
+ @photo = Array(@photo).map { |p| PhotoSize.new(p) }
222
+ end
223
+ end
224
+
225
+ class PaidMediaVideo < PaidMedia
226
+ fields :video
227
+
228
+ def initialize(data)
229
+ super(data)
230
+ @video = Video.new(@video) if @video.is_a?(Hash)
231
+ end
232
+ end
233
+
234
+ class Contact < BaseObject
235
+ fields :phone_number, :first_name, :last_name, :user_id, :vcard
236
+ end
237
+
238
+ class Dice < BaseObject
239
+ fields :emoji, :value
240
+ end
241
+
242
+ class PollOption < BaseObject
243
+ fields :persistent_id, :text, :text_entities, :voter_count, :added_by_user,
244
+ :added_by_chat, :addition_date
245
+
246
+ def initialize(data)
247
+ super(data)
248
+ @text_entities = Array(@text_entities).map { |e| MessageEntity.new(e) }
249
+ @added_by_user = User.new(@added_by_user) if @added_by_user.is_a?(Hash)
250
+ @added_by_chat = Chat.new(@added_by_chat) if @added_by_chat.is_a?(Hash)
251
+ end
252
+ end
253
+
254
+ class InputPollOption < BaseObject
255
+ fields :text, :text_parse_mode, :text_entities
256
+ end
257
+
258
+ class PollAnswer < BaseObject
259
+ fields :poll_id, :voter_chat, :user, :option_ids, :option_persistent_ids
260
+
261
+ def initialize(data)
262
+ super(data)
263
+ @voter_chat = Chat.new(@voter_chat) if @voter_chat.is_a?(Hash)
264
+ @user = User.new(@user) if @user.is_a?(Hash)
265
+ end
266
+ end
267
+
268
+ class Poll < BaseObject
269
+ fields :id, :question, :question_entities, :options, :total_voter_count,
270
+ :is_closed, :is_anonymous, :type, :allows_multiple_answers,
271
+ :allows_revoting, :correct_option_ids, :explanation,
272
+ :explanation_entities, :open_period, :close_date, :description,
273
+ :description_entities
274
+
275
+ def initialize(data)
276
+ super(data)
277
+ @question_entities = Array(@question_entities).map { |e| MessageEntity.new(e) }
278
+ @options = Array(@options).map { |o| PollOption.new(o) }
279
+ @explanation_entities = Array(@explanation_entities).map { |e| MessageEntity.new(e) }
280
+ @description_entities = Array(@description_entities).map { |e| MessageEntity.new(e) }
281
+ end
282
+ end
283
+
284
+ class ReplyParameters < BaseObject
285
+ fields :message_id, :chat_id, :allow_sending_without_reply, :quote,
286
+ :quote_parse_mode, :quote_entities, :quote_position, :checklist_task_id,
287
+ :poll_option_id
288
+ end
289
+ end