Skip to content

Commit

Permalink
feat: add config for timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
Samarium150 committed Apr 16, 2022
1 parent 098a8a0 commit fc85487
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "io.github.samarium150"
version = "1.3.0"
version = "1.4.0"

repositories {
maven("https://maven.aliyun.com/repository/public")
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/MiraiConsoleLoafersCalendar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object MiraiConsoleLoafersCalendar : KotlinPlugin(
JvmPluginDescription(
id = "io.github.samarium150.mirai.plugin.mirai-console-loafers-calendar",
name = "Loafers' Calender",
version = "1.3.0",
version = "1.4.0",
) {
author("Samarium")
}
Expand All @@ -47,15 +47,15 @@ object MiraiConsoleLoafersCalendar : KotlinPlugin(
internal val client = HttpClient()
private val scheduler = getScheduler()

private fun setupQuartz(schedule: String) {
private fun setupQuartz(schedule: String, timezone: String) {
val jobDetail = Subscription.init()
val trigger = TriggerBuilder.newTrigger()
.withIdentity("subscription", "mirai-console-loafers-calendar")
.startNow()
.withSchedule(
CronScheduleBuilder
.cronSchedule(schedule)
.inTimeZone(TimeZone.getTimeZone("GTM+08:00"))
.inTimeZone(TimeZone.getTimeZone(timezone))
)
.forJob(jobDetail)
.build()
Expand All @@ -74,7 +74,7 @@ object MiraiConsoleLoafersCalendar : KotlinPlugin(
Unsubscribe.register()
Clean.register()

setupQuartz(PluginConfig.cron)
setupQuartz(PluginConfig.cron, PluginConfig.timezone)
scheduler.start()

logger.info("Plugin loaded")
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/config/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ object PluginConfig : AutoSavePluginConfig("PluginConfig") {

@ValueDescription("Cron表达式")
val cron: String by value("0 0 12 ? * MON-SAT *")

@ValueDescription("执行Cron表达式的时区")
val timezone: String by value("GMT+08:00")
}

0 comments on commit fc85487

Please sign in to comment.