Skip to content

Commit

Permalink
* Added option to log Slack response messages
Browse files Browse the repository at this point in the history
* Added ticket number to Slack messages
  • Loading branch information
RoyCurtis committed Apr 8, 2016
1 parent 843a855 commit 76b6699
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected void run(CommandSender sender, String[] args) {
ticket.getSubmitter(),
ticket.getTicketLocation().getWorldName(),
ticket.getTicketLocation().getX(),
ticket.getTicketLocation().getZ()
ticket.getTicketLocation().getZ(),
ticket.getId()
);
}

Expand Down
22 changes: 12 additions & 10 deletions src/main/java/me/rafaskb/ticketmaster/integrations/Slack.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
public class Slack {


public static void sendMessage(String message, String username, String world, double x , double z){
public static void sendMessage(String message, String username, String world, double x , double z, int id){

URL url;
try {
url = new URL(ConfigLoader.getSlackwebhookurl());

Map<String,Object> params = new LinkedHashMap<>();
params.put("payload", generateMessage(message,username,world,x,z) );
params.put("payload", generateMessage(message,username,world,x,z,id) );

StringBuilder postData = new StringBuilder();
try {
Expand All @@ -42,13 +42,15 @@ public static void sendMessage(String message, String username, String world, do
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);

Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String response = "";
for ( int c = in.read(); c != -1; c = in.read() ) {
response +=(char) c;
}
if (ConfigLoader.isSlackDebug()) {
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String response = "";
for (int c = in.read(); c != -1; c = in.read()) {
response += (char) c;
}

TicketMaster.getInstance().getLogger().info("message from Slack server: "+response);
TicketMaster.getInstance().getLogger().info("message from Slack server: " + response);
}

} catch (IOException e) {
TicketMaster.getInstance().getLogger().warning("Ticket Master Slack integration IO error:"+e.getMessage());
Expand All @@ -60,10 +62,10 @@ public static void sendMessage(String message, String username, String world, do
}


private static String generateMessage(String message, String username, String world, double x , double z){
private static String generateMessage(String message, String username, String world, double x , double z, int id){

String m = "{";
m+= "\"text\":\""+username+" filed a ticket: "+message+" "+generateDynmapURL(world,x,z)+"\",";
m+= "\"text\":\""+username+" filed ticket #"+id+": "+message+" "+generateDynmapURL(world,x,z)+"\",";
m+= "\"username\":\"Ticket Master Bot\",";
m+= "\"icon_url\":\"https://minotar.net/avatar/"+username+"/100.png\"";
m+= "}";
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/rafaskb/ticketmaster/utils/ConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public static void setSlackEnable(boolean slackEnable) {
ConfigLoader.slackEnable = slackEnable;
}

public static boolean isSlackDebug() {
return slackDebug;
}

public static void setSlackDebug(boolean slackDebug) {
ConfigLoader.slackDebug = slackDebug;
}

public static String getDynmapurl() {
return dynmapurl;
}
Expand All @@ -32,6 +40,7 @@ public static void setSlackwebhookurl(String slackwebhookurl) {
}

private static boolean slackEnable;
private static boolean slackDebug;



Expand All @@ -44,6 +53,7 @@ public static void reloadConfig(){
setDynmapurl(TicketMaster.getInstance().getConfig().getString("dynmapurl"));
setSlackwebhookurl(TicketMaster.getInstance().getConfig().getString("slackwebhookURL"));
setSlackEnable(TicketMaster.getInstance().getConfig().getBoolean("enableSlackintergration"));
setSlackDebug(TicketMaster.getInstance().getConfig().getBoolean("enableSlackDebug"));


}
Expand Down

0 comments on commit 76b6699

Please sign in to comment.