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

Fix Guild Bans #279

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
13 changes: 7 additions & 6 deletions lib/discordrb/api/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,18 @@ def bans(token, server_id, limit = nil, before = nil, after = nil)
)
end

# Ban a user from a server and delete their messages from the last message_days days
# Ban a user from a server and delete their messages from seconds.
# https://discord.com/developers/docs/resources/guild#create-guild-ban
def ban_user(token, server_id, user_id, message_days, reason = nil)
reason = URI.encode_www_form_component(reason) if reason
def ban_user(token, server_id, user_id, message_seconds, reason = nil)
Discordrb::API.request(
:guilds_sid_bans_uid,
server_id,
:put,
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete_message_days=#{message_days}&reason=#{reason}",
nil,
Authorization: token
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
{ delete_message_seconds: message_seconds }.to_json,
Authorization: token,
content_type: :json,
'X-Audit-Log-Reason': reason
)
end

Expand Down
13 changes: 10 additions & 3 deletions lib/discordrb/data/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,17 @@ def server_unmute
end

# Bans this member from the server.
# @param message_days [Integer] How many days worth of messages sent by the member should be deleted.
# @param message_days [Integer] How many days worth of messages sent by the member should be deleted. This will be deprecated in 4.0.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this parameter be deprecated now and removed in 4.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per what @swarley has said in DAPI I was told to keep the argument as is and add seconds as an optional KWARG.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that comment referred to keeping it in version 3.x, not in 4.0. In semantic versioning (semver), a breaking change, like a backwards incompatible method signature change, is only allowed during major version changes, such as 3.x to 4.0. A deprecation is a warning that it will be removed in a future version, in this case likely 4.0. Therefore, it should be deprecated now and removed in 4.0, not, as the comment claims, be deprecated in 4.0, which would imply its existence in 4.0 (and thus its removal not earlier than in 5.0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that comment referred to keeping it in version 3.x, not in 4.0. In semantic versioning (semver), a breaking change, like a backwards incompatible method signature change, is only allowed during major version changes, such as 3.x to 4.0. A deprecation is a warning that it will be removed in a future version, in this case likely 4.0. Therefore, it should be deprecated now and removed in 4.0, not, as the comment claims, be deprecated in 4.0, which would imply its existence in 4.0 (and thus its removal not earlier than in 5.0).

Oh whoops. Seems like I misunderstood what you mean.

# @param message_seconds [Integer] How many seconds worth of messages sent by the member should be deleted.
# @param reason [String] The reason this member is being banned.
def ban(message_days = 0, reason: nil)
server.ban(@user, message_days, reason: reason)
def ban(message_days = 0, message_seconds: nil, reason: nil)
delete_messages = if message_days != 0 && message_days
message_days * 86_400
else
message_seconds || 0
end

server.ban(@user, delete_messages, reason: reason)
end

# Unbans this member from the server.
Expand Down
13 changes: 10 additions & 3 deletions lib/discordrb/data/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,17 @@ def bans(limit: nil, before_id: nil, after_id: nil)

# Bans a user from this server.
# @param user [User, String, Integer] The user to ban.
# @param message_days [Integer] How many days worth of messages sent by the user should be deleted.
# @param message_days [Integer] How many days worth of messages sent by the user should be deleted. This will be deprecated in 4.0.
# @param message_seconds [Integer] How many seconds of messages sent by the user should be deleted.
# @param reason [String] The reason the user is being banned.
def ban(user, message_days = 0, reason: nil)
API::Server.ban_user(@bot.token, @id, user.resolve_id, message_days, reason)
def ban(user, message_days = 0, message_seconds: nil, reason: nil)
delete_messages = if message_days != 0 && message_days
message_days * 86_400
else
message_seconds || 0
end

API::Server.ban_user(@bot.token, @id, user.resolve_id, delete_messages, reason)
end

# Unbans a previously banned user from this server.
Expand Down
Loading