Skip to content

Commit

Permalink
Changed LanguageEngine.class acc. to #48
Browse files Browse the repository at this point in the history
Cleaned up the language engine quite a bit and added support for simple String answers instead of embedded messages.
  • Loading branch information
Gregor7008 committed Oct 28, 2022
1 parent 1e27cba commit b2f5093
Show file tree
Hide file tree
Showing 48 changed files with 399 additions and 353 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ On the [29th of August 2021](https://github.com/Gregor7008/Butler-George/commit/
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If you aren't familiar with GitHub: [Reach out](https://github.com/Gregor7008/Butler-George/tree/V2#-contact-us) to us we're grateful to help!<br>

1. #### Quick Start
We currently have 5 languages to choose from: English (`en`), German (`de`), Spanish (`es`), French (`fr`) and Dutch (`nl`).<br>
To start translating, please copy the default `en` folder in `src/main/resources/languages` and rename it to either one of the already supported abbreviations or to the two letter abbreviation of a new language.<br>
We currently have 5 languages to choose from: English , German , Spanish , French and Dutch .<br>
To start translating, please copy the default `english` folder in `src/main/resources/languages` and rename it to either one of the already supported languages (lower case only) or any new language.<br>
<ins>**Please note:**</ins> A new language will not be available as soon as the folder is created, as we have add it to the bots internal list!

2. #### Keywords
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/assets/base/AwaitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public boolean complete(T event) {
try {
this.eventConsumer.accept(event);
} catch (InsufficientPermissionException e) {
MessageEmbed embed = LanguageEngine.fetchMessage(null, null, null, "insufficientperms")
MessageEmbed embed = LanguageEngine.getMessageEmbed(null, null, null, "insufficientperms")
.replaceDescription("{permissions}", e.getPermission().getName().toLowerCase());
if (event instanceof IMessageEditCallback) {
IMessageEditCallback messageEditCallbackEvent = (IMessageEditCallback) event;
Expand Down Expand Up @@ -204,9 +204,9 @@ private AwaitTask<T> timeout() {
this.cancelled = true;
};
if (message != null) {
message.editMessageEmbeds(LanguageEngine.fetchMessage(guild, user, null, keyword)).setComponents().queue(s -> {}, failureConsumer);
message.editMessageEmbeds(LanguageEngine.getMessageEmbed(guild, user, null, keyword)).setComponents().queue(s -> {}, failureConsumer);
} else {
channel.sendMessageEmbeds(LanguageEngine.fetchMessage(guild, user, null, keyword)).setComponents().queue(s -> {}, failureConsumer);
channel.sendMessageEmbeds(LanguageEngine.getMessageEmbed(guild, user, null, keyword)).setComponents().queue(s -> {}, failureConsumer);
}
}
return this;
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/assets/base/CustomMessageEmbed.java

This file was deleted.

54 changes: 54 additions & 0 deletions src/main/java/assets/base/MutableMessageEmbed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package assets.base;

import com.mongodb.lang.Nullable;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;

public class MutableMessageEmbed extends MessageEmbed {

EmbedBuilder eb = new EmbedBuilder();

public MutableMessageEmbed(MessageEmbed embed) {
super(embed.getUrl(), embed.getTitle(), embed.getDescription(), embed.getType(), embed.getTimestamp(),
embed.getColorRaw(), embed.getThumbnail(), embed.getSiteProvider(), embed.getAuthor(),
embed.getVideoInfo(), embed.getFooter(), embed.getImage(), embed.getFields());
eb.copyFrom(embed);
}

public MutableMessageEmbed replaceTitle(String target, String replacement) {
eb.setTitle(this.getTitle().replace(target, replacement));
return new MutableMessageEmbed(eb.build());
}

public MutableMessageEmbed replaceDescription(String target, String replacement) {
eb.setDescription(this.getDescription().replace(target, replacement));
return new MutableMessageEmbed(eb.build());
}

public MutableMessageEmbed setTitle(String title) {
eb.setTitle(title);
return new MutableMessageEmbed(eb.build());
}

public MutableMessageEmbed setDescription(String description) {
eb.setDescription(description);
return new MutableMessageEmbed(eb.build());
}

public MutableMessageEmbed setFooter(String replacement, @Nullable String iconURL) {
eb.setFooter(replacement, iconURL);
return new MutableMessageEmbed(eb.build());
}

public MutableMessageEmbed setAuthor(Member member) {
eb.setAuthor(member.getEffectiveName(), member.getAvatarUrl());
return new MutableMessageEmbed(eb.build());
}

public MutableMessageEmbed setThumbnail(String url) {
eb.setThumbnail(url);
return new MutableMessageEmbed(eb.build());
}
}
11 changes: 2 additions & 9 deletions src/main/java/assets/data/single/AutoMessageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,9 @@ public MessageCreateAction buildMessage(User user) {
String title_edit = Toolbox.processAutoMessage(title, guild, user, false);
String message_edit = Toolbox.processAutoMessage(message, guild, user, true);
if (embedded) {
return text_channel.sendMessageEmbeds(LanguageEngine.buildMessage(title_edit, message_edit, null));
return text_channel.sendMessageEmbeds(LanguageEngine.buildMessageEmbed(title_edit, message_edit));
} else {
StringBuilder sB = new StringBuilder();
if (!title.isBlank()) {
sB.append("**" + title_edit + "**\n");
}
if (!message.isBlank()) {
sB.append(message_edit);
}
return text_channel.sendMessage(sB.toString());
return text_channel.sendMessage(LanguageEngine.buildMessage(title_edit, message_edit));
}
} else {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/base/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void shutdown(ShutdownReason reason, @Nullable String additionalMessage)
offlineMessageBuilder.append(LanguageEngine.getRaw(guild, null, this, "addonpresent"));
offlineMessageBuilder.append(additionalMessage);
}
long msgid = guild.getTextChannelById(chid).sendMessageEmbeds(LanguageEngine.buildMessageFromRaw(offlineMessageBuilder.toString(), null)).complete().getIdLong();
long msgid = guild.getTextChannelById(chid).sendMessageEmbeds(LanguageEngine.buildMessageEmbed(offlineMessageBuilder.toString())).complete().getIdLong();
ConfigLoader.INSTANCE.getGuildConfig(guild).put("offlinemsg", new JSONArray().put(msgid).put(chid));
// Save ModMail status
JSONObject modmailDataSet = ConfigLoader.INSTANCE.getGuildConfig(guild, "modmails");
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/base/EventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
try {
slashCommandEventHandler.execute(event);
} catch (InsufficientPermissionException e) {
MessageEmbed embed = LanguageEngine.fetchMessage(event.getGuild(), event.getUser(), null, "insufficientperms")
MessageEmbed embed = LanguageEngine.getMessageEmbed(event.getGuild(), event.getUser(), null, "insufficientperms")
.replaceDescription("{permissions}", e.getPermission().getName().toLowerCase());
if (event.isAcknowledged()) {
event.getHook().retrieveOriginal().complete().editMessageEmbeds(embed).queue();
Expand All @@ -120,7 +120,7 @@ public void onUserContextInteraction(UserContextInteractionEvent event) {
try {
userContextEventHandler.execute(event);
} catch (InsufficientPermissionException e) {
MessageEmbed embed = LanguageEngine.fetchMessage(event.getGuild(), event.getUser(), null, "insufficientperms")
MessageEmbed embed = LanguageEngine.getMessageEmbed(event.getGuild(), event.getUser(), null, "insufficientperms")
.replaceDescription("{permissions}", e.getPermission().getName().toLowerCase());
if (event.isAcknowledged()) {
event.getHook().retrieveOriginal().complete().editMessageEmbeds(embed).queue();
Expand All @@ -143,7 +143,7 @@ public void onMessageContextInteraction(MessageContextInteractionEvent event) {
try {
messageContextEventHandler.execute(event);
} catch (InsufficientPermissionException e) {
MessageEmbed embed = LanguageEngine.fetchMessage(event.getGuild(), event.getUser(), null, "insufficientperms")
MessageEmbed embed = LanguageEngine.getMessageEmbed(event.getGuild(), event.getUser(), null, "insufficientperms")
.replaceDescription("{permissions}", e.getPermission().getName().toLowerCase());
if (event.isAcknowledged()) {
event.getHook().retrieveOriginal().complete().editMessageEmbeds(embed).queue();
Expand Down Expand Up @@ -177,7 +177,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
} else {
final JSONArray selectedTicketData = ConfigLoader.INSTANCE.getUserConfig(user).getJSONArray("selected_ticket");
if (selectedTicketData.isEmpty()) {
event.getChannel().sendMessageEmbeds(LanguageEngine.fetchMessage(null, user, this, "noticket")).queue();
event.getChannel().sendMessageEmbeds(LanguageEngine.getMessageEmbed(null, user, this, "noticket")).queue();
} else {
final Guild guild = event.getJDA().getGuildById(selectedTicketData.getLong(0));
final long ticketID = selectedTicketData.getLong(1);
Expand Down Expand Up @@ -212,7 +212,7 @@ public void onGuildMemberJoin(GuildMemberJoinEvent event) {
if (welcomemsg.getBoolean(3)) {
String title = Toolbox.processAutoMessage(welcomemsg.getString(1), guild, event.getUser(), false);
String message = Toolbox.processAutoMessage(welcomemsg.getString(2), guild, event.getUser(), true);
guild.getTextChannelById(welcomemsg.getLong(0)).sendMessageEmbeds(LanguageEngine.buildMessage(title, message, null)).queue();
guild.getTextChannelById(welcomemsg.getLong(0)).sendMessageEmbeds(LanguageEngine.buildMessageEmbed(title, message)).queue();
}
}
}
Expand All @@ -231,7 +231,7 @@ public void onGuildMemberRemove(GuildMemberRemoveEvent event) {
if (goodbyemsg.getBoolean(3)) {
String title = Toolbox.processAutoMessage(goodbyemsg.getString(1), guild, event.getUser(), false);
String message = Toolbox.processAutoMessage(goodbyemsg.getString(2), guild, event.getUser(), true);
guild.getTextChannelById(goodbyemsg.getLong(0)).sendMessageEmbeds(LanguageEngine.buildMessage(title, message, null)).queue();
guild.getTextChannelById(goodbyemsg.getLong(0)).sendMessageEmbeds(LanguageEngine.buildMessageEmbed(title, message)).queue();
}
}
if (ConfigLoader.INSTANCE.getMemberConfig(guild, user).getLong("customchannelcategory") != 0) {
Expand All @@ -258,7 +258,7 @@ public void onGuildMemberUpdateBoostTime(GuildMemberUpdateBoostTimeEvent event)
if (boostmsg.getBoolean(3)) {
String title = Toolbox.processAutoMessage(boostmsg.getString(1), guild, user, false);
String message = Toolbox.processAutoMessage(boostmsg.getString(2), guild, user, true);
guild.getTextChannelById(boostmsg.getLong(0)).sendMessageEmbeds(LanguageEngine.buildMessage(title, message, null)).queue();
guild.getTextChannelById(boostmsg.getLong(0)).sendMessageEmbeds(LanguageEngine.buildMessageEmbed(title, message)).queue();
}
}
}
Expand Down Expand Up @@ -377,14 +377,14 @@ public void onButtonInteraction(ButtonInteractionEvent event) {
} else if (buttonId.equals(buttonIdCriteria + "_denyclose")) {
final PrivateChannel userChannel = targetUser.openPrivateChannel().complete();
userChannel.retrieveMessageById(channelProperties.getLong(2)).complete().delete().queue();
userChannel.sendMessageEmbeds(LanguageEngine.fetchMessage(guild, targetUser, modmailCommandHandler, "closeDeniedPrivate")
userChannel.sendMessageEmbeds(LanguageEngine.getMessageEmbed(guild, targetUser, modmailCommandHandler, "closeDeniedPrivate")
.replaceDescription("{guild}", guild.getName())
.replaceDescription("{title}", ConfigLoader.INSTANCE.getMemberConfig(guild, targetUser)
.getJSONObject("modmails")
.getJSONArray(String.valueOf(channelProperties.getLong(1)))
.getString(1)))
.queue();
event.editMessageEmbeds(LanguageEngine.fetchMessage(guild, event.getUser(), modmailCommandHandler, "closeDeniedAdmin")).setComponents().queue();
event.editMessageEmbeds(LanguageEngine.getMessageEmbed(guild, event.getUser(), modmailCommandHandler, "closeDeniedAdmin")).setComponents().queue();
}
}
}
Expand Down
Loading

0 comments on commit b2f5093

Please sign in to comment.