@@ -26,6 +26,10 @@ package net.katsstuff.ackcord.data
26
26
import java .time .OffsetDateTime
27
27
import java .util .Base64
28
28
29
+ import scala .util .Try
30
+
31
+ import net .katsstuff .ackcord .util .MessageParser
32
+
29
33
// TODO
30
34
class ImageData (val rawData : String ) extends AnyVal
31
35
object ImageData {
@@ -201,7 +205,43 @@ case class Message(
201
205
nonce : Option [Snowflake ],
202
206
pinned : Boolean ,
203
207
messageType : MessageType
204
- ) extends GetChannel
208
+ ) extends GetChannel {
209
+
210
+ def channelMentions : Seq [ChannelId ] = {
211
+ MessageParser .channelRegex
212
+ .findAllMatchIn(content)
213
+ .flatMap { m =>
214
+ Try {
215
+ ChannelId (Snowflake (m.group(1 )))
216
+ }.toOption
217
+ }
218
+ .toSeq
219
+ }
220
+
221
+ /**
222
+ * Formats mentions in this message to their normal syntax with names.
223
+ */
224
+ def formatMentions (implicit c : CacheSnapshot ): String = {
225
+ val withUsers = mentions
226
+ .flatMap(_.resolve)
227
+ .foldRight(content)((user, content) => content.replace(user.mention, s " @ ${user.name}" ))
228
+ val withRoles = mentionRoles
229
+ .flatMap(_.resolve)
230
+ .foldRight(withUsers)((role, content) => content.replace(role.mention, s " @ ${role.name}" ))
231
+
232
+ val optGuildId = channelId.resolve.collect {
233
+ case channel : GuildChannel => channel.guildId
234
+ }
235
+
236
+ optGuildId.fold(withRoles) { guildId =>
237
+ val withChannels = channelMentions
238
+ .flatMap(_.guildResolve(guildId))
239
+ .foldRight(withRoles)((channel, content) => content.replace(channel.mention, s " @ ${channel.name}" ))
240
+
241
+ withChannels
242
+ }
243
+ }
244
+ }
205
245
206
246
/**
207
247
* A reaction to a message
0 commit comments