class WeebSh::User

Represents a user for shimakaze

Attributes

account[R]

@return [String] the ID of the account from the token

available_reputation[R]

@return [Integer, nil] the amount to times the user may give reputation

bot_id[R]

@return [String] the ID of the bot that issues reputation

cooldown[R]

@return [Array<Time>] the last time(s) this user has given reputation to another user

given_reputation[R]

@return [Array<Time>] the last time(s) this user has received reputation from another user

next_available_reputation[R]

@return [Array<Time>, nil] the timestamps referring to the remaining cooldown time until the user can give out reputation from now

rep[R]

@return [Integer] the reputation of the user

reputation[R]

@return [Integer] the reputation of the user

taken_reputation[R]

@return [Array<Time>] the last time(s) this user has given reputation to another user

Public Class Methods

new(data, interface) click to toggle source

@!visibility private

# File lib/weeb/data.rb, line 211
def initialize(data, interface)
  @interface = interface
  patch(data)
  @available_reputation = data['availableReputation']
  @next_available_reputation = data['nextAvailableReputation'] ? data['nextAvailableReputation'].map { |t| Time.parse(t) } : nil
end

Public Instance Methods

decrease(amount) click to toggle source

Decreases the user's reputation @param amount [Integer] the amount of reputation that will decrease @return [User] the class itself

# File lib/weeb/data.rb, line 230
def decrease(amount)
  response = WeebSh::API::Shimakaze.decrease(@interface, @bot_id, @id, amount)
  patch(response['user'])
  self
end
give(user) click to toggle source

Gives reputation to another user @Param user [User, String, resolve_id] the user to give reputation to @return [User] the class itself

# File lib/weeb/data.rb, line 247
def give(user)
  user_id = user.resolve_id if user.respond_to?(:resolve_id)
  response = API::Shimakaze.give(@interface, @bot_id, @id, user_id || user)
  patch(response['sourceUser'])
  user.patch(response['targetUser']) if user.is_a?(User)
  self
end
increase(amount) click to toggle source

Increases the user's reputation @param amount [Integer] the amount of reputation that will increase @return [User] the class itself

# File lib/weeb/data.rb, line 221
def increase(amount)
  response = WeebSh::API::Shimakaze.increase(@interface, @bot_id, @id, amount)
  patch(response['user'])
  self
end
inspect() click to toggle source

@!visibility private

# File lib/weeb/data.rb, line 279
def inspect
  "#<WeebSh::User @reputation=#{@reputation.inspect} @id=#{@id.inspect} @bot_id=#{@bot_id.inspect}>"
end
patch(data) click to toggle source

@!visibility private

# File lib/weeb/data.rb, line 267
def patch(data)
  @reputation = data['reputation']
  @id = data['userId']
  @bot_id = data['botId']
  @account = data['account']
  @cooldown = data['cooldown'].map { |t| Time.parse(t) }
  @given_reputation = data['givenReputation'].map { |t| Time.parse(t) }
  @available_reputation = data['availableReputation'] if data['availableReputation'].nil?
  @next_available_reputation = data['nextAvailableReputation'].map { |t| Time.parse(t) } if data['nextAvailableReputation'].nil?
end
recieve(user) click to toggle source

Recieves reputation to another user @Param user [User, String, resolve_id] the user to get reputation from @return [User] the class itself

# File lib/weeb/data.rb, line 258
def recieve(user)
  user_id = user.resolve_id if user.respond_to?(:resolve_id)
  response = API::Shimakaze.give(@interface, @bot_id, user_id || user, @id)
  patch(response['targetUser'])
  user.patch(response['sourceUser']) if user.is_a?(User)
  self
end
reset() click to toggle source

Resets the user @return [User] the class itself

# File lib/weeb/data.rb, line 238
def reset
  response = WeebSh::API::Shimakaze.reset(@interface, @bot_id, @id)
  patch(response['user'])
  self
end