Skip to content

Commit

Permalink
better formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Nov 2, 2023
1 parent 077809f commit f5eceea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
22 changes: 20 additions & 2 deletions src/main/kotlin/moe/nikky/twitch/TwitchApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import moe.nikky.debugF
import moe.nikky.errorF
import moe.nikky.infoF
import moe.nikky.traceF
import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -400,8 +402,24 @@ data class TwitchVideoData(
val viewCount: UInt,
val language: String,
val type: String,
val duration: String,
)
@SerialName("duration")
val durationString: String,
) {
val duration: Duration get() {
var input = durationString
val hours = input
.substringBefore('h')
.toIntOrNull() ?: 0
input = input.substringAfter('h')
val minutes = input
.substringBefore('m')
.toIntOrNull() ?: 0
val seconds = input
.substringBefore('s')
.toIntOrNull() ?: 0
return hours.hours + minutes.minutes + seconds.seconds
}
}

@Serializable
data class TwitchGameData(
Expand Down
15 changes: 9 additions & 6 deletions src/main/kotlin/moe/nikky/twitch/TwitchExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.storage.StorageType
import com.kotlindiscord.kord.extensions.storage.StorageUnit
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.time.TimestampType.RelativeTime
import com.kotlindiscord.kord.extensions.utils.getJumpUrl
import com.kotlindiscord.kord.extensions.utils.isPublished
import com.kotlindiscord.kord.extensions.utils.scheduling.Scheduler
Expand Down Expand Up @@ -887,16 +887,19 @@ class TwitchExtension() : Extension(), Klogging {
}
val twitchUrl = "[twitch.tv/${userData.displayName}](https://twitch.tv/${userData.login})"
val message = if (vod != null) {
val timestamp = RelativeTime.format(vod.createdAt.epochSeconds)
val cleanedVodTitle = vod.title
.replace("\\|\\|+".toRegex(), "|")
val vodUrl = "[${cleanedVodTitle}](${vod.url})"
"""
$twitchUrl
> last VOD: [${vod.title}](${vod.url})
> **${channelInfo.gameName}**
$twitchUrl streamed **${channelInfo.gameName}**
> $vodUrl
$timestamp for `${vod.duration}`
""".trimIndent()
} else {
"""
$twitchUrl
$twitchUrl streamed **${channelInfo.gameName}**
> ${channelInfo.title}
> **${channelInfo.gameName}**
""".trimIndent()
}
val messageId = oldMessage?.let {
Expand Down

0 comments on commit f5eceea

Please sign in to comment.