Skip to content

Commit 3527698

Browse files
authored
Disable components V2 for messages with "V1" content (#245)
1 parent eaabac3 commit 3527698

File tree

12 files changed

+63
-50
lines changed

12 files changed

+63
-50
lines changed

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/api/core/messages/DefaultBotCommandsMessages.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteract
1717
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
1818
import net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload
1919
import net.dv8tion.jda.api.utils.TimeFormat
20+
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
2021
import net.dv8tion.jda.api.utils.messages.MessageCreateData
2122
import java.time.Instant
2223
import java.util.*
@@ -123,5 +124,9 @@ open class DefaultBotCommandsMessages(
123124
return template
124125
}
125126

126-
protected fun String.toMessage(): MessageCreateData = MessageCreateData.fromContent(this)
127+
protected fun String.toMessage(): MessageCreateData =
128+
MessageCreateBuilder()
129+
.setContent(this)
130+
.useComponentsV2(false)
131+
.build()
127132
}

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/api/localization/context/LocalizationContext.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fun LocalizationContext.localizeOrNull(localizationPath: String, vararg entries:
285285
* @see MessageChannel.sendMessage
286286
*/
287287
fun MessageChannel.sendLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): MessageCreateAction =
288-
sendMessage(context.localize(localizationPath, *entries))
288+
sendMessage(context.localize(localizationPath, *entries)).useComponentsV2(false)
289289

290290
/**
291291
* Sends a localized message to the event's channel.
@@ -321,7 +321,7 @@ fun BaseCommandEvent.replyLocalized(context: LocalizationContext, localizationPa
321321
* @see IReplyCallback.reply
322322
*/
323323
fun IReplyCallback.replyLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): ReplyCallbackAction =
324-
reply(context.localize(localizationPath, *entries))
324+
reply(context.localize(localizationPath, *entries)).useComponentsV2(false)
325325

326326
/**
327327
* Replies a localized ephemeral message to this interaction and acknowledges it.
@@ -333,7 +333,7 @@ fun IReplyCallback.replyLocalized(context: LocalizationContext, localizationPath
333333
* @see IReplyCallback.reply
334334
*/
335335
fun IReplyCallback.replyLocalizedEphemeral(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): ReplyCallbackAction =
336-
reply(context.localize(localizationPath, *entries)).setEphemeral(true)
336+
reply(context.localize(localizationPath, *entries)).useComponentsV2(false).setEphemeral(true)
337337

338338
/**
339339
* Sends a localized followup message to this interaction hook.
@@ -348,7 +348,7 @@ fun IReplyCallback.replyLocalizedEphemeral(context: LocalizationContext, localiz
348348
* @see InteractionHook.sendMessage
349349
*/
350350
fun InteractionHook.sendLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): WebhookMessageCreateAction<Message> =
351-
sendMessage(context.localize(localizationPath, *entries))
351+
sendMessage(context.localize(localizationPath, *entries)).useComponentsV2(false)
352352

353353
/**
354354
* Sends a localized ephemeral followup message to this interaction hook.
@@ -363,7 +363,7 @@ fun InteractionHook.sendLocalized(context: LocalizationContext, localizationPath
363363
* @see InteractionHook.sendMessage
364364
*/
365365
fun InteractionHook.sendLocalizedEphemeral(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): WebhookMessageCreateAction<Message> =
366-
sendMessage(context.localize(localizationPath, *entries)).setEphemeral(true)
366+
sendMessage(context.localize(localizationPath, *entries)).useComponentsV2(false).setEphemeral(true)
367367
//endregion
368368

369369
//region Localized edits
@@ -377,7 +377,7 @@ fun InteractionHook.sendLocalizedEphemeral(context: LocalizationContext, localiz
377377
* @see IMessageEditCallback.editMessage
378378
*/
379379
fun IMessageEditCallback.editLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): MessageEditCallbackAction =
380-
editMessage(context.localize(localizationPath, *entries))
380+
editMessage(context.localize(localizationPath, *entries)).useComponentsV2(false)
381381

382382
/**
383383
* Replaces the entire original message with a localized message.
@@ -389,7 +389,7 @@ fun IMessageEditCallback.editLocalized(context: LocalizationContext, localizatio
389389
* @see IMessageEditCallback.editMessage
390390
*/
391391
fun IMessageEditCallback.replaceLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): MessageEditCallbackAction =
392-
editMessage(context.localize(localizationPath, *entries)).setReplace(true)
392+
editMessage(context.localize(localizationPath, *entries)).useComponentsV2(false).setReplace(true)
393393

