import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import static x30_pkg.x30_util.DynamicObject;
import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.sharding.*;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.hooks.*;
import net.dv8tion.jda.api.events.message.*;
import net.dv8tion.jda.api.events.message.react.*;
import static net.dv8tion.jda.api.requests.GatewayIntent.*;
class main {
//lib 1400315 // JDA 4.0 with opus
// JDA 4.2 with opus
//static LS _stickyLibs_discordBot = ll(#1400315); // can cause loader constraint violations
static ShardManager shardedDiscordBot40(ListenerAdapter listener, Object... __) { try {
String token = stringPar("token", __);
if (empty(token)) {
File tokenFile = javaxSecretDir("discord-bot-token");
token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)));
}
print("Making DefaultShardManagerBuilder");
DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(token,
GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES);
print("Have DefaultShardManagerBuilder");
if (boolPar("membersIntent", __))
builder.enableIntents(GUILD_MEMBERS);
builder.addEventListeners(listener);
print("Building JDA with token " + shorten(10, token));
ShardManager jda = builder.build();
print("Got JDA: " + jda);
//jda.awaitSatus(JDA.Status.CONNECTED);
//jda.awaitReady();
//print("Started sharded Discord bot (token: " + shorten(token, 7) + ")");
return jda;
} catch (Exception __e) { throw rethrow(__e); } }
static String stringPar(Object[] params, String name) {
return stringOptPar(params, name);
}
static String stringPar(String name, Object[] params) {
return stringOptPar(params, name);
}
static String stringPar(String name, Map params) {
return (String) optPar(name, params);
}
static String stringPar(String name, Object[] params, String defaultValue) {
return optPar(name, params, defaultValue);
}
static boolean empty(Collection c) { return c == null || c.isEmpty(); }
static boolean empty(Iterable c) { return c == null || !c.iterator().hasNext(); }
static boolean empty(CharSequence s) { return s == null || s.length() == 0; }
static boolean empty(Map map) { return map == null || map.isEmpty(); }
static boolean empty(Object[] o) { return o == null || o.length == 0; }
static boolean empty(BitSet bs) { return bs == null || bs.isEmpty(); }
static boolean empty(Object o) {
if (o instanceof Collection) return empty((Collection) o);
if (o instanceof String) return empty((String) o);
if (o instanceof Map) return empty((Map) o);
if (o instanceof Object[]) return empty((Object[]) o);
if (o instanceof byte[]) return empty((byte[]) o);
if (o == null) return true;
throw fail("unknown type for 'empty': " + getType(o));
}
static boolean empty(Iterator i) { return i == null || !i.hasNext(); }
static boolean empty(double[] a) { return a == null || a.length == 0; }
static boolean empty(float[] a) { return a == null || a.length == 0; }
static boolean empty(int[] a) { return a == null || a.length == 0; }
static boolean empty(long[] a) { return a == null || a.length == 0; }
static boolean empty(byte[] a) { return a == null || a.length == 0; }
static boolean empty(short[] a) { return a == null || a.length == 0; }
static boolean empty(MultiMap mm) { return mm == null || mm.isEmpty(); }
static boolean empty(File f) { return getFileSize(f) == 0; }
static File javaxSecretDir_dir; // can be set to work on different base dir
static File javaxSecretDir() {
return javaxSecretDir_dir != null ? javaxSecretDir_dir : new File(userHome(), "JavaX-Secret");
}
static File javaxSecretDir(String sub) {
return newFile(javaxSecretDir(), sub);
}
static A assertNempty(A a) {
return assertNempty("empty", a);
}
static A assertNempty(String msg, A a) {
if (empty(a)) throw fail(msg + ": " + a);
return a;
}
static String trim(String s) { return s == null ? null : s.trim(); }
static String trim(StringBuilder buf) { return buf.toString().trim(); }
static String trim(StringBuffer buf) { return buf.toString().trim(); }
static String loadTextFile(String fileName) {
return loadTextFile(fileName, null);
}
static String loadTextFile(File f, String defaultContents) { return loadTextFile(f, defaultContents, "UTF-8"); }
static String loadTextFile(File f, String defaultContents, String encoding) { try {
checkFileNotTooBigToRead(f);
if (f == null || !f.exists()) return defaultContents;
FileInputStream fileInputStream = new FileInputStream(f);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, encoding);
return loadTextFile(inputStreamReader);
} catch (Exception __e) { throw rethrow(__e); } }
public static String loadTextFile(File fileName) {
return loadTextFile(fileName, null);
}
static String loadTextFile(String fileName, String defaultContents) {
return fileName == null ? defaultContents : loadTextFile(newFile(fileName), defaultContents);
}
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);
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal