Class: Rubycord::Invite

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycord/data/invite.rb

Overview

A Discord invite to a channel

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channel ⇒ InviteChannel, Channel (readonly)

Returns the channel this invite references.

Returns:



46
47
48
# File 'lib/rubycord/data/invite.rb', line 46

def channel
  @channel
end

#code ⇒ String (readonly)

Returns this invite's code.

Returns:

  • (String) —

    this invite's code



68
69
70
# File 'lib/rubycord/data/invite.rb', line 68

def code
  @code
end

#created_at ⇒ Time? (readonly)

Returns when this invite was created, or nil if it's unknown.

Returns:

  • (Time, nil) —

    when this invite was created, or nil if it's unknown



82
83
84
# File 'lib/rubycord/data/invite.rb', line 82

def created_at
  @created_at
end

#inviter ⇒ User? (readonly) Also known as: user

Returns the user that made this invite. May also be nil if the user can't be determined.

Returns:

  • (User, nil) —

    the user that made this invite. May also be nil if the user can't be determined.



56
57
58
# File 'lib/rubycord/data/invite.rb', line 56

def inviter
  @inviter
end

#max_age ⇒ Integer? (readonly)

Returns the invites max age before it expires, or nil if it's unknown. If the max age is 0, the invite will never expire unless it's deleted.

Returns:

  • (Integer, nil) —

    the invites max age before it expires, or nil if it's unknown. If the max age is 0, the invite will never expire unless it's deleted.



79
80
81
# File 'lib/rubycord/data/invite.rb', line 79

def max_age
  @max_age
end

#member_count ⇒ Integer? (readonly) Also known as: user_count

Returns the amount of members in the server. Will be nil if it has not been resolved.

Returns:

  • (Integer, nil) —

    the amount of members in the server. Will be nil if it has not been resolved.



71
72
73
# File 'lib/rubycord/data/invite.rb', line 71

def member_count
  @member_count
end

#online_member_count ⇒ Integer? (readonly) Also known as: online_user_count

Returns the amount of online members in the server. Will be nil if it has not been resolved.

Returns:

  • (Integer, nil) —

    the amount of online members in the server. Will be nil if it has not been resolved.



75
76
77
# File 'lib/rubycord/data/invite.rb', line 75

def online_member_count
  @online_member_count
end

#revoked ⇒ true, false (readonly) Also known as: revoked?

Returns whether this invite is still valid.

Returns:

  • (true, false) —

    whether this invite is still valid.



64
65
66
# File 'lib/rubycord/data/invite.rb', line 64

def revoked
  @revoked
end

#server ⇒ InviteServer, Server (readonly)

Returns the server this invite references.

Returns:



49
50
51
# File 'lib/rubycord/data/invite.rb', line 49

def server
  @server
end

#temporary ⇒ true, false (readonly) Also known as: temporary?

Returns whether or not this invite grants temporary membership. If someone joins a server with this invite, they will be removed from the server when they go offline unless they've received a role.

Returns:

  • (true, false) —

    whether or not this invite grants temporary membership. If someone joins a server with this invite, they will be removed from the server when they go offline unless they've received a role.



60
61
62
# File 'lib/rubycord/data/invite.rb', line 60

def temporary
  @temporary
end

#uses ⇒ Integer (readonly) Also known as: max_uses

Returns the amount of uses left on this invite.

Returns:

  • (Integer) —

    the amount of uses left on this invite.



52
53
54
# File 'lib/rubycord/data/invite.rb', line 52

def uses
  @uses
end

Instance Method Details

#==(other) ⇒ Object

Code based comparison



113
114
115
# File 'lib/rubycord/data/invite.rb', line 113

def ==(other)
  other.respond_to?(:code) ? (@code == other.code) : (@code == other)
end

#delete(reason = nil) ⇒ Object Also known as: revoke

Deletes this invite

Parameters:

  • reason (String) (defaults to: nil) —

    The reason the invite is being deleted.



119
120
121
# File 'lib/rubycord/data/invite.rb', line 119

def delete(reason = nil)
  API::Invite.delete(@bot.token, @code, reason)
end

#inspect ⇒ Object

The inspect method is overwritten to give more useful output



126
127
128
# File 'lib/rubycord/data/invite.rb', line 126

def inspect
  "<Invite code=#{@code} channel=#{@channel} uses=#{@uses} temporary=#{@temporary} revoked=#{@revoked} created_at=#{@created_at} max_age=#{@max_age}>"
end

#url ⇒ Object

Creates an invite URL.



131
132
133
# File 'lib/rubycord/data/invite.rb', line 131

def url
  "https://discord.gg/#{@code}"
end