Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove discriminator from log messages & events. #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/main/java/com/jagrosh/vortex/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateDiscriminatorEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent;
import net.dv8tion.jda.api.hooks.EventListener;
import org.slf4j.Logger;
Expand Down Expand Up @@ -176,13 +175,6 @@ else if (event instanceof UserUpdateNameEvent)
unue.getUser().getMutualGuilds().stream().map(g -> g.getMember(unue.getUser())).forEach(m -> vortex.getAutoMod().dehoist(m));
}
}
else if (event instanceof UserUpdateDiscriminatorEvent)
{
// Make sure the discrim actually changed
UserUpdateDiscriminatorEvent udue = (UserUpdateDiscriminatorEvent) event;
if(!udue.getNewDiscriminator().equals(udue.getOldDiscriminator()))
vortex.getBasicLogger().logDiscrimChange((UserUpdateDiscriminatorEvent)event);
}
else if (event instanceof GuildMemberUpdateNicknameEvent)
{
vortex.getAutoMod().dehoist(((GuildMemberUpdateNicknameEvent) event).getMember());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void execute(CommandEvent event)
.replace("@here", "@h\u0435re") // cyrillic e
.replace("discord.gg/", "dis\u0441ord.gg/"); // cyrillic c;
String str = LINESTART + "ID: **" + guild.getId() + "**\n"
+ LINESTART + "Owner: " + (owner == null ? "Unknown" : "**" + owner.getUser().getName() + "**#" + owner.getUser().getDiscriminator()) + "\n";
+ LINESTART + "Owner: " + (owner == null ? "Unknown" : "**" + owner.getUser().getName() + "**") + "\n";
if(!guild.getVoiceChannels().isEmpty())
{
Region reg = guild.getVoiceChannels().get(0).getRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ else if(found.size()>1)
}
}
User user = member.getUser();
String title = (user.isBot() ? Emoji.BOT : USER_EMOJI)+" Information about **"+user.getName()+"** #"+user.getDiscriminator()+":";
String title = (user.isBot() ? Emoji.BOT : USER_EMOJI)+" Information about **"+user.getName()+"**:";
StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + user.getId() + "** ");
user.getFlags().forEach(flag -> str.append(OtherUtil.getEmoji(flag)));
if(user.getAvatarId() != null && user.getAvatarId().startsWith("a_"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected void execute(CommandEvent event)
String fmessage = message;
if(!role.isMentionable())
{
String reason = "Announcement by "+event.getAuthor().getName()+"#"+event.getAuthor().getDiscriminator();
String reason = "Announcement by "+event.getAuthor().getName();
role.getManager().setMentionable(true).reason(reason).queue(s ->
{
tc.sendMessage(fmessage).allowedMentions(EnumSet.of(Message.MentionType.ROLE)).queue(m ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private boolean lookupUser(long userId, CommandEvent event)
catch(Exception ignore) {}
if(u == null)
return false;
String text = (u.isBot() ? Emoji.BOT : USER_EMOJI) + " Information about **" + u.getName() + "**#" + u.getDiscriminator() + ":";
String text = (u.isBot() ? Emoji.BOT : USER_EMOJI) + " Information about **" + u.getName() + "**:";
EmbedBuilder eb = new EmbedBuilder();
eb.setThumbnail(u.getEffectiveAvatarUrl());
StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + u.getId() + "** ");
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/com/jagrosh/vortex/logging/BasicLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateDiscriminatorEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent;
import net.dv8tion.jda.api.exceptions.PermissionException;

Expand Down Expand Up @@ -217,25 +216,11 @@ public void logNameChange(UserUpdateNameEvent event)
.filter(tc -> tc!=null).distinct()
.forEachOrdered(tc ->
{
log(now, tc, NAME, "**"+event.getOldName()+"**#"+event.getUser().getDiscriminator()+" (ID:"
log(now, tc, NAME, "**"+event.getOldName()+"**"+" (ID:"
+event.getUser().getId()+") has changed names to "+FormatUtil.formatUser(event.getUser()), null);
});
}

public void logDiscrimChange(UserUpdateDiscriminatorEvent event)
{
OffsetDateTime now = OffsetDateTime.now();
event.getJDA().getMutualGuilds(event.getEntity()).stream()
.filter(guild -> vortex.getShardManager().isHighestAccount(guild))
.map(guild -> vortex.getDatabase().settings.getSettings(guild).getServerLogChannel(guild))
.filter(tc -> tc!=null).distinct()
.forEachOrdered(tc ->
{
log(now, tc, NAME, "**"+event.getUser().getName()+"**#"+event.getOldDiscriminator()+" (ID:"
+event.getUser().getId()+") has changed discrims to "+FormatUtil.formatUser(event.getUser()), null);
});
}

public void logGuildJoin(GuildMemberJoinEvent event)
{
TextChannel tc = vortex.getDatabase().settings.getSettings(event.getGuild()).getServerLogChannel(event.getGuild());
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/com/jagrosh/vortex/logging/MessageCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public List<CachedMessage> getMessages(Guild guild, Predicate<CachedMessage> pre

public class CachedMessage implements ISnowflake
{
private final String content, username, discriminator;
private final String content, username;
private final long id, author, channel, guild;
private final List<Attachment> attachments;

Expand All @@ -68,7 +68,6 @@ private CachedMessage(Message message)
id = message.getIdLong();
author = message.getAuthor().getIdLong();
username = message.getAuthor().getName();
discriminator = message.getAuthor().getDiscriminator();
channel = message.getChannel().getIdLong();
guild = message.isFromGuild() ? message.getGuild().getIdLong() : 0L;
attachments = message.getAttachments();
Expand Down Expand Up @@ -99,11 +98,6 @@ public String getUsername()
return username;
}

public String getDiscriminator()
{
return discriminator;
}

public long getAuthorId()
{
return author;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/jagrosh/vortex/utils/FormatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ public static String formatFullUserId(long userId)

public static String formatCachedMessageFullUser(CachedMessage msg)
{
return filterEveryone("**"+msg.getUsername()+"**#"+msg.getDiscriminator()+" (ID:"+msg.getAuthorId()+")");
return filterEveryone("**"+msg.getUsername()+"**"+" (ID:"+msg.getAuthorId()+")");
}

public static String formatUser(User user)
{
return filterEveryone("**"+user.getName()+"**#"+user.getDiscriminator());
return filterEveryone("**"+user.getName()+"**");
}

public static String formatFullUser(User user)
{
return filterEveryone("**"+user.getName()+"**#"+user.getDiscriminator()+" (ID:"+user.getId()+")");
return filterEveryone("**"+user.getName()+"**"+" (ID:"+user.getId()+")");
}

public static String capitalize(String input)
Expand Down Expand Up @@ -147,7 +147,7 @@ public static String listOfUser(List<User> list, String query)
{
String out = String.format(MULTIPLE_FOUND, "users", query);
for(int i=0; i<6 && i<list.size(); i++)
out+="\n - **"+list.get(i).getName()+"**#"+list.get(i).getDiscriminator()+" (ID:"+list.get(i).getId()+")";
out+="\n - **"+list.get(i).getName()+"**"+" (ID:"+list.get(i).getId()+")";
if(list.size()>6)
out+="\n**And "+(list.size()-6)+" more...**";
return out;
Expand All @@ -157,7 +157,7 @@ public static String listOfMember(List<Member> list, String query)
{
String out = String.format(MULTIPLE_FOUND, "members", query);
for(int i=0; i<6 && i<list.size(); i++)
out+="\n - **"+list.get(i).getUser().getName()+"**#"+list.get(i).getUser().getDiscriminator()+" (ID:"+list.get(i).getUser().getId()+")";
out+="\n - **"+list.get(i).getUser().getName()+"**"+" (ID:"+list.get(i).getUser().getId()+")";
if(list.size()>6)
out+="\n**And "+(list.size()-6)+" more...**";
return out;
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/com/jagrosh/vortex/utils/LogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class LogUtil
private final static String MODLOG_CASE = " `[%d]`";
private final static String EMOJI = " %s";
private final static String ACTION = " %s";
private final static String MODERATOR = " **%s**#%s";
private final static String TARGET_USER = " **%s**#%s (ID:%s)";
private final static String MODERATOR = " **%s**";
private final static String TARGET_USER = " **%s** (ID:%s)";
private final static String REASON = "\n`[ Reason ]` %s";

private final static String MODLOG_USER_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + ACTION + TARGET_USER + REASON;
Expand All @@ -62,41 +62,40 @@ public class LogUtil
public static String modlogUserFormat(OffsetDateTime time, ZoneId zone, int caseNum, User moderator, Action action, User target, String reason)
{
return String.format(MODLOG_USER_FORMAT, timeF(time, zone), caseNum, action.getEmoji(), moderator.getName(),
moderator.getDiscriminator(), action.getVerb(), target.getName(), target.getDiscriminator(), target.getId(),
action.getVerb(), target.getName(), target.getId(),
reasonF(reason));
}

public static String modlogTimeFormat(OffsetDateTime time, ZoneId zone, int caseNum, User moderator, Action action, long minutes, User target, String reason)
{
return String.format(MODLOG_TIME_FORMAT, timeF(time, zone), caseNum, action.getEmoji(), moderator.getName(),
moderator.getDiscriminator(), action.getVerb(), target.getName(), target.getDiscriminator(), target.getId(),
action.getVerb(), target.getName(), target.getId(),
FormatUtil.secondsToTime(minutes*60), reasonF(reason));
}

public static String modlogCleanFormat(OffsetDateTime time, ZoneId zone, int caseNum, User moderator, int numMessages, TextChannel channel, String criteria, String reason)
{
return String.format(MODLOG_CLEAN_FORMAT, timeF(time, zone), caseNum, Action.CLEAN.getEmoji(), moderator.getName(),
moderator.getDiscriminator(), Action.CLEAN.getVerb(), numMessages, channel.getAsMention(), criteria, reasonF(reason));
Action.CLEAN.getVerb(), numMessages, channel.getAsMention(), criteria, reasonF(reason));
}

public static String modlogStrikeFormat(OffsetDateTime time, ZoneId zone, int caseNum, User moderator, int givenStrikes, int oldStrikes, int newStrikes, User target, String reason)
{
return String.format(MODLOG_STRIKE_FORMAT, timeF(time, zone), caseNum, Action.STRIKE.getEmoji(), moderator.getName(),
moderator.getDiscriminator(), givenStrikes, oldStrikes, newStrikes, target.getName(), target.getDiscriminator(), target.getId(),
reasonF(reason));
givenStrikes, oldStrikes, newStrikes, target.getName(), target.getId(), reasonF(reason));
}

public static String modlogPardonFormat(OffsetDateTime time, ZoneId zone, int caseNum, User moderator, int pardonedStrikes, int oldStrikes, int newStrikes, User target, String reason)
{
return String.format(MODLOG_PARDON_FORMAT, timeF(time, zone), caseNum, Action.PARDON.getEmoji(), moderator.getName(),
moderator.getDiscriminator(), pardonedStrikes, oldStrikes, newStrikes, target.getName(), target.getDiscriminator(), target.getId(),
pardonedStrikes, oldStrikes, newStrikes, target.getName(), target.getId(),
reasonF(reason));
}

public static String modlogRaidFormat(OffsetDateTime time, ZoneId zone, int caseNum, User moderator, boolean enabled, String reason)
{
return String.format(MODLOG_RAID_FORMAT, timeF(time, zone), caseNum, enabled ? Action.RAIDMODE.getEmoji() : Action.NORAIDMODE.getEmoji(), moderator.getName(),
moderator.getDiscriminator(), enabled ? "ENABLED" : "DISABLED", reasonF(reason));
enabled ? "ENABLED" : "DISABLED", reasonF(reason));
}

public static int isCase(Message m, int caseNum)
Expand Down Expand Up @@ -161,7 +160,7 @@ private static void appendMessage(StringBuilder sb, Message m)
{
sb.append("\r\n\r\n[")
.append(m.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME))
.append("] ").append(m.getAuthor().getName()).append("#").append(m.getAuthor().getDiscriminator())
.append("] ").append(m.getAuthor().getName())
.append(" (").append(m.getAuthor().getId()).append(") : ").append(m.getContentRaw());
m.getAttachments().forEach(att -> sb.append("\n").append(att.getUrl()));
}
Expand All @@ -172,15 +171,15 @@ private static void appendMessage(StringBuilder sb, CachedMessage m, User author
.append(m.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME))
.append("] ");
if(author==null)
sb.append(m.getUsername()).append("#").append(m.getDiscriminator()).append(" (").append(m.getAuthorId());
sb.append(m.getUsername()).append(" (").append(m.getAuthorId());
else
sb.append(author.getName()).append("#").append(author.getDiscriminator()).append(" (").append(author.getId());
sb.append(author.getName()).append(" (").append(author.getId());
sb.append(") : ").append(m.getContentRaw());
m.getAttachments().forEach(att -> sb.append("\n").append(att.getUrl()));
}

// Audit logging formats
private final static String A_MOD = "%s#%s";
private final static String A_MOD = "%s";
private final static String A_TIME = " (%dm)";
private final static String A_REASON = ": %s";

Expand All @@ -197,14 +196,14 @@ public static String auditStrikeReasonFormat(Member moderator, int minutes, int

public static String auditReasonFormat(Member moderator, String reason)
{
return limit512(String.format(AUDIT_BASIC_FORMAT, moderator.getUser().getName(), moderator.getUser().getDiscriminator(), reasonF(reason)));
return limit512(String.format(AUDIT_BASIC_FORMAT, moderator.getUser().getName(), reasonF(reason)));
}

public static String auditReasonFormat(Member moderator, int minutes, String reason)
{
if(minutes<=0)
return auditReasonFormat(moderator, reason);
return limit512(String.format(AUDIT_TIMED_FORMAT, moderator.getUser().getName(), moderator.getUser().getDiscriminator(), minutes, reasonF(reason)));
return limit512(String.format(AUDIT_TIMED_FORMAT, moderator.getUser().getName(), minutes, reasonF(reason)));
}

public static ParsedAuditReason parse(Guild guild, String reason)
Expand Down