teleruby 1.5.1 → 1.5.4

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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +9 -0
  3. data/README.md +398 -0
  4. data/lib/api/all.rb +12 -0
  5. data/lib/api/delete_apis.rb +55 -0
  6. data/lib/api/get_apis.rb +162 -0
  7. data/lib/api/nstandard.rb +26 -0
  8. data/lib/api/other_apis.rb +225 -0
  9. data/lib/api/send_apis.rb +191 -0
  10. data/lib/api/set_apis.rb +130 -0
  11. data/lib/core_api.rb +41 -0
  12. data/lib/objects/all.rb +42 -0
  13. data/lib/objects/animation.rb +38 -0
  14. data/lib/objects/audio.rb +37 -0
  15. data/lib/objects/bot_command.rb +24 -0
  16. data/lib/objects/callback_query.rb +64 -0
  17. data/lib/objects/chat.rb +158 -0
  18. data/lib/objects/chat_member.rb +142 -0
  19. data/lib/objects/chat_permissions.rb +59 -0
  20. data/lib/objects/chat_photo.rb +37 -0
  21. data/lib/objects/chosen_inline_result.rb +43 -0
  22. data/lib/objects/contact.rb +37 -0
  23. data/lib/objects/dice.rb +21 -0
  24. data/lib/objects/document.rb +27 -0
  25. data/lib/objects/file.rb +32 -0
  26. data/lib/objects/game.rb +65 -0
  27. data/lib/objects/inline_query.rb +42 -0
  28. data/lib/objects/inlinekeyboardbutton.rb +59 -0
  29. data/lib/objects/inlinekeyboardmarkup.rb +30 -0
  30. data/lib/objects/location.rb +21 -0
  31. data/lib/objects/mask_position.rb +35 -0
  32. data/lib/objects/message.rb +378 -0
  33. data/lib/objects/message_entity.rb +93 -0
  34. data/lib/objects/order_info.rb +34 -0
  35. data/lib/objects/photo_size.rb +14 -0
  36. data/lib/objects/poll.rb +97 -0
  37. data/lib/objects/poll_answer.rb +29 -0
  38. data/lib/objects/poll_option.rb +22 -0
  39. data/lib/objects/pre_checkout_query.rb +48 -0
  40. data/lib/objects/same/common.rb +37 -0
  41. data/lib/objects/same/common_2.rb +38 -0
  42. data/lib/objects/shipping_address.rb +39 -0
  43. data/lib/objects/shipping_query.rb +32 -0
  44. data/lib/objects/sticker.rb +55 -0
  45. data/lib/objects/update.rb +174 -0
  46. data/lib/objects/user.rb +66 -0
  47. data/lib/objects/user_profile_photos.rb +35 -0
  48. data/lib/objects/venue.rb +40 -0
  49. data/lib/objects/video.rb +37 -0
  50. data/lib/objects/video_note.rb +48 -0
  51. data/lib/objects/voice.rb +20 -0
  52. data/lib/teleruby.rb +4 -40
  53. data/lib/teleruby/all_apis.rb +22 -0
  54. data/lib/teleruby/api/delete_apis.rb +58 -0
  55. data/lib/teleruby/api/get_apis.rb +172 -0
  56. data/lib/teleruby/api/nstandard.rb +27 -0
  57. data/lib/teleruby/api/other_apis.rb +241 -0
  58. data/lib/teleruby/api/send_apis.rb +206 -0
  59. data/lib/teleruby/api/set_apis.rb +137 -0
  60. data/lib/teleruby/core_api.rb +52 -0
  61. data/lib/teleruby/objects/all.rb +42 -0
  62. data/lib/teleruby/objects/animation.rb +40 -0
  63. data/lib/teleruby/objects/audio.rb +39 -0
  64. data/lib/teleruby/objects/bot_command.rb +24 -0
  65. data/lib/teleruby/objects/callback_query.rb +66 -0
  66. data/lib/teleruby/objects/chat.rb +164 -0
  67. data/lib/teleruby/objects/chat_member.rb +142 -0
  68. data/lib/teleruby/objects/chat_permissions.rb +59 -0
  69. data/lib/teleruby/objects/chat_photo.rb +37 -0
  70. data/lib/teleruby/objects/chosen_inline_result.rb +45 -0
  71. data/lib/teleruby/objects/contact.rb +37 -0
  72. data/lib/teleruby/objects/dice.rb +21 -0
  73. data/lib/teleruby/objects/document.rb +29 -0
  74. data/lib/teleruby/objects/file.rb +32 -0
  75. data/lib/teleruby/objects/game.rb +65 -0
  76. data/lib/teleruby/objects/inline_query.rb +44 -0
  77. data/lib/teleruby/objects/inlinekeyboardbutton.rb +59 -0
  78. data/lib/teleruby/objects/inlinekeyboardmarkup.rb +31 -0
  79. data/lib/teleruby/objects/location.rb +21 -0
  80. data/lib/teleruby/objects/mask_position.rb +35 -0
  81. data/lib/teleruby/objects/message.rb +400 -0
  82. data/lib/teleruby/objects/message_entity.rb +95 -0
  83. data/lib/teleruby/objects/order_info.rb +36 -0
  84. data/lib/teleruby/objects/photo_size.rb +14 -0
  85. data/lib/teleruby/objects/poll.rb +97 -0
  86. data/lib/teleruby/objects/poll_answer.rb +29 -0
  87. data/lib/teleruby/objects/poll_option.rb +22 -0
  88. data/lib/teleruby/objects/pre_checkout_query.rb +50 -0
  89. data/lib/teleruby/objects/same/common.rb +31 -0
  90. data/lib/teleruby/objects/same/common_2.rb +32 -0
  91. data/lib/teleruby/objects/shipping_address.rb +39 -0
  92. data/lib/teleruby/objects/shipping_query.rb +32 -0
  93. data/lib/teleruby/objects/sticker.rb +59 -0
  94. data/lib/teleruby/objects/update.rb +207 -0
  95. data/lib/teleruby/objects/user.rb +66 -0
  96. data/lib/teleruby/objects/user_profile_photos.rb +36 -0
  97. data/lib/teleruby/objects/venue.rb +40 -0
  98. data/lib/teleruby/objects/video.rb +39 -0
  99. data/lib/teleruby/objects/video_note.rb +50 -0
  100. data/lib/teleruby/objects/voice.rb +20 -0
  101. data/lib/teleruby/version.rb +3 -0
  102. data/msg.png +0 -0
  103. data/rdoc.png +0 -0
  104. data/teleruby.gemspec +9 -7
  105. metadata +109 -6
