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 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 up to a given amount of time.
# 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 parameter is deprecated and will be removed in 4.0.
# @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)
Droid00000 marked this conversation as resolved.
Show resolved Hide resolved
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 is deprecated and will be removed 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