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.
- checksums.yaml +4 -4
- data/LICENSE.md +9 -0
- data/README.md +398 -0
- data/lib/api/all.rb +12 -0
- data/lib/api/delete_apis.rb +55 -0
- data/lib/api/get_apis.rb +162 -0
- data/lib/api/nstandard.rb +26 -0
- data/lib/api/other_apis.rb +225 -0
- data/lib/api/send_apis.rb +191 -0
- data/lib/api/set_apis.rb +130 -0
- data/lib/core_api.rb +41 -0
- data/lib/objects/all.rb +42 -0
- data/lib/objects/animation.rb +38 -0
- data/lib/objects/audio.rb +37 -0
- data/lib/objects/bot_command.rb +24 -0
- data/lib/objects/callback_query.rb +64 -0
- data/lib/objects/chat.rb +158 -0
- data/lib/objects/chat_member.rb +142 -0
- data/lib/objects/chat_permissions.rb +59 -0
- data/lib/objects/chat_photo.rb +37 -0
- data/lib/objects/chosen_inline_result.rb +43 -0
- data/lib/objects/contact.rb +37 -0
- data/lib/objects/dice.rb +21 -0
- data/lib/objects/document.rb +27 -0
- data/lib/objects/file.rb +32 -0
- data/lib/objects/game.rb +65 -0
- data/lib/objects/inline_query.rb +42 -0
- data/lib/objects/inlinekeyboardbutton.rb +59 -0
- data/lib/objects/inlinekeyboardmarkup.rb +30 -0
- data/lib/objects/location.rb +21 -0
- data/lib/objects/mask_position.rb +35 -0
- data/lib/objects/message.rb +378 -0
- data/lib/objects/message_entity.rb +93 -0
- data/lib/objects/order_info.rb +34 -0
- data/lib/objects/photo_size.rb +14 -0
- data/lib/objects/poll.rb +97 -0
- data/lib/objects/poll_answer.rb +29 -0
- data/lib/objects/poll_option.rb +22 -0
- data/lib/objects/pre_checkout_query.rb +48 -0
- data/lib/objects/same/common.rb +37 -0
- data/lib/objects/same/common_2.rb +38 -0
- data/lib/objects/shipping_address.rb +39 -0
- data/lib/objects/shipping_query.rb +32 -0
- data/lib/objects/sticker.rb +55 -0
- data/lib/objects/update.rb +174 -0
- data/lib/objects/user.rb +66 -0
- data/lib/objects/user_profile_photos.rb +35 -0
- data/lib/objects/venue.rb +40 -0
- data/lib/objects/video.rb +37 -0
- data/lib/objects/video_note.rb +48 -0
- data/lib/objects/voice.rb +20 -0
- data/lib/teleruby.rb +4 -40
- data/lib/teleruby/all_apis.rb +22 -0
- data/lib/teleruby/api/delete_apis.rb +58 -0
- data/lib/teleruby/api/get_apis.rb +172 -0
- data/lib/teleruby/api/nstandard.rb +27 -0
- data/lib/teleruby/api/other_apis.rb +241 -0
- data/lib/teleruby/api/send_apis.rb +206 -0
- data/lib/teleruby/api/set_apis.rb +137 -0
- data/lib/teleruby/core_api.rb +52 -0
- data/lib/teleruby/objects/all.rb +42 -0
- data/lib/teleruby/objects/animation.rb +40 -0
- data/lib/teleruby/objects/audio.rb +39 -0
- data/lib/teleruby/objects/bot_command.rb +24 -0
- data/lib/teleruby/objects/callback_query.rb +66 -0
- data/lib/teleruby/objects/chat.rb +164 -0
- data/lib/teleruby/objects/chat_member.rb +142 -0
- data/lib/teleruby/objects/chat_permissions.rb +59 -0
- data/lib/teleruby/objects/chat_photo.rb +37 -0
- data/lib/teleruby/objects/chosen_inline_result.rb +45 -0
- data/lib/teleruby/objects/contact.rb +37 -0
- data/lib/teleruby/objects/dice.rb +21 -0
- data/lib/teleruby/objects/document.rb +29 -0
- data/lib/teleruby/objects/file.rb +32 -0
- data/lib/teleruby/objects/game.rb +65 -0
- data/lib/teleruby/objects/inline_query.rb +44 -0
- data/lib/teleruby/objects/inlinekeyboardbutton.rb +59 -0
- data/lib/teleruby/objects/inlinekeyboardmarkup.rb +31 -0
- data/lib/teleruby/objects/location.rb +21 -0
- data/lib/teleruby/objects/mask_position.rb +35 -0
- data/lib/teleruby/objects/message.rb +400 -0
- data/lib/teleruby/objects/message_entity.rb +95 -0
- data/lib/teleruby/objects/order_info.rb +36 -0
- data/lib/teleruby/objects/photo_size.rb +14 -0
- data/lib/teleruby/objects/poll.rb +97 -0
- data/lib/teleruby/objects/poll_answer.rb +29 -0
- data/lib/teleruby/objects/poll_option.rb +22 -0
- data/lib/teleruby/objects/pre_checkout_query.rb +50 -0
- data/lib/teleruby/objects/same/common.rb +31 -0
- data/lib/teleruby/objects/same/common_2.rb +32 -0
- data/lib/teleruby/objects/shipping_address.rb +39 -0
- data/lib/teleruby/objects/shipping_query.rb +32 -0
- data/lib/teleruby/objects/sticker.rb +59 -0
- data/lib/teleruby/objects/update.rb +207 -0
- data/lib/teleruby/objects/user.rb +66 -0
- data/lib/teleruby/objects/user_profile_photos.rb +36 -0
- data/lib/teleruby/objects/venue.rb +40 -0
- data/lib/teleruby/objects/video.rb +39 -0
- data/lib/teleruby/objects/video_note.rb +50 -0
- data/lib/teleruby/objects/voice.rb +20 -0
- data/lib/teleruby/version.rb +3 -0
- data/msg.png +0 -0
- data/rdoc.png +0 -0
- data/teleruby.gemspec +9 -7
- metadata +109 -6
data/lib/api/set_apis.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../core_api'
|
5
|
+
|
6
|
+
##
|
7
|
+
# Solomon Boloshe(Lee Crey)
|
8
|
+
# Friday, August 21 2020 06:35:33 PM +0300
|
9
|
+
|
10
|
+
module Telegram
|
11
|
+
module SetApis # rubocop:disable Metrics/ModuleLength
|
12
|
+
include CoreApi
|
13
|
+
# Use this method to set a custom title for an administrator
|
14
|
+
# in a supergroup promoted by the bot.
|
15
|
+
def set_cutom_title(chat_id, user_id, title)
|
16
|
+
if chat_id.to_i.negative?
|
17
|
+
raise BadRequestError, 'can\' set custom title for private chat'
|
18
|
+
end
|
19
|
+
hash = { chat_id: chat_id, user_id: user_id, custom_title: title }
|
20
|
+
response = http_post('setChatAdministratorCustomTitle', hash)
|
21
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
22
|
+
raise PermissionError, response.description
|
23
|
+
end
|
24
|
+
response.result
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_chat_permissions(chat_id, permissions)
|
28
|
+
unless chat_id.to_i.negative?
|
29
|
+
raise BadRequestError, 'can\' set permissions for private chat'
|
30
|
+
end
|
31
|
+
hash = { chat_id: chat_id, permissions: permissions }
|
32
|
+
response = http_post('setChatPermissions', hash)
|
33
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
34
|
+
raise PermissionError, response.description
|
35
|
+
end
|
36
|
+
response.result
|
37
|
+
end
|
38
|
+
|
39
|
+
# Use this method to set a new profile photo for the chat.
|
40
|
+
# Photos can't be changed for private chats.
|
41
|
+
def set_chat_photo(chat_id, file)
|
42
|
+
unless chat_id.to_i.negative?
|
43
|
+
fail BadRequestError, 'can\'t set photo for private chat'
|
44
|
+
end
|
45
|
+
hash = { chat_id: chat_id, photo: file }
|
46
|
+
data = http_post('setChatPhoto', hash)
|
47
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
48
|
+
raise PermissionError, data.description
|
49
|
+
end
|
50
|
+
data.result
|
51
|
+
end
|
52
|
+
|
53
|
+
# Use this method to change the title of a chat.
|
54
|
+
# Titles can't be changed for private chats.
|
55
|
+
def set_chat_title(chat_id, title)
|
56
|
+
unless chat_id.to_i.negative?
|
57
|
+
raise BadRequestError, 'can\'t set chat title for private'
|
58
|
+
end
|
59
|
+
|
60
|
+
hash = { chat_id: chat_id, title: title.to_s }
|
61
|
+
data = http_post('setChatTitle', hash)
|
62
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
63
|
+
raise PermissionError, data.description
|
64
|
+
end
|
65
|
+
|
66
|
+
data.result
|
67
|
+
end
|
68
|
+
|
69
|
+
# Use this method to change the description of a group,
|
70
|
+
# a supergroup or a channel.
|
71
|
+
def set_chat_description(chat_id, description)
|
72
|
+
unless chat_id.to_i.negative?
|
73
|
+
raise BadRequestError, 'can\'t set description for private chat'
|
74
|
+
end
|
75
|
+
|
76
|
+
hash = { chat_id: chat_id, description: description }
|
77
|
+
data = http_post('setChatDescription', hash)
|
78
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
79
|
+
raise PermissionError, data.description
|
80
|
+
end
|
81
|
+
|
82
|
+
data.result
|
83
|
+
end
|
84
|
+
|
85
|
+
# Use this method to set a new group sticker set for a supergroup.
|
86
|
+
def set_chat_sticker_set(chat_id, set_name)
|
87
|
+
hash = { chat_id: chat_id, set_name: set_name }
|
88
|
+
data = http_post('setChatStickerSet', hash)
|
89
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
90
|
+
raise StandardError, data.description
|
91
|
+
end
|
92
|
+
data.result
|
93
|
+
end
|
94
|
+
|
95
|
+
# Use this method to change the list of the bot's commands.
|
96
|
+
def set_my_command(command)
|
97
|
+
hash = { command: command }
|
98
|
+
data = http_post('setMyCommand', hash)
|
99
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
100
|
+
raise TokenError, data.description
|
101
|
+
end
|
102
|
+
data.result
|
103
|
+
end
|
104
|
+
|
105
|
+
# Use this method to move a sticker in a set created by the bot
|
106
|
+
# to a specific position. position must be int value
|
107
|
+
def set_sticker_position_in_the_set(sticker, position)
|
108
|
+
hash = { sticker: sticker, position: position }
|
109
|
+
data = http_post('setStickerPositionInTheSet', hash)
|
110
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
111
|
+
raise Error, data.description
|
112
|
+
end
|
113
|
+
data.result
|
114
|
+
end
|
115
|
+
|
116
|
+
# Use this method to set the thumbnail of a sticker set.
|
117
|
+
def set_sticker_set_thumb(name, user_id, params = {})
|
118
|
+
hash = { name: name, user_id: user_id }.merge!(params)
|
119
|
+
data = http_post('setStickerSetThumb', hash)
|
120
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
121
|
+
raise Error, data.description
|
122
|
+
end
|
123
|
+
data.result
|
124
|
+
end
|
125
|
+
|
126
|
+
def set_webhook(url, params = {})
|
127
|
+
raise NotImplementedError, 'not implemented'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/core_api.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'json'
|
5
|
+
require_relative 'objects/all'
|
6
|
+
|
7
|
+
module Telegram
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
# Raise when chat_id, and user_id are incorrect,
|
11
|
+
class IdError < Error; end
|
12
|
+
|
13
|
+
# Raise when bot token is incorrect.
|
14
|
+
class TokenError < Error; end
|
15
|
+
|
16
|
+
# Raise when bot has not appropriate admin right in supergroups.
|
17
|
+
class PermissionError < Error; end
|
18
|
+
|
19
|
+
# Raise when one of optional parameters is incorrect and telegram
|
20
|
+
# unalbe to do the requested operation.
|
21
|
+
class TelegramError < Error; end
|
22
|
+
|
23
|
+
class FatalError < Error; end
|
24
|
+
class BadRequestError < Error; end
|
25
|
+
class UndefinedMethod < Error; end
|
26
|
+
|
27
|
+
module CoreApi
|
28
|
+
@@base_uri = %q{https://api.telegram.org/bot}
|
29
|
+
@@file_uri = %q{https://api.telegram.org/file/bot} # to download files
|
30
|
+
|
31
|
+
def http_get(method, params = {})
|
32
|
+
body = Faraday.post(@@base_uri + @token + '/' + method, params).body
|
33
|
+
JSON.parse(body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def http_post(method, params = {})
|
37
|
+
body = Faraday.post(@@base_uri + @token + '/' + method, params).body
|
38
|
+
JSON.parse(body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/objects/all.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
|
6
|
+
require_relative 'poll'
|
7
|
+
require_relative 'location'
|
8
|
+
require_relative 'venue'
|
9
|
+
require_relative 'chat'
|
10
|
+
require_relative 'bot_command'
|
11
|
+
require_relative 'chat_permissions'
|
12
|
+
require_relative 'chat_photo'
|
13
|
+
require_relative 'callback_query'
|
14
|
+
require_relative 'file'
|
15
|
+
require_relative 'user_profile_photos'
|
16
|
+
require_relative 'poll_answer'
|
17
|
+
require_relative 'poll_option'
|
18
|
+
require_relative 'dice'
|
19
|
+
require_relative 'contact'
|
20
|
+
require_relative 'voice'
|
21
|
+
require_relative 'video'
|
22
|
+
require_relative 'audio'
|
23
|
+
require_relative 'photo_size'
|
24
|
+
require_relative 'document'
|
25
|
+
require_relative 'video_note'
|
26
|
+
require_relative 'user'
|
27
|
+
require_relative 'message_entity'
|
28
|
+
require_relative 'chat_member'
|
29
|
+
require_relative 'update'
|
30
|
+
require_relative 'chosen_inline_result'
|
31
|
+
require_relative 'sticker'
|
32
|
+
require_relative 'game'
|
33
|
+
require_relative 'inline_query'
|
34
|
+
require_relative 'shipping_query'
|
35
|
+
require_relative 'mask_position'
|
36
|
+
require_relative 'shipping_address'
|
37
|
+
require_relative 'pre_checkout_query'
|
38
|
+
require_relative 'order_info'
|
39
|
+
require_relative 'message'
|
40
|
+
require_relative 'animation'
|
41
|
+
require_relative 'inlinekeyboardbutton'
|
42
|
+
require_relative 'inlinekeyboardmarkup'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'photo_size'
|
5
|
+
require_relative 'same/common'
|
6
|
+
|
7
|
+
##
|
8
|
+
# +Sunday+, +August+ +23+ +2020+
|
9
|
+
# ===This object represents an animation file.
|
10
|
+
# (GIF or H.264/MPEG-4 AVC video without sound).
|
11
|
+
class Animation < Common
|
12
|
+
def initialize(obj) # :nodoc:
|
13
|
+
super(obj)
|
14
|
+
freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
# Duration of the video in seconds as defined by sender.
|
18
|
+
def duration
|
19
|
+
@obj.duration
|
20
|
+
end
|
21
|
+
|
22
|
+
# +Optional+. Original animation filename as defined by sender.
|
23
|
+
def file_name
|
24
|
+
@obj.file_name
|
25
|
+
end
|
26
|
+
|
27
|
+
# +Optional.+ MIME type of the file as defined by sender.
|
28
|
+
def mime_type
|
29
|
+
@obj.mime_type
|
30
|
+
end
|
31
|
+
|
32
|
+
def thumb
|
33
|
+
data = @obj.thumb
|
34
|
+
return PhotoSize.new(data) if data
|
35
|
+
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'same/common_2'
|
5
|
+
require_relative 'photo_size'
|
6
|
+
|
7
|
+
##
|
8
|
+
# +Monday,+ +August+ +24+ +2020+
|
9
|
+
# ===This object represents an audio file to be treated as music by the Telegram clients.
|
10
|
+
class Audio < Common2
|
11
|
+
def initialize(audio) # :nodoc:
|
12
|
+
super(audio)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Duration of the audio in seconds as defined by sender.
|
16
|
+
def duration
|
17
|
+
@obj.duration
|
18
|
+
end
|
19
|
+
|
20
|
+
# +Optional.+ Performer of the audio as defined by sender or by audio tags.
|
21
|
+
def performer
|
22
|
+
@obj.performer
|
23
|
+
end
|
24
|
+
|
25
|
+
# +Optional+. Title of the audio as defined by sender or by audio tags
|
26
|
+
def title
|
27
|
+
@obj.title
|
28
|
+
end
|
29
|
+
|
30
|
+
# +Optional.+ Thumbnail of the album cover to which the music file belongs.
|
31
|
+
def thumb
|
32
|
+
data = @obj.thumb
|
33
|
+
return PhotoSize.new(data) if data
|
34
|
+
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# +Saturday+, +August+ +22+ +2020+ +EAT+
|
5
|
+
|
6
|
+
# ===This object represents a bot command
|
7
|
+
|
8
|
+
class BotCommand
|
9
|
+
def initialize(bot) # :nodoc:
|
10
|
+
@bot = bot
|
11
|
+
freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
# Text of the command, 1-32 characters. Can contain only lowercase
|
15
|
+
# English letters, digits and underscores.
|
16
|
+
def command
|
17
|
+
@bot.command
|
18
|
+
end
|
19
|
+
|
20
|
+
# Description of the command, 3-256 characters.
|
21
|
+
def description
|
22
|
+
@bot.description
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'user'
|
5
|
+
require_relative 'message'
|
6
|
+
|
7
|
+
##
|
8
|
+
# +Monday+, +August+ +24+ +2020+
|
9
|
+
# ===This object represents an incoming callback query from a callback button in an inline keyboard.
|
10
|
+
# If the button that originated the query was
|
11
|
+
# attached to a message sent by the bot, the field message will be present.
|
12
|
+
# If the button was attached to a message sent via the bot (in inline mode),
|
13
|
+
# the field inline_message_id will be present. Exactly one of the fields data
|
14
|
+
# or game_short_name will be present.
|
15
|
+
class CallbackQuery
|
16
|
+
def initialize(query) # :nodoc:
|
17
|
+
@query = query
|
18
|
+
end
|
19
|
+
|
20
|
+
# Unique identifier for this query.
|
21
|
+
def id
|
22
|
+
@query.id
|
23
|
+
end
|
24
|
+
|
25
|
+
# Sender. Returns User object
|
26
|
+
def from
|
27
|
+
User.new(@query.from)
|
28
|
+
end
|
29
|
+
|
30
|
+
# +Optional+. Message with the callback button that originated the query.
|
31
|
+
# Note that message content and message date will not be available if
|
32
|
+
# the message is too old.
|
33
|
+
def message
|
34
|
+
data = @query.message
|
35
|
+
return Message.new(data) if data
|
36
|
+
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
# +Optional.+ Identifier of the message sent via the bot in inline mode,
|
41
|
+
# that originated the query.
|
42
|
+
def inline_message_id
|
43
|
+
@query.inline_message_id
|
44
|
+
end
|
45
|
+
|
46
|
+
# Global identifier, uniquely corresponding to the chat to which the
|
47
|
+
# message with the callback button was sent. Useful for high scores
|
48
|
+
# in games.
|
49
|
+
def chat_instance
|
50
|
+
@query.chat_instance
|
51
|
+
end
|
52
|
+
|
53
|
+
# +Optional.+ Data associated with the callback button. Be aware that
|
54
|
+
# a bad client can send arbitrary data in this field.
|
55
|
+
def data
|
56
|
+
@query.data
|
57
|
+
end
|
58
|
+
|
59
|
+
# +Optional.+ Short name of a Game to be returned, serves as the unique
|
60
|
+
# identifier for the game
|
61
|
+
def game_short_name
|
62
|
+
@query.game_short_name
|
63
|
+
end
|
64
|
+
end
|
data/lib/objects/chat.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'chat_permissions'
|
5
|
+
require_relative 'message'
|
6
|
+
require_relative 'chat_photo'
|
7
|
+
|
8
|
+
# +Sunday+, +August+ +23+ +2020+ +EAT+
|
9
|
+
|
10
|
+
# ===This object represents a chat.
|
11
|
+
class Chat
|
12
|
+
def initialize(chat) # :nodoc:
|
13
|
+
@chat = chat
|
14
|
+
end
|
15
|
+
|
16
|
+
# Unique identifier for this chat.
|
17
|
+
def id
|
18
|
+
@chat.id
|
19
|
+
end
|
20
|
+
|
21
|
+
# Type of chat, can be either +private+, +group+,
|
22
|
+
# +supergroup+ or +channel+.
|
23
|
+
def type
|
24
|
+
@chat.type
|
25
|
+
end
|
26
|
+
|
27
|
+
# +Optional+. *Title*, for +supergroups+, +channels+ and +group+ chats.
|
28
|
+
def title
|
29
|
+
@chat.title
|
30
|
+
end
|
31
|
+
|
32
|
+
# +Optional+. *Username*, for +private+ chats, +supergroups+ and
|
33
|
+
# +channels+ if available else nil is returned.
|
34
|
+
def username
|
35
|
+
@chat.username
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns true if chat type is private else false is returned.
|
39
|
+
def private?
|
40
|
+
type.eql? 'private'
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns true if chat type is supergroup else false is returned.
|
44
|
+
def supergroup?
|
45
|
+
type.eql? 'supergroup'
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns true if chat type is channel else false is returned.
|
49
|
+
def channel?
|
50
|
+
type.eql? 'channel'
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns true if chat has title else false is returned.
|
54
|
+
def has_title?
|
55
|
+
title.nil?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# ====Returned only for private chat
|
60
|
+
# It extends from Chat class.
|
61
|
+
class PrivateChat < Chat
|
62
|
+
def initialize(chat) # :nodoc:
|
63
|
+
super(chat)
|
64
|
+
end
|
65
|
+
|
66
|
+
# +Optional+. First name of the other party in a +private+ chat.
|
67
|
+
def first_name
|
68
|
+
@chat.first_name
|
69
|
+
end
|
70
|
+
|
71
|
+
# +Optional.+ Last name of the other party in a +private+ chat.
|
72
|
+
def last_name
|
73
|
+
@chat.last_name
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# ==== This object is returned only in get_chat methods
|
78
|
+
# It extends from Chat class.
|
79
|
+
class GetChat < Chat
|
80
|
+
def initialize(chat) # :nodoc:
|
81
|
+
super(chat)
|
82
|
+
end
|
83
|
+
|
84
|
+
# +Optional+. Returns ChatPhoto if available else false is returned.
|
85
|
+
def photo
|
86
|
+
data = @chat.photo
|
87
|
+
return ChatPhoto.new(data) if data
|
88
|
+
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
# +Optional.+ Description, for +groups+, +supergroups+ and +channel+
|
93
|
+
# chats.
|
94
|
+
def description
|
95
|
+
@chat.description
|
96
|
+
end
|
97
|
+
|
98
|
+
# +Optional.+ Chat invite link, for +groups+, +supergroups+ and +channel+
|
99
|
+
# chats. Each administrator in a chat generates their own invite links,
|
100
|
+
# so the bot must first generate the link using +export_chat_link.+
|
101
|
+
def invite_link
|
102
|
+
@chat.invite_link
|
103
|
+
end
|
104
|
+
|
105
|
+
# +Optional+. Pinned message, for +groups+, +supergroups+ and +channels.+
|
106
|
+
# Returns Message object.
|
107
|
+
def pinned_message
|
108
|
+
data = @chat.pinned_message
|
109
|
+
return Message.new(data) if data
|
110
|
+
|
111
|
+
false
|
112
|
+
end
|
113
|
+
|
114
|
+
# +Optional.+ Default chat member permissions, for +groups+ and
|
115
|
+
# +supergroups+. Returns ChatPermissions object.
|
116
|
+
def permissions
|
117
|
+
data = @chat.permissions
|
118
|
+
return ChatPermissions.new(data) if data
|
119
|
+
|
120
|
+
false
|
121
|
+
end
|
122
|
+
|
123
|
+
# +Optional.+ For +supergroups,+ the minimum allowed delay between
|
124
|
+
# consecutive messages sent by each unpriviledged user.
|
125
|
+
def slow_mode_delay
|
126
|
+
@chat.slow_mode_delay
|
127
|
+
end
|
128
|
+
|
129
|
+
# +Optional.+ For +supergroups,+ name of group sticker set.
|
130
|
+
def sticker_set_name
|
131
|
+
@chat.sticker_set_name
|
132
|
+
end
|
133
|
+
|
134
|
+
# +Optional.+ True, if the bot can change the group sticker set.
|
135
|
+
def can_set_sticker_set?
|
136
|
+
@chat.can_set_sticker_set
|
137
|
+
end
|
138
|
+
|
139
|
+
# Returns true if photo is set to chat else false is returned.
|
140
|
+
def has_photo?
|
141
|
+
photo ? true : false
|
142
|
+
end
|
143
|
+
|
144
|
+
# Returns true if description is set to chat else false is returned.
|
145
|
+
def has_description?
|
146
|
+
description.nil?
|
147
|
+
end
|
148
|
+
|
149
|
+
# Returns true if message is pinned in chat else false is returned.
|
150
|
+
def pinned_message?
|
151
|
+
pinned_message ? true : false
|
152
|
+
end
|
153
|
+
|
154
|
+
# Returns true if slow mode delay is set in chat.
|
155
|
+
def slow_mode_delay_set?
|
156
|
+
slow_mode_delay ? true : false
|
157
|
+
end
|
158
|
+
end
|