gruubY 0.2.1 → 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/config/config.rb +1 -1
- data/example/bot.rb +122 -2
- 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 +27 -14
- 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/group_manager.rb
CHANGED
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
class GroupManager
|
|
3
|
-
DEFAULT_WARN_LIMIT = 3
|
|
4
|
-
|
|
5
|
-
def initialize(api, session: nil, warn_limit: DEFAULT_WARN_LIMIT)
|
|
6
|
-
@api = api
|
|
7
|
-
@session = session
|
|
8
|
-
@warn_limit = warn_limit
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def ban(chat_id, user_id, **opts)
|
|
12
|
-
@api.ban_chat_member(chat_id: chat_id, user_id: user_id, **opts)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def unban(chat_id, user_id, **opts)
|
|
16
|
-
@api.unban_chat_member(chat_id: chat_id, user_id: user_id, **opts)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def kick(chat_id, user_id, **opts)
|
|
20
|
-
ban(chat_id, user_id, **opts)
|
|
21
|
-
unban(chat_id, user_id)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def restrict(chat_id, user_id, permissions:, **opts)
|
|
25
|
-
@api.restrict_chat_member(
|
|
26
|
-
chat_id: chat_id,
|
|
27
|
-
user_id: user_id,
|
|
28
|
-
permissions: permissions,
|
|
29
|
-
**opts
|
|
30
|
-
)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def mute(chat_id, user_id, until_date: nil)
|
|
34
|
-
restrict(
|
|
35
|
-
chat_id,
|
|
36
|
-
user_id,
|
|
37
|
-
permissions: { can_send_messages: false },
|
|
38
|
-
until_date: until_date
|
|
39
|
-
)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def unmute(chat_id, user_id)
|
|
43
|
-
permissions = {
|
|
44
|
-
can_send_messages: true,
|
|
45
|
-
can_send_audios: true,
|
|
46
|
-
can_send_documents: true,
|
|
47
|
-
can_send_photos: true,
|
|
48
|
-
can_send_videos: true,
|
|
49
|
-
can_send_video_notes: true,
|
|
50
|
-
can_send_voice_notes: true,
|
|
51
|
-
can_send_polls: true,
|
|
52
|
-
can_send_other_messages: true,
|
|
53
|
-
can_add_web_page_previews: true
|
|
54
|
-
}
|
|
55
|
-
restrict(chat_id, user_id, permissions: permissions)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def promote(chat_id, user_id, **opts)
|
|
59
|
-
@api.promote_chat_member(chat_id: chat_id, user_id: user_id, **opts)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def demote(chat_id, user_id)
|
|
63
|
-
promote(
|
|
64
|
-
chat_id,
|
|
65
|
-
user_id,
|
|
66
|
-
can_manage_chat: false,
|
|
67
|
-
can_delete_messages: false,
|
|
68
|
-
can_manage_video_chats: false,
|
|
69
|
-
can_restrict_members: false,
|
|
70
|
-
can_promote_members: false,
|
|
71
|
-
can_change_info: false,
|
|
72
|
-
can_invite_users: false,
|
|
73
|
-
can_post_stories: false,
|
|
74
|
-
can_edit_stories: false,
|
|
75
|
-
can_delete_stories: false,
|
|
76
|
-
can_post_messages: false,
|
|
77
|
-
can_edit_messages: false,
|
|
78
|
-
can_pin_messages: false,
|
|
79
|
-
can_manage_topics: false
|
|
80
|
-
)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def set_member_tag(chat_id, user_id, tag = nil)
|
|
84
|
-
@api.set_chat_member_tag(chat_id: chat_id, user_id: user_id, tag: tag)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def set_admin_title(chat_id, user_id, title)
|
|
88
|
-
@api.set_chat_administrator_custom_title(
|
|
89
|
-
chat_id: chat_id,
|
|
90
|
-
user_id: user_id,
|
|
91
|
-
custom_title: title
|
|
92
|
-
)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def set_administrator_title(chat_id, user_id, title)
|
|
96
|
-
set_admin_title(chat_id, user_id, title)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def set_chat_title(chat_id, title)
|
|
100
|
-
@api.set_chat_title(chat_id: chat_id, title: title)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def set_chat_description(chat_id, description)
|
|
104
|
-
@api.set_chat_description(chat_id: chat_id, description: description)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def set_chat_photo(chat_id, photo)
|
|
108
|
-
@api.set_chat_photo(chat_id: chat_id, photo: photo)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def delete_chat_photo(chat_id)
|
|
112
|
-
@api.delete_chat_photo(chat_id: chat_id)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def leave_chat(chat_id)
|
|
116
|
-
@api.leave_chat(chat_id: chat_id)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def set_permissions(chat_id, permissions, **opts)
|
|
120
|
-
@api.set_chat_permissions(chat_id: chat_id, permissions: permissions, **opts)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def lock(chat_id)
|
|
124
|
-
set_permissions(chat_id, { can_send_messages: false })
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def unlock(chat_id)
|
|
128
|
-
set_permissions(chat_id, { can_send_messages: true })
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def set_slow_mode(chat_id, seconds)
|
|
132
|
-
@api.set_slow_mode(chat_id: chat_id, seconds: seconds)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def pin(chat_id, message_id, **opts)
|
|
136
|
-
@api.pin_chat_message(chat_id: chat_id, message_id: message_id, **opts)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def unpin(chat_id, message_id = nil, **opts)
|
|
140
|
-
params = { chat_id: chat_id }.merge(opts)
|
|
141
|
-
params[:message_id] = message_id if message_id
|
|
142
|
-
@api.unpin_chat_message(**params)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def unpin_all(chat_id)
|
|
146
|
-
@api.unpin_all_chat_messages(chat_id: chat_id)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def approve_join_request(chat_id, user_id)
|
|
150
|
-
@api.approve_chat_join_request(chat_id: chat_id, user_id: user_id)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def decline_join_request(chat_id, user_id)
|
|
154
|
-
@api.decline_chat_join_request(chat_id: chat_id, user_id: user_id)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def get_chat(chat_id)
|
|
158
|
-
@api.get_chat(chat_id: chat_id)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def get_member(chat_id, user_id)
|
|
162
|
-
@api.get_chat_member(chat_id: chat_id, user_id: user_id)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def warn(chat_id, user_id, reason: nil)
|
|
166
|
-
key = warn_key(chat_id, user_id)
|
|
167
|
-
current = load_warns(key)
|
|
168
|
-
current += 1
|
|
169
|
-
store_warns(key, current)
|
|
170
|
-
|
|
171
|
-
{
|
|
172
|
-
user_id: user_id,
|
|
173
|
-
warns: current,
|
|
174
|
-
limit: @warn_limit,
|
|
175
|
-
reason: reason,
|
|
176
|
-
action: (current >= @warn_limit ? :kick : :none)
|
|
177
|
-
}
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def reset_warns(chat_id, user_id)
|
|
181
|
-
key = warn_key(chat_id, user_id)
|
|
182
|
-
store_warns(key, 0)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def enforce_warns(chat_id, user_id, reason: nil)
|
|
186
|
-
result = warn(chat_id, user_id, reason: reason)
|
|
187
|
-
return result unless result[:action] == :kick
|
|
188
|
-
|
|
189
|
-
kick(chat_id, user_id)
|
|
190
|
-
reset_warns(chat_id, user_id)
|
|
191
|
-
result
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
private
|
|
195
|
-
|
|
196
|
-
def warn_key(chat_id, user_id)
|
|
197
|
-
"warns:#{chat_id}:#{user_id}"
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def load_warns(key)
|
|
201
|
-
return 0 unless @session
|
|
202
|
-
|
|
203
|
-
value = @session.get(key)
|
|
204
|
-
value.is_a?(Hash) ? value["count"].to_i : value.to_i
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def store_warns(key, count)
|
|
208
|
-
return unless @session
|
|
209
|
-
|
|
210
|
-
@session.set(key, { "count" => count })
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
class GroupManager
|
|
3
|
+
DEFAULT_WARN_LIMIT = 3
|
|
4
|
+
|
|
5
|
+
def initialize(api, session: nil, warn_limit: DEFAULT_WARN_LIMIT)
|
|
6
|
+
@api = api
|
|
7
|
+
@session = session
|
|
8
|
+
@warn_limit = warn_limit
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def ban(chat_id, user_id, **opts)
|
|
12
|
+
@api.ban_chat_member(chat_id: chat_id, user_id: user_id, **opts)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def unban(chat_id, user_id, **opts)
|
|
16
|
+
@api.unban_chat_member(chat_id: chat_id, user_id: user_id, **opts)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def kick(chat_id, user_id, **opts)
|
|
20
|
+
ban(chat_id, user_id, **opts)
|
|
21
|
+
unban(chat_id, user_id)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def restrict(chat_id, user_id, permissions:, **opts)
|
|
25
|
+
@api.restrict_chat_member(
|
|
26
|
+
chat_id: chat_id,
|
|
27
|
+
user_id: user_id,
|
|
28
|
+
permissions: permissions,
|
|
29
|
+
**opts
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def mute(chat_id, user_id, until_date: nil)
|
|
34
|
+
restrict(
|
|
35
|
+
chat_id,
|
|
36
|
+
user_id,
|
|
37
|
+
permissions: { can_send_messages: false },
|
|
38
|
+
until_date: until_date
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def unmute(chat_id, user_id)
|
|
43
|
+
permissions = {
|
|
44
|
+
can_send_messages: true,
|
|
45
|
+
can_send_audios: true,
|
|
46
|
+
can_send_documents: true,
|
|
47
|
+
can_send_photos: true,
|
|
48
|
+
can_send_videos: true,
|
|
49
|
+
can_send_video_notes: true,
|
|
50
|
+
can_send_voice_notes: true,
|
|
51
|
+
can_send_polls: true,
|
|
52
|
+
can_send_other_messages: true,
|
|
53
|
+
can_add_web_page_previews: true
|
|
54
|
+
}
|
|
55
|
+
restrict(chat_id, user_id, permissions: permissions)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def promote(chat_id, user_id, **opts)
|
|
59
|
+
@api.promote_chat_member(chat_id: chat_id, user_id: user_id, **opts)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def demote(chat_id, user_id)
|
|
63
|
+
promote(
|
|
64
|
+
chat_id,
|
|
65
|
+
user_id,
|
|
66
|
+
can_manage_chat: false,
|
|
67
|
+
can_delete_messages: false,
|
|
68
|
+
can_manage_video_chats: false,
|
|
69
|
+
can_restrict_members: false,
|
|
70
|
+
can_promote_members: false,
|
|
71
|
+
can_change_info: false,
|
|
72
|
+
can_invite_users: false,
|
|
73
|
+
can_post_stories: false,
|
|
74
|
+
can_edit_stories: false,
|
|
75
|
+
can_delete_stories: false,
|
|
76
|
+
can_post_messages: false,
|
|
77
|
+
can_edit_messages: false,
|
|
78
|
+
can_pin_messages: false,
|
|
79
|
+
can_manage_topics: false
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def set_member_tag(chat_id, user_id, tag = nil)
|
|
84
|
+
@api.set_chat_member_tag(chat_id: chat_id, user_id: user_id, tag: tag)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def set_admin_title(chat_id, user_id, title)
|
|
88
|
+
@api.set_chat_administrator_custom_title(
|
|
89
|
+
chat_id: chat_id,
|
|
90
|
+
user_id: user_id,
|
|
91
|
+
custom_title: title
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def set_administrator_title(chat_id, user_id, title)
|
|
96
|
+
set_admin_title(chat_id, user_id, title)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def set_chat_title(chat_id, title)
|
|
100
|
+
@api.set_chat_title(chat_id: chat_id, title: title)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def set_chat_description(chat_id, description)
|
|
104
|
+
@api.set_chat_description(chat_id: chat_id, description: description)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def set_chat_photo(chat_id, photo)
|
|
108
|
+
@api.set_chat_photo(chat_id: chat_id, photo: photo)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def delete_chat_photo(chat_id)
|
|
112
|
+
@api.delete_chat_photo(chat_id: chat_id)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def leave_chat(chat_id)
|
|
116
|
+
@api.leave_chat(chat_id: chat_id)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def set_permissions(chat_id, permissions, **opts)
|
|
120
|
+
@api.set_chat_permissions(chat_id: chat_id, permissions: permissions, **opts)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def lock(chat_id)
|
|
124
|
+
set_permissions(chat_id, { can_send_messages: false })
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def unlock(chat_id)
|
|
128
|
+
set_permissions(chat_id, { can_send_messages: true })
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def set_slow_mode(chat_id, seconds)
|
|
132
|
+
@api.set_slow_mode(chat_id: chat_id, seconds: seconds)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def pin(chat_id, message_id, **opts)
|
|
136
|
+
@api.pin_chat_message(chat_id: chat_id, message_id: message_id, **opts)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def unpin(chat_id, message_id = nil, **opts)
|
|
140
|
+
params = { chat_id: chat_id }.merge(opts)
|
|
141
|
+
params[:message_id] = message_id if message_id
|
|
142
|
+
@api.unpin_chat_message(**params)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def unpin_all(chat_id)
|
|
146
|
+
@api.unpin_all_chat_messages(chat_id: chat_id)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def approve_join_request(chat_id, user_id)
|
|
150
|
+
@api.approve_chat_join_request(chat_id: chat_id, user_id: user_id)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def decline_join_request(chat_id, user_id)
|
|
154
|
+
@api.decline_chat_join_request(chat_id: chat_id, user_id: user_id)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def get_chat(chat_id)
|
|
158
|
+
@api.get_chat(chat_id: chat_id)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def get_member(chat_id, user_id)
|
|
162
|
+
@api.get_chat_member(chat_id: chat_id, user_id: user_id)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def warn(chat_id, user_id, reason: nil)
|
|
166
|
+
key = warn_key(chat_id, user_id)
|
|
167
|
+
current = load_warns(key)
|
|
168
|
+
current += 1
|
|
169
|
+
store_warns(key, current)
|
|
170
|
+
|
|
171
|
+
{
|
|
172
|
+
user_id: user_id,
|
|
173
|
+
warns: current,
|
|
174
|
+
limit: @warn_limit,
|
|
175
|
+
reason: reason,
|
|
176
|
+
action: (current >= @warn_limit ? :kick : :none)
|
|
177
|
+
}
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def reset_warns(chat_id, user_id)
|
|
181
|
+
key = warn_key(chat_id, user_id)
|
|
182
|
+
store_warns(key, 0)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def enforce_warns(chat_id, user_id, reason: nil)
|
|
186
|
+
result = warn(chat_id, user_id, reason: reason)
|
|
187
|
+
return result unless result[:action] == :kick
|
|
188
|
+
|
|
189
|
+
kick(chat_id, user_id)
|
|
190
|
+
reset_warns(chat_id, user_id)
|
|
191
|
+
result
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
private
|
|
195
|
+
|
|
196
|
+
def warn_key(chat_id, user_id)
|
|
197
|
+
"warns:#{chat_id}:#{user_id}"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def load_warns(key)
|
|
201
|
+
return 0 unless @session
|
|
202
|
+
|
|
203
|
+
value = @session.get(key)
|
|
204
|
+
value.is_a?(Hash) ? value["count"].to_i : value.to_i
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def store_warns(key, count)
|
|
208
|
+
return unless @session
|
|
209
|
+
|
|
210
|
+
@session.set(key, { "count" => count })
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|