Skip to content

Commit

Permalink
Functions to compact
Browse files Browse the repository at this point in the history
  • Loading branch information
Xh4H committed Jan 25, 2022
1 parent 8807d9a commit 3080994
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 137 deletions.
4 changes: 1 addition & 3 deletions src/rest/crud/audit_log.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
function retrieve(c::Client, ::Type{AuditLog}, g::AbstractGuild; kwargs...)
return get_guild_audit_log(c, g.id; kwargs...)
end
retrieve(c::Client, ::Type{AuditLog}, g::AbstractGuild; kwargs...) = get_guild_audit_log(c, g.id; kwargs...)
12 changes: 3 additions & 9 deletions src/rest/crud/ban.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
function create(c::Client, ::Type{Ban}, g::AbstractGuild, u::User; kwargs...)
return create_guild_ban(c, g.id, u.id; kwargs...)
end
create(c::Client, ::Type{Ban}, g::AbstractGuild, u::User; kwargs...) = create_guild_ban(c, g.id, u.id; kwargs...)

function retrieve(c::Client, ::Type{Ban}, g::AbstractGuild, u::User)
return get_guild_ban(c, g.id, u.id)
end
retrieve(c::Client, ::Type{Ban}, g::AbstractGuild, u::User) = get_guild_ban(c, g.id, u.id)
retrieve(c::Client, ::Type{Ban}, g::AbstractGuild) = get_guild_bans(c, g.id)

function delete(c::Client, b::Ban, g::AbstractGuild)
return remove_guild_ban(c, g.id, b.user.id)
end
delete(c::Client, b::Ban, g::AbstractGuild) = remove_guild_ban(c, g.id, b.user.id)
8 changes: 2 additions & 6 deletions src/rest/crud/channel.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
function create(c::Client, ::Type{DiscordChannel}, g::AbstractGuild; kwargs...)
return create_guild_channel(c, g.id; kwargs...)
end
function create(c::Client, ::Type{DiscordChannel}, u::User; kwargs...)
return create_dm(c; kwargs..., recipient_id=u.id)
end
create(c::Client, ::Type{DiscordChannel}, g::AbstractGuild; kwargs...) = create_guild_channel(c, g.id; kwargs...)
create(c::Client, ::Type{DiscordChannel}, u::User; kwargs...) = create_dm(c; kwargs..., recipient_id = u.id)

