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,142 @@
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 contains information about one member of a chat.
9
+ class ChatMember
10
+ def initialize(mem) # :nodoc:
11
+ @memb = mem
12
+ end
13
+
14
+ # Information about the user.
15
+ # Return User object.
16
+ def user
17
+ User.new(@memb.user)
18
+ end
19
+
20
+ # The member's status in the chat. Can be +creator+, +administrator+,
21
+ # +member+, +restricted+, +left+ or +kicked+.
22
+ def status
23
+ @memb.status
24
+ end
25
+
26
+ # +Optional.+ Owner and administrators only. Custom title for this user.
27
+ # check if user is admin using #admin? before going to use this method,
28
+ # unless nil is returned.
29
+ def custom_title
30
+ @memb.custom_title
31
+ end
32
+
33
+ # +Optional.+ Restricted and kicked only. Date when restrictions will be
34
+ # lifted for this user; unix time.
35
+ # Check if user is restricted or kicked using #member? before going to use
36
+ # this method else if user is not kicked or restricted then nil is returned.
37
+ def until_date
38
+ @memb.until_date
39
+ end
40
+
41
+ # +Optional.+ Administrators only. True, if the bot is allowed to edit
42
+ # administrator privileges of that user.
43
+ def can_be_edited?
44
+ @memb.can_be_edited
45
+ end
46
+
47
+ # +Optional.+ Administrators only. True, if the administrator can post in
48
+ # the channel; channels only.
49
+ def can_post_messages?
50
+ @memb.can_post_messages
51
+ end
52
+
53
+ # +Optional.+ Administrators only. True, if the administrator can edit
54
+ # messages of other users and can pin messages; channels only.
55
+ def can_edit_messages?
56
+ @memb.can_edit_messages
57
+ end
58
+
59
+ # +Optional.+ Administrators only. True, if the administrator can delete
60
+ # messages of other users.
61
+ def can_delete_messages?
62
+ @memb.can_delete_messages
63
+ end
64
+
65
+ # +Optional.+ Administrators only. True, if the administrator can restrict,
66
+ # #ban_chat_member or #unban_chat_member s.
67
+ def can_restrict_members?
68
+ @memb.can_restrict_members
69
+ end
70
+
71
+ # +Optional.+ Administrators only. True, if the administrator can add new
72
+ # administrators with a subset of their own privileges or demote
73
+ # administrators that he has promoted, directly or indirectly
74
+ # (promoted by administrators that were appointed by the user)
75
+ def can_promote_members?
76
+ @memb.can_promote_members
77
+ end
78
+
79
+ # +Optional.+ Administrators and restricted only. True, if the user is
80
+ # allowed to change the chat title, photo and other settings.
81
+ def can_change_info?
82
+ @memb.can_change_info
83
+ end
84
+
85
+ # +Optional.+ Administrators and restricted only. True, if the user
86
+ # is allowed to invite new users to the chat.
87
+ def can_invite_users?
88
+ @memb.can_invite_users
89
+ end
90
+
91
+ # +Optional.+ Administrators and restricted only. True, if the user is
92
+ # allowed to pin messages; groups and supergroups only.
93
+ def can_pin_messages?
94
+ @memb.can_pin_messages
95
+ end
96
+
97
+ # +Optional.+ Restricted only. True, if the user is a member of the
98
+ # chat at the moment of the reques.
99
+ def member?
100
+ @memb.is_member
101
+ end
102
+
103
+ # +Optional+. Restricted only. True, if the user is allowed to send text
104
+ # messages, contacts, locations and venues.
105
+ def can_send_messages?
106
+ @memb.can_send_messages
107
+ end
108
+
109
+ # +Optional+. Restricted only. True, if the user is allowed to send
110
+ # audios, documents, photos, videos, video notes and voice notes.
111
+ def can_send_media_messages?
112
+ @memb.can_send_media_messages
113
+ end
114
+
115
+ # +Optional.+ Restricted only. True, if the user is allowed to send polls
116
+ def can_send_polls?
117
+ @memb.can_send_polls
118
+ end
119
+
120
+ # +Optional.+ Restricted only. True, if the user is allowed to send
121
+ # animations, games, stickers and use inline bots.
122
+ def can_send_other_messages?
123
+ @memb.can_send_other_messages
124
+ end
125
+
126
+ # +Optional.+ Restricted only. True, if the user is allowed to add
127
+ # web page previews to their messages.
128
+ def can_add_web_page_previews?
129
+ @memb.can_add_web_page_previews
130
+ end
131
+
132
+ # Returns true if user if left the chat. +NB:+ That does not mean it
133
+ # checks if user is a part of chat. Kicked != left
134
+ def left?
135
+ status.eql? 'left'
136
+ end
137
+
138
+ # Returns true if user is admin
139
+ def admin?
140
+ (status.eql? 'creator') or (status.eql? 'administrator')
141
+ end
142
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ ##
5
+ # +Monday+, +August+ +24+ +2020+ +EAT+
6
+ # ===Describes actions that a non-administrator user is allowed to take in a chat.
7
+ class ChatPermissions
8
+ def initialize(perm) # :nodoc:
9
+ @perm = perm
10
+ end
11
+
12
+ # +Optional+. True, if the user is allowed to send text messages, contacts,
13
+ # locations and venues.
14
+ def can_send_messages?
15
+ @perm.can_send_messages
16
+ end
17
+
18
+ # +Optional.+ True, if the user is allowed to send +audios+, +documents+,
19
+ # +photos,+ +videos+, +video_notes+ and +voice_notes,+
20
+ # implies can_send_messages.
21
+ def can_send_media_messages?
22
+ @perm.can_send_media_messages
23
+ end
24
+
25
+ # +Optional+. True, if the user is allowed to +send_polls+, implies
26
+ # +can_send_messages?+
27
+ def can_send_polls?
28
+ @perm.can_send_polls
29
+ end
30
+
31
+ # +Optional.+ True, if the user is allowed to send animations, games
32
+ # stickers and use inline bots, implies can_send_media_messages
33
+ def can_send_other_messages?
34
+ @perm.can_send_other_messages
35
+ end
36
+
37
+ # +Optional.+ True, if the user is allowed to add web page previews to
38
+ # their messages, implies +can_send_media_messages?+
39
+ def can_add_web_page_previews?
40
+ @perm.can_add_web_page_previews
41
+ end
42
+
43
+ # +Optional.+ True, if the user is allowed to change the chat title,
44
+ # photo and other settings. Ignored in public supergroups.
45
+ def can_change_info?
46
+ @perm.can_change_info
47
+ end
48
+
49
+ # +Optional.+ True, if the user is allowed to invite new users to the chat.
50
+ def can_invite_users?
51
+ @perm.can_invite_users
52
+ end
53
+
54
+ # +Optional.+ True, if the user is allowed to pin messages.
55
+ # Ignored in public supergroups.
56
+ def can_pin_messages?
57
+ @perm.can_pin_messages
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ ##
5
+ # +Monday+, +August+ +24+ +2020+ +EAT+
6
+ # ===This object represents a chat photo.
7
+ class ChatPhoto
8
+ def initialize(photo) # :nodoc:
9
+ @photo = photo
10
+ end
11
+
12
+ # File identifier of small (160x160) chat photo. This file_id can be used
13
+ # only for photo download and only for as long as the photo is not changed.
14
+ def small_file_id
15
+ @photo.small_file_id
16
+ end
17
+
18
+ # Unique file identifier of small (160x160) chat photo, which is supposed
19
+ # to be the same over time and for different bots.
20
+ # Can't be used to download or reuse the file.
21
+ def small_file_unique_id
22
+ @photo.small_file_unique_id
23
+ end
24
+
25
+ # File identifier of big (640x640) chat photo. This file_id can be used
26
+ # only for photo download and only for as long as the photo is not changed.
27
+ def big_file_id
28
+ @photo.big_file_id
29
+ end
30
+
31
+ # Unique file identifier of big (640x640) chat photo, which is supposed
32
+ # to be the same over time and for different bots.
33
+ # Can't be used to download or reuse the file.
34
+ def big_file_unique_id
35
+ @photo.big_file_unique_id
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'user'
5
+ require_relative 'location'
6
+
7
+ # ===Represents a result of an inline query that was chosen by the user
8
+ # ====and sent to their chat partner.
9
+ class ChoseInlineResult
10
+ def initialize(result) # :nodoc:
11
+ @result = result
12
+ end
13
+
14
+ # The unique identifier for the result that was chosen.
15
+ def result_id
16
+ @result.result_id
17
+ end
18
+
19
+ # The user that chose the result.
20
+ def from
21
+ User.new(@result.from)
22
+ end
23
+
24
+ # +Optional+. Sender location, only for bots that require user location.
25
+ def location
26
+ lcation = @result.location
27
+ return Location.new(lcation) if lcation
28
+
29
+ false
30
+ end
31
+
32
+ # +Optional.+ Identifier of the sent inline message. Available only if
33
+ # there is an inline keyboard attached to the message. Will be also
34
+ # received in callback queries and can be used to edit the message.
35
+ def inline_message_id
36
+ @result.inline_message_id
37
+ end
38
+
39
+ # The query that was used to obtain the result.
40
+ def query
41
+ @result.query
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ ##
5
+ # +Monday+, +August+ +24+ +2020+ +EAT+
6
+ # ===This object represents a phone contact.
7
+ class Contact
8
+ def initialize(conta) # :nodoc:
9
+ @conta = conta
10
+ freeze
11
+ end
12
+
13
+ # Contact's phone number.
14
+ def phone_number
15
+ @conta.phone_number
16
+ end
17
+
18
+ # Contact's first name
19
+ def first_name
20
+ @conta.first_name
21
+ end
22
+
23
+ # +Optional+. Contact's last name
24
+ def last_name
25
+ @conta.last_name
26
+ end
27
+
28
+ # +Optional+. Contact's user identifier in Telegram
29
+ def user_id
30
+ @conta.user_id
31
+ end
32
+
33
+ # +Optional.+ Additional data about the contact in the form of a vCard
34
+ def vcard
35
+ @conta.vcard
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ # +Sunday+, +August+ +23+ +2020+ +EAT+
5
+
6
+ # ===This object represents an animated emoji that displays a random value.
7
+ class Dice
8
+ def initialize(dice) # :nodoc:
9
+ @dice = dice
10
+ end
11
+
12
+ # Emoji on which the dice throw animation is based.
13
+ def emoji
14
+ @dice.emoji
15
+ end
16
+
17
+ # Value of the dice
18
+ def value
19
+ @dice.value
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'same/common_2'
5
+ require_relative 'photo_size'
6
+
7
+ # +Sunday+, +August+ +23+ +2020+
8
+
9
+ # ===This object represents a general file (as opposed to Photo, Voice messages and Audio files).
10
+ # Extend Common2 clas.
11
+ class Document < Common2
12
+ def initialize(obj) # :nodoc:
13
+ super(obj)
14
+ end
15
+
16
+ # +Optional+. Original filename as defined by sender.
17
+ def file_name
18
+ @obj.file_name
19
+ end
20
+
21
+ def thumb
22
+ data = @obj.file_name
23
+ return PhotoSize.new(data) if data
24
+
25
+ false
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ ##
5
+ # +Monday+, +August+ +24+ +2020+
6
+ # ===This object represents a file ready to be downloaded.
7
+ class TFile
8
+ def initialize(file) # :nodoc:
9
+ @file = file
10
+ end
11
+
12
+ # Identifier for this file, which can be used to download or reuse the file.
13
+ def file_id
14
+ @file.file_id
15
+ end
16
+
17
+ # Unique identifier for this file, which is supposed to be the same over
18
+ # time and for different bots. Can't be used to download or reuse the file.
19
+ def file_unique_id
20
+ @file.file_unique_id
21
+ end
22
+
23
+ # +Optional+. File size, if known.
24
+ def file_size
25
+ @file.file_size
26
+ end
27
+
28
+ # +Optional+. File path.
29
+ def file_path
30
+ @file.file_path
31
+ end
32
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'animation'
5
+ require_relative 'photo_size'
6
+ require_relative 'message_entity'
7
+
8
+ # This object represents a game. Use BotFather to create and edit games,
9
+ # their short names will act as unique identifiers.
10
+ class Game
11
+ def initialize(game) # :nodoc:
12
+ @game = game
13
+ end
14
+
15
+ # Title of the game.
16
+ def title
17
+ @game.title
18
+ end
19
+
20
+ # Description of the game.
21
+ def description
22
+ @game.description
23
+ end
24
+
25
+ # +Optional.+ Brief description of the game or high scores included in
26
+ # the game message.
27
+ def text
28
+ @game.text
29
+ end
30
+
31
+ # +Optional+. Animation that will be displayed in the game message in
32
+ # chats. Upload via BotFather
33
+ def animation
34
+ @game.animation
35
+ end
36
+
37
+ # +Optional+. Special entities that appear in text, such as usernames,
38
+ # URLs, bot commands, etc.
39
+ def text_entities
40
+ t_ent = @game.text_entities
41
+ if t_ent.empty?
42
+ return false
43
+ end
44
+
45
+ ary = []
46
+ t_ent.each do |ent|
47
+ ary << MessageEntity.new(ent)
48
+ end
49
+ ary
50
+ end
51
+
52
+ # Photo that will be displayed in the game message in chats.
53
+ def photo
54
+ poto = @game.photo
55
+ if poto.empty?
56
+ return false
57
+ end
58
+
59
+ ary = []
60
+ poto.each do |p|
61
+ ary << PhotoSize.new(p)
62
+ end
63
+ ary
64
+ end
65
+ end