Skip to content

Commit

Permalink
2.4.10
Browse files Browse the repository at this point in the history
* changed Editlogging and DeleteLogging outputs to have how long ago the
message was posted before the event happened.
+ added a message counter tracker to get an average message count per
day per user.
  • Loading branch information
Vaerys-Dawn committed Feb 24, 2017
1 parent bf6941d commit 9df0477
Show file tree
Hide file tree
Showing 18 changed files with 643 additions and 402 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/Vaerys.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

675 changes: 340 additions & 335 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/java/Commands/CommandObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CommandObject {
public Characters characters;
public Servers servers;
public Competition competition;
public GuildUsers guildUsers;

public ArrayList<Command> commands = new ArrayList<>();
public ArrayList<DMCommand> dmCommands = new ArrayList<>();
Expand All @@ -52,6 +53,7 @@ public class CommandObject {

final static Logger logger = LoggerFactory.getLogger(CommandObject.class);


public CommandObject(IMessage message) {
this.message = message;
guild = message.getGuild();
Expand Down Expand Up @@ -85,6 +87,7 @@ private void init() {
characters = guildContent.getCharacters();
servers = guildContent.getServers();
competition = guildContent.getCompetition();
guildUsers = guildContent.getGuildUsers();
client = Globals.getClient();

commands = (ArrayList<Command>) Globals.getCommands().clone();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/GuildToggles/Toggles/UserRoleLogging.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public String name() {

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

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

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Handlers/MessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public MessageHandler(String command, String args, CommandObject commandObject)

checkBlacklist(commandObject);
checkMentionCount(commandObject);
commandObject.guildUsers.addXP(commandObject);
if (rateLimiting(commandObject)) {
return;
}
Expand Down
60 changes: 44 additions & 16 deletions src/main/java/Listeners/AnnotationListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
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.impl.obj.Channel;
import sx.blah.discord.handle.obj.*;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -63,26 +64,43 @@ public void onGuildCreateEvent(GuildCreateEvent event) {
CustomCommands customCommands = new CustomCommands();
Characters characters = new Characters();
Competition competition = new Competition();
GuildUsers guildUsers = new GuildUsers();

//Init Files
customCommands.initCustomCommands();
//Preps Objects for initial load
guildConfig.initConfig();
customCommands.initCustomCommands();

//null prevention code. unsure if needed still.
guildConfig.setProperlyInit(true);
servers.setProperlyInit(true);
customCommands.setProperlyInit(true);
characters.setProperlyInit(true);
competition.setProperlyInit(true);
guildUsers.setProperlyInit(true);

FileHandler.createDirectory(Utility.getDirectory(guildID));
FileHandler.createDirectory(Utility.getDirectory(guildID, true));
FileHandler.createDirectory(Utility.getGuildImageDir(guildID));

//initial load of all files, creates files if they don't already exist
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_GUILD_CONFIG), guildConfig);
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_SERVERS), servers);
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_CUSTOM), customCommands);
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_CHARACTERS), characters);
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_INFO));
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_COMPETITION), competition);
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_GUILD_USERS), guildUsers);

//loads all Files for the guild;
guildConfig = (GuildConfig) Utility.initFile(guildID, Constants.FILE_GUILD_CONFIG, GuildConfig.class);
customCommands = (CustomCommands) Utility.initFile(guildID, Constants.FILE_CUSTOM, CustomCommands.class);
servers = (Servers) Utility.initFile(guildID, Constants.FILE_SERVERS, Servers.class);
characters = (Characters) Utility.initFile(guildID, Constants.FILE_CHARACTERS, Characters.class);
competition = (Competition) Utility.initFile(guildID, Constants.FILE_COMPETITION, Competition.class);
guildUsers = (GuildUsers) Utility.initFile(guildID,Constants.FILE_GUILD_USERS, GuildUsers.class);

Globals.initGuild(guildID);
//sends objects to globals
Globals.initGuild(guildID,guildConfig,servers,customCommands,characters,competition,guildUsers);

logger.info("Finished Initialising Guild With ID: " + guildID);
}
Expand Down Expand Up @@ -267,7 +285,7 @@ public void onMessageDeleteEvent(MessageDeleteEvent event) {
return;
}
if (logging != null && command.guildConfig.deleteLogging) {
if (command.message.getContent() == null){
if (command.message.getContent() == null) {
return;
}
if (command.message.getContent().isEmpty()) {
Expand All @@ -282,7 +300,10 @@ public void onMessageDeleteEvent(MessageDeleteEvent event) {
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);
long difference = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond() - event.getMessage().getTimestamp().atZone(ZoneOffset.UTC).toEpochSecond();
System.out.println(difference);
String formatted = Utility.formatTimeDifference(difference);
Utility.sendMessage("> **@" + command.authorUserName + "'s** Message from " + formatted + " was **Deleted** in channel: " + command.channel.mention() + " with contents:\n" + content, logging);
}
}

Expand All @@ -303,20 +324,20 @@ public void joinLeaveLogging(GuildMemberEvent event, boolean joining) {
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);
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);
Utility.sendMessage("> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + "** has **Left** the server.", logging);
}
}
}
}

