Class: GrubY::GroupManager
- Inherits:
-
Object
- Object
- GrubY::GroupManager
- Defined in:
- lib/gruubY/group_manager.rb
Constant Summary collapse
- DEFAULT_WARN_LIMIT =
3
Instance Method Summary collapse
- #approve_join_request(chat_id, user_id) ⇒ Object
- #ban(chat_id, user_id, **opts) ⇒ Object
- #decline_join_request(chat_id, user_id) ⇒ Object
- #delete_chat_photo(chat_id) ⇒ Object
- #demote(chat_id, user_id) ⇒ Object
- #enforce_warns(chat_id, user_id, reason: nil) ⇒ Object
- #get_chat(chat_id) ⇒ Object
- #get_member(chat_id, user_id) ⇒ Object
-
#initialize(api, session: nil, warn_limit: DEFAULT_WARN_LIMIT) ⇒ GroupManager
constructor
A new instance of GroupManager.
- #kick(chat_id, user_id, **opts) ⇒ Object
- #leave_chat(chat_id) ⇒ Object
- #lock(chat_id) ⇒ Object
- #mute(chat_id, user_id, until_date: nil) ⇒ Object
- #pin(chat_id, message_id, **opts) ⇒ Object
- #promote(chat_id, user_id, **opts) ⇒ Object
- #reset_warns(chat_id, user_id) ⇒ Object
- #restrict(chat_id, user_id, permissions:, **opts) ⇒ Object
- #set_admin_title(chat_id, user_id, title) ⇒ Object
- #set_administrator_title(chat_id, user_id, title) ⇒ Object
- #set_chat_description(chat_id, description) ⇒ Object
- #set_chat_photo(chat_id, photo) ⇒ Object
- #set_chat_title(chat_id, title) ⇒ Object
- #set_member_tag(chat_id, user_id, tag = nil) ⇒ Object
- #set_permissions(chat_id, permissions, **opts) ⇒ Object
- #set_slow_mode(chat_id, seconds) ⇒ Object
- #unban(chat_id, user_id, **opts) ⇒ Object
- #unlock(chat_id) ⇒ Object
- #unmute(chat_id, user_id) ⇒ Object
- #unpin(chat_id, message_id = nil, **opts) ⇒ Object
- #unpin_all(chat_id) ⇒ Object
- #warn(chat_id, user_id, reason: nil) ⇒ Object
Constructor Details
#initialize(api, session: nil, warn_limit: DEFAULT_WARN_LIMIT) ⇒ GroupManager
Returns a new instance of GroupManager.
5 6 7 8 9 |
# File 'lib/gruubY/group_manager.rb', line 5 def initialize(api, session: nil, warn_limit: DEFAULT_WARN_LIMIT) @api = api @session = session @warn_limit = warn_limit end |
Instance Method Details
#approve_join_request(chat_id, user_id) ⇒ Object
149 150 151 |
# File 'lib/gruubY/group_manager.rb', line 149 def approve_join_request(chat_id, user_id) @api.approve_chat_join_request(chat_id: chat_id, user_id: user_id) end |
#ban(chat_id, user_id, **opts) ⇒ Object
11 12 13 |
# File 'lib/gruubY/group_manager.rb', line 11 def ban(chat_id, user_id, **opts) @api.ban_chat_member(chat_id: chat_id, user_id: user_id, **opts) end |
#decline_join_request(chat_id, user_id) ⇒ Object
153 154 155 |
# File 'lib/gruubY/group_manager.rb', line 153 def decline_join_request(chat_id, user_id) @api.decline_chat_join_request(chat_id: chat_id, user_id: user_id) end |
#delete_chat_photo(chat_id) ⇒ Object
111 112 113 |
# File 'lib/gruubY/group_manager.rb', line 111 def delete_chat_photo(chat_id) @api.delete_chat_photo(chat_id: chat_id) end |
#demote(chat_id, user_id) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gruubY/group_manager.rb', line 62 def demote(chat_id, user_id) promote( chat_id, user_id, can_manage_chat: false, can_delete_messages: false, can_manage_video_chats: false, can_restrict_members: false, can_promote_members: false, can_change_info: false, can_invite_users: false, can_post_stories: false, can_edit_stories: false, can_delete_stories: false, can_post_messages: false, can_edit_messages: false, can_pin_messages: false, can_manage_topics: false ) end |
#enforce_warns(chat_id, user_id, reason: nil) ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'lib/gruubY/group_manager.rb', line 185 def enforce_warns(chat_id, user_id, reason: nil) result = warn(chat_id, user_id, reason: reason) return result unless result[:action] == :kick kick(chat_id, user_id) reset_warns(chat_id, user_id) result end |
#get_chat(chat_id) ⇒ Object
157 158 159 |
# File 'lib/gruubY/group_manager.rb', line 157 def get_chat(chat_id) @api.get_chat(chat_id: chat_id) end |
#get_member(chat_id, user_id) ⇒ Object
161 162 163 |
# File 'lib/gruubY/group_manager.rb', line 161 def get_member(chat_id, user_id) @api.get_chat_member(chat_id: chat_id, user_id: user_id) end |
#kick(chat_id, user_id, **opts) ⇒ Object
19 20 21 22 |
# File 'lib/gruubY/group_manager.rb', line 19 def kick(chat_id, user_id, **opts) ban(chat_id, user_id, **opts) unban(chat_id, user_id) end |
#leave_chat(chat_id) ⇒ Object
115 116 117 |
# File 'lib/gruubY/group_manager.rb', line 115 def leave_chat(chat_id) @api.leave_chat(chat_id: chat_id) end |
#lock(chat_id) ⇒ Object
123 124 125 |
# File 'lib/gruubY/group_manager.rb', line 123 def lock(chat_id) (chat_id, { can_send_messages: false }) end |
#mute(chat_id, user_id, until_date: nil) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/gruubY/group_manager.rb', line 33 def mute(chat_id, user_id, until_date: nil) restrict( chat_id, user_id, permissions: { can_send_messages: false }, until_date: until_date ) end |
#pin(chat_id, message_id, **opts) ⇒ Object
135 136 137 |
# File 'lib/gruubY/group_manager.rb', line 135 def pin(chat_id, , **opts) @api.(chat_id: chat_id, message_id: , **opts) end |
#promote(chat_id, user_id, **opts) ⇒ Object
58 59 60 |
# File 'lib/gruubY/group_manager.rb', line 58 def promote(chat_id, user_id, **opts) @api.promote_chat_member(chat_id: chat_id, user_id: user_id, **opts) end |
#reset_warns(chat_id, user_id) ⇒ Object
180 181 182 183 |
# File 'lib/gruubY/group_manager.rb', line 180 def reset_warns(chat_id, user_id) key = warn_key(chat_id, user_id) store_warns(key, 0) end |
#restrict(chat_id, user_id, permissions:, **opts) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/gruubY/group_manager.rb', line 24 def restrict(chat_id, user_id, permissions:, **opts) @api.restrict_chat_member( chat_id: chat_id, user_id: user_id, permissions: , **opts ) end |
#set_admin_title(chat_id, user_id, title) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/gruubY/group_manager.rb', line 87 def set_admin_title(chat_id, user_id, title) @api.set_chat_administrator_custom_title( chat_id: chat_id, user_id: user_id, custom_title: title ) end |
#set_administrator_title(chat_id, user_id, title) ⇒ Object
95 96 97 |
# File 'lib/gruubY/group_manager.rb', line 95 def set_administrator_title(chat_id, user_id, title) set_admin_title(chat_id, user_id, title) end |
#set_chat_description(chat_id, description) ⇒ Object
103 104 105 |
# File 'lib/gruubY/group_manager.rb', line 103 def set_chat_description(chat_id, description) @api.set_chat_description(chat_id: chat_id, description: description) end |
#set_chat_photo(chat_id, photo) ⇒ Object
107 108 109 |
# File 'lib/gruubY/group_manager.rb', line 107 def set_chat_photo(chat_id, photo) @api.set_chat_photo(chat_id: chat_id, photo: photo) end |
#set_chat_title(chat_id, title) ⇒ Object
99 100 101 |
# File 'lib/gruubY/group_manager.rb', line 99 def set_chat_title(chat_id, title) @api.set_chat_title(chat_id: chat_id, title: title) end |
#set_member_tag(chat_id, user_id, tag = nil) ⇒ Object
83 84 85 |
# File 'lib/gruubY/group_manager.rb', line 83 def set_member_tag(chat_id, user_id, tag = nil) @api.set_chat_member_tag(chat_id: chat_id, user_id: user_id, tag: tag) end |
#set_permissions(chat_id, permissions, **opts) ⇒ Object
119 120 121 |
# File 'lib/gruubY/group_manager.rb', line 119 def (chat_id, , **opts) @api.(chat_id: chat_id, permissions: , **opts) end |
#set_slow_mode(chat_id, seconds) ⇒ Object
131 132 133 |
# File 'lib/gruubY/group_manager.rb', line 131 def set_slow_mode(chat_id, seconds) @api.set_slow_mode(chat_id: chat_id, seconds: seconds) end |
#unban(chat_id, user_id, **opts) ⇒ Object
15 16 17 |
# File 'lib/gruubY/group_manager.rb', line 15 def unban(chat_id, user_id, **opts) @api.unban_chat_member(chat_id: chat_id, user_id: user_id, **opts) end |
#unlock(chat_id) ⇒ Object
127 128 129 |
# File 'lib/gruubY/group_manager.rb', line 127 def unlock(chat_id) (chat_id, { can_send_messages: true }) end |
#unmute(chat_id, user_id) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gruubY/group_manager.rb', line 42 def unmute(chat_id, user_id) = { can_send_messages: true, can_send_audios: true, can_send_documents: true, can_send_photos: true, can_send_videos: true, can_send_video_notes: true, can_send_voice_notes: true, can_send_polls: true, can_send_other_messages: true, can_add_web_page_previews: true } restrict(chat_id, user_id, permissions: ) end |
#unpin(chat_id, message_id = nil, **opts) ⇒ Object
139 140 141 142 143 |
# File 'lib/gruubY/group_manager.rb', line 139 def unpin(chat_id, = nil, **opts) params = { chat_id: chat_id }.merge(opts) params[:message_id] = if @api.(**params) end |
#unpin_all(chat_id) ⇒ Object
145 146 147 |
# File 'lib/gruubY/group_manager.rb', line 145 def unpin_all(chat_id) @api.(chat_id: chat_id) end |
#warn(chat_id, user_id, reason: nil) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/gruubY/group_manager.rb', line 165 def warn(chat_id, user_id, reason: nil) key = warn_key(chat_id, user_id) current = load_warns(key) current += 1 store_warns(key, current) { user_id: user_id, warns: current, limit: @warn_limit, reason: reason, action: (current >= @warn_limit ? :kick : :none) } end |