discorb 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/discorb/guild.rb CHANGED
@@ -502,7 +502,6 @@ module Discorb
502
502
  # Fetch a member in the guild.
503
503
  # @macro async
504
504
  # @macro http
505
- # @macro members_intent
506
505
  #
507
506
  # @param [#to_s] id The ID of the member to fetch.
508
507
  #
@@ -519,6 +518,39 @@ module Discorb
519
518
  end
520
519
  end
521
520
 
521
+ # Fetch members in the guild.
522
+ # @macro async
523
+ # @macro http
524
+ # @macro members_intent
525
+ #
526
+ # @param [Integer] limit The maximum number of members to fetch, 0 for all.
527
+ # @param [Integer] after The ID of the member to start fetching after.
528
+ #
529
+ # @return [Async::Task<Array<Discorb::Member>>] The list of members.
530
+ #
531
+ def fetch_members(limit: 0, after: nil)
532
+ Async do
533
+ unless limit == 0
534
+ _resp, data = @client.http.get("/guilds/#{@id}/members?#{URI.encode_www_form({ after: after, limit: limit })}").wait
535
+ next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
536
+ end
537
+ ret = []
538
+ after = 0
539
+ loop do
540
+ params = { after: after, limit: 100 }
541
+ _resp, data = @client.http.get("/guilds/#{@id}/members?#{URI.encode_www_form(params)}").wait
542
+ ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
543
+ after = data.last[:user][:id]
544
+ if data.length != 1000
545
+ break
546
+ end
547
+ end
548
+ ret
549
+ end
550
+ end
551
+
552
+ alias fetch_member_list fetch_members
553
+
522
554
  #
523
555
  # Search for members by name in the guild.
524
556
  # @macro async
data/lib/discorb/http.rb CHANGED
@@ -242,12 +242,13 @@ module Discorb
242
242
  else
243
243
  API_BASE_URL + path
244
244
  end
245
- URI(full_path).path
245
+ uri = URI(full_path)
246
+ full_path.sub(uri.scheme + "://" + uri.host, "")
246
247
  end
247
248
 
248
249
  def get_response_data(resp)
249
- if resp["Via"].nil?
250
- raise CloudFlareBanError.new(@client, resp)
250
+ if resp["Via"].nil? && resp.code == "429"
251
+ raise CloudFlareBanError.new(resp, @client)
251
252
  end
252
253
  rd = resp.body
253
254
  if rd.nil? || rd.empty?
@@ -80,7 +80,7 @@ module Discorb
80
80
  @enable_emoticons = data[:enable_emoticons]
81
81
  @expire_behavior = self.class.expire_behavior[data[:expire_behavior]]
82
82
  @expire_grace_period = data[:expire_grace_period]
83
- @user = client.users[data[:user].to_i]
83
+ @user = @client.users[data[:user].to_i]
84
84
  @account = Account.new(data[:account])
85
85
  @subscriber_count = data[:subscriber_count]
86
86
  @revoked = data[:revoked]
@@ -82,7 +82,7 @@ module Discorb
82
82
  if @raw_value.key?(name)
83
83
  @raw_value[name]
84
84
  elsif name.end_with?("=") && @raw_value.key?(name[0..-2].to_sym)
85
- raise ArgumentError, "true/false expected" if (!args.is_a? TrueClass) || args.is_a?(FalseClass)
85
+ raise ArgumentError, "true/false expected" unless args.is_a? TrueClass or args.is_a?(FalseClass)
86
86
 
87
87
  @raw_value[name[0..-2].to_sym] = args
88
88
  else
@@ -108,6 +108,10 @@ module Discorb
108
108
  "#<#{self.class} value=#{value}>"
109
109
  end
110
110
 
111
+ def to_h
112
+ @raw_value
113
+ end
114
+
111
115
  class << self
112
116
  # Create new intent object from raw value.
113
117
  # @param value [Integer] The value of the intent.
@@ -121,12 +125,12 @@ module Discorb
121
125
 
122
126
  # Create new intent object with default values.
123
127
  def default
124
- from_value(32_509)
128
+ from_value(32509)
125
129
  end
126
130
 
127
131
  # Create new intent object with all intents.
128
132
  def all
129
- from_value(32_767)
133
+ from_value(32767)
130
134
  end
131
135
 
132
136
  # Create new intent object with no intents.
@@ -59,6 +59,8 @@ module Discorb
59
59
  # @!attribute [r] status
60
60
  # @macro client_cache
61
61
  # @return [Symbol] The status of the member. It's from the {#presence}.
62
+ # @!attribute [r] owner?
63
+ # @return [Boolean] Whether the member is the owner of the guild.
62
64
 
63
65
  # @!visibility private
64
66
  def initialize(client, guild_id, user_data, member_data)
@@ -99,18 +101,27 @@ module Discorb
99
101
  guild.voice_states[@id]
100
102
  end
101
103
 
104
+ def owner?
105
+ guild.owner_id == @id
106
+ end
107
+
102
108
  def guild
103
109
  @client.guilds[@guild_id]
104
110
  end
105
111
 
106
112
  def roles
107
- @role_ids.map { |r| guild.roles[r] }.sort_by(&:position)
113
+ @role_ids.map { |r| guild.roles[r] }.sort_by(&:position).reverse + [guild.roles[guild.id]]
108
114
  end
109
115
 
110
116
  def permissions
117
+ if owner?
118
+ return Permission.new((1 << 38) - 1)
119
+ end
111
120
  roles.map(&:permissions).sum(Permission.new(0))
112
121
  end
113
122
 
123
+ alias guild_permissions permissions
124
+
114
125
  def hoisted_role
115
126
  @hoisted_role_id && guild.roles[@hoisted_role_id]
116
127
  end
data/po/yard.pot CHANGED
@@ -203,7 +203,7 @@ msgid "client = Discorb::Client.new"
203
203
  msgstr ""
204
204
 
205
205
  #: ../README.md:35
206
- msgid "client.once :ready do\n"
206
+ msgid "client.once :standby do\n"
207
207
  " puts \"Logged in as #{client.user}\"\n"
208
208
  "end"
209
209
  msgstr ""