tok) {
List l = new ArrayList();
for (int i = 0; i < l(tok); i++) {
String t = tok.get(i);
if (odd(i) && eq(t, "{")) {
int j = findEndOfCurlyBracketPart(tok, i);
l.add(joinSubList(tok, i, j));
i = j - 1;
} else
l.add(t);
}
return l;
}
public static boolean startsWithAndEndsWith(String s, String prefix, String suffix) {
return startsWith(s, prefix) && endsWith(s, suffix);
}
public static boolean containsNewLines(String s) {
return containsNewLine(s);
}
public static String jlabel_textAsHTML_center(String text) {
return "" + replace(htmlencode(text), "\n", "
") + "
";
}
public static A popLast(List l) {
return liftLast(l);
}
public static List popLast(int n, List l) {
return liftLast(n, l);
}
public static List dropFirstAndLast(int n, List l) {
return new ArrayList(subList(l, n, l(l) - n));
}
public static List dropFirstAndLast(List l) {
return dropFirstAndLast(1, l);
}
public static String dropFirstAndLast(String s) {
return substring(s, 1, l(s) - 1);
}
public static boolean odd(int i) {
return (i & 1) != 0;
}
public static boolean odd(long i) {
return (i & 1) != 0;
}
public static boolean odd(BigInteger i) {
return odd(toInt(i));
}
public static int findEndOfCurlyBracketPart(List cnc, int i) {
int j = i + 2, level = 1;
while (j < cnc.size()) {
if (eq(cnc.get(j), "{"))
++level;
else if (eq(cnc.get(j), "}"))
--level;
if (level == 0)
return j + 1;
++j;
}
return cnc.size();
}
public static String htmlencode(Object o) {
return htmlencode(str(o));
}
public static String htmlencode(String s) {
if (s == null)
return "";
StringBuilder out = new StringBuilder(Math.max(16, s.length()));
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
int cp = s.codePointAt(i);
out.append("");
out.append(intToHex_flexLength(cp));
out.append(';');
i += Character.charCount(cp) - 1;
} else
out.append(c);
}
return out.toString();
}
public static A liftLast(List l) {
if (empty(l))
return null;
int i = l(l) - 1;
A a = l.get(i);
l.remove(i);
return a;
}
public static List liftLast(int n, List l) {
int i = l(l) - n;
List part = cloneSubList(l, i);
removeSubList(l, i);
return part;
}
public static int toInt(Object o) {
if (o == null)
return 0;
if (o instanceof Number)
return ((Number) o).intValue();
if (o instanceof String)
return parseInt((String) o);
throw fail("woot not int: " + getClassName(o));
}
public static int toInt(long l) {
if (l != (int) l)
throw fail("Too large for int: " + l);
return (int) l;
}
public static String intToHex_flexLength(int i) {
return Integer.toHexString(i);
}
public static List cloneSubList(List l, int startIndex, int endIndex) {
return newSubList(l, startIndex, endIndex);
}
public static List cloneSubList(List l, int startIndex) {
return newSubList(l, startIndex);
}
public static int parseInt(String s) {
return empty(s) ? 0 : Integer.parseInt(s);
}
public static int parseInt(char c) {
return Integer.parseInt(str(c));
}
public static List newSubList(List l, int startIndex, int endIndex) {
return cloneList(subList(l, startIndex, endIndex));
}
public static List newSubList(List l, int startIndex) {
return cloneList(subList(l, startIndex));
}
public static class MRUCache extends LinkedHashMap {
public int maxSize = 10;
public MRUCache() {
}
public MRUCache(int maxSize) {
this.maxSize = maxSize;
}
public boolean removeEldestEntry(Map.Entry eldest) {
return size() > maxSize;
}
public Object _serialize() {
return ll(maxSize, cloneLinkedHashMap(this));
}
public static MRUCache _deserialize(List l) {
MRUCache m = new MRUCache();
m.maxSize = (int) first(l);
m.putAll((LinkedHashMap) second(l));
return m;
}
}
public abstract static class CloseableIterableIterator extends IterableIterator implements AutoCloseable {
public void close() throws Exception {
}
}
public abstract static class VF2 {
public abstract void get(A a, B b);
}
public static interface IF2 {
public C get(A a, B b);
}
public static class Var implements IVar {
public Var() {
}
public Var(A v) {
this.v = v;
}
public A v;
public synchronized void set(A a) {
if (v != a) {
v = a;
notifyAll();
}
}
public synchronized A get() {
return v;
}
public synchronized boolean has() {
return v != null;
}
public synchronized void clear() {
v = null;
}
public String toString() {
return str(get());
}
}
public static interface IVF1 {
public void get(A a);
}
public abstract static class TokCondition {
public abstract boolean get(List tok, int i);
}
public abstract static class LiveValue {
public abstract Class getType();
public abstract A get();
public abstract void onChange(Runnable l);
public abstract void removeOnChangeListener(Runnable l);
public void onChangeAndNow(Runnable l) {
onChange(l);
callF(l);
}
}
public abstract static class IterableIterator implements Iterator, Iterable {
public Iterator iterator() {
return this;
}
public void remove() {
unsupportedOperation();
}
}
public static interface IVar {
public void set(A a);
public A get();
public boolean has();
public void clear();
}
public static java.awt.Color colorFromHex(String hex) {
return awtColor(hex);
}
public static void vm_cleanPrints() {
print_preprocess = new F1() {
public String get(String x) {
try {
return vm_cleanForPrint(x);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "vm_cleanForPrint(x)";
}
};
}
public static boolean logModuleOutput_installed = false;
public static void logModuleOutput() {
if (logModuleOutput_installed)
return;
logModuleOutput_installed = true;
final File logFile = getProgramFile("output.txt");
final LineBuffer buf = new LineBuffer(new VF1() {
public void get(String line) {
try {
appendToTextFile(logFile, "[" + localDateWithMilliseconds() + "] " + line + "\n");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "appendToTextFile(logFile, \"[\" + localDateWithMilliseconds() + \"] \" + line + \"...";
}
});
print_forAllThreads(new VF1() {
public void get(String s) {
try {
buf.append(s);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "buf.append(s);";
}
});
}
public static JDA discordBot(final VF1 onMessage) {
return discordBot(new ListenerAdapter() {
@Override
public void onMessageReceived(MessageReceivedEvent e) {
if (e.getAuthor().isBot()) {
print(" Msg from bot, skipping");
return;
}
pcallF(onMessage, e);
}
});
}
public static JDA discordBot(ListenerAdapter listener, Object... __) {
try {
JDABuilder builder = new JDABuilder(AccountType.BOT);
String token = stringPar("token", __);
if (empty(token)) {
File tokenFile = javaxSecretDir("discord-bot-token");
token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)));
}
builder.setToken(token);
builder.addEventListener(listener);
JDA jda = builder.build();
jda.awaitReady();
print("Started Discord bot (token: " + shorten(token, 7) + ")");
return jda;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Object dm_discord_lineForMsgID_unimported(long msgID) {
return dm_call(dm_gazelle_linesCRUD(), "lineForID", msgID);
}
public static Object[] litmapparams(Object... l) {
return new Object[] { litmap(l) };
}
public static DynModule dm_me() {
return dm_current_mandatory();
}
public static long rcall_long(String method, Object o, Object... args) {
return toLong(rcall(method, o, args));
}
public static Object rcall(String method, Object o, Object... args) {
return call_withVarargs(o, method, args);
}
public static long discord_guildIDFromEvent_gen(Object event) {
return rcall_long("getIdLong", rcall("getGuild", event));
}
public static AutoCloseable dm_registerAs(String... msgs) {
F0 f = new F0() {
public String get() {
try {
return dm_moduleID();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret dm_moduleID();";
}
};
return combineAutoCloseables(map(msgs, msg -> dm_vmBus_answerToMessage(msg, f)));
}
public static AutoCloseable dm_vmBus_answerToMessage(String msg, final IF0 f) {
final DynModule m = dm_current_mandatory();
return dm_ownResource(vmBus_addListener_basic(msg, new F2() {
public Object get(String _msg, Object arg) {
try {
AutoCloseable __946 = m.enter();
try {
return callF(f);
} finally {
_close(__946);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp m.enter();\r\n ret callF(f);";
}
}));
}
public static AutoCloseable dm_vmBus_answerToMessage(String msg, final F0 f) {
final DynModule m = dm_current_mandatory();
return dm_ownResource(vmBus_addListener_basic(msg, new F2() {
public Object get(String _msg, Object arg) {
try {
AutoCloseable __947 = m.enter();
try {
return callF(f);
} finally {
_close(__947);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp m.enter();\r\n ret callF(f);";
}
}));
}
public static AutoCloseable dm_vmBus_answerToMessage(String msg, final F1 f) {
final DynModule m = dm_current_mandatory();
return dm_ownResource(vmBus_addListener_basic(msg, new F2() {
public Object get(String _msg, Object arg) {
try {
AutoCloseable __948 = m.enter();
try {
return callF(f, arg);
} finally {
_close(__948);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp m.enter();\r\n ret callF(f, arg);";
}
}));
}
public static String jda_selfUserName(JDA jda) {
return jda_selfUser(jda).getName();
}
public static long jda_selfUserID(JDA jda) {
return jda.getSelfUser().getIdLong();
}
public static String dm_gazelle_linesCRUD() {
return dm_require("#1021628/GLines");
}
public static Object[] litobjectarray(Object... l) {
return litObjectArray(l);
}
public static String getChannel() {
return getChannelName();
}
public static String shortenForDiscord(String msg) {
return shorten(msg, 2000);
}
public static String gazelle_postedLinesCRUD() {
return dm_require("#1022603/GPostedLines");
}
public static long dm_discord_channelID(String name) {
return (long) dm_call(dm_gazelle_linesCRUD(), "getChannelID", name);
}
public static Object dm_pcall(Object moduleOrID, String method, Object... args) {
try {
return dm_call(moduleOrID, method, args);
} catch (Throwable __e) {
return null;
}
}
public static String absoluteURL(String url) {
return isAbsoluteURL(url) ? url : "http://" + url;
}
public static String dm_discord_startKeepAliveModule(Object mod) {
String discordToken = (String) (dm_get(mod, "discordToken"));
return dm_showNewModuleWithParams("#1024196/DiscordKeepAlive", "discordToken", discordToken);
}
public static JPanel centerAndSouthWithMargins(Component c, Component s) {
return applyDefaultMargin(centerAndSouth(c, withTopMargin(s)));
}
public static JPanel jrightalignedline(Component... components) {
return jrightAlignedLine(components);
}
public static JPanel jrightalignedline(List components) {
return jrightAlignedLine(components);
}
public static JCheckBox dm_fieldCheckBox(String field) {
return dm_fieldCheckBox(humanizeFormLabel(field), field);
}
public static JCheckBox dm_fieldCheckBox(String text, String field) {
if (isIdentifier(text) && !isIdentifier(field)) {
String temp = field;
field = text;
text = temp;
}
return jLiveValueCheckBox(text, dm_fieldLiveValue(field));
}
public static LinkedHashMap cloneLinkedHashMap(Map map) {
return map == null ? new LinkedHashMap() : new LinkedHashMap(map);
}
public static A onChange(A spinner, Object r) {
{
swing(new Runnable() {
public void run() {
try {
spinner.addChangeListener(changeListener(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "spinner.addChangeListener(changeListener(r));";
}
});
}
return spinner;
}
public static A onChange(A b, Object r) {
{
swing(new Runnable() {
public void run() {
try {
b.addItemListener(itemListener(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "b.addItemListener(itemListener(r));";
}
});
}
return b;
}
public static void onChange(JTextComponent tc, Object r) {
onUpdate(tc, r);
}
public static A onChange(A slider, final Object r) {
{
swing(new Runnable() {
public void run() {
try {
slider.addChangeListener(changeListener(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "slider.addChangeListener(changeListener(r));";
}
});
}
return slider;
}
public static JComboBox onChange(Object r, JComboBox cb) {
return onChange(cb, r);
}
public static JComboBox onChange(JComboBox cb, final Object r) {
if (isEditableComboBox(cb))
onChange(textFieldFromComboBox(cb), r);
else
onSelectedItem(cb, new VF1() {
public void get(String s) {
try {
callF(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(r)";
}
});
return cb;
}
public static UnsupportedOperationException unsupportedOperation() {
throw new UnsupportedOperationException();
}
public static java.awt.Color awtColor(String hex) {
byte[] b = bytesFromHex(dropPrefix("#", hex));
return new Color(ubyteToInt(b[0]), ubyteToInt(b[1]), ubyteToInt(b[2]));
}
public static String vm_cleanForPrint(Object o) {
String s = str(o);
return or((String) vmBus_query("cleanForPrint", s), s);
}
public static File getProgramFile(String progID, String fileName) {
if (new File(fileName).isAbsolute())
return new File(fileName);
return new File(getProgramDir(progID), fileName);
}
public static File getProgramFile(String fileName) {
return getProgramFile(getProgramID(), fileName);
}
public static void appendToTextFile(File file, String s) {
appendToFile(file, s);
}
public static void appendToTextFile(String file, String s) {
appendToTextFile(programFile(file), s);
}
public static String localDateWithMilliseconds(Date time) {
return localDateWithMilliseconds(time.getTime());
}
public static String localDateWithMilliseconds(long time) {
SimpleDateFormat format = simpleDateFormat_local("yyyy/MM/dd HH:mm:ss''SSSS");
return format.format(time);
}
public static String localDateWithMilliseconds() {
return localDateWithMilliseconds(now());
}
public static void print_forAllThreads(Object f) {
assertNull("todo", print_allThreads);
print_allThreads = f;
}
public static String stringPar(Object[] params, String name) {
return stringOptPar(params, name);
}
public static String stringPar(String name, Object[] params) {
return stringOptPar(params, name);
}
public static String stringPar(String name, Map params) {
return (String) optPar(name, params);
}
public static String stringPar(String name, Object[] params, String defaultValue) {
return optPar(name, params, defaultValue);
}
public static File javaxSecretDir_dir;
public static File javaxSecretDir() {
return javaxSecretDir_dir != null ? javaxSecretDir_dir : new File(userHome(), "JavaX-Secret");
}
public static File javaxSecretDir(String sub) {
return newFile(javaxSecretDir(), sub);
}
public static A assertNempty(A a) {
return assertNempty("empty", a);
}
public static A assertNempty(String msg, A a) {
if (empty(a))
throw fail(msg + ": " + a);
return a;
}
public static String loadTextFile(String fileName) {
return loadTextFile(fileName, null);
}
public static String loadTextFile(File f, String defaultContents) {
try {
checkFileNotTooBigToRead(f);
if (f == null || !f.exists())
return defaultContents;
FileInputStream fileInputStream = new FileInputStream(f);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
return loadTextFile(inputStreamReader);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String loadTextFile(File fileName) {
return loadTextFile(fileName, null);
}
public static String loadTextFile(String fileName, String defaultContents) {
return fileName == null ? defaultContents : loadTextFile(newFile(fileName), defaultContents);
}
public static String loadTextFile(Reader reader) throws IOException {
StringBuilder builder = new StringBuilder();
try {
char[] buffer = new char[1024];
int n;
while (-1 != (n = reader.read(buffer))) builder.append(buffer, 0, n);
} finally {
reader.close();
}
return str(builder);
}
public static int shorten_default = 100;
public static String shorten(String s) {
return shorten(s, shorten_default);
}
public static String shorten(String s, int max) {
return shorten(s, max, "...");
}
public static String shorten(String s, int max, String shortener) {
if (s == null)
return "";
if (max < 0)
return s;
return s.length() <= max ? s : substring(s, 0, min(s.length(), max - l(shortener))) + shortener;
}
public static String shorten(int max, String s) {
return shorten(s, max);
}
public static String dm_moduleID(Object module) {
return strOrNull(getOpt(dm_getStem(module), "id"));
}
public static String dm_moduleID() {
return dm_moduleID(dm_current_mandatory_generic());
}
public static AutoCloseable combineAutoCloseables(final AutoCloseable a, final AutoCloseable b) {
return a == null ? b : b == null ? a : new AutoCloseable() {
public String toString() {
return "a.close(); b.close();";
}
public void close() throws Exception {
a.close();
b.close();
}
};
}
public static AutoCloseable combineAutoCloseables(AutoCloseable a, AutoCloseable b, AutoCloseable c, AutoCloseable... more) {
return combineAutoCloseables(concatLists(ll(a, b, c), asList(more)));
}
public static AutoCloseable combineAutoCloseables(Iterable l) {
return foldl(new F2() {
public AutoCloseable get(AutoCloseable a, AutoCloseable b) {
try {
return combineAutoCloseables(a, b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "combineAutoCloseables(a,b)";
}
}, null, l);
}
public static AutoCloseable vmBus_addListener_basic(String msg, Object listener) {
Map map = vm_busListenersByMessage_live();
synchronized (map) {
Set listeners = map.get(msg);
if (listeners == null)
map.put(msg, listeners = syncIdentityHashSet());
return tempAdd(listeners, listener);
}
}
public static SelfUser jda_selfUser(JDA jda) {
return jda.getSelfUser();
}
public static String dm_require(String moduleLibID) {
return dm_makeModule(moduleLibID);
}
public static Object[] litObjectArray(Object... l) {
return l;
}
public static String getChannelName() {
return (String) callOpt(getMainBot(), "getChannelName");
}
public static boolean isAbsoluteURL(String s) {
return contains(s, "://");
}
public static Object dm_get(Object moduleOrID, String field) {
return get(dm_getModule(moduleOrID), field);
}
public static Object dm_get(String field, long moduleID) {
return dm_get(moduleID, field);
}
public static A applyDefaultMargin(final A c) {
if (c != null) {
swing(new Runnable() {
public void run() {
try {
c.setBorder(BorderFactory.createEmptyBorder(withMargin_defaultWidth, withMargin_defaultWidth, withMargin_defaultWidth, withMargin_defaultWidth));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.setBorder(BorderFactory.createEmptyBorder(withMargin_defaultWidth, withMarg...";
}
});
}
return c;
}
public static JPanel centerAndSouth(final Component c, final Component s) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, wrap(c));
if (s != null)
panel.add(BorderLayout.SOUTH, wrap(s));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new BorderLayout);\r\n panel.add(BorderLayout.CENT...";
}
});
}
public static int withTopMargin_defaultWidth = 6;
public static JPanel withTopMargin(Component c) {
return withTopMargin(withTopMargin_defaultWidth, c);
}
public static JPanel withTopMargin(final int w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(w, 0, 0, 0));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
public static JPanel jrightAlignedLine(final Component... components) {
return swing(new F0