Skip to content

Commit

Permalink
Be loud with errors in ReplyingCommand; retry message without reply i…
Browse files Browse the repository at this point in the history
…f original does not exist
  • Loading branch information
ScoreUnder committed Mar 6, 2021
1 parent 75c3755 commit 8f69cda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait ReplyingCommand extends Command {
} yield reply

override def execute(message: Message, args: String): Unit =
executeFuture(message, args)
executeFuture(message, args).failed.foreach(APIHelper.failure(s"executing the $name command"))

override def executeForEdit(message: Message, myMessageOption: Option[ID[Message]], args: String): Unit =
for (oldMessage <- myMessageOption; myReply <- executeAndGetMessage(message, args)) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/scala/score/discord/canti/wrappers/jda/RichMessage.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package score.discord.canti.wrappers.jda

import net.dv8tion.jda.api.entities.{Guild, Message, TextChannel}
import net.dv8tion.jda.api.exceptions.ErrorResponseException
import score.discord.canti.collections.ReplyCache
import score.discord.canti.functionality.ownership.MessageOwnership
import score.discord.canti.wrappers.jda.Conversions._
Expand All @@ -19,10 +20,16 @@ class RichMessage(val me: Message) extends AnyVal {
* @return the new Message, wrapped in Future
*/
def !(contents: MessageFromX)(implicit mo: MessageOwnership, replyCache: ReplyCache): Future[Message] =
me.reply(contents.toMessage).mentionRepliedUser(false).queueFuture().tap(_.foreach { message =>
mo(message) = me.getAuthor
replyCache += me.id -> message.id
})
me.reply(contents.toMessage).mentionRepliedUser(false).queueFuture()
.recoverWith {
case ex: ErrorResponseException if ex.getMeaning.contains("Unknown message") =>
// TODO: once JDA gets a real ErrorResponse for this, target that instead of the "Unknown message" string
me.getChannel.sendMessage(contents.toMessage).queueFuture()
}
.tap(_.foreach { message =>
mo(message) = me.getAuthor
replyCache += me.id -> message.id
})

def guild: Option[Guild] =
if (me.isFromGuild) Some(me.getGuild)
Expand Down

0 comments on commit 8f69cda

Please sign in to comment.