mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-11-29 13:45:38 -05:00
Night of Nights build: 5314
This commit is contained in:
@@ -15,3 +15,9 @@ src/main/kotlin
|
||||
|
||||
# proxies
|
||||
proxies.txt
|
||||
|
||||
# ignore the config
|
||||
config.yaml
|
||||
|
||||
# ignore chat attestation
|
||||
chatattestation
|
||||
|
||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="code style" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default copy" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -46,6 +46,7 @@ dependencies {
|
||||
implementation("com.github.luben:zstd-jni:1.5.6-9")
|
||||
implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.2")
|
||||
implementation("com.google.guava:guava:33.6.0-jre")
|
||||
implementation("net.dv8tion:JDA:6.7.0")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
|
||||
+33
-4
@@ -1,19 +1,48 @@
|
||||
<code_scheme name="Default" version="173">
|
||||
<code_scheme name="Default copy" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="DO_NOT_WRAP_AFTER_SINGLE_ANNOTATION" value="true" />
|
||||
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
|
||||
<option name="ENUM_FIELD_ANNOTATION_WRAP" value="5" />
|
||||
<option name="NEW_LINE_AFTER_LPAREN_IN_ANNOTATION" value="true" />
|
||||
<option name="RPAREN_ON_NEW_LINE_IN_ANNOTATION" value="true" />
|
||||
<option name="RECORD_COMPONENTS_WRAP" value="5" />
|
||||
<option name="NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER" value="true" />
|
||||
<option name="RPAREN_ON_NEW_LINE_IN_RECORD_HEADER" value="true" />
|
||||
<option name="DECONSTRUCTION_LIST_WRAP" value="5" />
|
||||
<option name="SPACE_BEFORE_DECONSTRUCTION_LIST" value="true" />
|
||||
<option name="MULTI_CATCH_TYPES_WRAP" value="5" />
|
||||
<option name="ALIGN_TYPES_IN_MULTI_CATCH" value="false" />
|
||||
</JavaCodeStyleSettings>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
|
||||
<option name="ALIGN_MULTILINE_RESOURCES" value="false" />
|
||||
<option name="ALIGN_MULTILINE_FOR" value="false" />
|
||||
<option name="SPACE_BEFORE_METHOD_PARENTHESES" value="true" />
|
||||
<option name="CALL_PARAMETERS_WRAP" value="2" />
|
||||
<option name="CALL_PARAMETERS_WRAP" value="5" />
|
||||
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="2" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
||||
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="RESOURCE_LIST_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="RESOURCE_LIST_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
||||
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
|
||||
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
|
||||
<option name="SWITCH_EXPRESSIONS_WRAP" value="5" />
|
||||
<option name="METHOD_ANNOTATION_WRAP" value="5" />
|
||||
<option name="CLASS_ANNOTATION_WRAP" value="5" />
|
||||
<option name="FIELD_ANNOTATION_WRAP" value="5" />
|
||||
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
|
||||
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
|
||||
<option name="ENUM_CONSTANTS_WRAP" value="5" />
|
||||
<option name="WRAP_ON_TYPING" value="0" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,7 +1,9 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
@@ -29,7 +29,7 @@
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
@@ -57,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
||||
Vendored
+52
-33
@@ -19,12 +19,39 @@
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
@rem Catch executions from older scripts and ensure they exit cleanly.
|
||||
@rem This can be removed once we can be reasonably confident that few people
|
||||
@rem will be migrating directly to this new wrapper.
|
||||
goto afterSafetyNet
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
goto exitWithErrorLevel
|
||||
:afterSafetyNet
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@@ -45,13 +72,14 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
1>&2 echo.
|
||||
1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
1>&2 echo.
|
||||
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
|
||||
1>&2 echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
@@ -59,35 +87,26 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
1>&2 echo.
|
||||
1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
1>&2 echo.
|
||||
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
|
||||
1>&2 echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem This label must not be changed. We rely on old scripts being able to jump to this point.
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
|
||||
@@ -39,6 +39,7 @@ public @NullMarked class Client extends NitoriBot {
|
||||
|
||||
|
||||
this.modules = List.of(
|
||||
this.discord = new DiscordModule(this),
|
||||
this.chat = new ChatModule(this),
|
||||
new SelfcareModule(this),
|
||||
this.position = new PositionModule(this),
|
||||
@@ -53,39 +54,17 @@ public @NullMarked class Client extends NitoriBot {
|
||||
new CommandSpyModule(this),
|
||||
this.world = new WorldModule(this),
|
||||
this.tabComplete = new TabCompleteModule(this),
|
||||
this.extrasMessaging = new ExtrasMessagingModule(this)
|
||||
this.extrasMessaging = new ExtrasMessagingModule(this),
|
||||
this.validation = new ValidationModule(this)
|
||||
);
|
||||
|
||||
try {
|
||||
connect();
|
||||
// connect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
private void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy) session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
).setProxy(new GetProxiesList().randomProxyIp()).setProtocol(protocol).create();
|
||||
|
||||
else session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
).setProtocol(protocol).create();
|
||||
Injector.inject(
|
||||
session,
|
||||
this
|
||||
);
|
||||
chatAttestation.inject(session);
|
||||
session.addListener(this);
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void disconnecting (DisconnectingEvent event) {
|
||||
Component component = event.getReason();
|
||||
|
||||
@@ -8,7 +8,27 @@ public class Config {
|
||||
public final Console console = new Console();
|
||||
public final Options[] bots = new Options[]{};
|
||||
public List<String> prefixes;
|
||||
public final Keys keys = new Keys();
|
||||
public final Discord discord = new Discord();
|
||||
|
||||
public static class DiscordRoles {
|
||||
public String trusted;
|
||||
public String admin;
|
||||
public String owner;
|
||||
}
|
||||
|
||||
public static class Discord {
|
||||
public String token;
|
||||
public String prefix;
|
||||
public String invite;
|
||||
public final DiscordRoles roles = new DiscordRoles();
|
||||
}
|
||||
|
||||
public static class Keys {
|
||||
public String trusted;
|
||||
public String admin;
|
||||
public String owner;
|
||||
}
|
||||
public static class Core {
|
||||
public boolean itemRefill;
|
||||
public final Area area = new Area();
|
||||
@@ -56,6 +76,7 @@ public class Config {
|
||||
public boolean useProxy;
|
||||
public String serverName;
|
||||
public String username;
|
||||
public String discordChannelId;
|
||||
public int reconnectDelay;
|
||||
public int selfcareInterval;
|
||||
public String mode;
|
||||
|
||||
@@ -6,7 +6,12 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.boot.LoadConfig;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.console.CreateConsole;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.discord.MessageLogger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.DiscordModule;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.slf4j.*;
|
||||
|
||||
@@ -16,9 +21,9 @@ import java.util.concurrent.*;
|
||||
|
||||
public class Main {
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
public static final ExecutorService virtualThreads = Executors.newVirtualThreadPerTaskExecutor();
|
||||
// public static final ExecutorService virtualThreads = Executors.newVirtualThreadPerTaskExecutor();
|
||||
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
public static final ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
public static final ConcurrentMap<String, Future<?>> services = new ConcurrentHashMap<>();
|
||||
public static final List<NitoriBot> Bots = new ArrayList<>();
|
||||
public static RepoCommitInfo repoCommitInfo = null;
|
||||
@@ -27,6 +32,8 @@ public class Main {
|
||||
public Config config;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static JDA discordClient;
|
||||
|
||||
void main () {
|
||||
try {
|
||||
botBuildInfo = new GetBotBuildInfo().getBuildInfo();
|
||||
@@ -36,6 +43,20 @@ public class Main {
|
||||
console = new CreateConsole();
|
||||
repoCommitInfo = new GetRepoInfo().getRepoInfo();
|
||||
|
||||
executor.setKeepAliveTime(500, TimeUnit.MILLISECONDS);
|
||||
executor.allowCoreThreadTimeOut(true);
|
||||
|
||||
JDABuilder builder = JDABuilder.createDefault(config.discord.token);
|
||||
builder.enableIntents(
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.DIRECT_MESSAGES,
|
||||
GatewayIntent.GUILD_MEMBERS
|
||||
);
|
||||
|
||||
discordClient = builder.build();
|
||||
discordClient.addEventListener(new MessageLogger(discordClient));
|
||||
discordClient.awaitReady();
|
||||
// discordClient.addEventListener(new MessageLogger());
|
||||
for (Config.Options options : bots) {
|
||||
final NitoriBot bot = new Client(
|
||||
options,
|
||||
@@ -44,6 +65,9 @@ public class Main {
|
||||
);
|
||||
Bots.add(bot);
|
||||
}
|
||||
for (NitoriBot bot : Bots) {
|
||||
bot.connect();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("{}", Main.class, e);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuil
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.ListenerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.*;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
@@ -27,7 +28,7 @@ public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingE
|
||||
public final LoggerManager logger = new LoggerManager();
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
//public final ExecutorService executorService = Main.executorService;
|
||||
public final ConcurrentMap<String, Future<?>> services = Main.services;
|
||||
public final BotBuildInfo botBuildInfo = Main.botBuildInfo;
|
||||
public final RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
|
||||
@@ -39,6 +40,7 @@ public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingE
|
||||
public CommandCoreModule core;
|
||||
public PlayerListModule players;
|
||||
public RegistryModule registry;
|
||||
public ValidationModule validation;
|
||||
public boolean loggedIn = false;
|
||||
public int entityId;
|
||||
public ClientNetworkSession session;
|
||||
@@ -49,9 +51,10 @@ public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingE
|
||||
public TabCompleteModule tabComplete;
|
||||
public ExtrasMessagingModule extrasMessaging;
|
||||
public List<?> modules;
|
||||
public final ChatAttestation chatAttestation = new ChatAttestation();
|
||||
public DiscordModule discord;
|
||||
//public final ChatAttestation chatAttestation = new ChatAttestation();
|
||||
|
||||
private void connect () throws IOException {
|
||||
public void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy) session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
@@ -67,7 +70,7 @@ public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingE
|
||||
session,
|
||||
this
|
||||
);
|
||||
chatAttestation.inject(session);
|
||||
ChatAttestation.inject(session);
|
||||
session.addListener(this);
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
+16
-18
@@ -14,31 +14,29 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LoadConfig {
|
||||
private static final String XDG_CONFIG_HOME = System.getenv("XDG_CONFIG_HOME");
|
||||
private final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
|
||||
private final Yaml yaml = new Yaml(yamlConfig);
|
||||
private final String homeDirectory = System.getProperty("user.home");
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoadConfig.class);
|
||||
public Config loadConfig () throws IOException {
|
||||
Path configDirectory;
|
||||
|
||||
if (XDG_CONFIG_HOME == null) configDirectory = Path.of(homeDirectory, ".config/NitoriBot");
|
||||
else configDirectory = Path.of(XDG_CONFIG_HOME, "NitoriBot");
|
||||
|
||||
final Path configPath = Path.of(String.valueOf(configDirectory), "config.yml");
|
||||
final Constructor yamlConfig = new Constructor(
|
||||
Config.class,
|
||||
new LoaderOptions()
|
||||
);
|
||||
final Yaml yaml = new Yaml(yamlConfig);
|
||||
final Path configPath = Path.of("config.yaml");
|
||||
if (!Files.exists(configPath)) {
|
||||
LOGGER.warn("config not found! creating it now");
|
||||
LOGGER.info(
|
||||
"config not found making config now"
|
||||
);
|
||||
|
||||
if (!Files.exists(configDirectory)) Files.createDirectory(configDirectory);
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yml");
|
||||
if (defaultConfig != null) {
|
||||
Files.copy(defaultConfig, configPath);
|
||||
}
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");
|
||||
Files.copy(
|
||||
defaultConfig,
|
||||
configPath
|
||||
);
|
||||
}
|
||||
|
||||
InputStream configFile = Files.newInputStream(configPath);
|
||||
|
||||
return yaml.load(configFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class ChatAttestation {
|
||||
|
||||
}
|
||||
|
||||
public MessagingEntrypointImpl inject (ClientSession clientNetworkSession) {
|
||||
public static MessagingEntrypointImpl inject (ClientSession clientNetworkSession) {
|
||||
MessagingEntrypointImpl messagingEntrypointImpl = new MessagingEntrypointImpl();
|
||||
Injector.inject(clientNetworkSession, messagingEntrypointImpl);
|
||||
return messagingEntrypointImpl;
|
||||
|
||||
-4
@@ -55,10 +55,6 @@ public class Signing {
|
||||
final String encodedKey = Base64.getEncoder()
|
||||
.encodeToString(valid.key().bc().getEncoded());
|
||||
|
||||
LOGGER.info(
|
||||
"Encoded public key: {}",
|
||||
encodedKey
|
||||
);
|
||||
yield new SigningResult(
|
||||
authenticated ? SigningStatus.VERIFIED : SigningStatus.VALID_UNVERIFIED,
|
||||
encodedKey
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
public enum CommandMessageSource {
|
||||
DISCORD, CONSOLE, INGAME
|
||||
}
|
||||
+27
-6
@@ -2,15 +2,36 @@ package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ParsedChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public record CommandSource(PlayerProfileData sender, boolean inGame, ParsedChatType chatType) {
|
||||
public void sendFeedback (NitoriBot bot, Component message) {
|
||||
final String selector = String.format("@p[nbt={UUID:uuid(\"%s\")}]", sender.uuid);
|
||||
public record CommandSource(
|
||||
PlayerProfileData sender,
|
||||
MessageReceivedEvent discordEvent,
|
||||
CommandMessageSource source,
|
||||
ChatType chatType,
|
||||
ParsedChatType parsedChatType
|
||||
) {
|
||||
public void sendFeedback (NitoriBot bot, Component component) {
|
||||
switch (source) {
|
||||
case CommandMessageSource.INGAME -> {
|
||||
final String selector = String.format("@p[nbt={UUID:uuid(\"%s\")}]", sender.uuid);
|
||||
|
||||
if (parsedChatType() == ParsedChatType.COMMANDSPY) bot.chat.tellraw(selector, component);
|
||||
else bot.chat.tellraw("@a", component);
|
||||
}
|
||||
case CommandMessageSource.DISCORD -> {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
discordEvent.getMessage().reply(message).queue();
|
||||
}
|
||||
case CommandMessageSource.CONSOLE -> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (chatType() == ParsedChatType.NORMAL) bot.chat.tellraw("@a", message);
|
||||
else bot.chat.tellraw(selector, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -41,17 +41,19 @@ public class HelpCommand implements CommandInfo {
|
||||
public Component getCommands (NitoriBot bot) {
|
||||
List<Component> Public = new ArrayList<>();
|
||||
List<Component> Trusted = new ArrayList<>();
|
||||
List<Component> Owner = new ArrayList<>();
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
switch (commands.getTrustLevel()) {
|
||||
case CommandTrustLevels.PUBLIC -> Public.add(Component.text(commands.getAliases().getFirst() + " ").color(convertColorString(bot.config.colors.help.Public)));
|
||||
case CommandTrustLevels.TRUSTED -> Trusted.add(Component.text(commands.getAliases().getFirst() + " ").color(convertColorString(bot.config.colors.help.trusted)));
|
||||
case CommandTrustLevels.OWNER -> Owner.add(Component.text(commands.getAliases().getFirst() + " ").color(convertColorString(bot.config.colors.help.owner)));
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Component.empty().append(Public).append(Component.text("\n")).append(Trusted);
|
||||
return Component.empty().append(Public).append(Component.text("\n")).append(Trusted).append(Component.text("\n")).append(Owner);
|
||||
}
|
||||
|
||||
private Component getUsages (NitoriBot bot, List<String> usages) {
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KillCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.OWNER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"kill",
|
||||
"kys",
|
||||
"stop"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "kills the bot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) throws CommandError {
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
Component.text("Killing Bot Process").color(convertColorString(bot.config.colors.commands.primary))
|
||||
);
|
||||
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ValidateCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.TRUSTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"validate",
|
||||
"val"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "validate within the bot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<hash>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) throws CommandError {
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
PlayerProfileData player = source.sender();
|
||||
Component component = null;
|
||||
|
||||
if (source.source().equals(CommandMessageSource.DISCORD)) throw new CommandError(Component.text("this command is meant to be ran in game!").color(NamedTextColor.RED));
|
||||
else {
|
||||
if (!player.alreadyValidated) {
|
||||
switch (player.trustLevel) {
|
||||
case CommandTrustLevels.TRUSTED -> component = Component.text("Validated as Trusted")
|
||||
.color(convertColorString(bot.config.colors.help.trusted));
|
||||
|
||||
case CommandTrustLevels.ADMIN -> component = Component.text("Validated as Admin")
|
||||
.color(convertColorString(bot.config.colors.help.admin));
|
||||
case CommandTrustLevels.OWNER -> component = Component.text("Validated as Owner")
|
||||
.color(convertColorString(bot.config.colors.help.owner));
|
||||
}
|
||||
|
||||
player.alreadyValidated = true;
|
||||
} else {
|
||||
component = Component.translatable("Validated as %s", Component.text(player.trustLevel.toString()))
|
||||
.color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
|
||||
source.sendFeedback(bot, component);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+3
@@ -1,6 +1,7 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.data;
|
||||
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
@@ -21,6 +22,8 @@ public class PlayerProfileData {
|
||||
public Vector3d position;
|
||||
public String dimension;
|
||||
public int entityId;
|
||||
public CommandTrustLevels trustLevel = CommandTrustLevels.PUBLIC;
|
||||
public boolean alreadyValidated = false;
|
||||
|
||||
public PlayerProfileData (
|
||||
UUID uuid,
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.discord;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.ListenerManager;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class MessageLogger extends ListenerAdapter {
|
||||
private JDA client;
|
||||
|
||||
@Override
|
||||
public void onMessageReceived (MessageReceivedEvent event) {
|
||||
if (event.getAuthor().getId().equals(client.getSelfUser().getId())) return;
|
||||
|
||||
for (NitoriBot bot : Main.Bots) {
|
||||
if (event.getChannel().getId().equals(bot.options.discordChannelId)) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.discordMessageReceived(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MessageLogger (JDA client) {
|
||||
this.client = client;
|
||||
}
|
||||
}
|
||||
/*for (NitoriBot bot : Main.Bots) {
|
||||
if (!event.getChannel().getId().equals(bot.options.discordChannelId)) return;
|
||||
|
||||
if (event.getAuthor().getId().equals(client.getSelfUser().getId())) return;
|
||||
|
||||
Component component = Component.translatable(
|
||||
"[%s] %s \u203a %s",
|
||||
Component.translatable(
|
||||
"%s%s %s",
|
||||
Component.text("Nitori").color(NamedTextColor.BLUE),
|
||||
Component.text("Bot").color(NamedTextColor.GREEN),
|
||||
Component.text("Discord").color(NamedTextColor.DARK_BLUE)
|
||||
),
|
||||
Component.text(event.getAuthor().getName()).color(NamedTextColor.GRAY),
|
||||
Component.text(event.getMessage().getContentRaw()).color(NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.AQUA);
|
||||
|
||||
bot.chat.tellraw(
|
||||
"@a",
|
||||
component
|
||||
);
|
||||
}*/
|
||||
+11
-1
@@ -5,6 +5,7 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums.Si
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.PlayerMessageData;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundTagQueryPacket;
|
||||
@@ -22,7 +23,11 @@ public interface Listener {
|
||||
) {
|
||||
}
|
||||
|
||||
default void chatReceived (ChatType chatType, SigningStatus signingStatus, Component message) {}
|
||||
default void chatReceived (
|
||||
ChatType chatType,
|
||||
Component message
|
||||
) {
|
||||
}
|
||||
|
||||
default void packetReceived (Packet packet) {
|
||||
}
|
||||
@@ -48,6 +53,11 @@ public interface Listener {
|
||||
) {
|
||||
}
|
||||
|
||||
default void discordMessageReceived (
|
||||
MessageReceivedEvent event
|
||||
) {
|
||||
}
|
||||
|
||||
default void tabCompleteReceived (ClientboundTagQueryPacket packet) {
|
||||
}
|
||||
}
|
||||
+17
-3
@@ -2,7 +2,9 @@ package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandMessageSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ParsedChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.PlayerMessageData;
|
||||
@@ -34,10 +36,16 @@ public class ChatCommandHandlerModule implements Listener {
|
||||
|
||||
String command = plainMessage.substring(prefix.length());
|
||||
|
||||
CommandSource source = new CommandSource(data.sender(), true, ParsedChatType.NORMAL);
|
||||
CommandSource source = new CommandSource(
|
||||
data.sender(),
|
||||
null,
|
||||
CommandMessageSource.INGAME,
|
||||
data.chatType(),
|
||||
ParsedChatType.NORMAL
|
||||
);
|
||||
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +58,13 @@ public class ChatCommandHandlerModule implements Listener {
|
||||
|
||||
String command = message.substring(prefix.length());
|
||||
|
||||
CommandSource source = new CommandSource(player, true, ParsedChatType.COMMANDSPY);
|
||||
CommandSource source = new CommandSource(
|
||||
player,
|
||||
null,
|
||||
CommandMessageSource.INGAME,
|
||||
ChatType.SYSTEM,
|
||||
ParsedChatType.COMMANDSPY
|
||||
);
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
}
|
||||
|
||||
+17
-14
@@ -62,6 +62,7 @@ public class ChatModule implements Listener {
|
||||
final Component message = packet.getContent();
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.chatReceived(ChatType.SYSTEM, message);
|
||||
listener.systemChatReceived(message);
|
||||
}
|
||||
}
|
||||
@@ -90,13 +91,12 @@ public class ChatModule implements Listener {
|
||||
);*/
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.chatReceived(ChatType.DISGUISED, message);
|
||||
listener.disguisedChatReceived(message);
|
||||
}
|
||||
|
||||
parseMessage(
|
||||
ChatType.DISGUISED,
|
||||
message,
|
||||
new PlayerMessageData(
|
||||
ChatType.DISGUISED, message, new PlayerMessageData(
|
||||
bot.players.getPlayerByUsername(ComponentUtil.componentToString(packet.getName())),
|
||||
packet.getMessage(),
|
||||
ChatType.DISGUISED,
|
||||
@@ -110,25 +110,25 @@ public class ChatModule implements Listener {
|
||||
final Component unsignedContent = packet.getUnsignedContent();
|
||||
final Component content = Component.text(packet.getContent());
|
||||
|
||||
SigningResult result = ChatAttestation.getSigningStatus(
|
||||
/*SigningResult result = ChatAttestation.getSigningStatus(
|
||||
packet.getContent(),
|
||||
packet.getSender(),
|
||||
ComponentUtil.componentToString(packet.getName())
|
||||
);
|
||||
);*/
|
||||
|
||||
//bot.chat.tellraw("@a", Component.text(result.toString()));
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.chatReceived(ChatType.PLAYER, unsignedContent);
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
listener.chatReceived(ChatType.PLAYER, result.status(), unsignedContent);
|
||||
//listener.chatReceived(ChatType.PLAYER, result.status(), unsignedContent);
|
||||
}
|
||||
|
||||
parseMessage(
|
||||
ChatType.PLAYER,
|
||||
unsignedContent,
|
||||
new PlayerMessageData(
|
||||
ChatType.PLAYER, unsignedContent, new PlayerMessageData(
|
||||
bot.players.getPlayerUUID(packet.getSender()),
|
||||
content, ChatType.PLAYER,
|
||||
content,
|
||||
ChatType.PLAYER,
|
||||
Objects.requireNonNull(bot.players.getPlayerUUID(packet.getSender())).displayName
|
||||
)
|
||||
);
|
||||
@@ -148,11 +148,14 @@ public class ChatModule implements Listener {
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
if (data.chatType() == ChatType.DISGUISED) {
|
||||
final PlayerMessageData playerMessageData = new PlayerMessageData(parsed.sender(), parsed.contents(), ChatType.DISGUISED, data.senderName());
|
||||
final PlayerMessageData playerMessageData = new PlayerMessageData(
|
||||
parsed.sender(),
|
||||
parsed.contents(),
|
||||
ChatType.DISGUISED,
|
||||
data.senderName()
|
||||
);
|
||||
listener.parsedMessage(playerMessageData);
|
||||
}
|
||||
|
||||
else listener.parsedMessage(data);
|
||||
} else listener.parsedMessage(data);
|
||||
}
|
||||
|
||||
} catch (Exception ignore) {
|
||||
|
||||
+2
-1
@@ -132,7 +132,8 @@ public class CommandCoreModule implements Listener {
|
||||
bot.session.send(new ServerboundSetCreativeModeSlotPacket(
|
||||
(short) 36,
|
||||
new ItemStack(
|
||||
bot.registry.getBlockRegistry("minecraft:command_block").itemId,
|
||||
529,
|
||||
// bot.registry.getBlockRegistry("minecraft:command_block").itemId,
|
||||
64,
|
||||
dataComponents
|
||||
)
|
||||
|
||||
+118
-13
@@ -1,12 +1,14 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandError;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner.KillCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted.ReconnectCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted.ValidateCommand;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.slf4j.Logger;
|
||||
@@ -32,6 +34,8 @@ public class CommandManagerModule {
|
||||
registerCommand(new ListCommand());
|
||||
registerCommand(new PlayerInfoCommand());
|
||||
registerCommand(new CoreCommand());
|
||||
registerCommand(new ValidateCommand());
|
||||
registerCommand(new KillCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (CommandInfo command) {
|
||||
@@ -48,7 +52,44 @@ public class CommandManagerModule {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void execute (CommandSource source, String commandName, String[] args) {
|
||||
private int getTrustLevelAsInteger (CommandTrustLevels trustLevel) {
|
||||
return switch (trustLevel) {
|
||||
case CommandTrustLevels.PUBLIC -> 0;
|
||||
case CommandTrustLevels.TRUSTED -> 1;
|
||||
case CommandTrustLevels.ADMIN -> 2;
|
||||
case CommandTrustLevels.OWNER -> 3;
|
||||
case CommandTrustLevels.CONSOLE -> 4;
|
||||
case CommandTrustLevels.DISABLED -> -69420;
|
||||
};
|
||||
}
|
||||
|
||||
private Component convertTrustLevelIdToComponent (int id) {
|
||||
return switch (id) {
|
||||
case 1 -> Component.text(CommandTrustLevels.TRUSTED.toString()).color(convertColorString(bot.config.colors.help.trusted));
|
||||
case 2 -> Component.text(CommandTrustLevels.ADMIN.toString()).color(convertColorString(bot.config.colors.help.admin));
|
||||
case 3 -> Component.text(CommandTrustLevels.OWNER.toString()).color(convertColorString(bot.config.colors.help.owner));
|
||||
default -> Component.text(CommandTrustLevels.PUBLIC.toString()).color(convertColorString(bot.config.colors.help.Public));
|
||||
};
|
||||
}
|
||||
|
||||
private int getDiscordRoleTrustLevelAsInteger (List<Role> role) {
|
||||
int trustLevel = 0;
|
||||
final var configRoles = bot.config.discord.roles;
|
||||
for (Role roles : role) {
|
||||
final String roleName = roles.getName();
|
||||
if (roleName.equals(configRoles.trusted)) trustLevel = 1;
|
||||
if (roleName.equals(configRoles.admin)) trustLevel = 2;
|
||||
if (roleName.equals(configRoles.owner)) trustLevel = 3;
|
||||
}
|
||||
|
||||
return trustLevel;
|
||||
}
|
||||
|
||||
public void execute (
|
||||
CommandSource source,
|
||||
String commandName,
|
||||
String[] args
|
||||
) {
|
||||
try {
|
||||
CommandInfo command = getCommand(commandName.toLowerCase());
|
||||
|
||||
@@ -60,22 +101,86 @@ public class CommandManagerModule {
|
||||
Component.translatable("command.context.here")
|
||||
).color(NamedTextColor.RED));
|
||||
|
||||
CommandContext context = new CommandContext(bot, args, source);
|
||||
CommandContext context = new CommandContext(
|
||||
bot,
|
||||
args,
|
||||
source
|
||||
);
|
||||
|
||||
command. execute(context);
|
||||
final int cmdTrustLevel = getTrustLevelAsInteger(command.getTrustLevel());
|
||||
|
||||
if (cmdTrustLevel != 0 && cmdTrustLevel < 4) {
|
||||
if (source.source().equals(CommandMessageSource.DISCORD)) {
|
||||
final MessageReceivedEvent event = source.discordEvent();
|
||||
final int userTrustLevel = getDiscordRoleTrustLevelAsInteger(event.getMember().getRoles());
|
||||
|
||||
if (userTrustLevel < cmdTrustLevel) {
|
||||
final Component playerTrustLevelComponent = convertTrustLevelIdToComponent(userTrustLevel);
|
||||
final Component cmdTrustLevelComponent = convertTrustLevelIdToComponent(cmdTrustLevel);
|
||||
|
||||
throw new CommandError(
|
||||
Component.translatable(
|
||||
"Your Trust Level (%s) does not meet the required Trust Level (%s) for the command: %s",
|
||||
playerTrustLevelComponent,
|
||||
cmdTrustLevelComponent,
|
||||
Component.text(commandName)
|
||||
).color(NamedTextColor.RED)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
final int playerTrustLevel = getTrustLevelAsInteger(source.sender().trustLevel);
|
||||
|
||||
if (args.length == 0)
|
||||
throw new CommandError(Component.text("Please provide a hash").color(NamedTextColor.RED));
|
||||
else {
|
||||
if (args[0].equals(bot.validation.trustedHash))
|
||||
source.sender().trustLevel = CommandTrustLevels.TRUSTED;
|
||||
else if (args[0].equals(bot.validation.adminHash))
|
||||
source.sender().trustLevel = CommandTrustLevels.ADMIN;
|
||||
else if (args[0].equals(bot.validation.ownerHash))
|
||||
source.sender().trustLevel = CommandTrustLevels.OWNER;
|
||||
}
|
||||
|
||||
if (playerTrustLevel < cmdTrustLevel)
|
||||
throw new CommandError(Component.text("Invalid Hash").color(NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
|
||||
command.execute(context);
|
||||
} catch (CommandError error) {
|
||||
source.sendFeedback(bot, error.message());
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
error.message()
|
||||
);
|
||||
} catch (Exception error) {
|
||||
source.sendFeedback(bot, Component.translatable("command.failed").color(NamedTextColor.DARK_RED));
|
||||
LOGGER.error("{}", CommandManagerModule.class, error);
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
Component.translatable("command.failed").color(NamedTextColor.DARK_RED)
|
||||
);
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
CommandManagerModule.class,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void executeString (CommandSource source, String command) {
|
||||
public void executeString (
|
||||
CommandSource source,
|
||||
String command
|
||||
) {
|
||||
String[] splitArguments = command.split(" ");
|
||||
String commandName = splitArguments[0];
|
||||
final String[] args = Arrays.copyOfRange(splitArguments, 1, splitArguments.length);
|
||||
final String[] args = Arrays.copyOfRange(
|
||||
splitArguments,
|
||||
1,
|
||||
splitArguments.length
|
||||
);
|
||||
|
||||
this.execute(source, commandName, args);
|
||||
this.execute(
|
||||
source,
|
||||
commandName,
|
||||
args
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandMessageSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundLoginFinishedPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
|
||||
public class DiscordModule extends ListenerAdapter implements Listener {
|
||||
private NitoriBot bot;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DiscordModule.class);
|
||||
private final List<String> discordQueue = new ArrayList<>();
|
||||
public JDA client = Main.discordClient;
|
||||
|
||||
@Override
|
||||
public void systemChatReceived (Component message) {
|
||||
sendComponent(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerChatReceived (Component message) {
|
||||
sendComponent(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disguisedChatReceived (Component message) {
|
||||
sendComponent(message);
|
||||
}
|
||||
|
||||
private void sendDiscordMessage (String message) {
|
||||
discordQueue.add(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void discordMessageReceived (MessageReceivedEvent event) {
|
||||
if (!event.getChannel().getId().equals(bot.options.discordChannelId)) return;
|
||||
|
||||
if (event.getMessage().getContentRaw().startsWith(bot.config.discord.prefix)) {
|
||||
|
||||
final String command = event.getMessage().getContentRaw().substring(bot.config.discord.prefix.length());
|
||||
final CommandSource source = new CommandSource(null, event, CommandMessageSource.DISCORD, null, null);
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
PlayerProfileData sender,
|
||||
MessageReceivedEvent discordEvent,
|
||||
CommandMessageSource source,
|
||||
ChatType chatType,
|
||||
ParsedChatType parsedChatType
|
||||
*/
|
||||
|
||||
Component component = Component.translatable(
|
||||
"[%s] %s \u203a %s",
|
||||
Component.translatable(
|
||||
"%s%s %s",
|
||||
Component.text("Nitori").color(NamedTextColor.BLUE),
|
||||
Component.text("Bot").color(NamedTextColor.GREEN),
|
||||
Component.text("Discord").color(NamedTextColor.DARK_BLUE)
|
||||
),
|
||||
Component.text(event.getAuthor().getName()).color(NamedTextColor.GRAY),
|
||||
Component.text(event.getMessage().getContentRaw()).color(NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.AQUA);
|
||||
|
||||
bot.chat.tellraw("@a", component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
if (packet instanceof final ClientboundLoginFinishedPacket p) {
|
||||
Timer timer = new Timer();
|
||||
|
||||
timer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
if (discordQueue.isEmpty()) return;
|
||||
try {
|
||||
final String message = String.join("\n", discordQueue);
|
||||
|
||||
client.getTextChannelById(bot.options.discordChannelId)
|
||||
.sendMessage("```ansi\n" + message.substring(
|
||||
0,
|
||||
Math.min(message.length(), 1984)
|
||||
) + "\n```")
|
||||
.queue();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("{}", DiscordModule.class, e);
|
||||
}
|
||||
discordQueue.clear();
|
||||
}
|
||||
}, 2000, 2000
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendComponent (
|
||||
Component component
|
||||
) {
|
||||
final String message = componentToAnsi(component);
|
||||
|
||||
try {
|
||||
sendDiscordMessage(message);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("{}", DiscordModule.class, e);
|
||||
}
|
||||
}
|
||||
|
||||
public DiscordModule (NitoriBot bot) throws InterruptedException {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
-4
@@ -68,10 +68,6 @@ public class PositionModule implements Listener {
|
||||
packet.getYRot()
|
||||
)
|
||||
);
|
||||
/*
|
||||
ServerboundAcceptTeleportationPacket(int id, double x, double y, double z, float yRot, float xRot)
|
||||
*/
|
||||
//bot.session.send(new ServerboundAcceptTeleportationPacket(packet.getId()));
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
if (!Objects.equals(bot.options.mode, "kaboom")) return;
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class RegistryModule implements Listener {
|
||||
|
||||
public RegistryModule (NitoriBot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
parseBlockRegistries();
|
||||
//parseBlockRegistries();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class SelfcareModule implements Listener {
|
||||
|
||||
public void login (ClientboundLoginFinishedPacket packet) {
|
||||
if (bot.options.mode.equals("totalfreedom")) return;
|
||||
timer = bot.executor.scheduleAtFixedRate(
|
||||
timer = bot.executor.scheduleWithFixedDelay(
|
||||
() -> {
|
||||
if (permission.level < 2 && bot.loggedIn) bot.chat.command("minecraft:op @s[type=player]");
|
||||
else if (gamemode.gamemode != 1)
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundChangeGameModePacket;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ValidationModule {
|
||||
private NitoriBot bot;
|
||||
public String trustedHash;
|
||||
public String adminHash;
|
||||
public String ownerHash;
|
||||
|
||||
private String generateHash (String key) {
|
||||
final long time = System.currentTimeMillis() / 2000;
|
||||
final String value = String.format(
|
||||
"%s%s",
|
||||
time,
|
||||
key
|
||||
);
|
||||
|
||||
return Hashing.sha256()
|
||||
.hashString(value, StandardCharsets.UTF_8)
|
||||
.toString()
|
||||
.substring(0, 16);
|
||||
}
|
||||
|
||||
public ValidationModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
trustedHash = generateHash(bot.config.keys.trusted);
|
||||
adminHash = generateHash(bot.config.keys.admin);
|
||||
ownerHash = generateHash(bot.config.keys.owner);
|
||||
}
|
||||
}, 0, 100);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"about": "NitoriBot (formerly FridayNightFunkinBoyfriendBot or FNFBoyfriendBot) is a bot made for the servers kaboom.pw (and clones) and Savage Friends",
|
||||
"about": "NitoriBot (originally known as FNFBoyfriendBot) Night-of-Nights is a modern rewrite of NitoriBot Reignite(v8.0.0) made for the servers kaboom.pw and for Savage Friends",
|
||||
"buildstring": {
|
||||
"botName": [
|
||||
{
|
||||
@@ -26,7 +26,7 @@
|
||||
"color": "blue"
|
||||
}
|
||||
],
|
||||
"build": "5313",
|
||||
"build": "5314",
|
||||
"versionReleaseDate": "N\\A",
|
||||
"initialBotRelease": "11/22/22"
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user