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)

    The user to kick.

  • reason (String)

    The reason for the ban.

Returns:

  • (Boolean)

    true if the user was kicked, otherwise false.



45
46
47
# File 'lib/chatrix/components/admin.rb', line 45

def ban(user, reason)
  @matrix.rooms.actions.ban @room.id, user.id, 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)

    The user to kick.

  • reason (String)

    The reason for the kick.

Returns:

  • (Boolean)

    true if the user was kicked, otherwise false.



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

def kick(user, reason)
  @matrix.rooms.actions.kick @room.id, user.id, 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)

    The user to unban.

Returns:

  • (Boolean)

    true if the user was unbanned, otherwise false.



53
54
55
# File 'lib/chatrix/components/admin.rb', line 53

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