Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

インラインコードやコードブロック内のリンクは無視したい #44

Open
Sayamame-beans opened this issue Sep 27, 2023 · 0 comments
Labels
enhancement New feature or request priority-low This may not be voluntarily worked on

Comments

@Sayamame-beans
Copy link
Collaborator

package io.github.kobi32768.quotebot
private val linkRegexWithValidCheck = Regex("""(?<!<)https://discord\.com/channels/\d{6,19}/\d{6,19}/\d{6,19}(?!>)""")
private val linkRegexWithoutValidCheck = Regex("""https://discord\.com/channels/\d{6,19}/\d{6,19}/\d{6,19}""")
private fun String.extractLinks(force: Boolean): Sequence<String> {
return (if (force) linkRegexWithoutValidCheck else linkRegexWithValidCheck)
.findAll(this)
.map { it.value }
}
fun String.extractIDs(force: Boolean): Sequence<MessageLink> = this.extractLinks(force)
.map { link ->
val (guildId, channelId, messageId) = link.removePrefix("https://discord.com/channels/").split('/')
MessageLink(guildId.toLong(), channelId.toLong(), messageId.toLong())
}
data class MessageLink(
val guildId: Long,
val channelId: Long,
val messageId: Long,
)

ちゃんとパースしないといけなくて微妙に面倒そう…

@Sayamame-beans Sayamame-beans added the enhancement New feature or request label Sep 27, 2023
@Sayamame-beans Sayamame-beans added the priority-low This may not be voluntarily worked on label Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority-low This may not be voluntarily worked on
Projects
None yet
Development

No branches or pull requests

1 participant