@@ -0,0 +1,400 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'user'
5
+ require_relative 'chat'
6
+ require_relative 'message_entity'
7
+ require_relative 'animation'
8
+ require_relative 'audio'
9
+ require_relative 'document'
10
+ require_relative 'photo_size'
11
+ require_relative 'sticker'
12
+ require_relative 'video'
13
+ require_relative 'contact'
14
+ require_relative 'dice'
15
+ require_relative 'venue'
16
+ require_relative 'game'
17
+ require_relative 'location'
18
+ require_relative 'inlinekeyboardmarkup'
19
+
20
+ ##
21
+ # +Monday+, +August+ +24+ +2020+ +EAT+
22
+ # ===This object represents a message.
23
+ class Message
24
+ def initialize(msg) # :nodoc:
25
+ @message = msg
26
+ end
27
+
28
+ # Unique message identifier inside the chat.
29
+ def message_id
30
+ @message.message_id
31
+ end
32
+
33
+ # +Optional.+ Sender, empty for messages sent to channels.
34
+ # Returns User object.
35
+ def from
36
+ frm = @message.from
37
+ unless frm.nil?
38
+ return User.new(frm)
39
+ end
40
+
41
+ false
42
+ end
43
+
44
+ # TDate Object the message was sent in Unix time
45
+ def date
46
+ return TDate.new(@message.date)
47
+ end
48
+
49
+ # Conversation the message belongs to.
50
+ # Returns Chat object
51
+ def chat
52
+ Chat.new(@message.chat)
53
+ end
54
+
55
+ # +Optional.+ For forwarded messages, sender of the original message.
56
+ # Returns Chat object
57
+ def forward_from
58
+ f_from = @message.forward_from
59
+ unless f_from.nil?
60
+ return User.new(f_from)
61
+ end
62
+
63
+ false
64
+ end
65
+
66
+ # +Optional.+ For messages forwarded from channels, information about
67
+ # the original channel.
68
+ # Returns Chat object.
69
+ def forward_from_chat
70
+ ff_chat = @message.forward_from_chat
71
+ unless ff_chat.nil?
72
+ return Chat.new(ff_chat)
73
+ end
74
+
75
+ false
76
+ end
77
+
78
+ # +Optional.+ For messages forwarded from channels, identifier of the
79
+ # original message in the channel.
80
+ def forward_from_message_id
81
+ @message.forward_from_message_id
82
+ end
83
+
84
+ # +Optional.+ For messages forwarded from channels, signature of the
85
+ # post author if present.
86
+ def forward_signature
87
+ @message.forward_signature
88
+ end
89
+
90
+ # +Optional+. Sender's name for messages forwarded from users who
91
+ # disallow adding a link to their account in forwarded messages.
92
+ def forward_sender_name
93
+ @message.forward_sender_name
94
+ end
95
+
96
+ # +Optional.+ For forwarded messages, date the original message was
97
+ # sent in Unix time.
98
+ # Returns TDate object.
99
+ def forward_date
100
+ TDate.new(@message.forward_date)
101
+ end
102
+
103
+ # +Optional.+ For replies, the original message. Note that the Message
104
+ # object in this field will not contain further #reply_to_message
105
+ # fields even if it itself is a reply.
106
+ # Returns Message object
107
+ def reply_to_message
108
+ r_t_msg = @message.reply_to_message
109
+ unless r_t_msg.nil?
110
+ return Message.new(r_t_msg)
111
+ end
112
+
113
+ false
114
+ end
115
+
116
+ # +Optional+. Bot through which the message was sent.
117
+ # Returns User object.
118
+ def via_bot
119
+ v_bot = @message.via_bot
120
+ unless v_bot.nil?
121
+ return User.new(v_bot)
122
+ end
123
+
124
+ false
125
+ end
126
+
127
+ # +Optional+. Retuns TDate object.
128
+ def edit_date
129
+ TDate.new(@messag.edit_date)
130
+ end
131
+
132
+ # +Optional+. The unique identifier of a media message group this
133
+ # message belongs to.
134
+ def media_group_id
135
+ @message.media_group_id
136
+ end
137
+
138
+ # +Optional.+ Signature of the post author for messages in channels.
139
+ def author_signature
140
+ @message.author_signature
141
+ end
142
+
143
+ # +Optional+. For text messages, the actual UTF-8 text of the message,
144
+ # 0-4096 characters
145
+ def text
146
+ @message.text
147
+ end
148
+
149
+ # +Optional.+ For text messages, special entities like usernames,
150
+ # URLs, bot commands, etc. that appear in the text.
151
+ # Returns array of MessageEntity object
152
+ def entities
153
+ empty_entity = []
154
+ entitys = @message.entities
155
+ unless entitys.empty?
156
+ entitys.each do |ent|
157
+ empty_entity << MessageEntity.new(ent)
158
+ end
159
+ return empty_entity
160
+ end
161
+
162
+ false
163
+ end
164
+
165
+ # +Optional.+ Message is an animation, information about the animation.
166
+ # For backward compatibility, when this field is set, the document
167
+ # field will also be set.
168
+ # Returns Animation object
169
+ def animation
170
+ an = @message.animation
171
+ unless an.nil?
172
+ return Animation.new(an)
173
+ end
174
+
175
+ false
176
+ end
177
+
178
+ # +Optional+. message is an Audio file, information about the file.
179
+ def audio
180
+ ad = @message.audio
181
+ if ad
182
+ return Audio.new(ad)
183
+ end
184
+
185
+ false
186
+ end
187
+
188
+ # +Optional+. message is a general file, information about the file.
189
+ # Returns Document object.
190
+ def document
191
+ doc = @message.document
192
+ unless doc.nil?
193
+ return Document.new(doc)
194
+ end
195
+
196
+ false
197
+ end
198
+
199
+ # +Optional+. message is a Photo, available sizes of the photo.
200
+ # returns array of PhotoSize object
201
+ def photo
202
+ poto = @message.photo
203
+ e_photo = []
204
+ unless poto.empty?
205
+ poto.each do
206
+ e_photo << PhotoSize.new(e_photo)
207
+ end
208
+ return e_photo
209
+ end
210
+
211
+ false
212
+ end
213
+
214
+ # +Optional.+ Message is a sticker, information about the sticker
215
+ # returns Sticker object
216
+ def sticker
217
+ stiker = @message.sticker
218
+ unless stiker.nil?
219
+ return Sticker.new(stiker)
220
+ end
221
+
222
+ false
223
+ end
224
+
225
+ # +Optional.+ Message is a Video, information about the video.
226
+ def video
227
+ vd = @message.video
228
+ unless vd.nil?
229
+ return Video.new(vd)
230
+ end
231
+
232
+ false
233
+ end
234
+
235
+ # +Optional.+ Message is a VideoNote, information about the video message.
236
+ def video_note
237
+ vnot = @message.video_note
238
+ unless vnot.nil?
239
+ return VideoNote.new(vnot)
240
+ end
241
+
242
+ false
243
+ end
244
+
245
+ # +Optional+. message is a Voice message, information about the file.
246
+ def voice
247
+ vc = @message.voice
248
+ unless vc.nil?
249
+ return Voice.new(vc)
250
+ end
251
+
252
+ false
253
+ end
254
+
255
+ # +Optional+. Caption for the animation, audio, document, photo, video
256
+ # or voice, 0-1024 characters.
257
+ def caption
258
+ @message.caption
259
+ end
260
+
261
+ # +Optional.+ For messages with a caption, special entities like
262
+ # usernames, URLs, bot commands, etc. that appear in the caption.
263
+ def caption_entities
264
+ c_entitys = @message.caption_entities
265
+ empty_ent = []
266
+ unless c_entitys.empty?
267
+ c_entitys.each do |ent|
268
+ empty_ent << MessageEntity.new(ent)
269
+ end
270
+ return empty_ent
271
+ end
272
+
273
+ false
274
+ end
275
+
276
+ # +Optional+. Message is a shared contact, information about the contact.
277
+ def contact
278
+ kontakt = @message.contact
279
+ unless kontakt.nil?
280
+ return Contact.new(kontakt)
281
+ end
282
+
283
+ false
284
+ end
285
+
286
+ # +Optional+. Message is a Dice with random value from 1 to 6.
287
+ def dice
288
+ dis = @message.dice
289
+ unless dis.nil?
290
+ return Dice.new(dis)
291
+ end
292
+
293
+ false
294
+ end
295
+
296
+ # +Optional+. Message is a Game, information about the game.
297
+ def game
298
+ gam = @message.game
299
+ unless gam.nil?
300
+ return Game.new(gam)
301
+ end
302
+
303
+ false
304
+ end
305
+
306
+ def text_msg?
307
+ !text.nil?
308
+ end
309
+
310
+ # returns true if the update is for replied msg
311
+ def reply_msg?
312
+ !@message.reply_to_message.nil?
313
+ end
314
+
315
+ def video_msg?
316
+ !@message.video.nil?
317
+ end
318
+
319
+ def audio_msg?
320
+ !@message.audio.nil?
321
+ end
322
+
323
+ def document_msg?
324
+ !@message.document.nil?
325
+ end
326
+
327
+ def contact_msg?
328
+ !@message.contact.nil?
329
+ end
330
+
331
+ def forward_msg?
332
+ !(@update.forward_from) || (@update.forward_from_chat).nil?
333
+ end
334
+
335
+ def animation_msg?
336
+ !@message.animation.nil?
337
+ end
338
+
339
+ def photo_msg?
340
+ !(@message.photo).empty?
341
+ end
342
+
343
+ def voice_msg?
344
+ !@message.voice.nil?
345
+ end
346
+
347
+ def video_note_msg?
348
+ !@message.video_note.nil?
349
+ end
350
+
351
+ def sticker_msg?
352
+ !@message.sticker.nil?
353
+ end
354
+
355
+ def game_msg?
356
+ !@message.game.nil?
357
+ end
358
+
359
+ def poll_msg?
360
+ !@message.poll.nil?
361
+ end
362
+
363
+ def venue_msg?
364
+ !@message.venue.nil?
365
+ end
366
+
367
+ def location_msg?
368
+ !@message.location.nil?
369
+ end
370
+
371
+ def new_chat_member?
372
+ !@message.new_chat_member.nil?
373
+ end
374
+
375
+ def left_chat_member?
376
+ !@message.left_chat_member.nil?
377
+ end
378
+
379
+ def new_chat_title?
380
+ !@message.new_chat_title.nil?
381
+ end
382
+
383
+ def new_chat_photo?
384
+ !@message.new_chat_photo.nil?
385
+ end
386
+
387
+ def pinned_msg?
388
+ !@message.pinned_message.nil?
389
+ end
390
+
391
+ def delete_chat_photo?
392
+ !@message.delete_chat_photo.nil?
393
+ end
394
+
395
+ def reply_markup?
396
+ !@message.reply_markup.nil?
397
+ end
398
+ end
399
+
400
+ # ughhhhh God!
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'user'
5
+
6
+ ##
7
+ # +Monday+, +August+ +24+ +2020+ +EAT+
8
+ # ===This object represents one special entity in a text message.
9
+ # For example, +hashtags,+ +usernames+, +URLs,+ etc.
10
+ class MessageEntity
11
+ def initialize(msg) # :nodoc:
12
+ @msg = msg
13
+ freeze
14
+ end
15
+
16
+ # Type of the entity. Can be +mention+( @username ), +hashtag+( #hashtag ),
17
+ # +cashtag+( $USD ), +bot_command+( /start@jobs_bot ),
18
+ # +url+( https://telegram.org ), +email+( do-not-reply@telegram.org ),
19
+ # +phone_number+( +1-212-555-0123 ), +bold+(bold text),
20
+ # *italic*(italic text), +underline+(underlined text),
21
+ # +strikethrough+(strikethrough text), +code+
22
+ # (monowidth string), +pre+ (monowidth block),
23
+ # +text_link+(for clickable text URLs),
24
+ # +text_mention+ (for users without usernames)
25
+ def type
26
+ @msg.type
27
+ end
28
+
29
+ # Offset in UTF-16 code units to the start of the entity.
30
+ def offset
31
+ @msg.offset
32
+ end
33
+
34
+ # Length of the entity in UTF-16 code units.
35
+ def length
36
+ @msg.length
37
+ end
38
+
39
+ # +Optional.+ For +text_link+ only, url that will be opened after user
40
+ # taps on the text.
41
+ def url
42
+ @msg.url
43
+ end
44
+
45
+ # +Optional.+ For +pre+ only, the programming language of the entity text.
46
+ def language
47
+ @msg.language
48
+ end
49
+
50
+ # +Optional+. For text_mention? only, the mentioned user.
51
+ # Returns User object
52
+ def user
53
+ usr = @msg.user
54
+ unless user.nil?
55
+ return User.new(usr)
56
+ end
57
+
58
+ false
59
+ end
60
+
61
+ # Returns true if entity #type is mention else false is returned.
62
+ def mention?
63
+ type.eql? 'mention'
64
+ end
65
+
66
+ # Returns true if entity #type is bot_command else false is returned.
67
+ def bot_command?
68
+ type.eql? 'bot_command'
69
+ end
70
+
71
+ # Return true if entity #type is url else false is returned.
72
+ def link?
73
+ type.elq? 'url'
74
+ end
75
+
76
+ # Returns true if entity #type is email else false is returned.
77
+ def email?
78
+ type.eql? 'email'
79
+ end
80
+
81
+ # Return true if entity #type is +phone_number+ else false is returned.
82
+ def phone_number?
83
+ type.eql? 'phone_number'
84
+ end
85
+
86
+ # Returns true if entity #type is +text_link+ else false is returned.
87
+ def text_link?
88
+ type.eql? 'text_link'
89
+ end
90
+
91
+ # Returns true if entity #type is +text_mention+ else false is returned.
92
+ def text_mention?
93
+ type.eql? 'text_mention'
94
+ end
95
+ end