Skip to content

Commit

Permalink
feat: google検索URLの特殊読み上げを追加 (#146)
Browse files Browse the repository at this point in the history
* feat: google検索URLの特殊読み上げを追加

* Update src/main/kotlin/com/jaoafa/vcspeaker/tts/replacers/UrlReplacer.kt

Co-authored-by: yuuaHP <identity@yuua.dev>

---------

Co-authored-by: yuuaHP <identity@yuua.dev>
  • Loading branch information
book000 and yuuahp authored Jun 15, 2024
1 parent c0d78c3 commit 0f8cbe4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/com/jaoafa/vcspeaker/tts/replacers/UrlReplacer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object UrlReplacer : BaseReplacer {
::replaceSteamAppUrl,
::replaceYouTubeUrl,
::replaceYouTubePlaylistUrl,
::replaceGoogleSearchUrl,
::replaceUrlToTitle,
::replaceUrl,
)
Expand Down Expand Up @@ -559,6 +560,24 @@ object UrlReplacer : BaseReplacer {
replacedText.replace(matchResult.value, replaceTo)
}

/**
* Google検索のURLを置換します。
*/
private suspend fun replaceGoogleSearchUrl(text: String, guildId: Snowflake) =
urlRegex.replaceAll(text) { replacedText, matchResult ->
val url = matchResult.value

val expectedUrlStarts = "https://www.google.com/search"
if (!url.startsWith(expectedUrlStarts)) return@replaceAll replacedText

val urlParams = Url(url).parameters
val query = urlParams["q"] ?: return@replaceAll replacedText

val replaceTo = "Google検索「$query」へのリンク"

replacedText.replace(matchResult.value, replaceTo)
}

/**
* URLをページのタイトルに置換します。
*/
Expand Down

0 comments on commit 0f8cbe4

Please sign in to comment.