Skip to content

Commit b692e60

Browse files
committed
Add more context send methods.
1 parent 2a8d380 commit b692e60

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'me.devoxin'
8-
version '3.0.1'
8+
version '3.0.2'
99

1010
repositories {
1111
maven {

src/main/kotlin/me/devoxin/flight/api/context/Context.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ interface Context {
4242
?: messageChannel.sendMessage(content).submit()
4343
}
4444

45+
fun respond(message: MessageCreateData): CompletableFuture<*> {
46+
return asSlashContext?.respond0(message)
47+
?: messageChannel.sendMessage(message).submit()
48+
}
49+
4550
fun send(content: String) {
4651
messageChannel.sendMessage(content).submit()
4752
}

src/main/kotlin/me/devoxin/flight/api/context/MessageContext.kt

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent
1414
import net.dv8tion.jda.api.requests.RestAction
1515
import net.dv8tion.jda.api.utils.FileUpload
1616
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
17+
import net.dv8tion.jda.api.utils.messages.MessageCreateData
1718
import java.util.regex.Pattern
1819

1920
class MessageContext(
@@ -66,13 +67,25 @@ class MessageContext(
6667
send0({ setEmbeds(EmbedBuilder().apply(embed).build()) }).submit()
6768
}
6869

70+
/**
71+
* Sends a message to the channel the Context was created from.
72+
* This is intended as a lower level function (compared to the other send methods)
73+
* to offer more functionality when needed.
74+
*
75+
* @param message
76+
* The message to send.
77+
*/
78+
fun send(message: MessageCreateData) {
79+
messageChannel.sendMessage(message).submit()
80+
}
81+
6982
/**
7083
* Sends a message embed to the channel the Context was created from.
7184
*
7285
* @param content
7386
* The content of the message.
7487
*
75-
* @return The created message.
88+
* @return The sent message.
7689
*/
7790
suspend fun sendAsync(content: String): Message {
7891
return send0({ setContent(content) }).submit().await()
@@ -84,7 +97,7 @@ class MessageContext(
8497
* @param attachment
8598
* The attachment to send.
8699
*
87-
* @return The created message.
100+
* @return The sent message.
88101
*/
89102
suspend fun sendAsync(attachment: FileUpload): Message {
90103
return send0(null, attachment).submit().await()
@@ -96,12 +109,26 @@ class MessageContext(
96109
* @param embed
97110
* Options to apply to the message embed.
98111
*
99-
* @return The created message.
112+
* @return The sent message.
100113
*/
101114
suspend fun sendAsync(embed: EmbedBuilder.() -> Unit): Message {
102115
return send0({ setEmbeds(EmbedBuilder().apply(embed).build()) }).submit().await()
103116
}
104117

118+
/**
119+
* Sends a message to the channel the Context was created from.
120+
* This is intended as a lower level function (compared to the other send methods)
121+
* to offer more functionality when needed.
122+
*
123+
* @param message
124+
* The message to send.
125+
*
126+
* @return The sent message.
127+
*/
128+
suspend fun sendAsync(message: MessageCreateData): Message {
129+
return messageChannel.sendMessage(message).submit().await()
130+
}
131+
105132
/**
106133
* Sends the message author a direct message.
107134
*
@@ -110,10 +137,24 @@ class MessageContext(
110137
*/
111138
fun sendPrivate(content: String) {
112139
author.openPrivateChannel().submit()
113-
.thenAccept {
114-
it.sendMessage(content).submit()
115-
.handle { _, _ -> it.delete().submit() }
116-
}
140+
.thenCompose { it.sendMessage(content).submit() }
141+
.thenCompose { it.channel.asPrivateChannel().delete().submit() }
142+
}
143+
144+
/**
145+
* Sends the message author a direct message.
146+
* This is intended as a lower level function (compared to the other send methods)
147+
* to offer more functionality when needed.
148+
*
149+
* @param message
150+
* The message to send.
151+
*
152+
* @return The sent message.
153+
*/
154+
fun sendPrivate(message: MessageCreateData) {
155+
author.openPrivateChannel().submit()
156+
.thenCompose { it.sendMessage(message).submit() }
157+
.thenCompose { it.channel.asPrivateChannel().delete().submit() }
117158
}
118159

119160
private fun send0(messageOpts: (MessageCreateBuilder.() -> Unit)? = null, vararg files: FileUpload): RestAction<Message> {

0 commit comments

Comments
 (0)