Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Better error handling for Shortify.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Dec 9, 2014
1 parent 5f535ed commit 16739f6
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/main/java/com/cnaude/purpleirc/Hooks/ShortifyHook.java
Expand Up @@ -18,6 +18,7 @@

import com.cnaude.purpleirc.PurpleIRC;
import com.nullblock.vemacs.Shortify.common.CommonConfiguration;
import com.nullblock.vemacs.Shortify.common.Shortener;
import com.nullblock.vemacs.Shortify.common.ShortifyException;
import com.nullblock.vemacs.Shortify.util.ShortifyUtility;
import java.io.File;
Expand All @@ -30,24 +31,40 @@ public class ShortifyHook {

private final PurpleIRC plugin;
private final CommonConfiguration configuration;
private final Shortener shortener;

/**
*
* @param plugin
*/
public ShortifyHook(PurpleIRC plugin) {
this.plugin = plugin;
configuration = ShortifyUtility.loadCfg(new File("plugins/Shortify/config.yml"));
this.configuration = ShortifyUtility.loadCfg(new File("plugins/Shortify/config.yml"));
this.shortener = ShortifyUtility.getShortener(configuration);
}

public String shorten(String message) {
String m = message;
try {
m = ShortifyUtility.shortenAll(message, Integer.valueOf(
configuration.getString("minlength", "20")), ShortifyUtility.getShortener(configuration), "");
} catch (ShortifyException ex) {
plugin.logError(ex.getMessage());
int minLength = 20;
plugin.logDebug("ShortifyBefore: " + m);
if (configuration != null) {
try {
minLength = Integer.valueOf(configuration.getString("minlength", "20"));
} catch (Exception ex) {
plugin.logError(ex.getMessage());
return message;
}
}

if (shortener != null) {
try {
m = ShortifyUtility.shortenAll(message, minLength, shortener, "");
} catch (ShortifyException ex) {
plugin.logError(ex.getMessage());
return message;
}
}
plugin.logDebug("ShortifyAfter: " + m);
return m;
}

Expand Down

0 comments on commit 16739f6

Please sign in to comment.