discorb 0.0.1 → 0.0.5

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.
@@ -264,7 +264,7 @@ module Discorb
264
264
  #
265
265
  def add_reaction(emoji)
266
266
  Async do |_task|
267
- @client.internet.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
267
+ @client.http.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
268
268
  end
269
269
  end
270
270
 
@@ -279,7 +279,7 @@ module Discorb
279
279
  #
280
280
  def remove_reaction(emoji)
281
281
  Async do |_task|
282
- @client.internet.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
282
+ @client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
283
283
  end
284
284
  end
285
285
 
@@ -295,7 +295,7 @@ module Discorb
295
295
  #
296
296
  def remove_reaction_of(emoji, member)
297
297
  Async do |_task|
298
- @client.internet.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}").wait
298
+ @client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}").wait
299
299
  end
300
300
  end
301
301
 
@@ -318,7 +318,7 @@ module Discorb
318
318
  after = 0
319
319
  users = []
320
320
  loop do
321
- _resp, data = @client.internet.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}").wait
321
+ _resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}").wait
322
322
  break if data.empty?
323
323
 
324
324
  users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
@@ -329,7 +329,7 @@ module Discorb
329
329
  end
330
330
  next users
331
331
  else
332
- _resp, data = @client.internet.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}").wait
332
+ _resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}").wait
333
333
  next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
334
334
  end
335
335
  end
@@ -490,9 +490,9 @@ module Discorb
490
490
  @guild_id = nil
491
491
  end
492
492
 
493
- if data[:author].nil? && data[:webhook_id]
493
+ if data[:member].nil? && data[:webhook_id]
494
494
  @webhook_id = Snowflake.new(data[:webhook_id])
495
- # @author = WebhookAuthor.new(data[:webhook_id])
495
+ @author = Webhook::Message::Author.new(data[:author])
496
496
  elsif data[:guild_id].nil? || data[:guild_id].empty?
497
497
  @author = @client.users[data[:author][:id]] || User.new(@client, data[:author])
498
498
  else
@@ -57,11 +57,11 @@ module Discorb
57
57
  end
58
58
  files = [file] if file
59
59
  if files
60
- headers, payload = Internet.multipart(payload, files)
60
+ headers, payload = HTTP.multipart(payload, files)
61
61
  else
62
62
  headers = {}
63
63
  end
64
- _resp, data = @client.internet.post("#{base_url.wait}/messages", payload, headers: headers).wait
64
+ _resp, data = @client.http.post("#{base_url.wait}/messages", payload, headers: headers).wait
65
65
  Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
66
66
  end
67
67
  end
@@ -76,7 +76,7 @@ module Discorb
76
76
  #
77
77
  def fetch_message(id)
78
78
  Async do
79
- _resp, data = @client.internet.get("#{base_url.wait}/messages/#{id}").wait
79
+ _resp, data = @client.http.get("#{base_url.wait}/messages/#{id}").wait
80
80
  Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
81
81
  end
82
82
  end
@@ -99,7 +99,7 @@ module Discorb
99
99
  after: Discorb::Utils.try(around, :id),
100
100
  around: Discorb::Utils.try(before, :id),
101
101
  }.filter { |_k, v| !v.nil? }.to_h
102
- _resp, messages = @client.internet.get("#{base_url.wait}/messages?#{URI.encode_www_form(params)}").wait
102
+ _resp, messages = @client.http.get("#{base_url.wait}/messages?#{URI.encode_www_form(params)}").wait
103
103
  messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
104
104
  end
105
105
  end
@@ -122,7 +122,7 @@ module Discorb
122
122
  if block_given?
123
123
  begin
124
124
  post_task = task.async do
125
- @client.internet.post("/channels/#{@id}/typing", {})
125
+ @client.http.post("/channels/#{@id}/typing", {})
126
126
  sleep(5)
127
127
  end
128
128
  yield
@@ -130,7 +130,7 @@ module Discorb
130
130
  post_task.stop
131
131
  end
132
132
  else
133
- @client.internet.post("/channels/#{@id}/typing", {})
133
+ @client.http.post("/channels/#{@id}/typing", {})
134
134
  end
135
135
  end
136
136
  end
data/lib/discorb/role.rb CHANGED
@@ -88,7 +88,7 @@ module Discorb
88
88
  #
89
89
  def move(position, reason: nil)
90
90
  Async do
91
- @client.internet.patch("/guilds/#{@guild_id}/roles", { id: @id, position: position }, reason: reason).wait
91
+ @client.http.patch("/guilds/#{@guild_id}/roles", { id: @id, position: position }, reason: reason).wait
92
92
  end
93
93
  end
94
94
 
@@ -113,7 +113,7 @@ module Discorb
113
113
  payload[:color] = color.to_i if color != :unset
114
114
  payload[:hoist] = hoist if hoist != :unset
115
115
  payload[:mentionable] = mentionable if mentionable != :unset
116
- @client.internet.patch("/guilds/#{@guild_id}/roles/#{@id}", payload, reason: reason).wait
116
+ @client.http.patch("/guilds/#{@guild_id}/roles/#{@id}", payload, reason: reason).wait
117
117
  end
