telbe 0.0.4 → 0.0.5
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/lib/telbe/base.rb +29 -0
- data/lib/telbe/bot.rb +188 -48
- data/lib/telbe/contact.rb +25 -3
- data/lib/telbe/inline.rb +9 -0
- data/lib/telbe/keyboard.rb +22 -20
- data/lib/telbe/location.rb +50 -26
- data/lib/telbe/media.rb +318 -11
- data/lib/telbe/poll.rb +21 -13
- data/lib/telbe/sticker.rb +136 -3
- data/lib/telbe/user.rb +74 -3
- data/lib/telbe/version.rb +1 -1
- data/lib/telbe/webhook.rb +24 -6
- data/lib/telbe.rb +5 -3
- data/telbe.gemspec +1 -2
- metadata +12 -25
- data/lib/telbe/helper.rb +0 -66
data/lib/telbe/user.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module Telbe
|
2
|
+
CHAT_MEMBER_STATUS = ["creator", "administrator", "member", "restricted", "left", "kicked"]
|
3
|
+
|
2
4
|
class Bot
|
3
5
|
def get_chat_administrators(chatid_descriptor)
|
4
6
|
request(:getChatAdministrators, chatid_descriptor).collect do |member_hash|
|
@@ -9,13 +11,82 @@ module Telbe
|
|
9
11
|
def get_chat_members_count(chatid_descriptor)
|
10
12
|
request(:getChatMembersCount, chatid_descriptor)
|
11
13
|
end
|
14
|
+
|
15
|
+
def get_me
|
16
|
+
User.new(request(:getMe))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ChatIdDescriptor
|
21
|
+
include SimplifyApi
|
22
|
+
attribute :chat_id, Integer, mandatory: true
|
12
23
|
end
|
13
|
-
|
24
|
+
|
25
|
+
# id Integer Unique identifier for this user or bot
|
26
|
+
# is_bot Boolean True, if this user is a bot
|
27
|
+
# first_name String User‘s or bot’s first name
|
28
|
+
# last_name String Optional. User‘s or bot’s last name
|
29
|
+
# username String Optional. User‘s or bot’s username
|
30
|
+
# language_code String Optional. IETF language tag of the user's language
|
14
31
|
class User
|
15
|
-
include
|
32
|
+
include SimplifyApi
|
33
|
+
attribute :id, Integer, mandatory: true
|
34
|
+
attribute :is_bot, values: [true, false], mandatory: true
|
35
|
+
attribute :first_name, String, mandatory: true
|
36
|
+
attribute :last_name, String
|
37
|
+
attribute :username, String
|
38
|
+
attribute :language_code, String
|
39
|
+
end
|
40
|
+
|
41
|
+
# Created to nest the arrays in UserProfilePhotos
|
42
|
+
class UserProfilePhoto
|
43
|
+
include SimplifyApi
|
44
|
+
attribute :photo, [PhotoSize]
|
45
|
+
end
|
46
|
+
|
47
|
+
# total_count Integer Total number of profile pictures the target user has
|
48
|
+
# photos Array of Array of PhotoSize Requested profile pictures (in up to 4 sizes each)
|
49
|
+
class UserProfilePhotos
|
50
|
+
include SimplifyApi
|
51
|
+
attribute :total_count, Integer
|
52
|
+
attribute :photos, [UserProfilePhoto]
|
16
53
|
end
|
17
54
|
|
55
|
+
# user User Information about the user
|
56
|
+
# status String The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left" or "kicked"
|
57
|
+
# until_date Integer Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
|
58
|
+
# can_be_edited Boolean Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
|
59
|
+
# can_change_info Boolean Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings
|
60
|
+
# can_post_messages Boolean Optional. Administrators only. True, if the administrator can post in the channel, channels only
|
61
|
+
# can_edit_messages Boolean Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only
|
62
|
+
# can_delete_messages Boolean Optional. Administrators only. True, if the administrator can delete messages of other users
|
63
|
+
# can_invite_users Boolean Optional. Administrators only. True, if the administrator can invite new users to the chat
|
64
|
+
# can_restrict_members Boolean Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
|
65
|
+
# can_pin_messages Boolean Optional. Administrators only. True, if the administrator can pin messages, groups and supergroups only
|
66
|
+
# can_promote_members Boolean Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
|
67
|
+
# is_member Boolean Optional. Restricted only. True, if the user is a member of the chat at the moment of the request
|
68
|
+
# can_send_messages Boolean Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
|
69
|
+
# can_send_media_messages Boolean Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
|
70
|
+
# can_send_other_messages Boolean Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
|
71
|
+
# can_add_web_page_previews Boolean Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages
|
18
72
|
class ChatMember
|
19
|
-
include
|
73
|
+
include SimplifyApi
|
74
|
+
attribute :user, User, mandatory: true
|
75
|
+
attribute :status, CHAT_MEMBER_STATUS, mandatory: true
|
76
|
+
attribute :until_date, Integer
|
77
|
+
attribute :can_be_edited, values: [true, false]
|
78
|
+
attribute :can_change_info, values: [true, false]
|
79
|
+
attribute :can_post_messages, values: [true, false]
|
80
|
+
attribute :can_edit_messages, values: [true, false]
|
81
|
+
attribute :can_delete_messages, values: [true, false]
|
82
|
+
attribute :can_invite_users, values: [true, false]
|
83
|
+
attribute :can_restrict_members, values: [true, false]
|
84
|
+
attribute :can_pin_messages, values: [true, false]
|
85
|
+
attribute :can_promote_members, values: [true, false]
|
86
|
+
attribute :is_member, values: [true, false]
|
87
|
+
attribute :can_send_messages, values: [true, false]
|
88
|
+
attribute :can_send_media_messages, values: [true, false]
|
89
|
+
attribute :can_send_other_messages, values: [true, false]
|
90
|
+
attribute :can_add_web_page_previews, values: [true, false]
|
20
91
|
end
|
21
92
|
end
|
data/lib/telbe/version.rb
CHANGED
data/lib/telbe/webhook.rb
CHANGED
@@ -13,15 +13,33 @@ module Telbe
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# url String Webhook URL, may be empty if webhook is not set up
|
17
|
+
# has_custom_certificate Boolean True, if a custom certificate was provided for webhook certificate checks
|
18
|
+
# pending_update_count Integer Number of updates awaiting delivery
|
19
|
+
# last_error_date Integer Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook
|
20
|
+
# last_error_message String Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
|
21
|
+
# max_connections Integer Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
|
22
|
+
# allowed_updates Array of String Optional. A list of update types the bot is subscribed to. Defaults to all update types
|
16
23
|
class WebHookInfo
|
17
|
-
include
|
24
|
+
include SimplifyApi
|
25
|
+
attribute :url, String, mandatory: true
|
26
|
+
attribute :has_custom_certificate, values: [true, false]
|
27
|
+
attribute :pending_update_count, Integer, mandatory: true
|
28
|
+
attribute :last_error_date, Integer
|
29
|
+
attribute :last_error_message, String
|
30
|
+
attribute :max_connections, Integer
|
31
|
+
attribute :allowed_updates, [String]
|
18
32
|
end
|
19
33
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
34
|
+
# url String Yes HTTPS url to send updates to. Use an empty string to remove webhook integration
|
35
|
+
# certificate InputFile Optional Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details.
|
36
|
+
# max_connections Integer Optional Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot‘s server, and higher values to increase your bot’s throughput.
|
37
|
+
# allowed_updates Array of String Optional List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
|
24
38
|
class WebHookDescriptor
|
25
|
-
include
|
39
|
+
include SimplifyApi
|
40
|
+
attribute :url, String, mandatory: true
|
41
|
+
attribute :certificate, InputFile
|
42
|
+
attribute :max_connections, Integer
|
43
|
+
attribute :allowed_updates, [String]
|
26
44
|
end
|
27
45
|
end
|
data/lib/telbe.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'excon'
|
2
2
|
require 'json'
|
3
|
+
require 'simplify_api'
|
3
4
|
|
4
|
-
require 'telbe/
|
5
|
-
require 'telbe/webhook'
|
6
|
-
require 'telbe/user'
|
5
|
+
require 'telbe/base'
|
7
6
|
require 'telbe/contact'
|
8
7
|
require 'telbe/keyboard'
|
8
|
+
require 'telbe/inline'
|
9
9
|
require 'telbe/poll'
|
10
10
|
require 'telbe/media'
|
11
|
+
require 'telbe/user'
|
11
12
|
require 'telbe/sticker'
|
12
13
|
require 'telbe/location'
|
14
|
+
require 'telbe/webhook'
|
13
15
|
require 'telbe/bot'
|
data/telbe.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_dependency "excon", ">= 0.64.0"
|
20
|
+
spec.add_dependency "simplify_api", "~> 0.1"
|
20
21
|
spec.add_development_dependency "bundler", "~> 2.0"
|
21
|
-
spec.add_development_dependency "rspec"
|
22
|
-
spec.add_development_dependency "minitest"
|
23
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telbe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Garcia Couto
|
@@ -25,47 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.64.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: simplify_api
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
42
|
+
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
47
|
+
version: '2.0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '2.0'
|
69
55
|
description: Still in development. A Telegram Bot Engine that eventually will support
|
70
56
|
all of Telegrams features.
|
71
57
|
email:
|
@@ -78,9 +64,10 @@ files:
|
|
78
64
|
- Gemfile
|
79
65
|
- README.md
|
80
66
|
- lib/telbe.rb
|
67
|
+
- lib/telbe/base.rb
|
81
68
|
- lib/telbe/bot.rb
|
82
69
|
- lib/telbe/contact.rb
|
83
|
-
- lib/telbe/
|
70
|
+
- lib/telbe/inline.rb
|
84
71
|
- lib/telbe/keyboard.rb
|
85
72
|
- lib/telbe/location.rb
|
86
73
|
- lib/telbe/media.rb
|
data/lib/telbe/helper.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
def camelize
|
3
|
-
self.split('_').collect(&:capitalize).join
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module Telbe
|
8
|
-
module InitializeFromHash
|
9
|
-
def initialize(opts)
|
10
|
-
opts.each_pair do |k, v|
|
11
|
-
if Telbe::const_defined?(k.to_s.camelize) then
|
12
|
-
case v
|
13
|
-
when Hash
|
14
|
-
v = Telbe::const_get(k.to_s.camelize).new(v)
|
15
|
-
when Array
|
16
|
-
v.collect! { |i| Telbe::const_get(k.to_s.camelize).new(i) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
create_and_set_instance_variable("#{k}", v)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_h
|
24
|
-
h = {}
|
25
|
-
instance_variables.each do |i|
|
26
|
-
k = /\@(.*)/.match(i.to_s)[1]
|
27
|
-
v = instance_variable_get(i)
|
28
|
-
if v.class.inspect.start_with?("Telbe") then
|
29
|
-
h[k] = v.to_h
|
30
|
-
else
|
31
|
-
h[k] = v
|
32
|
-
end
|
33
|
-
end
|
34
|
-
h
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_json
|
38
|
-
self.to_h.to_json
|
39
|
-
end
|
40
|
-
|
41
|
-
def method_missing(method_name, *args, &block)
|
42
|
-
case method_name
|
43
|
-
when /(.*)\=$/
|
44
|
-
create_and_set_instance_variable("#{$1}", args[0])
|
45
|
-
else
|
46
|
-
super(method_name, args, block)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def respond_to_missing?(method_name, *args)
|
51
|
-
case method_name
|
52
|
-
when /(.*)\=$/
|
53
|
-
true # always respond to assignment methods
|
54
|
-
else
|
55
|
-
super(method_name, args)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
def create_and_set_instance_variable(name, value)
|
61
|
-
instance_variable_set("@#{name}", value)
|
62
|
-
define_singleton_method("#{name}=") { |arg| instance_variable_set("@#{name}", arg) }
|
63
|
-
define_singleton_method("#{name}") { instance_variable_get("@#{name}") }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|