394394
/**
395395
* Edits the text content of the original message with a localized message.
@@ -401,7 +401,7 @@ fun IMessageEditCallback.replaceLocalized(context: LocalizationContext, localiza
401401
* @see InteractionHook.editOriginal
402402
*/
403403
fun InteractionHook.editLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): WebhookMessageEditAction<Message> =
404-
editOriginal(context.localize(localizationPath, *entries))
404+
editOriginal(context.localize(localizationPath, *entries)).useComponentsV2(false)
405405

406406
/**
407407
* Replaces the entire original message with a localized message.
@@ -413,7 +413,7 @@ fun InteractionHook.editLocalized(context: LocalizationContext, localizationPath
413413
* @see InteractionHook.editOriginal
414414
*/
415415
fun InteractionHook.replaceLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): WebhookMessageEditAction<Message> =
416-
editOriginal(context.localize(localizationPath, *entries)).setReplace(true)
416+
editOriginal(context.localize(localizationPath, *entries)).useComponentsV2(false).setReplace(true)
417417

418418
/**
419419
* Edits the text content of the message with a localized message.
@@ -425,7 +425,7 @@ fun InteractionHook.replaceLocalized(context: LocalizationContext, localizationP
425425
* @see Message.editMessage
426426
*/
427427
fun Message.editLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): MessageEditAction =
428-
editMessage(context.localize(localizationPath, *entries))
428+
editMessage(context.localize(localizationPath, *entries)).useComponentsV2(false)
429429

430430
/**
431431
* Replaces the entire message with a localized message.
@@ -437,5 +437,5 @@ fun Message.editLocalized(context: LocalizationContext, localizationPath: String
437437
* @see Message.editMessage
438438
*/
439439
fun Message.replaceLocalized(context: LocalizationContext, localizationPath: String, vararg entries: PairEntry): MessageEditAction =
440-
editMessage(context.localize(localizationPath, *entries)).setReplace(true)
440+
editMessage(context.localize(localizationPath, *entries)).useComponentsV2(false).setReplace(true)
441441
//endregion

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/api/pagination/menu/AbstractMenu.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ abstract class AbstractMenu<E, T : AbstractMenu<E, T>> protected constructor(
3535
editor?.accept(this as T, builder, embedBuilder, page)
3636

3737
builder.setEmbeds(embedBuilder.build())
38+
builder.useComponentsV2(false)
3839
}
3940

4041
companion object {

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/api/pagination/nested/AbstractNestedPaginator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ abstract class AbstractNestedPaginator<T : AbstractNestedPaginator<T>> protected
111111
@Suppress("UNCHECKED_CAST")
112112
selectedItem.pageEditor.accept(this as T, builder, embedBuilder, page)
113113
builder.setEmbeds(embedBuilder.build())
114+
builder.useComponentsV2(false)
114115
}
115116

