Skip to content

Commit

Permalink
v7.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
deso85 committed Dec 23, 2023
1 parent 95c78eb commit a4e4245
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Antony</groupId>
<artifactId>Antony</artifactId>
<version>7.12.0</version>
<version>7.12.1</version>

<properties>
<resteasy.version>6.2.6.Final</resteasy.version>
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/bot/antony/commands/AntonyCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

public class AntonyCmd extends ServerCommand {

Member member;
GuildMessageChannel channel;

// --------------------------------------------------
// Constructor
// --------------------------------------------------
Expand All @@ -29,41 +32,58 @@ public AntonyCmd() {
// --------------------------------------------------
@Override
public void performCommand(Member member, GuildMessageChannel channel, Message message) {
this.member = member;
this.channel = channel;

String[] userMessage = message.getContentDisplay().split(" ");
if (userMessage.length > 1) {
switch (userMessage[1].toLowerCase()) {
case "help":
printHelp(channel);
break;
default:
channel.sendMessageEmbeds(getCommandList(member).build()).queue();
listCommands();
break;
}
} else {
channel.sendMessageEmbeds(getCommandList(member).build()).queue();
listCommands();
}
}

private EmbedBuilder getCommandList(Member member) {
private void listCommands() {
StringBuilder ebField;
EmbedBuilder eb = new EmbedBuilder().setTitle("***Antony***")
.setColor(Antony.getBaseColor())
.setDescription("Du kannst folgende Befehle nutzen:")
.setThumbnail(member.getJDA().getSelfUser().getEffectiveAvatarUrl())
.setFooter("Version " + Antony.getVersion());
.setThumbnail(member.getJDA().getSelfUser().getEffectiveAvatarUrl());


int fieldCounter = 0;
for(Entry<String, ServerCommand> entry : Antony.getCmdMan().getAvailableCommands(member).entrySet()) {

if(fieldCounter >= 25) { //Embed may only have 25 fields
channel.sendMessageEmbeds(eb.build()).queue();
eb = new EmbedBuilder()
.setColor(Antony.getBaseColor());
fieldCounter = 0;
}

ebField = new StringBuilder();
ebField.append(entry.getValue().getDescription());
if(entry.getValue().getDescription().isEmpty()) {
System.out.println("ALARM!");
}
if(entry.getValue().getExample() != null && !entry.getValue().getExample().isEmpty()) {
ebField.append("\n*__Beispiel:__ "
+ Antony.getCmdPrefix() + entry.getValue().getName() + " "
+ entry.getValue().getExample() + "*");
}
eb.addField(Antony.getCmdPrefix() + entry.getValue().getName(), ebField.toString(), false);

fieldCounter++;
}

return eb;
eb.setFooter("Version " + Antony.getVersion());
channel.sendMessageEmbeds(eb.build()).queue();
}

/**
Expand All @@ -78,7 +98,6 @@ private EmbedBuilder getCommandList(Member member) {
BotCommand pnlink = new BotCommand("pnlink", "Gibt einen formatierten Text für einen Kanal aus, der z.B. in PNs genutzt werden kann, um Kanäle zu verlinken, was über # nicht möglich ist. (Das letzte Leerzeichen der Ausgabe muss entfernt werden)", "#kanal1");
BotCommand sells = new BotCommand("sells", "Listet zu der gesuchten Ameisenart alle Shops und zugehörigen Preise. Die Shops werden nach Namen sortiert ausgegeben. Die Daten werden von https://antcheck.info zur Verfügung gestellt. Vielen Dank hierfür!", "Lasius niger");
BotCommand serverstats = new BotCommand("serverstats", "Zeigt Serverstatistiken.");
BotCommand userinfo = new BotCommand("userinfo", "Zeigt Details über den Benutzer.", "Antony");
//Commands for mods
BotCommand user = new BotCommand("user", "Funktion zur Verwaltung von Discord Usern.");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bot/antony/commands/ChangelogCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void performCommand(Member member, GuildMessageChannel channel, Message m
private List<ChangeLogEntry> getChangeLog(int limit) {
String cmdPrefix = Antony.getCmdPrefix();
List<ChangeLogEntry> changeLog = new ArrayList<ChangeLogEntry>();
changeLog.add(new ChangeLogEntry("23.12.2023 - Version 7.12.1", "Korrektur am Befehl ***" + cmdPrefix + "antony*** eingebaut, der nicht funktioniert hatte, wenn man zu viele Befehle ausführen darf. Das \"Escapen\" von Zeichen in z.B. Namen wurde in eine zentrale Funktion überführt und damit auch Fehler in manchen Ausgaben von Funktionen behoben. Die User-Info wird nun für verschiedene Funktionen zentral generiert."));
changeLog.add(new ChangeLogEntry("17.12.2023 - Version 7.12.0", "Die administrative Funktion ***" + cmdPrefix + "shoppingmanager*** wurde hinzugefügt. Den Befehl ***" + cmdPrefix + "shopping*** greift nun auf eine separat gespeicherte Liste zu."));
changeLog.add(new ChangeLogEntry("10.12.2023 - Version 7.11.0", "Der Befehl ***" + cmdPrefix + "shops*** wurde hinzugefügt. Über diesen Befehl lassen sich alle bekannten Shops, auch gefiltert, ausgeben. Zudem wurde eine Korrektur für den Befehl ***" + cmdPrefix + "userinfo*** implementiert, um durch Sonderzeichen hervorgerufene Anzeigefehler zu beheben. Ein paar Programmbibliotheken wurden aktualisiert."));
changeLog.add(new ChangeLogEntry("20.09.2023 - Version 7.10.4", "Die administrative Reaction zum Anzeigen des Avatars wurde dahingehend überarbeitet, dass nun auch der serverspezifische Avatar angezeigt wird, sofern dieser von dem User-Avatar abweicht. Der Befehl ***" + cmdPrefix + "showavatar*** zeigt weiterhin nur den für den Server gültigen Avatar. Zudem gibt ***" + cmdPrefix + "serverstats*** nun auch die Info aus, wann der Server erstellt wurde."));
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/bot/antony/commands/UserInfoCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,7 @@ public void performCommand(Member member, GuildMessageChannel channel, Message m


if(outputlight) {
StringBuilder sb = new StringBuilder();

sb.append("ID: " + getMember().getId() + "\n");
sb.append("Tag: " + getMember().getUser().getAsTag().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*") + "\n");
sb.append("Name: " + getMember().getUser().getName().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*"));
if(getMember().getNickname() != null) {
sb.append("\nNickname: " + getMember().getNickname().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*"));
}

channel.sendMessage(sb.toString()).queue();
channel.sendMessage(Utils.getAllUserInfos(getMember())).queue();
} else {
channel.sendMessageEmbeds(getUserEB().build()).queue();
}
Expand Down Expand Up @@ -195,9 +186,9 @@ private EmbedBuilder getUserEB() {
//Build Title or Author
StringBuilder ebHeadline = new StringBuilder();
ebHeadline.append(getMemberOnlineStatus() + " ");
ebHeadline.append(getMember().getUser().getAsTag());
ebHeadline.append(Utils.escapeControlChars(getMember().getUser().getAsTag()));
if (getMember().getNickname() != null) {
ebHeadline.append(" - " + getMember().getNickname());
ebHeadline.append(" - " + Utils.escapeControlChars(getMember().getNickname()));
}

//Build status string
Expand Down Expand Up @@ -227,10 +218,10 @@ private EmbedBuilder getUserEB() {
.addField("Zuletzt online gesehen", lastOnline, false);

if(names.length() > 0) {
eb.addField("Bekannte Namen", names.toString().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*"), false);
eb.addField("Bekannte Namen", Utils.escapeControlChars(names.toString()), false);
}
if(nicknames.length() > 0) {
eb.addField("Bekannte Nicknames", nicknames.toString().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*"), false);
eb.addField("Bekannte Nicknames", Utils.escapeControlChars(nicknames.toString()), false);
}

eb.setFooter("Member #" + (getMemberList().indexOf(getMember())+1) + " | User ID: " + getMember().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import bot.antony.Antony;
import bot.antony.events.softban.UserDataSB;
import bot.antony.utils.Utils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
Expand All @@ -31,7 +32,7 @@ public void perform(MessageReactionAddEvent event) {
setVariables(event);
if(shallTrigger(event.getMember())) {
removeReaction();
UserDataSB user = new UserDataSB(message.getAuthor().getId(), message.getAuthor().getName());
UserDataSB user = new UserDataSB(message.getAuthor().getId(), Utils.escapeControlChars(message.getAuthor().getName()));
String logMsg = "";
if(Antony.getSoftbanController().ban(user)) {
logMsg = "🔨 User soft banned by " + reactor.getAsMention();
Expand All @@ -41,7 +42,7 @@ public void perform(MessageReactionAddEvent event) {
}
} else {
Antony.getSoftbanController().unban(user);
logMsg = "🔨 Softban removed from user \"" + user.getName() + "\" by " + reactor.getAsMention();
logMsg = "🔨 Softban removed from user \"" + Utils.escapeControlChars(user.getName()) + "\" by " + reactor.getAsMention();
if(responseChannel != null) {
responseChannel.sendMessage(logMsg).complete();
}
Expand Down Expand Up @@ -74,7 +75,7 @@ public EmbedBuilder getEmbedBuilder() {
TextChannel txtChan = message.getChannel().asTextChannel();
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.red)
.setAuthor(message.getAuthor().getAsTag() + " | ID: " + message.getAuthor().getId(), null, message.getAuthor().getAvatarUrl())
.setAuthor(Utils.escapeControlChars(message.getAuthor().getAsTag()) + " | ID: " + message.getAuthor().getId(), null, message.getAuthor().getAvatarUrl())
.setDescription(message.getContentDisplay())
.addField("#" + txtChan.getName(), "**[Hier klicken, um zur Nachricht zu kommen.](https://discord.com/channels/" + guild.getId() + "/" + txtChan.getId() + "/" + message.getId() + ")**", false)
.setFooter(formatter.format(date));
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/bot/antony/events/reaction/add/ImageReaction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bot.antony.events.reaction.add;

import bot.antony.Antony;
import bot.antony.utils.Utils;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;

public class ImageReaction extends MessageReaction {
Expand Down Expand Up @@ -28,15 +29,8 @@ public void perform(MessageReactionAddEvent event) {
}

public void printUserinfo() {
StringBuilder sb = new StringBuilder();
sb.append("ID: " + message.getAuthor().getId() + "\n");
sb.append("Tag: " + message.getAuthor().getAsTag() + "\n");
sb.append("Name: " + message.getAuthor().getName());
if(message.getMember().getNickname() != null) {
sb.append("\nNickname: " + message.getMember().getNickname());
}
if(responseChannel != null) {
responseChannel.sendMessage(sb.toString()).queue();
responseChannel.sendMessage(Utils.getAllUserInfos(message.getMember())).queue();
if(!message.getAuthor().getEffectiveAvatarUrl().equals(message.getMember().getEffectiveAvatarUrl())) {
responseChannel.sendMessage("Avatar:").queue();
responseChannel.sendMessage(message.getAuthor().getEffectiveAvatarUrl() + "?size=2048").queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ private boolean toggleVoiceMute() {
private void printInfo(boolean muted) {
StringBuilder sb = new StringBuilder();
sb.append("ID: " + message.getAuthor().getId() + "\n");
sb.append("Tag: " + message.getAuthor().getAsTag() + "\n");
sb.append("Name: " + message.getAuthor().getName());
sb.append("Tag: " + Utils.escapeControlChars(message.getAuthor().getAsTag()) + "\n");
sb.append("Name: " + Utils.escapeControlChars(message.getAuthor().getName()));
if(message.getMember().getNickname() != null) {
sb.append("\nNickname: " + message.getMember().getNickname());
sb.append("\nNickname: " + Utils.escapeControlChars(message.getMember().getNickname()));
}
if(responseChannel != null) {
if(muted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void perform(MessageReactionAddEvent event) {
setVariables(event);
if(shallTrigger(event.getMember())) {
UserData usrData = new UserData(reactor);
logMessage.append("User [" + usrData.toString() + "] REDFLAGGED "
logMessage.append("User [" + Utils.escapeControlChars(usrData.toString()) + "] REDFLAGGED "
+ "message [" + message.getId() + "] "
+ "in channel #" + message.getChannel().getName() + " (CID: " + message.getChannel().getId() + ").");

Expand Down Expand Up @@ -97,7 +97,7 @@ public void printHeader() {
if(reactor.getUser().equals(user)) {
sb.append("__");
}
sb.append(user.getAsTag() + " (" + user.getId() + ")");
sb.append(Utils.escapeControlChars(user.getAsTag()) + " (" + user.getId() + ")");
if(reactor.getUser().equals(user)) {
sb.append("__");
}
Expand All @@ -117,7 +117,7 @@ public void printMessageEmbed() {
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm");
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.red)
.setAuthor(message.getAuthor().getAsTag() + " | ID: " + message.getAuthor().getId(), null, message.getAuthor().getAvatarUrl())
.setAuthor(Utils.escapeControlChars(message.getAuthor().getAsTag()) + " | ID: " + message.getAuthor().getId(), null, message.getAuthor().getAvatarUrl())
.setDescription(message.getContentDisplay())
.addField("#" + message.getChannel().getName(), "**[Hier klicken, um zur Nachricht zu kommen.](https://discord.com/channels/" + guild.getId() + "/" + message.getChannel().getId() + "/" + message.getId() + ")**", false)
.setFooter(formatter.format(date));
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/bot/antony/events/reaction/add/SpyReaction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bot.antony.events.reaction.add;

import bot.antony.Antony;
import bot.antony.utils.Utils;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;

public class SpyReaction extends MessageReaction {
Expand Down Expand Up @@ -28,15 +29,8 @@ public void perform(MessageReactionAddEvent event) {
}

public void printUserinfo() {
StringBuilder sb = new StringBuilder();
sb.append("ID: " + message.getAuthor().getId() + "\n");
sb.append("Tag: " + message.getAuthor().getAsTag().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*") + "\n");
sb.append("Name: " + message.getAuthor().getName().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*"));
if(message.getMember() != null && message.getMember().getNickname() != null) {
sb.append("\nNickname: " + message.getMember().getNickname().replace("|", "\\|").replace("_", "\\_").replace("*", "\\*"));
}
if(responseChannel != null) {
responseChannel.sendMessage(sb.toString()).queue();
responseChannel.sendMessage(Utils.getAllUserInfos(message.getMember())).queue();
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/bot/antony/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
Expand Down Expand Up @@ -226,4 +227,27 @@ public static void addBooleanChoiceReactions(Message msg) {
msg.addReaction(Emoji.fromUnicode("✅")).queue();
msg.addReaction(Emoji.fromUnicode("❌")).queue();
}

public static String escapeControlChars(String text) {
return text.replace("|", "\\|")
.replace("_", "\\_")
.replace("*", "\\*");
}

public static String getAllUserInfos(Member member) {
User user = member.getUser();
StringBuilder sb = new StringBuilder();

sb.append("ID: " + user.getId() + "\n");
sb.append("Tag: " + escapeControlChars(user.getAsTag()) + "\n");
sb.append("Discord User Name: " + escapeControlChars(user.getName()));
if(user.getGlobalName() != null) {
sb.append("\nDisplay Name: " + escapeControlChars(user.getGlobalName()));
}
if(member != null && member.getNickname() != null) {
sb.append("\nNickname: " + escapeControlChars(member.getNickname()));
}

return sb.toString();
}
}

0 comments on commit a4e4245

Please sign in to comment.