Skip to content

Commit 394f11d

Browse files
committed
Updated stuff
1 parent e68ec4f commit 394f11d

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import org.mangorage.mangobotgradle.util.GitVersion
22

33
buildscript {
44
repositories {
5-
mavenCentral()
65
mavenLocal()
6+
mavenCentral()
77
maven {
88
url = uri("https://plugins.gradle.org/m2/")
99
}
@@ -17,7 +17,7 @@ buildscript {
1717

1818
dependencies {
1919
classpath 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2'
20-
classpath 'org.mangorage:MangoBotGradle:6.0.11'
20+
classpath 'org.mangorage:MangoBotGradle:6.0.17'
2121
}
2222
}
2323

@@ -73,16 +73,19 @@ dependencies {
7373
testImplementation platform('org.junit:junit-bom:5.9.1')
7474
testImplementation 'org.junit.jupiter:junit-jupiter'
7575

76-
installer('org.mangorage:installer:4.0.20')
76+
installer('org.mangorage:installer:4.0.26')
77+
bootstrap("org.mangorage:mangobotbootstrap:1.0.66")
7778

78-
bootstrap("org.mangorage:mangobotbootstrap:1.0.43")
79-
plugin('org.mangorage:mangobot:12.0.74')
79+
plugin('org.mangorage:mangobot:12.0.76')
8080

8181
library('org.slf4j:slf4j-simple:2.0.13') // Use a recent version)
8282
library('org.luaj:luaj-jme:3.0.1')
8383

8484
library('dev.arbjerg:lavaplayer:+')
8585
library('dev.lavalink.youtube:common:+')
86+
87+
library("com.google.zxing:core:3.5.4")
88+
library("com.google.zxing:javase:3.5.4")
8689
}
8790

8891
test {

src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
requires luaj.jme;
2020
requires org.apache.logging.log4j;
2121
requires org.mangorage.bootstrap;
22+
requires com.google.zxing;
23+
requires com.google.zxing.javase;
2224

2325

2426
exports org.mangorage.mangobotplugin.entrypoint;

src/main/java/org/mangorage/mangobotplugin/commands/internal/HomeDepotAlertCommand.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package org.mangorage.mangobotplugin.commands.internal;
22

3+
import com.google.zxing.BinaryBitmap;
4+
import com.google.zxing.LuminanceSource;
5+
import com.google.zxing.MultiFormatReader;
6+
import com.google.zxing.Result;
7+
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
8+
import com.google.zxing.common.HybridBinarizer;
39
import net.dv8tion.jda.api.entities.Message;
410
import org.mangorage.commonutils.misc.Arguments;
511
import org.mangorage.mangobotcore.jda.command.api.CommandResult;
612
import org.mangorage.mangobotcore.jda.command.api.ICommand;
713

14+
import javax.imageio.ImageIO;
15+
import java.awt.image.BufferedImage;
816
import java.io.BufferedReader;
17+
import java.io.InputStream;
918
import java.io.InputStreamReader;
1019
import java.net.HttpURLConnection;
1120
import java.net.URL;
@@ -36,6 +45,24 @@ public String usage() {
3645
public CommandResult execute(Message message, Arguments arguments) {
3746
if (message.getAuthor().getIdLong() != 194596094200643584L) return CommandResult.DEVELOPERS_ONLY;
3847
if (message.isFromGuild()) return CommandResult.PASS;
48+
if (!arguments.has(0)) {
49+
50+
final var attachment = message.getAttachments().getFirst();
51+
if (attachment != null) {
52+
executor.submit(() -> {
53+
try {
54+
message.reply(
55+
readQrFromUrl(attachment.getUrl())
56+
).queue();
57+
} catch (Exception e) {
58+
message.reply(e.getMessage()).queue();
59+
}
60+
});
61+
}
62+
63+
return CommandResult.PASS;
64+
}
65+
3966
executor.submit(() -> {
4067
message.reply(
4168
createAssociateTask(
@@ -46,6 +73,23 @@ public CommandResult execute(Message message, Arguments arguments) {
4673
return CommandResult.PASS;
4774
}
4875

76+
public static String readQrFromUrl(String imageUrl) throws Exception {
77+
URL url = new URL(imageUrl);
78+
79+
try (InputStream is = url.openStream()) {
80+
BufferedImage image = ImageIO.read(is);
81+
if (image == null) {
82+
throw new IllegalArgumentException("Not an image. Try again.");
83+
}
84+
85+
LuminanceSource source = new BufferedImageLuminanceSource(image);
86+
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
87+
88+
Result result = new MultiFormatReader().decode(bitmap);
89+
return result.getText();
90+
}
91+
}
92+
4993
/**
5094
* Sends a POST request to Home Depot API to create an associate help task.
5195
* @param taskId The identifier for the task (e.g., "TRA128")
@@ -65,9 +109,11 @@ public static String createAssociateTask(String taskId) {
65109
conn.setRequestProperty("Origin", "https://www.homedepot.com");
66110
conn.setRequestProperty("Referer", "https://www.homedepot.com/");
67111
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36");
112+
conn.setRequestProperty("Content-Type", "application/json");
113+
conn.setRequestProperty("Connection", "keep-alive");
68114

69-
conn.setFixedLengthStreamingMode(0);
70115
conn.setDoOutput(true);
116+
conn.getOutputStream().write(new byte[0]);
71117

72118
int responseCode = conn.getResponseCode();
73119

0 commit comments

Comments
 (0)