This commit is contained in:
Bella 2020-03-26 20:59:51 -04:00
parent 3e9c275513
commit 4bb470d9ce
No known key found for this signature in database
GPG Key ID: 815562EA23BFE344
7 changed files with 144 additions and 6 deletions

View File

@ -75,6 +75,8 @@ dependencies {
exclude group: 'com.google.guava', module: 'guava'
}
compile 'club.minnced:java-discord-rpc:v2.0.1'
compile 'com.github.MrPowerGamerBR:TemmieWebhook:-SNAPSHOT'
compile 'com.github.kevinsawicki:http-request:http-request-6.0'
}
processResources {
@ -108,6 +110,8 @@ shadowJar {
include(dependency('org.yaml:snakeyaml'))
include(dependency('org.reflections:reflections'))
include(dependency('org.javassist:javassist'))
include(dependency('com.github.MrPowerGamerBR:TemmieWebhook'))
include(dependency('com.github.kevinsawicki:http-request'))
}
exclude 'dummyThing' // can someone explain why this is here
classifier = 'release'

View File

@ -1,5 +1,6 @@
#Thu Mar 26 18:02:24 EDT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -66,7 +66,7 @@ import java.util.Optional;
)
public class KamiMod {
static final String MODNAME = "KAMI Blue";
public static final String MODNAME = "KAMI Blue";
public static final String MODID = "kamiblue";
public static final String MODVER = "v1.1.2-beta";
public static final String MODVERSMALL = "v1.1.2-beta";

View File

@ -0,0 +1,37 @@
package me.zeroeightsix.kami.command.commands;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
import me.zeroeightsix.kami.module.ModuleManager;
import me.zeroeightsix.kami.module.modules.chat.DiscordForward;
/**
* @author S-B99
* Created by S-B99 on 26/03/20
*/
public class DiscordForwardCommand extends Command {
public DiscordForwardCommand() {
super("discordforward", new ChunkBuilder().append("webhook url").append("avatar url").build(), "webhook");
}
@Override
public void call(String[] args) {
DiscordForward df = (DiscordForward) ModuleManager.getModuleByName("DiscordForward");
if (args[0] != null && !args[0].equals("")) {
df.url.setValue(args[0]);
Command.sendChatMessage(df.getChatName() + "Set URL to \"" + args[0] + "\"!");
} else if (args[0] == null) {
Command.sendErrorMessage(df.getChatName() + "Error: you must specify a URL or \"\" for the first parameter when running the command");
}
if (args[1] == null) return;
if (!args[1].equals("")) {
df.avatar.setValue(args[1]);
Command.sendChatMessage(df.getChatName() + "Set Avatar to \"" + args[1] + "\"!");
} else {
df.avatar.setValue(KamiMod.GITHUB_LINK + "raw/assets/assets/icons/kami.png");
Command.sendChatMessage(df.getChatName() + "Reset Avatar!");
}
}
}

View File

@ -0,0 +1,83 @@
package me.zeroeightsix.kami.module.modules.chat;
import com.mrpowergamerbr.temmiewebhook.DiscordMessage;
import com.mrpowergamerbr.temmiewebhook.TemmieWebhook;
import me.zero.alpine.listener.EventHandler;
import me.zero.alpine.listener.Listener;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.event.events.PacketEvent;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.module.ModuleManager;
import me.zeroeightsix.kami.module.modules.gui.InfoOverlay;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.util.ColourTextFormatting;
import me.zeroeightsix.kami.util.TimeUtil;
import net.minecraft.network.play.server.SPacketChat;
import net.minecraft.util.text.TextFormatting;
import java.util.regex.Pattern;
import static me.zeroeightsix.kami.util.ColourTextFormatting.toTextMap;
/**
* @author S-B99
* Created by S-B99 on 26/03/20
*/
@Module.Info(name = "DiscordForward", category = Module.Category.CHAT, description = "Sends your chat to a set Discord channel")
public class DiscordForward extends Module {
private Setting<Boolean> time = register(Settings.b("Timestamp", true));
private Setting<Boolean> all = register(Settings.b("All Messages", false));
private Setting<Boolean> queue = register(Settings.booleanBuilder("Queue Position").withValue(true).withVisibility(v -> !all.getValue()).build());
private Setting<Boolean> direct = register(Settings.booleanBuilder("Direct Messages").withValue(true).withVisibility(v -> !all.getValue()).build());
public Setting<String> url = register(Settings.s("URL", "unchanged"));
public Setting<String> avatar = register(Settings.s("Avatar", KamiMod.GITHUB_LINK + "raw/assets/assets/icons/kami.png"));
@EventHandler
public Listener<PacketEvent.Receive> listener = new Listener<>(event -> {
if (mc.player == null || isDisabled()) return;
if (!(event.getPacket() instanceof SPacketChat)) return;
SPacketChat sPacketChat = (SPacketChat) event.getPacket();
if (shouldSend(sPacketChat.getChatComponent().getUnformattedText())) {
sendMessage(KamiMod.MODNAME, getTime() + sPacketChat.chatComponent.getUnformattedText(), avatar.getValue());
}
});
public void onEnable() {
if (url.getValue().equalsIgnoreCase("unchanged")) {
Command.sendErrorMessage(getChatName() + "You must first set a webhook url with the '&7" + Command.getCommandPrefix() + "discordforward&r' command");
disable();
}
}
private boolean shouldSend(String message) {
if (all.getValue()) return true;
else if (isQueue(message)) return true;
else return isDirect(message);
}
private boolean isDirect(String message) {
if (direct.getValue() && message.contains("whispers:")) return true;
else return direct.getValue() && Pattern.compile("to.*:", Pattern.CASE_INSENSITIVE).matcher(message).find();
}
private boolean isQueue(String message) {
if (queue.getValue() && message.contains("Position in queue:")) {
return true;
} else return queue.getValue() && message.contains("2b2t is full");
}
private String getTime() {
if (!time.getValue() || ModuleManager.getModuleByName("ChatTimestamp").isEnabled()) return "";
InfoOverlay info = (InfoOverlay) ModuleManager.getModuleByName("InfoOverlay");
return "[" + TimeUtil.getFinalTime(info.timeUnitSetting.getValue(), info.timeTypeSetting.getValue(), info.doLocale.getValue()) + "] ";
}
private void sendMessage(String username, String content, String avatarUrl) {
TemmieWebhook tm = new TemmieWebhook(url.getValue());
DiscordMessage dm = new DiscordMessage(username, content, avatarUrl);
tm.sendMessage(dm);
}
}

View File

@ -47,9 +47,9 @@ public class InfoOverlay extends Module {
private Setting<Boolean> speed = register(Settings.booleanBuilder("Speed").withValue(true).withVisibility(v -> page.getValue().equals(Page.THREE)).build());
private Setting<SpeedUnit> speedUnit = register(Settings.enumBuilder(SpeedUnit.class).withName("Speed Unit").withValue(SpeedUnit.KMH).withVisibility(v -> page.getValue().equals(Page.THREE) && speed.getValue()).build());
private Setting<Boolean> time = register(Settings.booleanBuilder("Time").withValue(true).withVisibility(v -> page.getValue().equals(Page.THREE)).build());
private Setting<TimeUtil.TimeType> timeTypeSetting = register(Settings.enumBuilder(TimeUtil.TimeType.class).withName("Time Format").withValue(TimeUtil.TimeType.HHMMSS).withVisibility(v -> page.getValue().equals(Page.THREE) && time.getValue()).build());
private Setting<TimeUtil.TimeUnit> timeUnitSetting = register(Settings.enumBuilder(TimeUtil.TimeUnit.class).withName("Time Unit").withValue(TimeUtil.TimeUnit.H12).withVisibility(v -> page.getValue().equals(Page.THREE) && time.getValue()).build());
private Setting<Boolean> doLocale = register(Settings.booleanBuilder("Time Show AMPM").withValue(true).withVisibility(v -> page.getValue().equals(Page.THREE) && time.getValue()).build());
public Setting<TimeUtil.TimeType> timeTypeSetting = register(Settings.enumBuilder(TimeUtil.TimeType.class).withName("Time Format").withValue(TimeUtil.TimeType.HHMMSS).withVisibility(v -> page.getValue().equals(Page.THREE) && time.getValue()).build());
public Setting<TimeUtil.TimeUnit> timeUnitSetting = register(Settings.enumBuilder(TimeUtil.TimeUnit.class).withName("Time Unit").withValue(TimeUtil.TimeUnit.H12).withVisibility(v -> page.getValue().equals(Page.THREE) && time.getValue()).build());
public Setting<Boolean> doLocale = register(Settings.booleanBuilder("Time Show AMPM").withValue(true).withVisibility(v -> page.getValue().equals(Page.THREE) && time.getValue()).build());
public Setting<ColourTextFormatting.ColourCode> firstColour = register(Settings.enumBuilder(ColourTextFormatting.ColourCode.class).withName("First Colour").withValue(ColourTextFormatting.ColourCode.WHITE).withVisibility(v -> page.getValue().equals(Page.THREE)).build());
public Setting<ColourTextFormatting.ColourCode> secondColour = register(Settings.enumBuilder(ColourTextFormatting.ColourCode.class).withName("Second Colour").withValue(ColourTextFormatting.ColourCode.BLUE).withVisibility(v -> page.getValue().equals(Page.THREE)).build());

View File

@ -62,4 +62,17 @@ public class TimeUtil {
}
return getStringColour(colourCode1) + time(dateFormatter(timeUnit, timeType)) + getStringColour(colourCode2) + locale;
}
public static String getFinalTime(TimeUnit timeUnit, TimeType timeType, Boolean doLocale) {
String locale = "";
String time = time(TimeUtil.dateFormatter(TimeUnit.H24, TimeType.HH));
if (timeUnit == TimeUnit.H12 && doLocale) {
if ((Integer.parseInt(time)) - 12 >= 0) { // checks if the 24 hour time minus 12 is negative or 0, if it is it's pm
locale = "pm";
} else {
locale = "am";
}
}
return time(dateFormatter(timeUnit, timeType)) + locale;
}
}