gruubY 0.2.2 → 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.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +11 -6
- data/Rakefile +51 -51
- data/example/bot.rb +120 -1
- data/example/generate_user_session.rb +81 -81
- data/example/tdlib.rb +77 -77
- data/example/userbot.rb +133 -133
- data/lib/gruubY/api.rb +540 -363
- data/lib/gruubY/async.rb +13 -13
- data/lib/gruubY/bot.rb +104 -90
- data/lib/gruubY/bound.rb +14 -14
- data/lib/gruubY/client.rb +310 -296
- data/lib/gruubY/context.rb +296 -242
- data/lib/gruubY/dispatcher.rb +60 -60
- data/lib/gruubY/enums.rb +57 -62
- data/lib/gruubY/exception.rb +5 -5
- data/lib/gruubY/file_stream.rb +17 -17
- data/lib/gruubY/filters.rb +292 -292
- data/lib/gruubY/group_manager.rb +213 -213
- data/lib/gruubY/handlers.rb +225 -170
- data/lib/gruubY/keyboard.rb +49 -49
- data/lib/gruubY/media.rb +38 -38
- data/lib/gruubY/middleware.rb +18 -18
- data/lib/gruubY/plugin.rb +26 -26
- data/lib/gruubY/raw.rb +25 -25
- data/lib/gruubY/retry.rb +14 -14
- data/lib/gruubY/server.rb +18 -18
- data/lib/gruubY/session.rb +30 -30
- data/lib/gruubY/tdlib/client.rb +565 -565
- data/lib/gruubY/tdlib/client_manager.rb +37 -37
- data/lib/gruubY/tdlib/decorators.rb +17 -17
- data/lib/gruubY/tdlib/errors.rb +6 -6
- data/lib/gruubY/tdlib/group_manager.rb +58 -58
- data/lib/gruubY/tdlib/native.rb +72 -72
- data/lib/gruubY/tdlib/schema_builder.rb +237 -237
- data/lib/gruubY/tdlib/tdjson.rb +49 -49
- data/lib/gruubY/tdlib/user_session.rb +69 -69
- data/lib/gruubY/types/base_object.rb +72 -72
- data/lib/gruubY/types/bound_entities.rb +289 -245
- data/lib/gruubY/types/chat.rb +93 -93
- data/lib/gruubY/types/chat_info.rb +32 -31
- data/lib/gruubY/types/extra.rb +289 -251
- data/lib/gruubY/types/message.rb +301 -295
- data/lib/gruubY/types/message_entity.rb +14 -14
- data/lib/gruubY/types/registry.rb +86 -67
- data/lib/gruubY/types/user.rb +47 -31
- data/lib/gruubY/webapp.rb +22 -22
- data/lib/gruubY.rb +39 -41
- data/plugins/logger.rb +7 -7
- metadata +3 -9
- data/example/ntgcalls.rb +0 -80
- data/lib/gruubY/ntgcalls/native.rb +0 -100
- data/lib/gruubY/ntgcalls.rb +0 -478
- data/lib/gruubY/raw_types.rb +0 -57
- data/plugins/media_tools.rb +0 -13
data/lib/gruubY/handlers.rb
CHANGED
|
@@ -1,170 +1,225 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
module Handlers
|
|
3
|
-
class BaseHandler
|
|
4
|
-
attr_reader :callback, :filters, :group, :exceptions
|
|
5
|
-
|
|
6
|
-
def initialize(callback = nil, filters: nil, group: 0, exceptions: nil, &block)
|
|
7
|
-
@callback = callback || block
|
|
8
|
-
@filters = filters
|
|
9
|
-
@group = group.to_i
|
|
10
|
-
@exceptions = exceptions
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def event
|
|
14
|
-
raise NotImplementedError
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def extract(ctx)
|
|
18
|
-
ctx
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def client_only?
|
|
22
|
-
false
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class MessageHandler < BaseHandler
|
|
27
|
-
def event = :message
|
|
28
|
-
def extract(ctx) = ctx.message
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
class EditedMessageHandler < BaseHandler
|
|
32
|
-
def event = :edited_message
|
|
33
|
-
def extract(ctx) = ctx.edited_message
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class
|
|
37
|
-
def event = :
|
|
38
|
-
def extract(ctx) = ctx.
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
class
|
|
42
|
-
def event = :
|
|
43
|
-
def extract(ctx) = ctx.
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class
|
|
47
|
-
def event = :
|
|
48
|
-
def extract(ctx) = ctx.
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
class
|
|
52
|
-
def event = :
|
|
53
|
-
def extract(ctx) = ctx.
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
class
|
|
57
|
-
def event = :
|
|
58
|
-
def extract(ctx) = ctx.
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
class
|
|
62
|
-
def event = :
|
|
63
|
-
def extract(ctx) = ctx.
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
class
|
|
67
|
-
def event = :
|
|
68
|
-
def extract(ctx) = ctx.
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
class
|
|
72
|
-
def event = :
|
|
73
|
-
def extract(ctx) = ctx.
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
class
|
|
77
|
-
def event = :
|
|
78
|
-
def extract(ctx) = ctx.
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
class
|
|
82
|
-
def event = :
|
|
83
|
-
def extract(ctx) = ctx.
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
class
|
|
87
|
-
def event = :
|
|
88
|
-
def extract(ctx) = ctx.
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
class
|
|
92
|
-
def event = :
|
|
93
|
-
def extract(ctx) = ctx.
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
class
|
|
97
|
-
def event = :
|
|
98
|
-
def extract(ctx) = ctx.
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
class
|
|
102
|
-
def event = :
|
|
103
|
-
def extract(ctx) = ctx.
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
class
|
|
107
|
-
def event = :
|
|
108
|
-
def extract(ctx) = ctx.
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
class
|
|
112
|
-
def event = :
|
|
113
|
-
def extract(ctx) = ctx.
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
class
|
|
117
|
-
def event = :
|
|
118
|
-
def extract(ctx) = ctx.
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
class
|
|
122
|
-
def event = :
|
|
123
|
-
def extract(ctx) = ctx.
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
class
|
|
127
|
-
def event = :
|
|
128
|
-
def extract(ctx) = ctx.
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
class
|
|
132
|
-
def event = :
|
|
133
|
-
def extract(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
def
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
def
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
1
|
+
module GrubY
|
|
2
|
+
module Handlers
|
|
3
|
+
class BaseHandler
|
|
4
|
+
attr_reader :callback, :filters, :group, :exceptions
|
|
5
|
+
|
|
6
|
+
def initialize(callback = nil, filters: nil, group: 0, exceptions: nil, &block)
|
|
7
|
+
@callback = callback || block
|
|
8
|
+
@filters = filters
|
|
9
|
+
@group = group.to_i
|
|
10
|
+
@exceptions = exceptions
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def event
|
|
14
|
+
raise NotImplementedError
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def extract(ctx)
|
|
18
|
+
ctx
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def client_only?
|
|
22
|
+
false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class MessageHandler < BaseHandler
|
|
27
|
+
def event = :message
|
|
28
|
+
def extract(ctx) = ctx.message
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class EditedMessageHandler < BaseHandler
|
|
32
|
+
def event = :edited_message
|
|
33
|
+
def extract(ctx) = ctx.edited_message
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class ChannelPostHandler < BaseHandler
|
|
37
|
+
def event = :channel_post
|
|
38
|
+
def extract(ctx) = ctx.channel_post
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class EditedChannelPostHandler < BaseHandler
|
|
42
|
+
def event = :edited_channel_post
|
|
43
|
+
def extract(ctx) = ctx.edited_channel_post
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class DeletedMessagesHandler < BaseHandler
|
|
47
|
+
def event = :deleted_messages
|
|
48
|
+
def extract(ctx) = ctx.deleted_messages
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class BusinessMessageHandler < BaseHandler
|
|
52
|
+
def event = :business_message
|
|
53
|
+
def extract(ctx) = ctx.business_message
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class EditedBusinessMessageHandler < BaseHandler
|
|
57
|
+
def event = :edited_business_message
|
|
58
|
+
def extract(ctx) = ctx.edited_business_message
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class GuestMessageHandler < BaseHandler
|
|
62
|
+
def event = :guest_message
|
|
63
|
+
def extract(ctx) = ctx.guest_message
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class DeletedBusinessMessagesHandler < BaseHandler
|
|
67
|
+
def event = :deleted_business_messages
|
|
68
|
+
def extract(ctx) = ctx.deleted_business_messages
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class BusinessConnectionHandler < BaseHandler
|
|
72
|
+
def event = :business_connection
|
|
73
|
+
def extract(ctx) = ctx.business_connection
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class CallbackQueryHandler < BaseHandler
|
|
77
|
+
def event = :callback_query
|
|
78
|
+
def extract(ctx) = ctx.callback_query
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class ChatBoostHandler < BaseHandler
|
|
82
|
+
def event = :chat_boost
|
|
83
|
+
def extract(ctx) = ctx.chat_boost
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class ChatJoinRequestHandler < BaseHandler
|
|
87
|
+
def event = :chat_join_request
|
|
88
|
+
def extract(ctx) = ctx.chat_join_request
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class ChatMemberUpdatedHandler < BaseHandler
|
|
92
|
+
def event = :chat_member_updated
|
|
93
|
+
def extract(ctx) = ctx.chat_member_updated
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class ChosenInlineResultHandler < BaseHandler
|
|
97
|
+
def event = :chosen_inline_result
|
|
98
|
+
def extract(ctx) = ctx.chosen_inline_result
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
class InlineQueryHandler < BaseHandler
|
|
102
|
+
def event = :inline_query
|
|
103
|
+
def extract(ctx) = ctx.inline_query
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class MessageReactionCountHandler < BaseHandler
|
|
107
|
+
def event = :message_reaction_count
|
|
108
|
+
def extract(ctx) = ctx.message_reaction_count
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
class MessageReactionHandler < BaseHandler
|
|
112
|
+
def event = :message_reaction
|
|
113
|
+
def extract(ctx) = ctx.message_reaction
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
class PollHandler < BaseHandler
|
|
117
|
+
def event = :poll
|
|
118
|
+
def extract(ctx) = ctx.poll_update
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
class PollAnswerHandler < BaseHandler
|
|
122
|
+
def event = :poll_answer
|
|
123
|
+
def extract(ctx) = ctx.poll_answer
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
class ChatMemberHandler < BaseHandler
|
|
127
|
+
def event = :chat_member
|
|
128
|
+
def extract(ctx) = ctx.chat_member_updated
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
class MyChatMemberHandler < BaseHandler
|
|
132
|
+
def event = :my_chat_member
|
|
133
|
+
def extract(ctx) = ctx.my_chat_member
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
class RemovedChatBoostHandler < BaseHandler
|
|
137
|
+
def event = :removed_chat_boost
|
|
138
|
+
def extract(ctx) = ctx.removed_chat_boost
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
class WidgetQueryHandler < BaseHandler
|
|
142
|
+
def event = :widget_query
|
|
143
|
+
def extract(ctx) = ctx.widget_query
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class SharedWidgetQueryHandler < BaseHandler
|
|
147
|
+
def event = :shared_widget_query
|
|
148
|
+
def extract(ctx) = ctx.shared_widget_query
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class BotSubscriptionUpdatedHandler < BaseHandler
|
|
152
|
+
def event = :bot_subscription_updated
|
|
153
|
+
def extract(ctx) = ctx.bot_subscription_updated
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
class MessageGenerationStoppedHandler < BaseHandler
|
|
157
|
+
def event = :message_generation_stopped
|
|
158
|
+
def extract(ctx) = ctx.message_generation_stopped
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
class PreCheckoutQueryHandler < BaseHandler
|
|
162
|
+
def event = :pre_checkout_query
|
|
163
|
+
def extract(ctx) = ctx.pre_checkout_query
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
class PurchasedPaidMediaHandler < BaseHandler
|
|
167
|
+
def event = :purchased_paid_media
|
|
168
|
+
def extract(ctx) = ctx.purchased_paid_media
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class ShippingQueryHandler < BaseHandler
|
|
172
|
+
def event = :shipping_query
|
|
173
|
+
def extract(ctx) = ctx.shipping_query
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
class StoryHandler < BaseHandler
|
|
177
|
+
def event = :story
|
|
178
|
+
def extract(ctx) = ctx.story_update
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
class UserStatusHandler < BaseHandler
|
|
182
|
+
def event = :user_status
|
|
183
|
+
def extract(ctx) = ctx.user_status
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
class StartHandler < BaseHandler
|
|
187
|
+
def event = :start
|
|
188
|
+
def extract(_ctx) = nil
|
|
189
|
+
def client_only? = true
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
class StopHandler < BaseHandler
|
|
193
|
+
def event = :stop
|
|
194
|
+
def extract(_ctx) = nil
|
|
195
|
+
def client_only? = true
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
class ConnectHandler < BaseHandler
|
|
199
|
+
def event = :connect
|
|
200
|
+
def extract(_ctx) = nil
|
|
201
|
+
def client_only? = true
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class DisconnectHandler < BaseHandler
|
|
205
|
+
def event = :disconnect
|
|
206
|
+
def extract(_ctx) = nil
|
|
207
|
+
def client_only? = true
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
class ErrorHandler < BaseHandler
|
|
211
|
+
def event = :error
|
|
212
|
+
def extract(ctx) = ctx.error_payload
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
class ManagedBotUpdatedHandler < BaseHandler
|
|
216
|
+
def event = :managed_bot
|
|
217
|
+
def extract(ctx) = ctx.managed_bot_updated
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
class RawUpdateHandler < BaseHandler
|
|
221
|
+
def event = :raw_update
|
|
222
|
+
def extract(ctx) = ctx.update
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
data/lib/gruubY/keyboard.rb
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
class Keyboard
|
|
3
|
-
class << self
|
|
4
|
-
def inline(rows)
|
|
5
|
-
{ inline_keyboard: rows }
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def reply(rows, resize_keyboard: true, one_time_keyboard: false, is_persistent: false)
|
|
9
|
-
{
|
|
10
|
-
keyboard: rows,
|
|
11
|
-
resize_keyboard: resize_keyboard,
|
|
12
|
-
one_time_keyboard: one_time_keyboard,
|
|
13
|
-
is_persistent: is_persistent
|
|
14
|
-
}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def button(text, data = nil)
|
|
18
|
-
{
|
|
19
|
-
text: text.to_s,
|
|
20
|
-
callback_data: data.to_s
|
|
21
|
-
}
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def url_button(text, url)
|
|
25
|
-
{
|
|
26
|
-
text: text.to_s,
|
|
27
|
-
url: url.to_s
|
|
28
|
-
}
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def web_app_button(text, url)
|
|
32
|
-
{
|
|
33
|
-
text: text.to_s,
|
|
34
|
-
web_app: {
|
|
35
|
-
url: url.to_s
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def switch_inline_button(text, query:, in_current_chat: false)
|
|
41
|
-
key = in_current_chat ? :switch_inline_query_current_chat : :switch_inline_query
|
|
42
|
-
{
|
|
43
|
-
text: text.to_s,
|
|
44
|
-
key => query.to_s
|
|
45
|
-
}
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
class Keyboard
|
|
3
|
+
class << self
|
|
4
|
+
def inline(rows)
|
|
5
|
+
{ inline_keyboard: rows }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def reply(rows, resize_keyboard: true, one_time_keyboard: false, is_persistent: false)
|
|
9
|
+
{
|
|
10
|
+
keyboard: rows,
|
|
11
|
+
resize_keyboard: resize_keyboard,
|
|
12
|
+
one_time_keyboard: one_time_keyboard,
|
|
13
|
+
is_persistent: is_persistent
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def button(text, data = nil)
|
|
18
|
+
{
|
|
19
|
+
text: text.to_s,
|
|
20
|
+
callback_data: data.to_s
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def url_button(text, url)
|
|
25
|
+
{
|
|
26
|
+
text: text.to_s,
|
|
27
|
+
url: url.to_s
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def web_app_button(text, url)
|
|
32
|
+
{
|
|
33
|
+
text: text.to_s,
|
|
34
|
+
web_app: {
|
|
35
|
+
url: url.to_s
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def switch_inline_button(text, query:, in_current_chat: false)
|
|
41
|
+
key = in_current_chat ? :switch_inline_query_current_chat : :switch_inline_query
|
|
42
|
+
{
|
|
43
|
+
text: text.to_s,
|
|
44
|
+
key => query.to_s
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/gruubY/media.rb
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
require "net/http"
|
|
2
|
-
|
|
3
|
-
module GrubY
|
|
4
|
-
class Media
|
|
5
|
-
def initialize(token)
|
|
6
|
-
@base = "https://api.telegram.org/bot#{token}/"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def send_photo(chat_id, file)
|
|
10
|
-
post_file("sendPhoto", "photo", chat_id, file)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def send_video(chat_id, file)
|
|
14
|
-
post_file("sendVideo", "video", chat_id, file)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def send_audio(chat_id, file)
|
|
18
|
-
post_file("sendAudio", "audio", chat_id, file)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def post_file(method, field_name, chat_id, file)
|
|
22
|
-
uri = URI(@base + method)
|
|
23
|
-
|
|
24
|
-
File.open(file, "rb") do |io|
|
|
25
|
-
req = Net::HTTP::Post.new(uri)
|
|
26
|
-
form_data = [
|
|
27
|
-
["chat_id", chat_id],
|
|
28
|
-
[field_name, io]
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
req.set_form form_data, "multipart/form-data"
|
|
32
|
-
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
33
|
-
http.request(req)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
1
|
+
require "net/http"
|
|
2
|
+
|
|
3
|
+
module GrubY
|
|
4
|
+
class Media
|
|
5
|
+
def initialize(token)
|
|
6
|
+
@base = "https://api.telegram.org/bot#{token}/"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def send_photo(chat_id, file)
|
|
10
|
+
post_file("sendPhoto", "photo", chat_id, file)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def send_video(chat_id, file)
|
|
14
|
+
post_file("sendVideo", "video", chat_id, file)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def send_audio(chat_id, file)
|
|
18
|
+
post_file("sendAudio", "audio", chat_id, file)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def post_file(method, field_name, chat_id, file)
|
|
22
|
+
uri = URI(@base + method)
|
|
23
|
+
|
|
24
|
+
File.open(file, "rb") do |io|
|
|
25
|
+
req = Net::HTTP::Post.new(uri)
|
|
26
|
+
form_data = [
|
|
27
|
+
["chat_id", chat_id],
|
|
28
|
+
[field_name, io]
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
req.set_form form_data, "multipart/form-data"
|
|
32
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
33
|
+
http.request(req)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/gruubY/middleware.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
class Middleware
|
|
3
|
-
def initialize
|
|
4
|
-
@stack = []
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def use(&block)
|
|
8
|
-
@stack << block
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def run(ctx, &final)
|
|
12
|
-
chain = @stack.reverse.inject(final) do |nxt, mw|
|
|
13
|
-
proc { mw.call(ctx, nxt) }
|
|
14
|
-
end
|
|
15
|
-
chain.call
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
class Middleware
|
|
3
|
+
def initialize
|
|
4
|
+
@stack = []
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def use(&block)
|
|
8
|
+
@stack << block
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def run(ctx, &final)
|
|
12
|
+
chain = @stack.reverse.inject(final) do |nxt, mw|
|
|
13
|
+
proc { mw.call(ctx, nxt) }
|
|
14
|
+
end
|
|
15
|
+
chain.call
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/gruubY/plugin.rb
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
class Plugin
|
|
3
|
-
def self.load(bot, path)
|
|
4
|
-
absolute_path = File.expand_path(path, Dir.pwd)
|
|
5
|
-
|
|
6
|
-
unless File.exist?(absolute_path)
|
|
7
|
-
raise "Plugin file not found at: #{absolute_path}"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
mod = Module.new
|
|
11
|
-
mod.module_eval(File.read(absolute_path), absolute_path)
|
|
12
|
-
|
|
13
|
-
if mod.const_defined?(:Plugin)
|
|
14
|
-
plugin_mod = mod.const_get(:Plugin)
|
|
15
|
-
if plugin_mod.respond_to?(:register)
|
|
16
|
-
plugin_mod.register(bot)
|
|
17
|
-
else
|
|
18
|
-
raise "Plugin module in #{path} must define register(bot)"
|
|
19
|
-
end
|
|
20
|
-
elsif mod.respond_to?(:register)
|
|
21
|
-
mod.register(bot)
|
|
22
|
-
else
|
|
23
|
-
raise "Plugin in #{path} must define register(bot)"
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
class Plugin
|
|
3
|
+
def self.load(bot, path)
|
|
4
|
+
absolute_path = File.expand_path(path, Dir.pwd)
|
|
5
|
+
|
|
6
|
+
unless File.exist?(absolute_path)
|
|
7
|
+
raise "Plugin file not found at: #{absolute_path}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
mod = Module.new
|
|
11
|
+
mod.module_eval(File.read(absolute_path), absolute_path)
|
|
12
|
+
|
|
13
|
+
if mod.const_defined?(:Plugin)
|
|
14
|
+
plugin_mod = mod.const_get(:Plugin)
|
|
15
|
+
if plugin_mod.respond_to?(:register)
|
|
16
|
+
plugin_mod.register(bot)
|
|
17
|
+
else
|
|
18
|
+
raise "Plugin module in #{path} must define register(bot)"
|
|
19
|
+
end
|
|
20
|
+
elsif mod.respond_to?(:register)
|
|
21
|
+
mod.register(bot)
|
|
22
|
+
else
|
|
23
|
+
raise "Plugin in #{path} must define register(bot)"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
27
|
end
|