-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.2.1 merge
- Loading branch information
Showing
19 changed files
with
314 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/main/java/de/voidtech/gerald/commands/fun/ChatCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/de/voidtech/gerald/commands/fun/LmgtfyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/de/voidtech/gerald/commands/info/JishoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package main.java.de.voidtech.gerald.commands.info; | ||
|
||
import java.awt.Color; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.microsoft.playwright.Page; | ||
|
||
import main.java.de.voidtech.gerald.annotations.Command; | ||
import main.java.de.voidtech.gerald.commands.AbstractCommand; | ||
import main.java.de.voidtech.gerald.commands.CommandCategory; | ||
import main.java.de.voidtech.gerald.service.PlaywrightService; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
||
@Command | ||
public class JishoCommand extends AbstractCommand { | ||
|
||
@Autowired | ||
private PlaywrightService playwrightService; | ||
|
||
private static final String JISHO_BASE_URL = "https://jisho.org/search/"; | ||
|
||
@Override | ||
public void executeInternal(Message message, List<String> args) { | ||
message.getChannel().sendTyping().queue(); | ||
String search = JISHO_BASE_URL + String.join("+", args); | ||
byte[] resultImage = getJishoScreenshot(search); | ||
message.getChannel().sendMessage(constructResultEmbed(search)) | ||
.addFile(resultImage, "screenshot.png").queue(); | ||
} | ||
|
||
private MessageEmbed constructResultEmbed(String url) { | ||
MessageEmbed jishoEmbed = new EmbedBuilder() | ||
.setColor(Color.ORANGE) | ||
.setTitle("**Your Search Result:**", url) | ||
.setImage("attachment://screenshot.png") | ||
.setFooter("Powered by Jisho") | ||
.build(); | ||
return jishoEmbed; | ||
} | ||
|
||
private byte[] getJishoScreenshot(String search) { | ||
Page jishoPage = playwrightService.getBrowser().newPage(); | ||
jishoPage.navigate(search); | ||
jishoPage.setViewportSize(1200, 1500); | ||
byte[] screenshotBytesBuffer = jishoPage.screenshot(); | ||
jishoPage.close(); | ||
|
||
return screenshotBytesBuffer; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Allows you to get some translations from jisho! Jisho translates English to Japanese"; | ||
} | ||
|
||
@Override | ||
public String getUsage() { | ||
return "jisho [english to be translated]"; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "jisho"; | ||
} | ||
|
||
@Override | ||
public CommandCategory getCommandCategory() { | ||
return CommandCategory.INFO; | ||
} | ||
|
||
@Override | ||
public boolean isDMCapable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean requiresArguments() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String[] getCommandAliases() { | ||
String[] aliases = {"japanese"}; | ||
return aliases; | ||
} | ||
|
||
@Override | ||
public boolean canBeDisabled() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.