Skip to content

Commit

Permalink
Consistency changes, additional IJ files (see full description)
Browse files Browse the repository at this point in the history
Negative checks will now pass by default for events that are missing the entity type.

Extension command functions no longer have nullable arguments builders in some cases.
  • Loading branch information
gdude2002 committed Aug 8, 2021
1 parent 66fe34c commit 2c0f524
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 39 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
12 changes: 12 additions & 0 deletions kord-extensions/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions kord-extensions/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions kord-extensions/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public fun notInChannel(builder: suspend () -> ChannelBehavior): Check<*> = {
if (eventChannel == null) {
logger.nullChannel(event)

fail()
pass()
} else {
val channel = builder()

Expand Down Expand Up @@ -95,7 +95,7 @@ public fun notInChannel(builder: suspend () -> ChannelBehavior): Check<*> = {
*/
public fun inCategory(builder: suspend () -> CategoryBehavior): Check<*> = {
val logger = KotlinLogging.logger("com.kotlindiscord.kord.extensions.checks.inCategory")
val eventChannel = channelFor(event)
val eventChannel = topChannelFor(event)

if (eventChannel == null) {
logger.nullChannel(event)
Expand Down Expand Up @@ -132,12 +132,12 @@ public fun inCategory(builder: suspend () -> CategoryBehavior): Check<*> = {
*/
public fun notInCategory(builder: suspend () -> CategoryBehavior): Check<*> = {
val logger = KotlinLogging.logger("com.kotlindiscord.kord.extensions.checks.notInCategory")
val eventChannel = channelFor(event)
val eventChannel = topChannelFor(event)

if (eventChannel == null) {
logger.nullChannel(event)

fail()
pass()
} else {
val category = builder()
val channels = category.channels.toList().map { it.id }
Expand Down Expand Up @@ -344,7 +344,7 @@ public fun notInChannel(id: Snowflake): Check<*> = {
if (channel == null) {
logger.noChannelId(id)

fail()
pass()
} else {
notInChannel { channel }()
}
Expand Down Expand Up @@ -386,7 +386,7 @@ public fun notInCategory(id: Snowflake): Check<*> = {
if (category == null) {
logger.noCategoryId(id)

fail()
pass()
} else {
notInCategory { category }()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public fun notChannelType(vararg channelTypes: ChannelType): Check<*> = {
if (eventChannel == null) {
logger.nullChannel(event)

fail()
pass()
} else {
val type = eventChannel.asChannel().type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import java.util.*
* **Note:** This check can't tell the difference between an event that wasn't fired within a guild, and an event
* that fired within a guild the bot doesn't have access to, or that it can't get the GuildBehavior for (for
* example, due to a niche Kord configuration).
*
* @param event Event object to check.
*/
public val anyGuild: Check<*> = {
val logger = KotlinLogging.logger("com.kotlindiscord.kord.extensions.checks.anyGuild")
Expand All @@ -40,8 +38,6 @@ public val anyGuild: Check<*> = {
* **Note:** This check can't tell the difference between an event that wasn't fired within a guild, and an event
* that fired within a guild the bot doesn't have access to, or that it can't get the GuildBehavior for (for
* example, due to a niche Kord configuration).
*
* @param event Event object to check.
*/
public val noGuild: Check<*> = {
val logger = KotlinLogging.logger("com.kotlindiscord.kord.extensions.checks.noGuild")
Expand Down Expand Up @@ -112,7 +108,7 @@ public fun notInGuild(builder: suspend () -> GuildBehavior): Check<*> = {
if (eventGuild == null) {
logger.nullGuild(event)

fail()
pass()
} else {
val guild = builder()

Expand Down Expand Up @@ -173,7 +169,7 @@ public fun notInGuild(id: Snowflake): Check<*> = {
if (guild == null) {
logger.noGuildId(id)

fail()
pass()
} else {
notInGuild { guild }()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public fun notHasPermission(perm: Permission): Check<*> = {
if (member == null) {
logger.nullMember(event)

fail()
pass()
} else {
val memberObj = member.asMember()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public fun notHasRole(builder: suspend () -> RoleBehavior): Check<*> = {
if (member == null) {
logger.nullMember(event)

fail()
pass()
} else {
val role = builder()

Expand Down Expand Up @@ -151,7 +151,7 @@ public fun topRoleNotEqual(builder: suspend () -> RoleBehavior): Check<*> = {
if (member == null) {
logger.nullMember(event)

fail()
pass()
} else {
val role = builder()

Expand Down Expand Up @@ -426,7 +426,7 @@ public fun notHasRole(id: Snowflake): Check<*> = {
if (role == null) {
logger.noRoleId(id)

fail()
pass()
} else {
notHasRole { role }()
}
Expand Down Expand Up @@ -468,7 +468,7 @@ public fun topRoleNotEqual(id: Snowflake): Check<*> = {
if (role == null) {
logger.noRoleId(id)

fail()
pass()
} else {
topRoleNotEqual { role }()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ import mu.KotlinLogging
*/
public fun inTopChannel(builder: suspend () -> ChannelBehavior): Check<*> = {
val logger = KotlinLogging.logger("com.kotlindiscord.kord.extensions.checks.inChannel")

// TODO: When we can get the thread parent, checks will need looking at again
// val thread = threadFor(event)
//
// val eventChannel = when(thread) {
// is NewsChannelThread -> thread
// is TextChannelThread -> thread
//
// else -> channelFor(event)
// }

val eventChannel = topChannelFor(event)

if (eventChannel == null) {
Expand Down Expand Up @@ -75,7 +64,7 @@ public fun notInTopChannel(builder: suspend () -> ChannelBehavior): Check<*> = {
if (eventChannel == null) {
logger.nullChannel(event)

fail()
pass()
} else {
val channel = builder()

Expand Down Expand Up @@ -146,7 +135,7 @@ public fun notInTopChannel(id: Snowflake): Check<*> = {
if (channel == null) {
logger.noChannelId(id)

fail()
pass()
} else {
notInChannel { channel }()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.io.Serializable
import java.util.*
import kotlin.reflect.KClass

private val logger = KotlinLogging.logger {}

Expand All @@ -38,11 +37,9 @@ private val defaultLocale: Locale
* function.
*
* @param extension The [Extension] that registered this event handler.
* @param type A [KClass] representing the event type this handler is subscribed to. This is for internal use.
*/
public open class EventHandler<T : Event>(
public val extension: Extension,
public val type: KClass<*>
public val extension: Extension
) : KoinComponent {
/** Sentry adapter, for easy access to Sentry functions. **/
public val sentry: SentryAdapter by inject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public abstract class Extension : KoinComponent {
*/
@ExtensionDSL
public open suspend fun <T : Arguments> command(
arguments: (() -> T)?,
arguments: () -> T,
body: suspend MessageCommand<T>.() -> Unit
): MessageCommand<T> {
val commandObj = MessageCommand(this, arguments)
Expand Down Expand Up @@ -205,7 +205,7 @@ public abstract class Extension : KoinComponent {
*/
@ExtensionDSL
public open suspend fun <T : Arguments> slashCommand(
arguments: (() -> T),
arguments: () -> T,
body: suspend SlashCommand<T>.() -> Unit
): SlashCommand<T> {
val commandObj = SlashCommand(this, arguments)
Expand Down Expand Up @@ -266,7 +266,7 @@ public abstract class Extension : KoinComponent {
*/
@ExtensionDSL
public open suspend fun <T : Arguments> group(
arguments: (() -> T)?,
arguments: () -> T,
body: suspend GroupCommand<T>.() -> Unit
): GroupCommand<T> {
val commandObj = GroupCommand(this, arguments)
Expand Down Expand Up @@ -355,7 +355,7 @@ public abstract class Extension : KoinComponent {
public suspend inline fun <reified T : Event> event(
noinline body: suspend EventHandler<T>.() -> Unit
): EventHandler<T> {
val eventHandler = EventHandler<T>(this, T::class)
val eventHandler = EventHandler<T>(this)
val logger = KotlinLogging.logger {}

body.invoke(eventHandler)
Expand Down

0 comments on commit 2c0f524

Please sign in to comment.