Skip to content

Commit 12960b3

Browse files
committed
配置文件增强,更新内置配置版本为v29
1 parent f47d6d6 commit 12960b3

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

app/src/main/assets/default_conf

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

app/src/main/java/me/teble/xposed/autodaily/task/filter/GroupTaskFilterChain.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import me.teble.xposed.autodaily.ui.errInfo
1515
import me.teble.xposed.autodaily.utils.LogUtil
1616
import me.teble.xposed.autodaily.utils.TimeUtil
1717
import java.net.SocketTimeoutException
18-
import java.util.*
18+
import java.util.Date
1919

2020
class GroupTaskFilterChain(
2121
val taskGroup: TaskGroup
@@ -58,7 +58,7 @@ class GroupTaskFilterChain(
5858
}
5959
try {
6060
XANotification.setContent("正在执行任务${task.id}")
61-
TaskUtil.execute(reqType, task, relayTaskMap, env.toMutableMap())
61+
TaskUtil.execute(reqType, task, relayTaskMap, env)
6262
} catch (e: SocketTimeoutException) {
6363
LogUtil.e(e, "执行任务${task.id}异常: ")
6464
} catch (e: Throwable) {

app/src/main/java/me/teble/xposed/autodaily/task/model/TaskModels.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ fun TaskCondition.test(env: MutableMap<String, Any>): Boolean {
142142
if (v2 == null) v2 = "null"
143143
LogUtil.d("test: $v1 $operator $v2")
144144
return when (operator) {
145-
"=" -> v1 == v2
146-
"!=" -> v1 != v2
145+
"=", "==" -> v1.toString() == v2.toString()
146+
"!=" -> v1.toString() != v2.toString()
147147
">" -> if (isNumber(v1 as String) and isNumber(v2 as String)) BigInteger(v1) > BigInteger(v2) else v1.toString() > v2.toString()
148148
"<" -> if (isNumber(v1 as String) and isNumber(v2 as String)) BigInteger(v1) < BigInteger(v2) else v1.toString() < v2.toString()
149149
">=" -> if (isNumber(v1 as String) and isNumber(v2 as String)) BigInteger(v1) >= BigInteger(v2) else v1.toString() >= v2.toString()

app/src/main/java/me/teble/xposed/autodaily/task/util/EnvFormatUtil.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ object EnvFormatUtil {
4949
val name = s.substring(start, end)
5050
LogUtil.d("name -> $name")
5151
this[index] = name
52-
values.add(getFormatArgValue(name, qDomain, env))
52+
val value = getFormatArgValue(name, qDomain, env)
53+
LogUtil.d("value -> $value")
54+
values.add(value)
5355
}
5456
}
5557
LogUtil.d("evalString -> $evalStr")
@@ -154,6 +156,7 @@ object EnvFormatUtil {
154156

155157
argFunc.startsWith("taskEnable(") -> {
156158
val taskName = argFunc.substring(11, argFunc.length - 1)
159+
LogUtil.d("taskEnable($taskName) -> ${Task(taskName).enable}")
157160
return Task(taskName).enable.toString()
158161
}
159162

@@ -169,14 +172,18 @@ object EnvFormatUtil {
169172
if (ReUtil.contains(FUN_REG, argField)) {
170173
return getFormatArgFunction(argField, qDomain, env)
171174
}
172-
val res = when (argField) {
175+
val splitIdx = argField.indexOf(":")
176+
val argName = if (splitIdx == -1) argField else argField.substring(0, splitIdx)
177+
val defaultValue = if (splitIdx == -1) null else argField.substring(splitIdx + 1)
178+
val res = when (argName) {
173179
"week_day_index" -> buildString { append((DateUtil.dayOfWeek(TimeUtil.getCNDate()) + 5) % 7) }
174180
"week_day" -> buildString { append((DateUtil.dayOfWeek(TimeUtil.getCNDate()) + 5) % 7 + 1) }
175181
"random" -> CalculationUtil.getRandom().toString()
176182
"microsecond" -> CalculationUtil.getMicrosecondTime().toString()
177183
"second" -> CalculationUtil.getSecondTime().toString()
178184
"uin" -> currentUin.toString()
179185
"qua" -> VersionUtil.qua
186+
"qVer" -> VersionUtil.qqVersionName
180187
"csrf_token" -> CalculationUtil.getCSRFToken(ticketManager.getSkey() ?: "")
181188
"skey" -> ticketManager.getSkey() ?: ""
182189
"bkn" -> {
@@ -221,8 +228,15 @@ object EnvFormatUtil {
221228
"mini_login_code" -> miniLoginManager.syncGetLoginCode(env["mini_app_id"] as String)
222229
?: throw RuntimeException("获取mini_login_code失败")
223230

224-
else -> env[argField] ?: throw RuntimeException("不存在的变量 $argField")
231+
else -> env[argName] ?: let {
232+
LogUtil.w("没有找到对应的参数: $argName")
233+
""
234+
}
235+
}
236+
return if (res is String && defaultValue != null) {
237+
res.ifEmpty { defaultValue }
238+
} else {
239+
res
225240
}
226-
return res
227241
}
228242
}

app/src/main/java/me/teble/xposed/autodaily/task/util/TaskUtil.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ object TaskUtil {
4848
}
4949
} ?: emptyList()
5050
generateEnv(task, env)
51-
if (task.conditions?.all { it.test(env) } == false) {
52-
LogUtil.i("任务条件不满足,跳过:${task.id}")
53-
if (task.cron != null && task.cron != "basic") {
54-
val now = TimeUtil.getCNDate()
55-
task.lastExecTime = now.format()
56-
val realCron = format(task.cron, null, env)
57-
val nextTime = CronPatternUtil.nextDateAfter(
58-
TimeZone.getTimeZone("GMT+8"),
59-
CronPattern(realCron),
60-
Date(TimeUtil.cnTimeMillis() + 1),
61-
true
62-
)!!
63-
task.nextShouldExecTime = Date(nextTime.time + TimeUtil.offsetTime).format()
64-
task.lastExecMsg = "不满足任务执行条件,跳过执行"
65-
}
66-
return true
67-
}
6851
val repeatNum = format(task.repeat, null, env).toInt()
6952
LogUtil.d("重复请求次数 -> $repeatNum")
7053
val currDateStr = TimeUtil.getCNDate().formatDate()
@@ -85,6 +68,23 @@ object TaskUtil {
8568
return false
8669
}
8770
}
71+
if (task.conditions?.all { it.test(env) } == false) {
72+
LogUtil.i("任务条件不满足,跳过:${task.id}")
73+
if (task.cron != null && task.cron != "basic") {
74+
val now = TimeUtil.getCNDate()
75+
task.lastExecTime = now.format()
76+
val realCron = format(task.cron, null, env)
77+
val nextTime = CronPatternUtil.nextDateAfter(
78+
TimeZone.getTimeZone("GMT+8"),
79+
CronPattern(realCron),
80+
Date(TimeUtil.cnTimeMillis() + 1),
81+
true
82+
)!!
83+
task.nextShouldExecTime = Date(nextTime.time + TimeUtil.offsetTime).format()
84+
task.lastExecMsg = "不满足任务执行条件,跳过执行"
85+
}
86+
return true
87+
}
8888
val taskReqUtil = ReqFactory.getReq(reqType)
8989
val requests = taskReqUtil.create(task, env)
9090
val startRepeatNum = status.reqCount / requests.size

0 commit comments

Comments
 (0)