Skip to content

Commit

Permalink
Version 1.2.1 merge
Browse files Browse the repository at this point in the history
Version 1.2.1 merge
  • Loading branch information
Montori authored Jul 1, 2021
2 parents 2434304 + 6554de4 commit 7b33ec5
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/voidtech/gerald/GlobalConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public class GlobalConstants {
public static final String STREAM_URL = "https://twitch.tv/elementalmp4";
public static final String LINKTREE_URL = "https://linktr.ee/GeraldBot";
public static final String INVITE_URL = "https://discord.com/api/oauth2/authorize?client_id=555816892141404163&permissions=805694544&scope=bot";
public static final String VERSION = "1.2.0 - Mucho Mocha";
public static final String VERSION = "1.2.1 - Mucho Mocha";
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private String getStatsString(String giver, String receiver, ActionType action,
return statsString;
}

public void sendAction(Message message, ActionType action) {
public void sendAction(Message message, ActionType action) {
if(message.getMentionedMembers().isEmpty()) {
message.getChannel().sendMessage("You need to mention someone to " + action.getType() + "!").queue();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package main.java.de.voidtech.gerald.commands.fun;

import java.awt.*;
import java.awt.Color;
import java.util.List;

import main.java.de.voidtech.gerald.GlobalConstants;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import main.java.de.voidtech.gerald.GlobalConstants;
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.entities.ChatChannel;
import main.java.de.voidtech.gerald.service.ChatbotService;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;

@Command
public class ChatCommand extends AbstractCommand{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void sendWebhookMessage(Message message, List<String> args, Member membe
for (int i = 1; i < args.size(); i++) {
messageToBeSent += args.get(i) + " ";
}
Webhook impersonateHook = webhookManager.getOrCreateWebhook((TextChannel) message.getChannel(), "BGImpersonate");
Webhook impersonateHook = webhookManager.getOrCreateWebhook((TextChannel) message.getChannel(), "BGImpersonate", message.getJDA().getSelfUser().getId());
webhookManager.postMessage(messageToBeSent, memberToBeImpersonated.getUser().getAvatarUrl(), memberToBeImpersonated.getUser().getName(), impersonateHook);
message.delete().queue();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main.java.de.voidtech.gerald.commands.fun;

import java.util.List;

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 net.dv8tion.jda.api.entities.Message;

import java.util.List;

@Command
public class LmgtfyCommand extends AbstractCommand {

Expand Down
58 changes: 25 additions & 33 deletions src/main/java/de/voidtech/gerald/commands/info/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public class HelpCommand extends AbstractCommand{
private List<AbstractCommand> commands;

@Autowired
MessageHandler msgHandler;
private MessageHandler msgHandler;

private static final String TRUE_EMOTE = "\u2705";
private static final String FALSE_EMOTE = "\u274C";

private String capitaliseFirstLetter(String word) {
return word.substring(0, 1).toUpperCase() + word.substring(1);
Expand Down Expand Up @@ -53,19 +56,17 @@ private void showCategoryList(Message message) {

private boolean isCommandCategory(String categoryName) {
for (CommandCategory commandCategory : CommandCategory.values()) {
if (commandCategory.getCategory().equals(categoryName)) {
if (commandCategory.getCategory().equals(categoryName))
return true;
}
}
return false;
};


private String getCategoryIconByName(String name) {
for (CommandCategory commandCategory : CommandCategory.values()) {
if (commandCategory.getCategory().equals(name)) {
if (commandCategory.getCategory().equals(name))
return commandCategory.getIcon();
}
}
return "";
}
Expand All @@ -75,10 +76,9 @@ private boolean isCommand(String commandName) {
if (msgHandler.aliases.containsKey(commandToBeFound)) {
return true;
} else {
for (AbstractCommand command : commands) {
for (AbstractCommand command : commands)
if(command.getName().equals(commandToBeFound)) {
return true;
}
}
}
return false;
Expand All @@ -87,9 +87,8 @@ private boolean isCommand(String commandName) {
private void showCommandCategory(Message message, String categoryName) {
String commandList = "";
for (AbstractCommand command : commands) {
if(command.getCommandCategory().getCategory().equals(categoryName)) {
if(command.getCommandCategory().getCategory().equals(categoryName))
commandList = commandList + "`" + command.getName() + "`, ";
}
}
commandList = commandList.substring(0, commandList.length() - 2);

Expand All @@ -106,13 +105,11 @@ private void showCommandCategory(Message message, String categoryName) {

private AbstractCommand getCommand(String name) {
String commandToBeFound = name;
if (msgHandler.aliases.containsKey(name)) {
if (msgHandler.aliases.containsKey(name))
commandToBeFound = msgHandler.aliases.get(name);
}
for (AbstractCommand command : commands) {
if(command.getName().equals(commandToBeFound)) {
if(command.getName().equals(commandToBeFound))
return command;
}
}
return null;
}
Expand All @@ -128,37 +125,30 @@ private void showCommand(Message message, String commandName) {
.addField("Category", "```" + capitaliseFirstLetter(commandToBeDisplayed.getCommandCategory().getCategory()) + "```", true)
.addField("Description", "```" + commandToBeDisplayed.getDescription() + "```", false)
.addField("Usage", "```" + commandToBeDisplayed.getUsage() + "```", false)
.addField("Requires Arguments", "```" + commandToBeDisplayed.requiresArguments() + "```", true)
.addField("Is DM Capable", "```" + commandToBeDisplayed.isDMCapable() + "```", true)
.addField("Requires Arguments", "```" + showBooleanEmote(commandToBeDisplayed.requiresArguments()) + "```", true)
.addField("Is DM Capable", "```" + showBooleanEmote(commandToBeDisplayed.isDMCapable()) + "```", true)
.addField("Command Aliases", "```" + String.join(", ", commandToBeDisplayed.getCommandAliases()) + "```", false)
.setFooter("Barista Gerald Version " + GlobalConstants.VERSION, message.getJDA().getSelfUser().getAvatarUrl())
.build();
message.getChannel().sendMessage(commandHelpEmbed).queue();
}

private String showBooleanEmote(boolean option) {
return option ? TRUE_EMOTE : FALSE_EMOTE;
}

@Override
public void executeInternal(Message message, List<String> args) {
if (!commands.contains(this)) commands.add(this);

//Don't ask...
if (!commands.contains(this)) {
commands.add(this);
}

if (args.size() == 0) {
if (args.size() == 0)
showCategoryList(message);
} else {

else {
String itemToBeQueried = args.get(0).toLowerCase();

if (isCommandCategory(itemToBeQueried)) {
showCommandCategory(message, itemToBeQueried);
} else if (isCommand(itemToBeQueried)) {
showCommand(message, itemToBeQueried);
} else {
message.getChannel().sendMessage("**That command/category could not be found!**").queue();
}
if (isCommandCategory(itemToBeQueried)) showCommandCategory(message, itemToBeQueried);
else if (isCommand(itemToBeQueried)) showCommand(message, itemToBeQueried);
else message.getChannel().sendMessage("**That command/category could not be found!**").queue();
}

}

@Override
Expand All @@ -168,7 +158,9 @@ public String getDescription() {

@Override
public String getUsage() {
return "help OR help [name of command] OR help [name of category]";
return "help\n"
+ "help [name of command]\n"
+ "help [name of category]";
}

@Override
Expand Down
96 changes: 96 additions & 0 deletions src/main/java/de/voidtech/gerald/commands/info/JishoCommand.java
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class TwitchCommand extends AbstractCommand{
private static final String TWITCH_URL_MATCHER = "https:\\/\\/(www\\.)?twitch.tv\\/.*";

private boolean validTwitchUrl(String streamerUrl) {
return streamerUrl.matches(TWITCH_URL_MATCHER) && Arrays.asList(streamerUrl.split("/")).size() == 4;
return streamerUrl.matches(TWITCH_URL_MATCHER);
}

private boolean validChannelId(String channelId, Message message) {
Expand Down Expand Up @@ -138,6 +138,9 @@ private void streamerSetupGetMessage(Message message, String streamerName, Strin
}

private void streamerSetupFinishSetup(Message message, String streamerName, String channelId, String notificationMessage) {
System.out.println(streamerName);
System.out.println(channelId);
System.out.println(notificationMessage);
message.getChannel().sendMessage("**Setup completed!**\n\nStreamer Url: " + TWITCH_BASE_URL + streamerName + "\nChannel: <#" + channelId + ">\nNotification Message: " + notificationMessage).queue();
twitchService.addSubscription(streamerName, channelId, notificationMessage, serverService.getServer(message.getGuild().getId()).getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class RoutineCommand extends AbstractCommand {

@Autowired
private ServerService serverService;

private static final String TRUE_EMOTE = "\u2705";
private static final String FALSE_EMOTE = "\u274C";

@Override
public void executeInternal(Message message, List<String> args) {
Expand All @@ -33,11 +36,12 @@ public void executeInternal(Message message, List<String> args) {
.setTitle("Barista Gerald - Routines")
.setThumbnail(message.getJDA().getSelfUser().getAvatarUrl())
.setFooter("Routine Count: "+ routineCount + " | Note: Some routines cannot be disabled. The commands they power require them to function. Try disabling the command instead!");

for (AbstractRoutine routine: routines) {
routineInformation.addField(routine.getName(), String.format("Description: %s\nCan be disabled: %s\nIs disabled Here: %s",
routineInformation.addField(routine.getName(), String.format("```Description: %s\nCan be disabled: %s\nIs disabled Here: %s```",
routine.getDescription(),
routine.canBeDisabled() ? ":white_check_mark:" : ":x:",
server.getRoutineBlacklist().contains(routine.getName()) ? ":white_check_mark:" : ":x:"),
routine.canBeDisabled() ? TRUE_EMOTE : FALSE_EMOTE,
server.getRoutineBlacklist().contains(routine.getName()) ? TRUE_EMOTE : FALSE_EMOTE),
false);
}
message.getChannel().sendMessage(routineInformation.build()).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import main.java.de.voidtech.gerald.GlobalConstants;
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.entities.GlobalConfig;
import main.java.de.voidtech.gerald.service.GeraldConfig;
import main.java.de.voidtech.gerald.service.GlobalConfigService;
import net.dv8tion.jda.api.entities.Activity.ActivityType;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.internal.entities.EntityBuilder;
import main.java.de.voidtech.gerald.commands.CommandCategory;
import main.java.de.voidtech.gerald.entities.GlobalConfig;

@Command
public class ActivityCommand extends AbstractCommand {
Expand Down
Loading

0 comments on commit 7b33ec5

Please sign in to comment.