Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventSubscriber
- public void onMessageUpdateEvent(MessageUpdateEvent event) {
- if (event.getNewMessage().getContent() == null || event.getOldMessage().getContent() == null) {
- return;
- }
- if (event.getNewMessage().getContent().isEmpty() || event.getOldMessage().getContent().isEmpty()) {
- return;
- }
- if (event.getNewMessage().getContent().equals(event.getOldMessage().getContent())) {
- return;
- }
- if (event.getChannel().isPrivate()) {
- return;
- }
- CommandObject command = new CommandObject(event.getMessage());
- IUser ourUser = command.client.getOurUser();
- List<String> logID = command.guildConfig.getChannelIDsByType(Command.CHANNEL_SERVER_LOG);
- List<String> dontLog = command.guildConfig.getChannelIDsByType(Command.CHANNEL_DONT_LOG);
- if (dontLog != null) {
- for (String id : dontLog) {
- if (command.channelSID.equals(id)) {
- return;
- }
- }
- }
- if (logID != null) {
- String serverLogID = logID.get(0);
- if (command.guildConfig.dontLogBot && command.author.isBot()) {
- return;
- }
- if (event.getMessage() == null) {
- return;
- }
- if (serverLogID != null && serverLogID.equals(command.channelSID) && ourUser.getStringID().equals(command.authorSID)) {
- return;
- }
- if (command.guildConfig.editLogging) {
- //formats how long ago this was.
- String formatted;
- String oldContent;
- String newContent;
- StringBuilder response = new StringBuilder();
- ZonedDateTime oldMessageTime = event.getOldMessage().getTimestamp().atZone(ZoneOffset.UTC);
- ZonedDateTime newMessageTime = event.getNewMessage().getEditedTimestamp().get().atZone(ZoneOffset.UTC);
- int charLimit;
- long difference = newMessageTime.toEpochSecond() - oldMessageTime.toEpochSecond();
- if (command.guildConfig.useTimeStamps) {
- formatted = "at `" + Utility.formatTimestamp(oldMessageTime) + " - UTC`";
- } else {
- formatted = "from " + Utility.formatTimeDifference(difference);
- }
- response.append("> **@" + command.authorUserName + "'s** Message " + formatted + " was **Edited** in channel: " + command.channel.mention() + ". ");
- //remove excess text that would cause a max char limit error.
- if (command.message.getContent().isEmpty()) {
- return;
- }
- if (command.guildConfig.extendEditLog) {
- charLimit = 900;
- } else {
- charLimit = 1800;
- }
- if (event.getOldMessage().getContent().length() > charLimit) {
- oldContent = Utility.unFormatMentions(event.getOldMessage()).substring(0, charLimit) + "...";
- } else {
- oldContent = Utility.unFormatMentions(event.getOldMessage());
- }
- if (event.getNewMessage().getContent().length() > charLimit) {
- newContent = Utility.unFormatMentions(event.getNewMessage()).substring(0, charLimit) + "...";
- } else {
- newContent = Utility.unFormatMentions(event.getNewMessage());
- }
- response.append("**\nMessage's Old Contents:**\n" + oldContent);
- if (command.guildConfig.extendEditLog) {
- response.append("\n**Message's New Contents:**\n" + newContent);
- }
- Utility.sendLog(response.toString(), command.guildConfig, false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment