class WeebSh::User
Represents a user for shimakaze
Attributes
@return [String] the ID of the account from the token
@return [Integer, nil] the amount to times the user may give reputation
@return [String] the ID of the bot that issues reputation
@return [Array<Time>] the last time(s) this user has given reputation to another user
@return [Array<Time>] the last time(s) this user has received reputation from another user
@return [Array<Time>, nil] the timestamps referring to the remaining cooldown time until the user can give out reputation from now
@return [Integer] the reputation of the user
@return [Integer] the reputation of the user
@return [Array<Time>] the last time(s) this user has given reputation to another user
Public Class Methods
@!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
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
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
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
@!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
@!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
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
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