116117
override fun putComponents(builder: MessageCreateBuilder) {

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/api/pagination/paginator/Paginator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Paginator internal constructor(
3737
val embedBuilder = EmbedBuilder()
3838
editor.accept(this, builder, embedBuilder, page)
3939
builder.setEmbeds(embedBuilder.build())
40+
builder.useComponentsV2(false)
4041
}
4142

4243
object Defaults {

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/commands/text/BaseCommandEventImpl.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal open class BaseCommandEventImpl(
4747
override fun getArgumentsStr(): String = argumentsStr
4848

4949
override fun reportError(message: String, e: Throwable) {
50-
channel.sendMessage(message).queue(null) { t: Throwable? -> logger.error(t) { "Could not send message to channel : $message" } }
50+
channel.sendMessage(message).useComponentsV2(false).queue(null) { t: Throwable? -> logger.error(t) { "Could not send message to channel : $message" } }
5151
context.dispatchException(message, e)
5252
}
5353

@@ -80,8 +80,8 @@ internal open class BaseCommandEventImpl(
8080
iconStream: InputStream?,
8181
embed: MessageEmbed
8282
): RestAction<Message> = when {
83-
iconStream != null -> channel.sendTyping().flatMap { channel.sendFiles(FileUpload.fromData(iconStream, "icon.jpg")).setEmbeds(embed) }
84-
else -> channel.sendTyping().flatMap { channel.sendMessageEmbeds(embed) }
83+
iconStream != null -> channel.sendTyping().flatMap { channel.sendFiles(FileUpload.fromData(iconStream, "icon.jpg")).setEmbeds(embed).useComponentsV2(false) }
84+
else -> channel.sendTyping().flatMap { channel.sendMessageEmbeds(embed).useComponentsV2(false) }
8585
}
8686

8787
@CheckReturnValue
@@ -90,39 +90,39 @@ internal open class BaseCommandEventImpl(
9090
@CheckReturnValue
9191
override fun reactError(): RestAction<Void> = channel.addReactionById(messageId, Emojis.X)
9292

93-
override fun respond(text: CharSequence): MessageCreateAction = channel.sendMessage(text)
93+
override fun respond(text: CharSequence): MessageCreateAction = channel.sendMessage(text).useComponentsV2(false)
9494

95-
override fun respondFormat(format: String, vararg args: Any): MessageCreateAction = channel.sendMessageFormat(format, *args)
95+
override fun respondFormat(format: String, vararg args: Any): MessageCreateAction = channel.sendMessageFormat(format, *args).useComponentsV2(false)
9696

97-
override fun respond(embed: MessageEmbed, vararg other: MessageEmbed): MessageCreateAction = channel.sendMessageEmbeds(embed, *other)
97+
override fun respond(embed: MessageEmbed, vararg other: MessageEmbed): MessageCreateAction = channel.sendMessageEmbeds(embed, *other).useComponentsV2(false)
9898

9999
override fun respondFile(vararg fileUploads: FileUpload): MessageCreateAction = channel.sendFiles(*fileUploads)
100100

101101
@CheckReturnValue
102-
override fun reply(text: CharSequence): MessageCreateAction = message.reply(text)
102+
override fun reply(text: CharSequence): MessageCreateAction = message.reply(text).useComponentsV2(false)
103103

104104
@CheckReturnValue
105-
override fun replyFormat(format: String, vararg args: Any): MessageCreateAction = message.replyFormat(format, *args)
105+
override fun replyFormat(format: String, vararg args: Any): MessageCreateAction = message.replyFormat(format, *args).useComponentsV2(false)
106106

107107
@CheckReturnValue
108-
override fun reply(embed: MessageEmbed, vararg other: MessageEmbed): MessageCreateAction = message.replyEmbeds(embed, *other)
108+
override fun reply(embed: MessageEmbed, vararg other: MessageEmbed): MessageCreateAction = message.replyEmbeds(embed, *other).useComponentsV2(false)
109109

110110
@CheckReturnValue
111111
override fun replyFile(vararg fileUploads: FileUpload): RestAction<Message> =
112112
channel.sendTyping().flatMap { message.replyFiles(*fileUploads) }
113113

114114
override fun indicateError(text: CharSequence): RestAction<Message> = when {
115-
guild.selfMember.hasPermission(guildChannel, MESSAGE_ADD_REACTION, MESSAGE_HISTORY) -> reactError().flatMap { channel.sendMessage(text) }
116-
else -> channel.sendMessage(text)
115+
guild.selfMember.hasPermission(guildChannel, MESSAGE_ADD_REACTION, MESSAGE_HISTORY) -> reactError().flatMap { channel.sendMessage(text).useComponentsV2(false) }
116+
else -> channel.sendMessage(text).useComponentsV2(false)
117117
}
118118

119119
override fun indicateErrorFormat(format: String, vararg args: Any): RestAction<Message> = when {
120-
guild.selfMember.hasPermission(guildChannel, MESSAGE_ADD_REACTION, MESSAGE_HISTORY) -> reactError().flatMap { channel.sendMessageFormat(format, *args) }
121-
else -> channel.sendMessageFormat(format, *args)
120+
guild.selfMember.hasPermission(guildChannel, MESSAGE_ADD_REACTION, MESSAGE_HISTORY) -> reactError().flatMap { channel.sendMessageFormat(format, *args).useComponentsV2(false) }
121+
else -> channel.sendMessageFormat(format, *args).useComponentsV2(false)
122122
}
123123

124124
override fun indicateError(embed: MessageEmbed, vararg other: MessageEmbed): RestAction<Message> = when {
125-
guild.selfMember.hasPermission(guildChannel, MESSAGE_ADD_REACTION, MESSAGE_HISTORY) -> reactError().flatMap { channel.sendMessageEmbeds(embed, *other) }
126-
else -> channel.sendMessageEmbeds(embed, *other)
125+
guild.selfMember.hasPermission(guildChannel, MESSAGE_ADD_REACTION, MESSAGE_HISTORY) -> reactError().flatMap { channel.sendMessageEmbeds(embed, *other).useComponentsV2(false) }
126+
else -> channel.sendMessageEmbeds(embed, *other).useComponentsV2(false)
127127
}
128-
}
128+
}

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/core/BContextImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal class BContextImpl internal constructor(
6262
logger.warn { "Could not send exception DM to owner '${channel.user?.effectiveName}' ($ownerId)" }
6363
}
6464

65-
channel.sendMessage(content).queue(
65+
channel.sendMessage(content).useComponentsV2(false).queue(
6666
null,
6767
ErrorHandler().handle(ErrorResponse.CANNOT_SEND_TO_USER) {
6868
onUserNotFound()

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/core/messages/autoconfigure/BotCommandsMessagesDefaultMessagesAdapter.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteract
1414
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
1515
import net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload
1616
import net.dv8tion.jda.api.utils.TimeFormat
17+
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
1718
import net.dv8tion.jda.api.utils.messages.MessageCreateData
1819
import java.time.Instant
1920

@@ -94,5 +95,9 @@ internal class BotCommandsMessagesDefaultMessagesAdapter internal constructor(
9495
return defaultMessages.modalExpiredErrorMsg.toMessage()
9596
}
9697

97-
private fun String.toMessage(): MessageCreateData = MessageCreateData.fromContent(this)
98+
private fun String.toMessage(): MessageCreateData =
99+
MessageCreateBuilder()
100+
.setContent(this)
101+
.useComponentsV2(false)
102+
.build()
98103
}

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/localization/interaction/LocalizableEditCallbackImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ internal class LocalizableEditCallbackImpl internal constructor(
1212
) : LocalizableEditCallback {
1313

1414
override fun editUser(localizationPath: String, vararg entries: Localization.Entry): MessageEditCallbackAction =
15-
editCallback.editMessage(interaction.getUserMessage(localizationPath, *entries))
15+
editCallback.editMessage(interaction.getUserMessage(localizationPath, *entries)).useComponentsV2(false)
1616

1717
override fun editGuild(localizationPath: String, vararg entries: Localization.Entry): MessageEditCallbackAction =
18-
editCallback.editMessage(interaction.getGuildMessage(localizationPath, *entries))
18+
editCallback.editMessage(interaction.getGuildMessage(localizationPath, *entries)).useComponentsV2(false)
1919

2020
override fun editLocalized(
2121
locale: Locale,
2222
localizationPath: String,
2323
vararg entries: Localization.Entry,
2424
): MessageEditCallbackAction {
25-
return editCallback.editMessage(interaction.getLocalizedMessage(locale, localizationPath, *entries))
25+
return editCallback.editMessage(interaction.getLocalizedMessage(locale, localizationPath, *entries)).useComponentsV2(false)
2626
}
27-
}
27+
}

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/localization/interaction/LocalizableInteractionHookImpl.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ internal class LocalizableInteractionHookImpl internal constructor(
1515
InteractionHook by interactionHook {
1616

1717
override fun sendUser(localizationPath: String, vararg entries: Localization.Entry): WebhookMessageCreateAction<Message> =
18-
interactionHook.sendMessage(localizableInteraction.getUserMessage(localizationPath, *entries))
18+
interactionHook.sendMessage(localizableInteraction.getUserMessage(localizationPath, *entries)).useComponentsV2(false)
1919

2020
override fun sendGuild(localizationPath: String, vararg entries: Localization.Entry): WebhookMessageCreateAction<Message> =
21-
interactionHook.sendMessage(localizableInteraction.getGuildMessage(localizationPath, *entries))
21+
interactionHook.sendMessage(localizableInteraction.getGuildMessage(localizationPath, *entries)).useComponentsV2(false)
2222

2323
override fun sendLocalized(
2424
locale: Locale,
2525
localizationPath: String,
2626
vararg entries: Localization.Entry,
2727
): WebhookMessageCreateAction<Message> {
28-
return interactionHook.sendMessage(localizableInteraction.getLocalizedMessage(locale, localizationPath, *entries))
28+
return interactionHook.sendMessage(localizableInteraction.getLocalizedMessage(locale, localizationPath, *entries)).useComponentsV2(false)
2929
}
3030

3131
override fun editUser(localizationPath: String, vararg entries: Localization.Entry): WebhookMessageEditAction<Message> =
32-
interactionHook.editOriginal(localizableInteraction.getUserMessage(localizationPath, *entries))
32+
interactionHook.editOriginal(localizableInteraction.getUserMessage(localizationPath, *entries)).useComponentsV2(false)
3333

3434
override fun editGuild(localizationPath: String, vararg entries: Localization.Entry): WebhookMessageEditAction<Message> =
35-
interactionHook.editOriginal(localizableInteraction.getGuildMessage(localizationPath, *entries))
35+
interactionHook.editOriginal(localizableInteraction.getGuildMessage(localizationPath, *entries)).useComponentsV2(false)
3636

3737
override fun editLocalized(
3838
locale: Locale,
3939
localizationPath: String,
4040
vararg entries: Localization.Entry
4141
): WebhookMessageEditAction<Message> {
42-
return interactionHook.editOriginal(localizableInteraction.getLocalizedMessage(locale, localizationPath, *entries))
42+
return interactionHook.editOriginal(localizableInteraction.getLocalizedMessage(locale, localizationPath, *entries)).useComponentsV2(false)
4343
}
44-
}
44+
}

0 commit comments

Comments
 (0)