From bda4556e9d3840dbbcece6a24e0301d415126695 Mon Sep 17 00:00:00 2001 From: TheMonitorLizard Date: Mon, 17 Jul 2017 14:18:25 -0500 Subject: [PATCH 1/2] Fixed color Setter in KEmbedBuilder --- src/main/kotlin/club/minnced/kjda/builders/KJDAEmbedBuilder.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/club/minnced/kjda/builders/KJDAEmbedBuilder.kt b/src/main/kotlin/club/minnced/kjda/builders/KJDAEmbedBuilder.kt index 2c10f0a..7dca2fb 100644 --- a/src/main/kotlin/club/minnced/kjda/builders/KJDAEmbedBuilder.kt +++ b/src/main/kotlin/club/minnced/kjda/builders/KJDAEmbedBuilder.kt @@ -32,6 +32,7 @@ class KEmbedBuilder internal constructor() : Appendable { var title: String? = null var url : String? = null var color: Int? = null + set(value) { field = value?.and(0xFFFFFF) } var thumbnail: String? = null var image : String? = null From f71b940de8f4990e69055493c2966248365b431a Mon Sep 17 00:00:00 2001 From: TheMonitorLizard Date: Wed, 23 Aug 2017 22:57:59 -0500 Subject: [PATCH 2/2] First Pass on various RestAction extensions --- .../minnced/kjda/KJDARestActionExtensions.kt | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/kotlin/club/minnced/kjda/KJDARestActionExtensions.kt diff --git a/src/main/kotlin/club/minnced/kjda/KJDARestActionExtensions.kt b/src/main/kotlin/club/minnced/kjda/KJDARestActionExtensions.kt new file mode 100644 index 0000000..d3bff9b --- /dev/null +++ b/src/main/kotlin/club/minnced/kjda/KJDARestActionExtensions.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2016 - 2017 Florian Spieß + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@file:Suppress("UNUSED") +@file:JvmName("KJDARestActionExtensions") +package club.minnced.kjda + +import net.dv8tion.jda.core.Permission +import net.dv8tion.jda.core.managers.GuildController +import net.dv8tion.jda.core.requests.restaction.AuditableRestAction +import net.dv8tion.jda.core.requests.restaction.ChannelAction +import net.dv8tion.jda.core.requests.restaction.PermissionOverrideAction +import net.dv8tion.jda.core.requests.restaction.RoleAction +import java.awt.Color + +// Guild Controller shortcuts + +infix inline fun GuildController.createRole(init: RoleAction.() -> Unit) = with(createRole()) +{ + init() + promise() +} + +inline fun GuildController.createTextChannel(name: String, init: ChannelAction.() -> Unit) = with(createTextChannel(name)) +{ + init() + promise() +} + +inline fun GuildController.createVoiceChannel(name: String, init: ChannelAction.() -> Unit) = with(createVoiceChannel(name)) +{ + init() + promise() +} + +infix inline fun RoleAction.name(lazy: () -> String?) : RoleAction = setName(lazy()) +infix inline fun RoleAction.color(lazy: () -> Color?) : RoleAction = setColor(lazy()) +infix inline fun RoleAction.hoisted(lazy: () -> Boolean) : RoleAction = setHoisted(lazy()) +infix inline fun RoleAction.mentionable(lazy: () -> Boolean) : RoleAction = setMentionable(lazy()) +infix inline fun RoleAction.permissions(lazy: ArrayList.() -> Unit) : RoleAction = with(ArrayList()) +{ + lazy(this) + setPermissions(this) +} + +infix inline fun ChannelAction.name(lazy: () -> String) : ChannelAction = setName(lazy()) +infix inline fun ChannelAction.topic(lazy: () -> String) : ChannelAction = setTopic(lazy()) +infix inline fun ChannelAction.userLimit(lazy: () -> Int) : ChannelAction = setUserlimit(lazy()) +infix inline fun ChannelAction.bitrate(lazy: () -> Int) : ChannelAction = setBitrate(lazy()) + +infix inline fun AuditableRestAction.reason(lazy: () -> String) = reason(lazy()).promise() + +infix inline fun T.allow(lazy: ArrayList.() -> Unit) : T = + with(ArrayList()) { + lazy() + this@allow + } +infix inline fun T.deny(lazy: ArrayList.() -> Unit) : T = + with(ArrayList()) { + lazy() + this@deny + } \ No newline at end of file