retrieve(c::Client, ::Type{DiscordChannel}, channel::Integer) = get_channel(c, channel)
retrieve(c::Client, ::Type{DiscordChannel}, g::AbstractGuild) = get_guild_channels(c, g.id)
Expand Down
8 changes: 4 additions & 4 deletions src/rest/crud/crud.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Banning a [`Member`](@ref):
create(c, Ban, guild, member; reason="baz")
```
"""
function create end
create() = ()

"""
retrieve(c::Client, ::Type{T}, args...; kwargs...) -> Future{Response}
Expand All @@ -43,7 +43,7 @@ Getting an [`Invite`](@ref) to a [`Guild`](@ref) by code:
retrieve(c, Invite, "abcdef")
```
"""
function retrieve end
retrieve() = ()

"""
update(c::Client, x::T, args...; kwargs...) -> Future{Response}
Expand All @@ -64,7 +64,7 @@ Updating a [`Role`](@ref):
update(c, role, guild; permissions=8)
```
"""
function update end
update() = ()

"""
delete(c::Client, x::T, args...) -> Future{Response}
Expand All @@ -86,7 +86,7 @@ update/delete method which takes a type parameter):
delete(c, Reaction, message)
```
"""
function delete end
delete() = ()

include("audit_log.jl")
include("ban.jl")
Expand Down
20 changes: 5 additions & 15 deletions src/rest/crud/emoji.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
function create(c::Client, ::Type{Emoji}, g::AbstractGuild; kwargs...)
return create_guild_emoji(c, g.id; kwargs...)
end
create(c::Client, ::Type{Emoji}, g::AbstractGuild; kwargs...) = create_guild_emoji(c, g.id; kwargs...)

function retrieve(c::Client, ::Type{Emoji}, g::AbstractGuild, e::Emoji)
return get_guild_emoji(c, g.id, e.id)
end
function retrieve(c::Client, ::Type{Emoji}, g::AbstractGuild)
return list_guild_emojis(c, g.id)
end
retrieve(c::Client, ::Type{Emoji}, g::AbstractGuild, e::Emoji) = get_guild_emoji(c, g.id, e.id)
retrieve(c::Client, ::Type{Emoji}, g::AbstractGuild) = list_guild_emojis(c, g.id)

function update(c::Client, e::Emoji, g::AbstractGuild; kwargs...)
return modify_guild_emoji(c, g.id, e.id; kwargs...)
end
update(c::Client, e::Emoji, g::AbstractGuild; kwargs...) = modify_guild_emoji(c, g.id, e.id; kwargs...)

function delete(c::Client, e::Emoji, g::AbstractGuild)
return delete_guild_emoji(c, g.id, e.id)
end
delete(c::Client, e::Emoji, g::AbstractGuild) = delete_guild_emoji(c, g.id, e.id)
4 changes: 1 addition & 3 deletions src/rest/crud/guild_embed.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
retrieve(c::Client, ::Type{GuildEmbed}, g::AbstractGuild) = get_guild_embed(c, g.id)

function update(c::Client, ::GuildEmbed, g::AbstractGuild; kwargs...)
return modify_guild_embed(c, g.id; kwargs...)
end
update(c::Client, ::GuildEmbed, g::AbstractGuild; kwargs...) = modify_guild_embed(c, g.id; kwargs...)
12 changes: 3 additions & 9 deletions src/rest/crud/integration.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
function create(c::Client, ::Type{Integration}, g::AbstractGuild; kwargs...)
return create_guild_integration(c, g.id; kwargs...)
end
create(c::Client, ::Type{Integration}, g::AbstractGuild; kwargs...) = create_guild_integration(c, g.id; kwargs...)

retrieve(c::Client, ::Type{Integration}, g::AbstractGuild) = get_guild_integrations(c, g.id)

function update(c::Client, i::Integration, g::AbstractGuild; kwargs...)
return modify_guild_integration(c, g.id, i.id; kwargs...)
end
update(c::Client, i::Integration, g::AbstractGuild; kwargs...) = modify_guild_integration(c, g.id, i.id; kwargs...)

function delete(c::Client, i::Integration, g::AbstractGuild)
return delete_guild_integration(c, g.id, i.id)
end
delete(c::Client, i::Integration, g::AbstractGuild) = delete_guild_integration(c, g.id, i.id)
8 changes: 2 additions & 6 deletions src/rest/crud/invite.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
function create(c::Client, ::Type{Invite}, ch::DiscordChannel; kwargs...)
return create_channel_invite(c, ch.id; kwargs...)
end
create(c::Client, ::Type{Invite}, ch::DiscordChannel; kwargs...) = create_channel_invite(c, ch.id; kwargs...)

retrieve(c::Client, ::Type{Invite}, g::AbstractGuild) = get_guild_invites(c, g.id)
retrieve(c::Client, ::Type{Invite}, ch::DiscordChannel) = get_channel_invites(c, ch.id)
function retrieve(c::Client, ::Type{Invite}, invite::AbstractString; kwargs...)
return get_invite(c, invite; kwargs...)
end
retrieve(c::Client, ::Type{Invite}, invite::AbstractString; kwargs...) = get_invite(c, invite; kwargs...)

delete(c::Client, i::Invite) = delete_invite(c, i.code)
28 changes: 7 additions & 21 deletions src/rest/crud/member.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
function create(c::Client, ::Type{Member}, g::AbstractGuild, u::User; kwargs...)
return add_guild_member(c, g.id, u.id; kwargs...)
end
create(c::Client, ::Type{Member}, g::AbstractGuild, u::User; kwargs...) = add_guild_member(c, g.id, u.id; kwargs...)

function retrieve(c::Client, ::Type{Member}, g::AbstractGuild, u::User)
return get_guild_member(c, g.id, u.id)
end
function retrieve(c::Client, ::Type{Member}, g::AbstractGuild)
return list_guild_members(c, g.id)
end
retrieve(c::Client, ::Type{Member}, g::AbstractGuild, u::User) = get_guild_member(c, g.id, u.id)
retrieve(c::Client, ::Type{Member}, g::AbstractGuild) = list_guild_members(c, g.id)

function update(c::Client, m::Member, g::AbstractGuild; kwargs...)
return modify_guild_member(c, g.id, m.user.id; kwargs...)
end
function update(c::Client, m::Member, r::Role, g::AbstractGuild)
return add_guild_member_role(c, g.id, m.user.id, r.id)
end
update(c::Client, m::Member, g::AbstractGuild; kwargs...) = modify_guild_member(c, g.id, m.user.id; kwargs...)
update(c::Client, m::Member, r::Role, g::AbstractGuild) = add_guild_member_role(c, g.id, m.user.id, r.id)

function delete(c::Client, m::Member, g::AbstractGuild)
return remove_guild_member(c, g.id, m.user.id)
end
function delete(c::Client, m::Member, r::Role, g::AbstractGuild)
return remove_guild_member_role(c, g.id, m.user.id, r.id)
end
delete(c::Client, m::Member, g::AbstractGuild) = remove_guild_member(c, g.id, m.user.id)
delete(c::Client, m::Member, r::Role, g::AbstractGuild) = remove_guild_member_role(c, g.id, m.user.id, r.id)
22 changes: 6 additions & 16 deletions src/rest/crud/message.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
function create(c::Client, ::Type{Message}, ch::DiscordChannel; kwargs...)
return create_message(c, ch.id; kwargs...)
end
create(c::Client, ::Type{Message}, ch::DiscordChannel; kwargs...) = create_message(c, ch.id; kwargs...)

function retrieve(c::Client, ::Type{Message}, ch::DiscordChannel, message::Integer)
return get_channel_message(c, ch.id, message)
end
function retrieve(
retrieve(c::Client, ::Type{Message}, ch::DiscordChannel, message::Integer) = get_channel_message(c, ch.id, message)
retrieve(
c::Client,
::Type{Message},
ch::DiscordChannel;
pinned::Bool=false,
kwargs...,
)
return if pinned
) = if pinned
get_pinned_messages(c, ch.id)
else
get_channel_messages(c, ch.id; kwargs...)
end
end

update(c::Client, m::Message; kwargs...) = edit_message(c, m.channel_id, m.id; kwargs...)

function delete(c::Client, m::Message; pinned::Bool=false)
return if pinned
delete(c::Client, m::Message; pinned::Bool=false) = if pinned
delete_pinned_channel_message(c, m.channel_id, m.id)
else
delete_message(c, m.channel_id, m.id)
end
end
function delete(c::Client, ms::Vector{Message})
return bulk_delete_messages(c, ms[1].channel_id; messages=map(m -> m.id, ms))
end
delete(c::Client, ms::Vector{Message}) = bulk_delete_messages(c, ms[1].channel_id; messages = map(m -> m.id, ms))
16 changes: 4 additions & 12 deletions src/rest/crud/overwrite.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
function create(c::Client, ::Type{Overwrite}, ch::DiscordChannel, r::Role; kwargs...)
return edit_channel_permissions(c, ch.id, r.id; kwargs..., type=OT_ROLE)
end
function create(c::Client, ::Type{Overwrite}, ch::DiscordChannel, u::User; kwargs...)
return edit_channel_permissions(c, ch.id, u.id; kwargs..., type=OT_MEMBER)
end
create(c::Client, ::Type{Overwrite}, ch::DiscordChannel, r::Role; kwargs...) = edit_channel_permissions(c, ch.id, r.id; kwargs..., type = OT_ROLE)
create(c::Client, ::Type{Overwrite}, ch::DiscordChannel, u::User; kwargs...) = edit_channel_permissions(c, ch.id, u.id; kwargs..., type = OT_MEMBER)

function update(c::Client, o::Overwrite, ch::DiscordChannel; kwargs...)
return edit_channel_permissions(c, ch.id, o.id; kwargs..., type=o.type)
end
update(c::Client, o::Overwrite, ch::DiscordChannel; kwargs...) = edit_channel_permissions(c, ch.id, o.id; kwargs..., type = o.type)

function delete(c::Client, o::Overwrite, ch::DiscordChannel)
return delete_channel_permission(c, ch.id, o.id)
end
delete(c::Client, o::Overwrite, ch::DiscordChannel) = delete_channel_permission(c, ch.id, o.id)
12 changes: 3 additions & 9 deletions src/rest/crud/reaction.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
function create(c::Client, ::Type{Reaction}, m::Message, emoji::StringOrChar)
return create_reaction(c, m.channel_id, m.id, emoji)
end
create(c::Client, ::Type{Reaction}, m::Message, emoji::StringOrChar) = create_reaction(c, m.channel_id, m.id, emoji)
function create(c::Client, ::Type{Reaction}, m::Message, e::Emoji)
emoji = e.id === nothing ? e.name : "$(e.name):$(e.id)"
return create_reaction(c, m.channel_id, m.id, emoji)
end

function retrieve(c::Client, ::Type{Reaction}, m::Message, emoji::StringOrChar)
return get_reactions(c, m.channel_id, m.id, emoji)
end
retrieve(c::Client, ::Type{Reaction}, m::Message, emoji::StringOrChar) = get_reactions(c, m.channel_id, m.id, emoji)
retrieve(c::Client, ::Type{Reaction}, m::Message, e::Emoji) = get(Reaction, c, m, e.name)

function delete(c::Client, ::Type{Reaction}, m::Message)
return delete_all_reactions(c, m.channel_id, m.id)
end
delete(c::Client, ::Type{Reaction}, m::Message) = delete_all_reactions(c, m.channel_id, m.id)
function delete(c::Client, emoji::StringOrChar, m::Message, u::User)
return if c.state.user !== nothing && u.id == c.state.user.id
delete_own_reaction(c, m.channel_id, m.id, emoji)
Expand Down
8 changes: 2 additions & 6 deletions src/rest/crud/role.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
function create(c::Client, ::Type{Role}, g::AbstractGuild; kwargs...)
return create_guild_role(c, g.id; kwargs...)
end
create(c::Client, ::Type{Role}, g::AbstractGuild; kwargs...) = create_guild_role(c, g.id; kwargs...)

retrieve(c::Client, ::Type{Role}, g::AbstractGuild) = get_guild_roles(c, g.id)

function update(c::Client, r::Role, g::AbstractGuild; kwargs...)
return modify_guild_role(c, g.id, r.id; kwargs...)
end
update(c::Client, r::Role, g::AbstractGuild; kwargs...) = modify_guild_role(c, g.id, r.id; kwargs...)

delete(c::Client, r::Role, g::AbstractGuild) = delete_guild_role(c, g.id, r.id)
4 changes: 1 addition & 3 deletions src/rest/crud/user.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
function retrieve(c::Client, ::Type{User}, user::Integer)
return if me(c) !== nothing && me(c).id == user
retrieve(c::Client, ::Type{User}, user::Integer) = if me(c) !== nothing && me(c).id == user
get_current_user(c)
else
get_user(c, user)
end
end
retrieve(c::Client, ::Type{User}) = get_current_user(c)

update(c::Client; kwargs...) = modify_current_user(c; kwargs...)
4 changes: 1 addition & 3 deletions src/rest/crud/voice_region.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
function retrieve(c::Client, ::Type{VoiceRegion}, g::AbstractGuild)
return get_guild_voice_regions(c, g.id)
end
retrieve(c::Client, ::Type{VoiceRegion}, g::AbstractGuild) = get_guild_voice_regions(c, g.id)
retrieve(c::Client, ::Type{VoiceRegion}) = list_voice_regions(c)
16 changes: 4 additions & 12 deletions src/rest/crud/webhook.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
function create(c::Client, ::Type{Webhook}, ch::DiscordChannel; kwargs...)
return create_webhook(c, ch.id; kwargs...)
end
create(c::Client, ::Type{Webhook}, ch::DiscordChannel; kwargs...) = create_webhook(c, ch.id; kwargs...)

retrieve(c::Client, ::Type{Webhook}, ch::DiscordChannel) = get_channel_webhooks(c, ch.id)
retrieve(c::Client, ::Type{Webhook}, g::AbstractGuild) = get_guild_webhooks(c, g.id)
retrieve(c::Client, ::Type{Webhook}, webhook::Integer) = get_webhook(c, webhook)
function retrieve(c::Client, ::Type{Webhook}, webhook::Integer, token::AbstractString)
return get_webhook_with_token(c, webhook, token)
end
retrieve(c::Client, ::Type{Webhook}, webhook::Integer, token::AbstractString) = get_webhook_with_token(c, webhook, token)

update(c::Client, w::Webhook; kwargs...) = modify_webhook(c, w.id; kwargs...)
function update(c::Client, w::Webhook, token::AbstractString; kwargs...)
return modify_webhook_with_token(c, w.id, token; kwargs...)
end
update(c::Client, w::Webhook, token::AbstractString; kwargs...) = modify_webhook_with_token(c, w.id, token; kwargs...)

delete(c::Client, w::Webhook) = delete_webhook(c, w.id)
function delete(c::Client, w::Webhook, token::AbstractString)
return delete_webhook_with_token(c, w.id, token)
end
delete(c::Client, w::Webhook, token::AbstractString) = delete_webhook_with_token(c, w.id, token)

0 comments on commit 3080994

Please sign in to comment.