Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel#permission_overwrites= argument type mismatched with docs #238

Open
anna328p opened this issue Sep 26, 2023 · 0 comments
Open

Channel#permission_overwrites= argument type mismatched with docs #238

anna328p opened this issue Sep 26, 2023 · 0 comments

Comments

@anna328p
Copy link

Summary

Here's the documentation for Channel#permission_overwrites= (as rendered by YARD):

#permission_overwrites=(overwrites) ⇒ Object

Bulk sets this channels permission overwrites

Parameters:

  • overwrites (Array<Overwrite>)

When I try to call the method as documented (channel.permission_overwrites = [ow1, ow2]), I get a stack trace like the following:

Exception: #<NoMethodError: undefined method `to_hash' for nil:NilClass>
[...]/lib/discordrb/data/channel.rb:968:in `block in update_channel_data'
[...]/lib/discordrb/data/channel.rb:968:in `map'
[...]/lib/discordrb/data/channel.rb:968:in `update_channel_data'
[...]/lib/discordrb/data/channel.rb:346:in `permission_overwrites='
(eval):1:in `block in <module:Admin>'
[...]/qbot/modules/admin.rb:45:in `eval'
[...]/qbot/modules/admin.rb:45:in `block in <module:Admin>'
[...]/lib/discordrb/commands/parser.rb:108:in `call'
[...]/qbot/lib/qbot/patches.rb:35:in `call'
[...]/lib/discordrb/commands/command_bot.rb:240:in `execute_command'
[...]/qbot/lib/qbot/hooks.rb:30:in `execute_command'
[...]/lib/discordrb/commands/command_bot.rb:340:in `simple_execute'
[...]/lib/discordrb/commands/command_bot.rb:498:in `block in execute_chain'

This is because the implementation of this method doesn't match the docs. Here's the code for that method:

def permission_overwrites=(overwrites)
update_channel_data(permission_overwrites: overwrites)
end

Here's the code for the method it calls:

def update_channel_data(new_data)
new_nsfw = new_data[:nsfw].is_a?(TrueClass) || new_data[:nsfw].is_a?(FalseClass) ? new_data[:nsfw] : @nsfw
# send permission_overwrite only when explicitly set
overwrites = new_data[:permission_overwrites] ? new_data[:permission_overwrites].map { |_, v| v.to_hash } : nil
response = JSON.parse(API::Channel.update(@bot.token, @id,
new_data[:name] || @name,
new_data[:topic] || @topic,
new_data[:position] || @position,
new_data[:bitrate] || @bitrate,
new_data[:user_limit] || @user_limit,
new_nsfw,
overwrites,
new_data[:parent_id] || @parent_id,
new_data[:rate_limit_per_user] || @rate_limit_per_user))
update_data(response)
end

The expression new_data[:permission_overwrites].map { |_, v| v.to_hash } is present here, which I infer assumes new_data[:permission_overwrites] is a Hash (or something else that can be destructured into pairs). However, this makes no sense semantically, since the relevant Discord API endpoint (PATCH /channels/{channel.id}) takes an array of permission overwrite objects.


Environment

Ruby version:

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux]

Discordrb version:

discordrb (3.4.2 faace0f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant