File tree Expand file tree Collapse file tree 5 files changed +55
-5
lines changed
Expand file tree Collapse file tree 5 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ dependencies {
3030 implementation(" net.dv8tion:JDA:4.2.1_253" ) {
3131 exclude(module = " opus-java" ) // optional, for if you don't plan to use voice chat
3232 }
33- implementation(" com.github.yttrian:koncorda:0.3.0 " )
33+ implementation(" com.github.yttrian:koncorda:0.3.1 " )
3434}
3535```
3636
Original file line number Diff line number Diff line change 11import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22
33group = " org.yttr"
4- version = " 0.3.0 "
4+ version = " 0.3.1 "
55
66plugins {
77 id(" tanvd.kosogor" ) version " 1.0.10" apply true
Original file line number Diff line number Diff line change 11package org.yttr.koncorda.command
22
33import kotlinx.coroutines.future.await
4+ import net.dv8tion.jda.api.MessageBuilder
5+ import net.dv8tion.jda.api.entities.Message
6+ import net.dv8tion.jda.api.entities.MessageEmbed
47import net.dv8tion.jda.api.events.message.MessageReceivedEvent
58
69data class CommandCall (val event : MessageReceivedEvent , val args : List <String >) {
710 /* *
8- * Respond to the event.
11+ * Respond to the event with text .
912 */
1013 suspend fun MessageReceivedEvent.respond (content : String ) {
11- if (content.isNotBlank()) channel.sendMessage(content).submit().await()
14+ if (content.isNotBlank()) respond(MessageBuilder ().setContent(content).build())
15+ }
16+
17+ /* *
18+ * Respond to the event with an embed.
19+ */
20+ suspend fun MessageReceivedEvent.respond (embed : MessageEmbed ) {
21+ respond(MessageBuilder ().setEmbed(embed).build())
22+ }
23+
24+ /* *
25+ * Respond the the event with a complex message.
26+ */
27+ suspend fun MessageReceivedEvent.respond (message : Message ) {
28+ channel.sendMessage(message).submit().await()
1229 }
1330}
Original file line number Diff line number Diff line change @@ -5,3 +5,23 @@ import org.yttr.koncorda.command.CommandCall
55interface CommandCheck {
66 suspend fun check (call : CommandCall ): Boolean
77}
8+
9+ infix fun CommandCheck.or (right : CommandCheck ): CommandCheck = composite(this , right, Boolean ::or )
10+
11+ infix fun CommandCheck.and (right : CommandCheck ): CommandCheck = composite(this , right, Boolean ::and )
12+
13+ operator fun CommandCheck.not (): CommandCheck = object : CommandCheck {
14+ override suspend fun check (call : CommandCall ): Boolean = ! this @not.check(call)
15+ }
16+
17+ private fun composite (
18+ left : CommandCheck ,
19+ right : CommandCheck ,
20+ predicate : (Boolean , Boolean ) -> Boolean
21+ ): CommandCheck {
22+ return object : CommandCheck {
23+ override suspend fun check (call : CommandCall ): Boolean {
24+ return predicate(left.check(call), right.check(call))
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change 11import command.HelpCommand
22import command.TestCommand
33import command.check.Useless
4+ import net.dv8tion.jda.api.MessageBuilder
45import net.dv8tion.jda.api.requests.GatewayIntent
56import org.yttr.koncorda.await
67import org.yttr.koncorda.command.check.Impossible
8+ import org.yttr.koncorda.command.check.and
9+ import org.yttr.koncorda.command.check.not
10+ import org.yttr.koncorda.command.check.or
711import org.yttr.koncorda.commands
812import org.yttr.koncorda.koncorda
913import org.yttr.koncorda.onReady
@@ -30,7 +34,16 @@ fun main() {
3034 event.respond(" Hello ${event.author} !" )
3135 }
3236 check(Useless ) {
33- leaf(" world" ) { event.respond(" Yay!" ) }
37+ leaf(" world" ) { event.respond(MessageBuilder ().setContent(" Yay!" ).build()) }
38+ }
39+ check(Useless and Impossible ) {
40+ leaf(" everyone" ) { event.respond(" Huh?" ) }
41+ }
42+ check(Useless and ! Impossible ) {
43+ leaf(" everybody" ) { event.respond(" Hmm." ) }
44+ }
45+ check(Useless or Impossible ) {
46+ leaf(" everything" ) { event.respond(" Hmm." ) }
3447 }
3548 }
3649
You can’t perform that action at this time.
0 commit comments