118
118
  end
119
119
 
@@ -126,7 +126,7 @@ module Discorb
126
126
  #
127
127
  def delete!(reason: nil)
128
128
  Async do
129
- @client.internet.delete("/guilds/#{@guild_id}/roles/#{@id}", reason: reason).wait
129
+ @client.http.delete("/guilds/#{@guild_id}/roles/#{@id}", reason: reason).wait
130
130
  end
131
131
  end
132
132
 
@@ -73,7 +73,7 @@ module Discorb
73
73
  payload[:name] = name unless name == :unset
74
74
  payload[:description] = description unless description == :unset
75
75
  payload[:tags] = tag.name unless tag == :unset
76
- @client.internet.patch("/guilds/#{@guild_id}/stickers/#{@id}", payload, audit_log_reason: reason).wait
76
+ @client.http.patch("/guilds/#{@guild_id}/stickers/#{@id}", payload, audit_log_reason: reason).wait
77
77
  end
78
78
  end
79
79
 
@@ -88,7 +88,7 @@ module Discorb
88
88
  #
89
89
  def delete!(reason: nil)
90
90
  Async do
91
- @client.internet.delete("/guilds/#{@guild_id}/stickers/#{@id}", audit_log_reason: reason).wait
91
+ @client.http.delete("/guilds/#{@guild_id}/stickers/#{@id}", audit_log_reason: reason).wait
92
92
  end
93
93
  end
94
94
 
data/lib/discorb/user.rb CHANGED
@@ -74,7 +74,7 @@ module Discorb
74
74
  Async do
75
75
  next @dm_channel_id if @dm_channel_id
76
76
 
77
- dm_channel = @client.internet.post("/users/#{@id}/channels", { recipient_id: @client.user.id }).wait
77
+ dm_channel = @client.http.post("/users/#{@id}/channels", { recipient_id: @client.user.id }).wait
78
78
  @dm_channel_id = dm_channel[:id]
79
79
  "/channels/#{@dm_channel_id}"
80
80
  end
@@ -155,7 +155,7 @@ module Discorb
155
155
  else
156
156
  payload[:avatar] = avatar.to_s
157
157
  end
158
- @client.internet.patch("/users/@me", payload).wait
158
+ @client.http.patch("/users/@me", payload).wait
159
159
  self
160
160
  end
161
161
  end
@@ -179,7 +179,7 @@ module Discorb
179
179
  payload = {}
180
180
  payload[:topic] = topic if topic != :unset
181
181
  payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != :unset
182
- @client.internet.edit("/stage-instances/#{@channel_id}", payload, audit_log_reason: reason).wait
182
+ @client.http.edit("/stage-instances/#{@channel_id}", payload, audit_log_reason: reason).wait
183
183
  self
184
184
  end
185
185
  end
@@ -193,7 +193,7 @@ module Discorb
193
193
  #
194
194
  def delete!(reason: nil)
195
195
  Async do
196
- @client.internet.delete("/stage-instances/#{@channel_id}", reason: reason).wait
196
+ @client.http.delete("/stage-instances/#{@channel_id}", reason: reason).wait
197
197
  self
198
198
  end
199
199
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "async/http/internet"
4
-
5
3
  module Discorb
6
4
  #
7
5
  # Represents a webhook.
@@ -36,7 +34,7 @@ module Discorb
36
34
  @token = ""
37
35
  @application_id = data[:application_id]
38
36
  @client = client
39
- @internet = Discorb::Internet.new(client)
37
+ @http = Discorb::HTTP.new(client)
40
38
  end
41
39
 
42
40
  def inspect
@@ -79,13 +77,13 @@ module Discorb
79
77
  payload[:avatar_url] = avatar_url if avatar_url != :unset
80
78
  files = [file] if file
81
79
  if files
82
- headers, payload = Internet.multipart(payload, files)
80
+ headers, payload = HTTP.multipart(payload, files)
83
81
  else
84
82
  headers = {
85
83
  "Content-Type" => "application/json",
86
84
  }
87
85
  end
88
- _resp, data = @internet.post("#{url}?wait=#{wait}", payload, headers: headers).wait
86
+ _resp, data = @http.post("#{url}?wait=#{wait}", payload, headers: headers).wait
89
87
 
90
88
  data && Webhook::Message.new(self, data)
91
89
  end
@@ -109,7 +107,7 @@ module Discorb
109
107
  payload[:name] = name if name != :unset
110
108
  payload[:avatar] = avatar if avatar != :unset
111
109
  payload[:channel_id] = Utils.try(channel, :id) if channel != :unset
112
- @internet.patch(url.to_s, payload).wait
110
+ @http.patch(url.to_s, payload).wait
113
111
  end
114
112
  end
115
113
 
@@ -122,7 +120,7 @@ module Discorb
122
120
  #
123
121
  def delete!
124
122
  Async do
125
- @internet.delete(url).wait
123
+ @http.delete(url).wait
126
124
  self
127
125
  end
128
126
  end
@@ -165,9 +163,9 @@ module Discorb
165
163
  "Content-Type" => "application/json",
166
164
  }
167
165
  else
