Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("fabric-loom") version "1.15-SNAPSHOT"
id("net.fabricmc.fabric-loom") version "1.16-SNAPSHOT"
id("com.gradleup.shadow") version "9.3.1"
}

Expand All @@ -24,7 +24,6 @@ loom {
repositories {
mavenCentral()
maven("https://maven.isxander.dev/releases")
maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1")
exclusiveContent {
forRepository {
maven {
Expand All @@ -41,21 +40,18 @@ repositories {
dependencies {
// To change the versions see the gradle.properties file
minecraft("com.mojang:minecraft:${project.property("minecraft_version")}")
mappings(loom.officialMojangMappings())
modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}")
implementation("net.fabricmc:fabric-loader:${project.property("loader_version")}")

modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}")
implementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}")

shadow(implementation("org.mongodb:mongodb-driver-sync:5.6.3")!!)
shadow(implementation("net.dv8tion:JDA:6.3.0") { exclude("opus-java") })
shadow(modImplementation("maven.modrinth:fabric-yaml-configuration:1.0.1")!!)

shadow(implementation("dev.vankka:mcdiscordreserializer:4.3.0")!!)
shadow(modImplementation("net.kyori:adventure-platform-mod-shared-fabric-repack:6.8.0")!!)
shadow(implementation("net.kyori:adventure-platform-mod-shared:6.9.0")!!)

shadow(implementation("com.sparkjava:spark-core:2.9.4")!!)

modRuntimeOnly("me.djtheredstoner:DevAuth-fabric:1.2.2")
runtimeOnly("net.litetex.mcm:dev-auth-neo:1.1.0")
}

tasks.processResources {
Expand Down Expand Up @@ -83,12 +79,6 @@ tasks {
archiveClassifier = "shadowed-only"
// minimize()
}
remapJar {
dependsOn(shadowJar)
mustRunAfter(shadowJar)
inputFile = file(shadowJar.get().archiveFile)
archiveClassifier = ""
}
}

java { toolchain.languageVersion = JavaLanguageVersion.of(21) }
java { toolchain.languageVersion = JavaLanguageVersion.of(25) }
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.configuration-cache=false
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.11
loader_version=0.18.4
minecraft_version=26.1.2
loader_version=0.19.2
# Mod Properties
mod_version=2.19.2
mod_version=2.20.0
maven_group=net.legitimoose
archives_base_name=Legitimoose-Bot
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.141.3+1.21.11
fabric_version=0.149.1+26.1.2
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 0 additions & 3 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/client/java/net/legitimoose/bot/LegitimooseBotClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.ClientCommands;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -97,17 +97,17 @@ private void schedulePeriodicalMessage() {
private void registerCommands() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, context) -> {
dispatcher.register(
ClientCommandManager.literal("scraper")
.then(ClientCommandManager.literal("reload")
ClientCommands.literal("scraper")
.then(ClientCommands.literal("reload")
.executes(LegitimooseBotClient::reloadConfig)
)
.then(ClientCommandManager.literal("on")
.then(ClientCommands.literal("on")
.executes((source)->{
Scraper.getInstance().override(false);
return 0;
})
)
.then(ClientCommandManager.literal("off")
.then(ClientCommands.literal("off")
.executes((source)->{
Scraper.getInstance().override(true);
return 0;
Expand All @@ -119,7 +119,7 @@ private void registerCommands() {

private static int reloadConfig(CommandContext<?> context) {
try {
CONFIG.reloadConfiguration();
CONFIG.reload();
} catch (Exception e) {
LOGGER.error(e.getMessage());
return 1;
Expand Down Expand Up @@ -166,7 +166,7 @@ private static void message(String message) {
LocalPlayer player = Minecraft.getInstance().player;

if (player != null) {
player.displayClientMessage(Component.literal(message), false);
player.sendSystemMessage(Component.literal(message));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/client/java/net/legitimoose/bot/chat/GameChatHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void handleChat(Component component) {
lastMessages.add(message);

if (handleChat) {
DiscordWebhook webhook = new DiscordWebhook(CONFIG.getString("webhook"));
DiscordWebhook webhook = new DiscordWebhook(CONFIG.webhook);
handleChat(component, message, webhook);
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public void handleMsgMessage(MsgMatcher msg) {
User user;
if (discordReceiverName != null) {
String finalUsername = discordReceiverName.replace("@", "");
user = DiscordBot.jda.getGuildById(CONFIG.getString("guildId"))
user = DiscordBot.jda.getGuildById(CONFIG.guildId)
.findMembers(s -> s.getUser().getName().equals(finalUsername))
.get().getFirst().getUser();
} else {
Expand Down Expand Up @@ -272,7 +272,7 @@ private boolean shouldLogMessage(String senderName, String message) {
Minecraft.getInstance().player.getPlainTextName().equals(senderName)))
return false;

return !message.startsWith(CONFIG.getString("secretPrefix"));
return !message.startsWith(CONFIG.secretPrefix);
}

public static GameChatHandler getInstance() {
Expand Down
10 changes: 5 additions & 5 deletions src/client/java/net/legitimoose/bot/discord/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void run() {
new Rejoin(),
new Send()
);
jda = JDABuilder.createDefault(CONFIG.getString("token"))
jda = JDABuilder.createDefault(CONFIG.token)
.enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)
.build();

Expand Down Expand Up @@ -98,7 +98,7 @@ public static void run() {

@Override
public void onGuildReady(GuildReadyEvent event) {
if (!event.getGuild().getId().equals(CONFIG.getString("guildId"))) return;
if (!event.getGuild().getId().equals(CONFIG.guildId)) return;
event.getGuild()
.updateCommands()
.addCommands(
Expand All @@ -119,7 +119,7 @@ public void onGuildReady(GuildReadyEvent event) {
public void onMessageReceived(MessageReceivedEvent event) {
String discordNick;
if (event.isWebhookMessage()) {
if (!event.getAuthor().getId().equals(CONFIG.getString("bridgeWebhookId"))) return;
if (!event.getAuthor().getId().equals(CONFIG.bridgeWebhookId)) return;
discordNick = event.getAuthor().getEffectiveName();
} else {
discordNick = event.getMember().getEffectiveName();
Expand All @@ -131,9 +131,9 @@ public void onMessageReceived(MessageReceivedEvent event) {
if (!event.getMessage().getAttachments().isEmpty()) {
message += " <blue>[Attachment Included]</blue>";
}
if (CONFIG.getString("channelId").isEmpty())
if (CONFIG.channelId.isEmpty())
LOGGER.error("Discord channel ID is not set in config!");
if (event.getChannel().getId().equals(CONFIG.getString("channelId"))) {
if (event.getChannel().getId().equals(CONFIG.channelId)) {
Minecraft.getInstance().player.connection.sendChat(McUtil.sanitizeString(message));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
bypassCooldown = false;
username = event.getUser().getEffectiveName();
} else {
bypassCooldown = event.getMember().getPermissions().contains(Permission.MANAGE_SERVER) && event.getGuild().getId().equals(CONFIG.getString("guildId"));
bypassCooldown = event.getMember().getPermissions().contains(Permission.MANAGE_SERVER) && event.getGuild().getId().equals(CONFIG.guildId);
username = event.getMember().getEffectiveName();
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/java/net/legitimoose/bot/scraper/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Database {
private static final String DATABASE_NAME = "legitimooseapi";

private static final MongoClient mongoClient =
MongoClients.create(CONFIG.getString("mongoUri"));
MongoClients.create(CONFIG.mongoUri);

private final MongoDatabase database =
mongoClient.getDatabase(DATABASE_NAME);
Expand Down
10 changes: 5 additions & 5 deletions src/client/java/net/legitimoose/bot/scraper/Scraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.ContainerInput;
import net.minecraft.world.item.ItemStack;
import org.bson.BsonArray;
import org.bson.BsonDateTime;
Expand All @@ -43,7 +43,7 @@ public class Scraper {

private volatile boolean scrapeOverride = false;

private final DiscordWebhook errorWebhook = new DiscordWebhook(CONFIG.getString("errorWebhook"));
private final DiscordWebhook errorWebhook = new DiscordWebhook(CONFIG.errorWebhook);

private final Pattern jamScorePattern = Pattern.compile("^CategoryScore\\(rank=(.*), score=(.*)\\)");
private final Pattern ownerNamePattern = Pattern.compile("^by (?:[^|]+\\|\\s*)?(.+)");
Expand Down Expand Up @@ -89,7 +89,7 @@ private void error(String message, Exception exception) throws IOException, URIS
}

public void scrape() {
if (!CONFIG.getBoolean("scrape", true)) return;
if (!CONFIG.scrape) return;
Minecraft client = Minecraft.getInstance();
MongoCollection<Document> stats = Database.getStats();
stats.createIndex(Indexes.descending("timestamp"));
Expand Down Expand Up @@ -262,8 +262,8 @@ public void scrape() {
LOGGER.info("Scraped page #{}", i);
Minecraft.getInstance()
.gameMode
.handleInventoryMouseClick(
client.player.containerMenu.containerId, 32, 0, ClickType.PICKUP, client.player
.handleContainerInput(
client.player.containerMenu.containerId, 32, 0, ContainerInput.PICKUP, client.player
);
waitSeconds(1); // wait a sec to give legmos time to load
}
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/net/legitimoose/bot/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.legitimoose.bot;

import com.google.gson.Gson;

import java.io.*;
import java.nio.file.Files;

public class Config {
public static final Gson gson = new Gson();

private transient File file;

public String token;
public String webhook;
public String errorWebhook;
public boolean scrape;
public String bridgeWebhookId;
public String mongoUri;
public String secretPrefix;
public String channelId;
public String guildId;

public static Config create(File file, InputStream defaultFile) throws IOException {
if (!file.exists()) {
Files.copy(defaultFile, file.toPath());
}
Config config = gson.fromJson(new FileReader(file), Config.class);
config.file = file;
return config;
}

public void reload() throws FileNotFoundException {
Config temp = gson.fromJson(new FileReader(file), Config.class);

this.token = temp.token;
this.webhook = temp.webhook;
this.errorWebhook = temp.errorWebhook;
this.scrape = temp.scrape;
this.bridgeWebhookId = temp.bridgeWebhookId;
this.mongoUri = temp.mongoUri;
this.secretPrefix = temp.secretPrefix;
this.channelId = temp.channelId;
this.guildId = temp.guildId;
}
}
15 changes: 4 additions & 11 deletions src/main/java/net/legitimoose/bot/LegitimooseBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.mountcode.libraries.yaml.InvalidConfigurationException;
import ru.mountcode.mods.fabricyamlconfiguration.yaml.FabricConfiguration;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class LegitimooseBot implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("legitimoose-bot");
public static final FabricConfiguration CONFIG = new FabricConfiguration();
public static Config CONFIG;

@Override
public void onInitialize() {
InputStream defaultConfigFile = LegitimooseBot.class.getResourceAsStream("/assets/legitimoose-bot/config/legitimoosebot.yml");

CONFIG.setDefault(defaultConfigFile);
CONFIG.setFile("config/legitimoosebot.yml");

try {
CONFIG.initialize();
CONFIG = Config.create(new File("config/legitimoosebot.json"), defaultConfigFile);
} catch (IOException e) {
LOGGER.error("Configuration file cannot be generated", e);
} catch (InvalidConfigurationException e) {
LOGGER.error("Configuration file cannot be loaded", e);
LOGGER.error("failed to initialize config", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"token": "",
"webhook": "",
"errorWebhook": "",
"scrape": true,
"bridgeWebhookId": "1473335695299837992",
"mongoUri": "mongodb://127.0.0.1:27017/",
"secretPrefix": "::",
"channelId": "",
"guildId": "1311574348989071440"
}

This file was deleted.

Loading