-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: replacerをobjectに切り出し * feat: URLに関する置換処理を作成 * fix: とりあえず一部review対応 * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/tools/Emoji.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Apply suggestions from code review Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/tools/Twitter.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * Update src/main/kotlin/com/jaoafa/vcspeaker/voicetext/textreplacers/UrlReplacer.kt Co-authored-by: yuuaHP <identity@yuua.dev> * fix: renamed file * fix: models/originalをパッケージで分類するように * feat: isThreadを拡張関数に変更 --------- Co-authored-by: yuuaHP <identity@yuua.dev>
- Loading branch information
Showing
18 changed files
with
844 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/jaoafa/vcspeaker/models/original/discord/DiscordInvite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.jaoafa.vcspeaker.models.original.discord | ||
|
||
import dev.kord.common.entity.Snowflake | ||
|
||
data class DiscordInvite( | ||
val code: String, | ||
val guildId: Snowflake, | ||
val guildName: String, | ||
val channelId: Snowflake, | ||
val channelName: String, | ||
val inviterId: Snowflake?, | ||
val inviterName: String?, | ||
val eventId: Snowflake?, | ||
val eventName: String?, | ||
) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/jaoafa/vcspeaker/models/original/twitter/Tweet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.jaoafa.vcspeaker.models.original.twitter | ||
|
||
data class Tweet( | ||
var authorName: String, | ||
var html: String, | ||
var plainText: String, | ||
) |
117 changes: 117 additions & 0 deletions
117
src/main/kotlin/com/jaoafa/vcspeaker/models/response/discord/DiscordGetInviteResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.jaoafa.vcspeaker.models.response.discord | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class DiscordGetInviteResponse( | ||
val type: Long, | ||
val code: String, | ||
val inviter: Inviter, | ||
@SerialName("expires_at") | ||
val expiresAt: String, | ||
val flags: Long, | ||
val guild: Guild, | ||
@SerialName("guild_id") | ||
val guildId: String, | ||
val channel: Channel, | ||
@SerialName("guild_scheduled_event") | ||
val guildScheduledEvent: GuildScheduledEvent? = null, | ||
@SerialName("approximate_member_count") | ||
val approximateMemberCount: Long, | ||
@SerialName("approximate_presence_count") | ||
val approximatePresenceCount: Long, | ||
) | ||
|
||
@Serializable | ||
data class AvatarDecorationData( | ||
val type: Long, | ||
val id: String, | ||
) | ||
|
||
@Serializable | ||
data class Inviter( | ||
val id: String, | ||
val username: String, | ||
val avatar: String, | ||
val discriminator: String, | ||
@SerialName("public_flags") | ||
val publicFlags: Long, | ||
val flags: Long, | ||
val banner: String? = null, | ||
@SerialName("accent_color") | ||
val accentColor: Long? = null, | ||
@SerialName("global_name") | ||
val globalName: String, | ||
@SerialName("avatar_decoration_data") | ||
val avatarDecorationData: AvatarDecorationData? = null, | ||
@SerialName("banner_color") | ||
val bannerColor: Long? = null, | ||
) | ||
|
||
@Serializable | ||
data class Guild( | ||
val id: String, | ||
val name: String, | ||
val splash: String, | ||
val banner: String, | ||
val description: String? = null, | ||
val icon: String, | ||
val features: List<String>, | ||
@SerialName("verification_level") | ||
val verificationLevel: Long, | ||
@SerialName("vanity_url_code") | ||
val vanityUrlCode: String? = null, | ||
@SerialName("nsfw_level") | ||
val nsfwLevel: Long, | ||
val nsfw: Boolean, | ||
@SerialName("premium_subscription_count") | ||
val premiumSubscriptionCount: Long, | ||
) | ||
|
||
@Serializable | ||
data class Channel( | ||
val id: String, | ||
val type: Long, | ||
val name: String, | ||
) | ||
|
||
@Serializable | ||
data class GuildScheduledEvent( | ||
val id: String, | ||
@SerialName("guild_id") | ||
val guildId: String, | ||
val name: String, | ||
val description: String, | ||
@SerialName("channel_id") | ||
val channelId: String? = null, | ||
@SerialName("creator_id") | ||
val creatorId: String, | ||
val image: String, | ||
@SerialName("scheduled_start_time") | ||
val scheduledStartTime: String, | ||
@SerialName("scheduled_end_time") | ||
val scheduledEndTime: String, | ||
val status: Long, | ||
@SerialName("entity_type") | ||
val entityType: Long, | ||
@SerialName("entity_id") | ||
val entityId: String? = null, | ||
@SerialName("recurrence_rule") | ||
val recurrenceRule: String? = null, | ||
@SerialName("user_count") | ||
val userCount: Long, | ||
@SerialName("privacy_level") | ||
val privacyLevel: Long, | ||
@SerialName("sku_ids") | ||
val skuIds: List<String>, | ||
@SerialName("auto_start") | ||
val autoStart: Boolean, | ||
@SerialName("entity_metadata") | ||
val entityMetadata: EntityMetadata, | ||
) | ||
|
||
@Serializable | ||
data class EntityMetadata( | ||
val location: String, | ||
) |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/jaoafa/vcspeaker/models/response/twitter/TwitterOEmbedResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.jaoafa.vcspeaker.models.response.twitter | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TwitterOEmbedResponse( | ||
val url: String, | ||
@SerialName("author_name") | ||
val authorName: String, | ||
@SerialName("author_url") | ||
val authorUrl: String, | ||
val html: String, | ||
val width: Long, | ||
val height: Long? = null, | ||
val type: String, | ||
@SerialName("cache_age") | ||
val cacheAge: String, | ||
@SerialName("provider_name") | ||
val providerName: String, | ||
@SerialName("provider_url") | ||
val providerUrl: String, | ||
val version: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.jaoafa.vcspeaker.tools | ||
|
||
import com.jaoafa.vcspeaker.models.original.twitter.Tweet | ||
import com.jaoafa.vcspeaker.models.response.twitter.TwitterOEmbedResponse | ||
import io.ktor.client.* | ||
import io.ktor.client.call.* | ||
import io.ktor.client.engine.cio.* | ||
import io.ktor.client.plugins.contentnegotiation.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import io.ktor.serialization.kotlinx.json.* | ||
import kotlinx.serialization.json.Json | ||
import net.htmlparser.jericho.Source | ||
|
||
object Twitter { | ||
private const val baseURL = "https://publish.twitter.com/oembed" | ||
private val client = HttpClient(CIO) { | ||
install(ContentNegotiation) { | ||
json(Json { | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
}) | ||
} | ||
} | ||
|
||
suspend fun getTweet(screenName: String, tweetId: String): Tweet? { | ||
val tweetUrl = "https://twitter.com/$screenName/status/$tweetId" | ||
val response = client.get(baseURL) { | ||
parameter("url", tweetUrl) | ||
} | ||
|
||
return when (response.status) { | ||
HttpStatusCode.OK -> { | ||
val json: TwitterOEmbedResponse = response.body() | ||
Tweet( | ||
json.authorName, | ||
json.html, | ||
Source(json.html.replace("<a.*>(.*)</a>", "")) | ||
.getFirstElement("p") | ||
.renderer | ||
.setMaxLineLength(Integer.MAX_VALUE) | ||
.setNewLine(null) | ||
.toString() | ||
) | ||
} | ||
|
||
else -> null | ||
} | ||
} | ||
} |
Oops, something went wrong.