168
- headers, payload = Internet.multipart(payload, files)
166
+ headers, payload = HTTP.multipart(payload, files)
169
167
  end
170
- _resp, data = @internet.patch("#{url}/messages/#{Utils.try(message, :id)}", payload, headers: headers).wait
168
+ _resp, data = @http.patch("#{url}/messages/#{Utils.try(message, :id)}", payload, headers: headers).wait
171
169
  message.send(:_set_data, data)
172
170
  message
173
171
  end
@@ -180,7 +178,7 @@ module Discorb
180
178
  #
181
179
  def delete_message!(message)
182
180
  Async do
183
- @internet.delete("#{url}/messages/#{Utils.try(message, :id)}").wait
181
+ @http.delete("#{url}/messages/#{Utils.try(message, :id)}").wait
184
182
  message
185
183
  end
186
184
  end
@@ -200,7 +198,7 @@ module Discorb
200
198
  def initialize(url)
201
199
  @url = url
202
200
  @token = ""
203
- @internet = Discorb::Internet.new(self)
201
+ @http = Discorb::HTTP.new(self)
204
202
  end
205
203
  end
206
204
 
@@ -362,6 +360,7 @@ module Discorb
362
360
  # @return [Boolean] Whether the author is a bot.
363
361
  # @note This will be always `true`.
364
362
  attr_reader :bot
363
+ alias bot? bot
365
364
  # @return [Discorb::Snowflake] The ID of the author.
366
365
  attr_reader :id
367
366
  # @return [String] The name of the author.
data/lib/discorb.rb CHANGED
@@ -39,7 +39,7 @@ module Discorb
39
39
  end
40
40
  end
41
41
 
42
- require_order = %w[common flag dictionary error internet intents emoji_table modules] +
42
+ require_order = %w[common flag dictionary error http intents emoji_table modules] +
43
43
  %w[user member guild emoji channel embed message] +
44
44
  %w[application audit_logs color components event extension] +
45
45
  %w[file guild_template image integration interaction invite log permission] +
metadata CHANGED
@@ -1,25 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-28 00:00:00.000000000 Z
12
- dependencies: []
13
- description: "# discorb\n[![rubydoc](https://img.shields.io/badge/Document-rubydoc.info-blue.svg)](https://rubydoc.info/gems/discorb)\n[![Gem](https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/discorb)\n[![Gem](https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/discorb)
14
- \ \n\ndiscorb is a Discord API wrapper for Ruby.\n\n## Installation\n\nAdd this
15
- line to your application's Gemfile:\n\n```ruby\ngem 'discorb'\n```\n\nAnd then execute:\n\n
16
- \ $ bundle install\n\nOr install it yourself as:\n\n $ gem install discorb\n\n##
17
- Usage\n\n### Simple ping-pong\n\n```ruby\nrequire \"discorb\"\n\nclient = Discorb::Client.new\n\nclient.once
18
- :ready do\n puts \"Logged in as #{client.user}\"\nend\n\nclient.on :message do
19
- |_task, message|\n next if message.author.bot?\n next unless message.content ==
20
- \"ping\"\n\n message.channel.post(\"Pong!\")\nend\n\nclient.run(ENV[\"DISCORD_BOT_TOKEN\"])\n```\n\n##
21
- Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sevenc-nanashi/discorb.\n\n##
22
- License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n"
11
+ date: 2021-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: async-http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: async-websocket
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mime-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description:
23
70
  email:
24
71
  - sevenc-nanashi@sevenbot.jp
25
72
  executables: []
@@ -71,11 +118,11 @@ files:
71
118
  - lib/discorb/gateway_requests.rb
72
119
  - lib/discorb/guild.rb
73
120
  - lib/discorb/guild_template.rb
121
+ - lib/discorb/http.rb
74
122
  - lib/discorb/image.rb
75
123
  - lib/discorb/integration.rb
76
124
  - lib/discorb/intents.rb
77
125
  - lib/discorb/interaction.rb
78
- - lib/discorb/internet.rb
79
126
  - lib/discorb/invite.rb
80
127
  - lib/discorb/log.rb
81
128
  - lib/discorb/member.rb
@@ -90,14 +137,14 @@ files:
90
137
  - lib/discorb/utils.rb
91
138
  - lib/discorb/voice_state.rb
92
139
  - lib/discorb/webhook.rb
93
- homepage: https://github.com/sevenc-nanashi/discorb
140
+ homepage: https://github.com/discorb-lib/discorb
94
141
  licenses:
95
142
  - MIT
96
143
  metadata:
97
144
  allowed_push_host: https://rubygems.org
98
- homepage_uri: https://github.com/sevenc-nanashi/discorb
99
- source_code_uri: https://github.com/sevenc-nanashi/discorb
100
- changelog_uri: https://github.com/sevenc-nanashi/discorb/blob/main/Changelog.md
145
+ homepage_uri: https://github.com/discorb-lib/discorb
146
+ source_code_uri: https://github.com/discorb-lib/discorb
147
+ changelog_uri: https://github.com/discorb-lib/discorb/blob/main/Changelog.md
101
148
  post_install_message:
102
149
  rdoc_options: []
103
150
  require_paths: