Class: Chatrix::Components::Admin

Inherits:
Object
  • Object
show all
Defined in:
lib/chatrix/components/admin.rb

Overview

Provides administrative actions for a room.

Instance Method Summary collapse

Constructor Details

#initialize(room, matrix) ⇒ Admin

Initializes a new Admin instance.

Parameters:

  • room (Room)

    The room to administrate.

  • matrix (Matrix)

    Matrix API instance.



14
15
16
17
# File 'lib/chatrix/components/admin.rb', line 14

def initialize(room, matrix)
  @room = room
  @matrix = matrix
end

Instance Method Details

#ban(user, reason) ⇒ Boolean

Bans a user from the room.

Parameters:

  • user (User, String)

    The user to kick, can be either a User object or a String (user ID).

  • reason (String)

    The reason for the ban.

Returns:

  • (Boolean)

    true if the user was kicked, otherwise false.



47
48
49
# File 'lib/chatrix/components/admin.rb', line 47

def ban(user, reason)
  @matrix.rooms.actions.ban @room.id, user, reason
end

#joinObject

Joins the room. Can only be used on public rooms or if the user has been invited.



21
22
23
# File 'lib/chatrix/components/admin.rb', line 21

def join
  @matrix.rooms.actions.join @room.id
end

#kick(user, reason) ⇒ Boolean

Kicks a user from the room.

Parameters:

  • user (User, String)

    The user to kick, can be either a User object or a String (user ID).

  • reason (String)

    The reason for the kick.

Returns:

  • (Boolean)

    true if the user was kicked, otherwise false.



37
38
39
# File 'lib/chatrix/components/admin.rb', line 37

def kick(user, reason)
  @matrix.rooms.actions.kick @room.id, user, reason
end

#leaveObject

Leaves the room. If the user is currently invited to the room, leaving the room is the same as rejecting the invite.



27
28
29
# File 'lib/chatrix/components/admin.rb', line 27

def leave
  @matrix.rooms.actions.leave @room.id
end

#unban(user) ⇒ Boolean

Unbans a user from the room.

Parameters:

  • user (User, String)

    The user to unban, can be either a User objec or a String (user ID).

Returns:

  • (Boolean)

    true if the user was unbanned, otherwise false.



56
57
58
# File 'lib/chatrix/components/admin.rb', line 56

def unban(user)
  @matrix.rooms.actions.unban @room.id, user
end