diff options
author | Marko Zajc <marko@zajc.eu.org> | 2023-09-07 01:43:50 +0200 |
---|---|---|
committer | Marko Zajc <marko@zajc.eu.org> | 2023-09-07 01:43:50 +0200 |
commit | a21ea2a584f8e66873cb1312e177aab8d58cd74f (patch) | |
tree | fb8ab2b695747ba587a0ea888e015cbfc8a16aeb | |
parent | b6e5d5c979926316cbffdd42a90b566252383acf (diff) |
[module-utilities] Fix CalculatorCommand's handling of long results
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | module-utilities/src/main/java/libot/commands/CalculatorCommand.java | 40 |
2 files changed, 25 insertions, 16 deletions
@@ -13,3 +13,4 @@ | |||
13 | /.env | 13 | /.env |
14 | /changelog.txt | 14 | /changelog.txt |
15 | /stage | 15 | /stage |
16 | /qalculate-helper | ||
diff --git a/module-utilities/src/main/java/libot/commands/CalculatorCommand.java b/module-utilities/src/main/java/libot/commands/CalculatorCommand.java index a08a81f..84d8567 100644 --- a/module-utilities/src/main/java/libot/commands/CalculatorCommand.java +++ b/module-utilities/src/main/java/libot/commands/CalculatorCommand.java | |||
@@ -69,14 +69,14 @@ public class CalculatorCommand extends Command { | |||
69 | private static final String MODE_EXACT = "exact"; | 69 | private static final String MODE_EXACT = "exact"; |
70 | private static final String MODE_NORMAL = ""; | 70 | private static final String MODE_NORMAL = ""; |
71 | 71 | ||
72 | private static final byte SEPARATOR = 0; | 72 | private static final byte SEPARATOR = 0x00; |
73 | 73 | ||
74 | private static final byte TYPE_MESSAGE = 1; | 74 | private static final byte TYPE_MESSAGE = 0x01; |
75 | private static final byte TYPE_RESULT = 2; | 75 | private static final byte TYPE_RESULT = 0x02; |
76 | 76 | ||
77 | private static final byte LEVEL_INFO = 1; | 77 | private static final byte LEVEL_INFO = 0x01; |
78 | private static final byte LEVEL_WARN = 2; | 78 | private static final byte LEVEL_WARN = 0x02; |
79 | private static final byte LEVEL_ERROR = 3; | 79 | private static final byte LEVEL_ERROR = 0x03; |
80 | 80 | ||
81 | private static final byte RESULT_APPROXIMATION = 2; | 81 | private static final byte RESULT_APPROXIMATION = 2; |
82 | 82 | ||
@@ -124,12 +124,17 @@ public class CalculatorCommand extends Command { | |||
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | if (m.isEmpty() && resultFile != null) | 127 | if (!m.isEmpty()) { |
128 | c.reply("No output", DISABLED); | 128 | if (resultFile != null) |
129 | else if (resultFile == null) | 129 | c.replyraw(m).addFile(resultFile, mode).queue(); |
130 | c.reply(m); | 130 | else |
131 | else | 131 | c.reply(m); |
132 | c.replyraw(m).addFile(resultFile, "result.txt").submit(); | 132 | } else { |
133 | if (resultFile != null) | ||
134 | c.replyFile(resultFile, "result.txt"); | ||
135 | else | ||
136 | c.reply("No output", DISABLED); | ||
137 | } | ||
133 | } | 138 | } |
134 | 139 | ||
135 | @Nullable | 140 | @Nullable |
@@ -204,9 +209,12 @@ public class CalculatorCommand extends Command { | |||
204 | 209 | ||
205 | var b = new ProcessBuilder(command); | 210 | var b = new ProcessBuilder(command); |
206 | b.environment().clear(); | 211 | b.environment().clear(); |
207 | b.environment().put("HOME", getenv(ENV_QALCULATE_HOME)); | 212 | if (getenv(ENV_QALCULATE_HOME) != null) { |
208 | b.environment().put("ENV", getenv(ENV_QALCULATE_HOME) + "/.profile"); | 213 | b.environment().put("HOME", getenv(ENV_QALCULATE_HOME)); |
209 | b.directory(DATA_HOME.toFile()); | 214 | b.environment().put("ENV", getenv(ENV_QALCULATE_HOME) + "/.profile"); |
215 | } | ||
216 | if (DATA_HOME != null) | ||
217 | b.directory(DATA_HOME.toFile()); | ||
210 | return b.start(); | 218 | return b.start(); |
211 | } | 219 | } |
212 | 220 | ||
@@ -259,7 +267,7 @@ public class CalculatorCommand extends Command { | |||
259 | 267 | ||
260 | @Override | 268 | @Override |
261 | public String[] getAliases() { | 269 | public String[] getAliases() { |
262 | return array("calc", "c", "calculate"); | 270 | return array("calc", "c", "calculate", "qalc"); |
263 | } | 271 | } |
264 | 272 | ||
265 | @Override | 273 | @Override |