@EventSubscriber
public void onMessageUpdateEvent(MessageUpdateEvent event) {
if (event.getNewMessage().getContent() == null || event.getOldMessage().getContent() == null){
if (event.getNewMessage().getContent() == null || event.getOldMessage().getContent() == null) {
return;
}
if (event.getNewMessage().getContent().isEmpty() || event.getOldMessage().getContent().isEmpty()){
if (event.getNewMessage().getContent().isEmpty() || event.getOldMessage().getContent().isEmpty()) {
return;
}
if (event.getNewMessage().getContent().equals(event.getOldMessage().getContent())) {
Expand All @@ -337,6 +358,13 @@ public void onMessageUpdateEvent(MessageUpdateEvent event) {
return;
}
if (logging != null && command.guildConfig.editLogging) {
//formats how long ago this was.
ZonedDateTime oldMessageTime = event.getOldMessage().getTimestamp().atZone(ZoneOffset.UTC);
ZonedDateTime newMessageTime = event.getNewMessage().getEditedTimestamp().get().atZone(ZoneOffset.UTC);
long difference = newMessageTime.toEpochSecond() - oldMessageTime.toEpochSecond();
String formatted = Utility.formatTimeDifference(difference);

//remove excess text that would cause a max char limit error.
if (command.message.getContent().isEmpty()) {
return;
}
Expand All @@ -346,28 +374,28 @@ public void onMessageUpdateEvent(MessageUpdateEvent event) {
} else {
content = event.getOldMessage().getContent();
}
Utility.sendMessage("> **@" + command.authorUserName + "'s** Message was Edited in channel: " + command.channel.mention() + " Old Contents:\n" + content, logging);
Utility.sendMessage("> **@" + command.authorUserName + "'s** Message from " + formatted + " was **Edited** in channel: " + command.channel.mention() + ".\n**Message's 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) {
if (content.getGuildConfig().userRoleLogging) {
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()));
for (int i = 0; i < oldRoles.size();i++){
if (oldRoles.get(i).equalsIgnoreCase("@everyone")){
for (int i = 0; i < oldRoles.size(); i++) {
if (oldRoles.get(i).equalsIgnoreCase("@everyone")) {
oldRoles.remove(i);
}
}
for (int i = 0; i < newRoles.size();i++){
if (newRoles.get(i).equalsIgnoreCase("@everyone")){
for (int i = 0; i < newRoles.size(); i++) {
if (newRoles.get(i).equalsIgnoreCase("@everyone")) {
newRoles.remove(i);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/Main/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class Constants {
public static final String FILE_GUILD_CONFIG = "Guild_Config.json";
public static final String FILE_SERVERS = "Servers.json";
public static final String FILE_CHARACTERS = "Characters.json";
public static final String FILE_GUILD_USERS = "Guild_Users.json";
public static final String FILE_INFO = "Info.txt";
public static final String FILE_CONFIG = DIRECTORY_STORAGE + "Config.json";
public static final String FILE_CONFIG_BACKUP = DIRECTORY_BACKUPS + "Config.json";
Expand Down Expand Up @@ -87,6 +88,4 @@ public class Constants {
"Goodness what have you all done to the place since I was last here?;;" +
"My My My Its a brand new day isn't it? looks like we're all still here.}";
public static final String DAILY_MESSAGE_7 = "> A new Day arrives, Prepare for fun.";


}
14 changes: 7 additions & 7 deletions src/main/java/Main/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Handlers.FileHandler;
import Objects.DailyMessageObject;
import Objects.GuildContentObject;
import Objects.UserTypeObject;
import POGOs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -52,6 +53,8 @@ public class Globals {

final static Logger logger = LoggerFactory.getLogger(Globals.class);
private static GlobalData globalData;
public static int baseXPModifier;
public static int xpForLevelOne;

public static void initConfig(IDiscordClient ourClient, Config config, GlobalData newGlobalData) {
if (newGlobalData != null) {
Expand All @@ -69,6 +72,8 @@ public static void initConfig(IDiscordClient ourClient, Config config, GlobalDat
argsMax = config.argsMax;
maxWarnings = config.maxWarnings;
dailyMessages = config.dailyMessages;
baseXPModifier = config.baseXpModifier;
xpForLevelOne = config.xpForLevelOne;
initCommands();
}

Expand Down Expand Up @@ -224,22 +229,17 @@ else if (!Files.exists(Paths.get(Constants.DIRECTORY_GLOBAL_IMAGES + defaultAvat
throw new IllegalArgumentException("maxWarnings cannot be less than or equals 0");
}

public static void initGuild(String guildID) {
public static void initGuild(String guildID, GuildConfig guildConfig, Servers servers, CustomCommands customCommands, Characters characters, Competition competition, GuildUsers guildUsers) {
for (GuildContentObject contentObject : guildContentObjects) {
if (guildID.equals(contentObject.getGuildID())) {
return;
}
}
GuildConfig guildConfig = (GuildConfig) Utility.initFile(guildID, Constants.FILE_GUILD_CONFIG, GuildConfig.class);
CustomCommands customCommands = (CustomCommands) Utility.initFile(guildID, Constants.FILE_CUSTOM, CustomCommands.class);
Servers servers = (Servers) Utility.initFile(guildID, Constants.FILE_SERVERS, Servers.class);
Characters characters = (Characters) Utility.initFile(guildID, Constants.FILE_CHARACTERS, Characters.class);
Competition competition = (Competition) Utility.initFile(guildID, Constants.FILE_COMPETITION, Competition.class);

IGuild guild = client.getGuildByID(guildID);
guildConfig.updateVariables(guild);

GuildContentObject guildContentObject = new GuildContentObject(guildID, guildConfig, customCommands, servers, characters, competition);
GuildContentObject guildContentObject = new GuildContentObject(guildID, guildConfig, customCommands, servers, characters, competition,guildUsers);
guildContentObjects.add(guildContentObject);
}

Expand Down
36 changes: 27 additions & 9 deletions src/main/java/Main/TimedEvents.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package Main;

import Commands.Command;
import Objects.DailyMessageObject;
import Objects.ReminderObject;
import Objects.TimedObject;
import Objects.WaiterObject;
import Objects.*;
import POGOs.GuildConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -75,6 +72,9 @@ private static void doEventDaily(ZonedDateTime nowUTC) {
logger.debug("Now UTC = " + Utility.formatTimeSeconds(nowUTC.toEpochSecond()));
logger.debug("Midnight UTC = " + Utility.formatTimeSeconds(midnightUTC.toEpochSecond()));
logger.debug("Delay = " + Utility.formatTimeSeconds(initialDelay));
if (initialDelay < 120) {
initialDelay += 24 * 60 * 60;
}
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
Expand Down Expand Up @@ -112,6 +112,8 @@ public void run() {
Utility.backupFile(g.getGuildID(), Constants.FILE_INFO);
Utility.backupFile(g.getGuildID(), Constants.FILE_COMPETITION);
GuildConfig guildConfig = Globals.getGuildContent(g.getGuildID()).getGuildConfig();
GuildContentObject contentObject = Globals.getGuildContent(g.getGuildID());
contentObject.getGuildUsers().addLevels();

//daily messages
if (guildConfig.getChannelTypeID(Command.CHANNEL_GENERAL) != null) {
Expand Down Expand Up @@ -215,8 +217,16 @@ public void run() {

private static void doEventMin(ZonedDateTime nowUTC) {
ZonedDateTime nextTimeUTC;
nextTimeUTC = nowUTC.withSecond(0).withMinute(nowUTC.getMinute() + 1);
long initialDelay = (nextTimeUTC.toEpochSecond() - nowUTC.toEpochSecond());
long initialDelay = 0;
if (nowUTC.getMinute() != 60) {
nextTimeUTC = nowUTC.withSecond(0).withMinute(nowUTC.getMinute() + 1);
} else {
nextTimeUTC = nowUTC.withSecond(0).withHour(nowUTC.getHour() + 1).withMinute(0);
}
initialDelay = (nextTimeUTC.toEpochSecond() - nowUTC.toEpochSecond());
if (initialDelay < 30) {
initialDelay += 60;
}
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
Expand Down Expand Up @@ -245,10 +255,18 @@ public void run() {
}

private static void doEventFiveMin(ZonedDateTime nowUTC) {
while (!Globals.getClient().isReady());
while (!Globals.getClient().isReady()) ;
ZonedDateTime nextTimeUTC;
nextTimeUTC = nowUTC.withSecond(0).withMinute(nowUTC.getMinute() + 1);
long initialDelay = (nextTimeUTC.toEpochSecond() - nowUTC.toEpochSecond());
long initialDelay = 0;
if (nowUTC.getMinute() != 60) {
nextTimeUTC = nowUTC.withSecond(0).withMinute(nowUTC.getMinute() + 1);
} else {
nextTimeUTC = nowUTC.withSecond(0).withHour(nowUTC.getHour() + 1).withMinute(0);
}
initialDelay = (nextTimeUTC.toEpochSecond() - nowUTC.toEpochSecond());
if (initialDelay < 30) {
initialDelay += 60;
}
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
Expand Down
Loading

0 comments on commit 9df0477

Please sign in to comment.