Skip to content

Commit

Permalink
2.4.7 - The logging update.
Browse files Browse the repository at this point in the history
+ toggles for UserRoleLogging, MessageEditLogging, JoinLeaveLogging.
  • Loading branch information
Vaerys-Dawn committed Feb 21, 2017
1 parent 3794590 commit 41f3f92
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 192 deletions.
483 changes: 313 additions & 170 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/java/GuildToggles/ToggleInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static ArrayList<GuildToggle> get(){
guildToggles.add(new ShitpostFiltering());
guildToggles.add(new Voting());
guildToggles.add(new RateLimiting());
guildToggles.add(new JoinLeaveLgging());
guildToggles.add(new EditLogging());
guildToggles.add(new UserRoleLogging());

//modules
guildToggles.add(new ModuleChars());
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/GuildToggles/Toggles/EditLogging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package GuildToggles.Toggles;

import Commands.CommandObject;
import GuildToggles.GuildToggle;
import POGOs.GuildConfig;

/**
* Created by Vaerys on 21/02/2017.
*/
public class EditLogging implements GuildToggle {
@Override
public String name() {
return "EditLogging";
}

@Override
public boolean toggle(GuildConfig config) {
return config.editLogging = !config.editLogging;
}

@Override
public boolean get(GuildConfig config) {
return config.editLogging;
}

@Override
public void execute(CommandObject command) {

}

@Override
public boolean isModule() {
return false;
}
}
35 changes: 35 additions & 0 deletions src/main/java/GuildToggles/Toggles/JoinLeaveLgging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package GuildToggles.Toggles;

import Commands.CommandObject;
import GuildToggles.GuildToggle;
import POGOs.GuildConfig;

/**
* Created by Vaerys on 21/02/2017.
*/
public class JoinLeaveLgging implements GuildToggle{
@Override
public String name() {
return "JoinLeaveLogging";
}

@Override
public boolean toggle(GuildConfig config) {
return config.joinLeaveLogging = !config.joinLeaveLogging;
}

@Override
public boolean get(GuildConfig config) {
return config.joinLeaveLogging;
}

@Override
public void execute(CommandObject command) {

}

@Override
public boolean isModule() {
return false;
}
}
35 changes: 35 additions & 0 deletions src/main/java/GuildToggles/Toggles/UserRoleLogging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package GuildToggles.Toggles;

import Commands.CommandObject;
import GuildToggles.GuildToggle;
import POGOs.GuildConfig;

/**
* Created by Vaerys on 21/02/2017.
*/
public class UserRoleLogging implements GuildToggle {
@Override
public String name() {
return "UserRoleLogging";
}

@Override
public boolean toggle(GuildConfig config) {
return config.userRoleUpdatelogging = !config.userRoleUpdatelogging;
}

@Override
public boolean get(GuildConfig config) {
return config.userRoleUpdatelogging;
}

@Override
public void execute(CommandObject command) {

}

@Override
public boolean isModule() {
return false;
}
}
125 changes: 104 additions & 21 deletions src/main/java/Listeners/AnnotationListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Main.Globals;
import Main.TimedEvents;
import Main.Utility;
import Objects.GuildContentObject;
import Objects.SplitFirstObject;
import POGOs.*;
import org.slf4j.Logger;
Expand All @@ -21,13 +22,19 @@
import sx.blah.discord.handle.impl.events.guild.channel.message.MentionEvent;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageDeleteEvent;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageUpdateEvent;
import sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionAddEvent;
import sx.blah.discord.handle.impl.events.guild.member.GuildMemberEvent;
import sx.blah.discord.handle.impl.events.guild.member.UserJoinEvent;
import sx.blah.discord.handle.impl.events.guild.member.UserLeaveEvent;
import sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent;
import sx.blah.discord.handle.impl.events.guild.role.RoleDeleteEvent;
import sx.blah.discord.handle.impl.events.guild.role.RoleUpdateEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.impl.obj.Channel;
import sx.blah.discord.handle.obj.*;

import java.util.ArrayList;
import java.util.stream.Collectors;

/**
* Created by Vaerys on 03/08/2016.
Expand Down Expand Up @@ -81,7 +88,7 @@ public void onGuildCreateEvent(GuildCreateEvent event) {
}

@EventSubscriber
public void onGuildLeaveEvent(GuildLeaveEvent event){
public void onGuildLeaveEvent(GuildLeaveEvent event) {
Globals.unloadGuild(event.getGuild().getID());
}

Expand All @@ -102,7 +109,7 @@ public void onReadyEvent(ReadyEvent event) {
// TODO: 16/01/2017 make level decay toggleable
// TODO: 16/01/2017 make everything optional/ modifiable
@EventSubscriber
public void onMessageRecivedEvent(MessageReceivedEvent event) {
public void onMessageReceivedEvent(MessageReceivedEvent event) {
if (event.getMessage().getChannel().isPrivate()) {
new DMHandler(event.getMessage());
return;
Expand All @@ -114,7 +121,7 @@ public void onMessageRecivedEvent(MessageReceivedEvent event) {
String messageLC = message.toString().toLowerCase();
String args = "";
String command = "";
while (!event.getClient().isReady());
while (!event.getClient().isReady()) ;
GuildConfig guildConfig = Globals.getGuildContent(guild.getID()).getGuildConfig();

//Set Console Response Channel.
Expand Down Expand Up @@ -226,7 +233,7 @@ public void onReactionAddEvent(ReactionAddEvent event) {
}
return;
}
if (Utility.canBypass(event.getUser(),event.getGuild())){
if (Utility.canBypass(event.getUser(), event.getGuild())) {
if (event.getReaction().toString().equals("❌")) {
if (event.getMessage().getAuthor().getID().equals(Globals.getClient().getOurUser().getID())) {
Utility.deleteMessage(event.getMessage());
Expand All @@ -236,8 +243,8 @@ public void onReactionAddEvent(ReactionAddEvent event) {
}

@EventSubscriber
public void onMessageDeleteEvent(MessageDeleteEvent event){
if (event.getChannel().isPrivate()){
public void onMessageDeleteEvent(MessageDeleteEvent event) {
if (event.getChannel().isPrivate()) {
return;
}
CommandObject command = new CommandObject(event.getMessage());
Expand All @@ -247,32 +254,108 @@ public void onMessageDeleteEvent(MessageDeleteEvent event){
String infoID = command.guildConfig.getChannelTypeID(Command.CHANNEL_INFO);
String serverLogID = command.guildConfig.getChannelTypeID(Command.CHANNEL_SERVER_LOG);
String adminLogID = command.guildConfig.getChannelTypeID(Command.CHANNEL_ADMIN_LOG);
if (event.getMessage() == null){
if (event.getMessage() == null) {
return;
}
if (serverLogID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)){
if (serverLogID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)) {
return;
}
if (infoID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)){
if (infoID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)) {
return;
}
if (adminLogID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)){
if (adminLogID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)) {
return;
}
if (logging != null && command.guildConfig.deleteLogging){
if (command.message.getContent().isEmpty()){
if (logging != null && command.guildConfig.deleteLogging) {
if (command.message.getContent().isEmpty()) {
return;
}
int charLimit = 1800;
if (command.message.getContent().length() > charLimit){
content = command.message.getContent().substring(0,1800);
}else {
if (command.message.getContent().length() > charLimit) {
content = command.message.getContent().substring(0, 1800);
} else {
content = command.message.getContent();
}
if ((content.equals("`Loading...`") || content.equals("`Working...`")) && command.authorID.equals(command.client.getOurUser().getID())){
if ((content.equals("`Loading...`") || content.equals("`Working...`")) && command.authorID.equals(command.client.getOurUser().getID())) {
return;
}
Utility.sendMessage("> **@" + command.authorUserName + "'s** Message was deleted in channel: " + command.channel.mention() + " with contents:\n" + content, logging);
}
}

@EventSubscriber
public void onUserJoinEvent(UserJoinEvent event) {
joinLeaveLogging(event, true);
}

@EventSubscriber
public void onUserLeaveEvent(UserLeaveEvent event) {
joinLeaveLogging(event, false);
}

public void joinLeaveLogging(GuildMemberEvent event, boolean joining) {
IGuild guild = event.getGuild();
GuildContentObject content = Globals.getGuildContent(guild.getID());
if (content.getGuildConfig().joinLeaveLogging) {
IChannel logging = Globals.getClient().getChannelByID(content.getGuildConfig().getChannelTypeID(Command.CHANNEL_SERVER_LOG));
if (logging != null) {
if (joining) {
Utility.sendMessage("> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + " Has Joined the Server.", logging);
} else {
Utility.sendMessage("> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + " Has Left the Server.", logging);
}
}
}
}

@EventSubscriber
public void onMessageUpdateEvent(MessageUpdateEvent event) {
if (event.getNewMessage().getContent().equals(event.getOldMessage().getContent())) {
return;
}
if (event.getChannel().isPrivate()) {
return;
}
CommandObject command = new CommandObject(event.getMessage());
String content;
IChannel logging = command.client.getChannelByID(command.guildConfig.getChannelTypeID(Command.CHANNEL_SERVER_LOG));
IUser ourUser = command.client.getOurUser();
String serverLogID = command.guildConfig.getChannelTypeID(Command.CHANNEL_SERVER_LOG);
if (event.getMessage() == null) {
return;
}
if (serverLogID != null && serverLogID.equals(command.channelID) && ourUser.getID().equals(command.authorID)) {
return;
}
if (logging != null && command.guildConfig.editLogging) {
if (command.message.getContent().isEmpty()) {
return;
}
Utility.sendMessage("> **@" + command.authorUserName+ "'s** Message was deleted in channel: " + command.channel.mention() + " with contents:\n" + content,logging);
int charLimit = 1800;
if (command.message.getContent().length() > charLimit) {
content = command.message.getContent().substring(0, 1800);
} else {
content = command.message.getContent();
}
Utility.sendMessage("> **@" + command.authorUserName + "'s** Message was Edited in channel: " + command.channel.mention() + " Old Contents:\n" + content, logging);
}
}

@EventSubscriber
public void onUserRoleUpdateEvent(UserRoleUpdateEvent event) {
IGuild guild = event.getGuild();
GuildContentObject content = Globals.getGuildContent(guild.getID());
if (content.getGuildConfig().userRoleUpdatelogging) {
IChannel logging = Globals.getClient().getChannelByID(content.getGuildConfig().getChannelTypeID(Command.CHANNEL_SERVER_LOG));
if (logging != null) {
ArrayList<String> oldRoles = new ArrayList<>();
ArrayList<String> newRoles = new ArrayList<>();
oldRoles.addAll(event.getOldRoles().stream().map(IRole::getName).collect(Collectors.toList()));
newRoles.addAll(event.getNewRoles().stream().map(IRole::getName).collect(Collectors.toList()));
String prefix = "> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + "'s** Role have been Updated.";

Utility.sendMessage(prefix + "\nOld Roles: " + Utility.listFormatter(oldRoles, true) + "\nNew Roles: " + Utility.listFormatter(newRoles, true), logging);
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/POGOs/GuildConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class GuildConfig {
public boolean generalLogging = false;
public boolean adminLogging = false;
public boolean deleteLogging = false;
public boolean joinLeaveLogging = false;
public boolean userRoleUpdatelogging = false;
public boolean editLogging = false;
public boolean denyInvites = false;
public boolean maxMentions = true;
public boolean dailyMessage = true;
Expand Down Expand Up @@ -52,6 +55,7 @@ public class GuildConfig {
private int rateLimit;



public String getPrefixCommand() {
return prefixCommand;
}
Expand Down
Binary file modified target/JavaDiscordSAILv2.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Tue Feb 21 17:51:11 AEDT 2017
#Tue Feb 21 18:55:02 AEDT 2017
version=2.4.6
groupId=com.github.vaerys
artifactId=DiscordSAIL
Binary file modified target/original-JavaDiscordSAILv2.jar
Binary file not shown.

0 comments on commit 41f3f92

Please sign in to comment.