Skip to content

Commit 952b4c0

Browse files
committed
Redid some command stuff...
1 parent 1c6f226 commit 952b4c0

18 files changed

Lines changed: 151 additions & 1417 deletions

src/main/java/module-info.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@
3232

3333
exports org.mangorage.mangobotplugin to net.dv8tion.jda;
3434

35-
exports org.mangorage.mangobotplugin.commands.music;
3635
exports org.mangorage.mangobotplugin.pagedlist to net.dv8tion.jda;
3736

3837
opens org.mangorage.mangobotplugin.commands.trick to com.google.gson;
3938
opens org.mangorage.mangobotplugin.commands.trick.lua to com.google.gson;
40-
opens org.mangorage.mangobotplugin.commands.music;
4139

4240

4341
provides Plugin with org.mangorage.mangobotplugin.entrypoint.MangoBot;

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

Lines changed: 0 additions & 163 deletions
This file was deleted.

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

Lines changed: 0 additions & 130 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.mangorage.mangobotplugin.commands.internal.homedepot;
2+
3+
import net.dv8tion.jda.api.entities.Message;
4+
import org.mangorage.mangobotcore.api.command.v1.CommandParseResult;
5+
import org.mangorage.mangobotcore.api.jda.command.v2.AbstractJDACommand;
6+
import org.mangorage.mangobotcore.api.jda.command.v2.JDACommandResult;
7+
8+
public final class HomeDepotCommand extends AbstractJDACommand {
9+
public HomeDepotCommand(String name) {
10+
super(name);
11+
addSubCommand(
12+
new HomeDepotScanQRSubCommand()
13+
);
14+
addSubCommand(
15+
new HomeDepotSendAlertSubCommand()
16+
);
17+
}
18+
19+
@Override
20+
public JDACommandResult run(Message message, String[] strings, CommandParseResult commandParseResult) throws Throwable {
21+
22+
return JDACommandResult.PASS;
23+
}
24+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.mangorage.mangobotplugin.commands.internal.homedepot;
2+
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;
9+
import net.dv8tion.jda.api.entities.Message;
10+
import org.mangorage.mangobotcore.api.command.v1.CommandParseResult;
11+
import org.mangorage.mangobotcore.api.jda.command.v2.AbstractJDACommand;
12+
import org.mangorage.mangobotcore.api.jda.command.v2.JDACommandResult;
13+
14+
import javax.imageio.ImageIO;
15+
import java.awt.image.BufferedImage;
16+
import java.io.InputStream;
17+
import java.net.URL;
18+
19+
public final class HomeDepotScanQRSubCommand extends AbstractJDACommand {
20+
public HomeDepotScanQRSubCommand() {
21+
super("scanqr");
22+
}
23+
24+
@Override
25+
public JDACommandResult run(Message message, String[] strings, CommandParseResult commandParseResult) throws Throwable {
26+
final var attachment = message.getAttachments().getFirst();
27+
if (attachment != null) {
28+
message.reply(
29+
readQrFromUrl(attachment.getUrl())
30+
).queue();
31+
}
32+
return JDACommandResult.PASS;
33+
}
34+
35+
public static String readQrFromUrl(String imageUrl) throws Exception {
36+
URL url = new URL(imageUrl);
37+
38+
try (InputStream is = url.openStream()) {
39+
BufferedImage image = ImageIO.read(is);
40+
if (image == null) {
41+
throw new IllegalArgumentException("Not an image. Try again.");
42+
}
43+
44+
LuminanceSource source = new BufferedImageLuminanceSource(image);
45+
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
46+
47+
Result result = new MultiFormatReader().decode(bitmap);
48+
return result.getText();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)