Skip to content

Commit

Permalink
バージョン番号を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Jul 19, 2023
1 parent 3256add commit c7db371
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 91 deletions.
65 changes: 0 additions & 65 deletions .idea/dataSources/648c6ef7-2bba-4e14-b21f-f6619a5657a5.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>dev.cosgy</groupId>
<artifactId>TextToSpeak</artifactId>
<version>0.4.0-beta.6</version>
<version>0.4.0</version>
<packaging>jar</packaging>

<repositories>
Expand Down
31 changes: 23 additions & 8 deletions src/main/java/dev/cosgy/textToSpeak/Listener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,29 @@ class Listener(private val bot: Bot) : ListenerAdapter() {
val owner = bot.jda?.getUserById(bot.config.ownerId)
if (owner != null) {
val currentVersion = OtherUtil.currentVersion
val latestVersion = OtherUtil.latestVersion
if (latestVersion != null && !currentVersion.equals(
latestVersion,
ignoreCase = true
) && TextToSpeak.CHECK_UPDATE
) {
val msg = String.format(OtherUtil.NEW_VERSION_AVAILABLE, currentVersion, latestVersion)
owner.openPrivateChannel().queue { pc: PrivateChannel -> pc.sendMessage(msg).queue() }
// 現在のバージョンがリリース版かを確認
if (!OtherUtil.isBetaVersion(currentVersion)) {
// リリースバージョンの場合
val latestVersion = OtherUtil.latestVersion
if (latestVersion != null && !currentVersion.equals(
latestVersion,
ignoreCase = true
) && TextToSpeak.CHECK_UPDATE
) {
val msg = String.format(OtherUtil.NEW_VERSION_AVAILABLE, currentVersion, latestVersion)
owner.openPrivateChannel().queue { pc: PrivateChannel -> pc.sendMessage(msg).queue() }
}
}else{
// ベータバージョンの場合
val latestBeta = OtherUtil.latestBetaVersion
if(latestBeta != null && OtherUtil.compareVersions(currentVersion, latestBeta) != 0){
val msg = String.format(
OtherUtil.NEW_BETA_VERSION_AVAILABLE, currentVersion,
OtherUtil.latestBetaVersion,
OtherUtil.latestBetaVersion
)
owner.openPrivateChannel().queue { pc: PrivateChannel -> pc.sendMessage(msg).queue() }
}
}
}
}, 0, 24, TimeUnit.HOURS)
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/dev/cosgy/textToSpeak/utils/OtherUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import java.nio.file.Paths
import java.util.*

object OtherUtil {
//TODO: ベータバージョンよりリリースバージョンの方が新しいバージョンだった場合はNEW_VERSION_AVAILABLEのメッセージは出す。
const val NEW_VERSION_AVAILABLE = ("利用可能な新しいバージョンがあります!\n"
+ "現在のバージョン: %s\n"
+ "最新のバージョン: %s\n\n"
Expand Down Expand Up @@ -138,14 +139,16 @@ object OtherUtil {
}
} else {
val latestBeta = latestBetaVersion
if (latestBeta != null && compareVersions(version, latestBeta) == 0) {
prompt.alert(Prompt.Level.INFO, "Beta Version", "最新のベータバージョンを使用中です。")
} else {
prompt.alert(
Prompt.Level.WARNING,
"Beta Version",
String.format(NEW_BETA_VERSION_AVAILABLE, version, latestBetaVersion, latestBetaVersion)
)
if(latestBeta != null) {
if (compareVersions(version, latestBeta) == 0) {
prompt.alert(Prompt.Level.INFO, "Beta Version", "最新のベータバージョンを使用中です。")
} else {
prompt.alert(
Prompt.Level.WARNING,
"Beta Version",
String.format(NEW_BETA_VERSION_AVAILABLE, version, latestBetaVersion, latestBetaVersion)
)
}
}
}

Expand Down Expand Up @@ -185,7 +188,7 @@ object OtherUtil {
return null
}

private val latestBetaVersion: String?
val latestBetaVersion: String?
get() {
try {
val client = OkHttpClient()
Expand Down Expand Up @@ -218,13 +221,13 @@ object OtherUtil {
return null
}

private fun isBetaVersion(version: String): Boolean {
fun isBetaVersion(version: String): Boolean {
val versionParts = version.split("-")
return versionParts.lastOrNull()?.startsWith("beta") ?: false
}


private fun compareVersions(version1: String, version2: String): Int {
fun compareVersions(version1: String, version2: String): Int {
val parts1 = version1.split("[.-]".toRegex()).toTypedArray()
val parts2 = version2.split("[.-]".toRegex()).toTypedArray()
val length = maxOf(parts1.size, parts2.size)
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
</encoder>
</appender>

<!--<root level="INFO">
<root level="INFO">
<appender-ref ref="Simple"/>
<appender-ref ref="File"/>
</root>-->
<root level="DEBUG">
</root>
<!--<root level="DEBUG">
<appender-ref ref="Simple"/>
<appender-ref ref="File"/>
</root>
</root>-->

<!--<root level="TRACE">
<appender-ref ref="Simple"/>
Expand Down

0 comments on commit c7db371

Please sign in to comment.