Skip to content

Commit

Permalink
Added Logger
Browse files Browse the repository at this point in the history
Also changed default command to diw echo.
  • Loading branch information
CoolV1994 committed Oct 27, 2014
1 parent f064c01 commit c0d1727
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Binary file not shown.
27 changes: 18 additions & 9 deletions src/CommandListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import com.vexsoftware.votifier.Votifier;
import com.vexsoftware.votifier.model.Vote;
Expand All @@ -10,6 +11,7 @@
* Created by Vinnie on 10/17/14.
*/
public class CommandListener implements VoteListener {
private Logger log = Logger.getLogger("CommandListener");
private List<String> commands = new ArrayList<String>();

public CommandListener() {
Expand All @@ -19,15 +21,16 @@ public CommandListener() {
try {
configFile.createNewFile();

String defaultCommand = "say Thanks {username} for voting on {serviceName}!";
String defaultCommand = "diw echo Thanks &a{username} for voting on &9{serviceName}!";
commands.add(defaultCommand);

FileWriter fw = new FileWriter(configFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.newLine();
bw.write(defaultCommand);
bw.close();
} catch (IOException e) {
e.printStackTrace();
log.warning("Error creating default CommandListener configuration.");
}
}
else
Expand All @@ -40,10 +43,11 @@ public CommandListener() {
commands.add(currentLine);
}
} catch (IOException e) {
e.printStackTrace();
log.warning("Error loading CommandListener configuration.");
} finally {
try {
if (br != null)br.close();
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
Expand All @@ -53,21 +57,26 @@ public CommandListener() {

@Override
public void voteMade(Vote vote) {
log.info("Received: " + vote);
if (vote.getUsername() != null) {
for (int i = 0; i < commands.size(); i++) {
String command = commands.get(i);
for (String command : commands) {
// Voter's Username
if(command.contains("{username}")) {
command = command.replace("{username}", vote.getUsername());
}
if(command.contains("{address}")) {
command = command.replace("{address}", vote.getAddress());
}
// Website voted on
if(command.contains("{serviceName}")) {
command = command.replace("{serviceName}", vote.getServiceName());
}
// Voter's IP Address
if(command.contains("{address}")) {
command = command.replace("{address}", vote.getAddress());
}
// Time of Vote
if(command.contains("{timeStamp}")) {
command = command.replace("{timeStamp}", vote.getTimeStamp());
}
// Run command
Votifier.getServer().executeCommand(command);
}
}
Expand Down

0 comments on commit c0d1727

Please sign in to comment.