From 01e47e3d67fd700d419f7d9466af7bed751fbaa8 Mon Sep 17 00:00:00 2001 From: Ackochanski Date: Tue, 17 Oct 2017 14:48:42 -0400 Subject: [PATCH 01/16] first commit to User.Java --- src/nyc/c4q/ramonaharrison/model/User.java | 125 ++++++++++++++++++--- 1 file changed, 109 insertions(+), 16 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/model/User.java b/src/nyc/c4q/ramonaharrison/model/User.java index bc309eb..a1f11f0 100644 --- a/src/nyc/c4q/ramonaharrison/model/User.java +++ b/src/nyc/c4q/ramonaharrison/model/User.java @@ -2,6 +2,7 @@ import org.json.simple.JSONObject; + /** * Created by Ramona Harrison * on 8/26/16 @@ -13,24 +14,116 @@ public class User { - // TODO: implement private fields for each of the following user JSON keys: - // "id" - // "name" - // "deleted" - // "color" - // "profile" - // "is_admin" - // "is_owner" - // "is_primary_owner" - // "is_restricted" - // "is_ultra_restricted" - // "has_2fa" - // "two_factor_type" - // "has_files" + private String id; + private String name; + private boolean deleted; + private String color; + private String profile; + private boolean isAdmin; + private boolean isOwner; + private boolean isPrimaryOwner; + private boolean isRestricted; + private boolean has2fa; + private boolean twoFactorType; + private boolean hasFiles; + public User(JSONObject json) { - // TODO: parse a user from the incoming json + + if (json.get("id") != null) { + this.id = (String) json.get("id"); + } + + if (json.get("name") != null) { + this.name = (String) json.get("name"); + } + + if (json.get("deleted") != null) { + this.deleted = (Boolean) json.get("deleted"); + } + + if (json.get("color") != null) { + this.color = (String) json.get("color"); + } + + if (json.get("profile") != null) { + this.profile = (String) json.get("profile"); + } + + if (json.get("is_admin") != null) { + this.isAdmin = (Boolean) json.get("is_admin"); + } + + if (json.get("is_owner") != null) { + this.isOwner = (Boolean) json.get("is_owner"); + } + + if (json.get("is_primary_owner") != null) { + this.isPrimaryOwner = (Boolean) json.get("is_primary_owner"); + } + + if (json.get("is_restricted") != null) { + this.isRestricted = (Boolean) json.get("is_restricted"); + } + + if (json.get("has_2fa") != null) { + this.has2fa = (Boolean) json.get("has_2fa"); + } + + if (json.get("two_factor_type") != null) { + this.twoFactorType = (Boolean) json.get("two_factor_type"); + } + + if (json.get("has_files") != null) { + this.hasFiles = (Boolean) json.get("has_file"); + } } - // TODO add getters to access private fields + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public boolean deleted() { + return deleted; + } + + public String getcolor() { + return color; + } + + public String getProfile() { + return profile; + } + + public boolean IsAdmin() { + return isAdmin; + } + + public boolean isOwner() { + return isOwner; + } + + public boolean isPrimaryOwner() { + return isPrimaryOwner; + } + + public boolean isRestricted() { + return isRestricted; + } + + public boolean has2fa() { + return has2fa; + } + + public boolean twoFactorType() { + return twoFactorType; + } + + public boolean hasFiles() { + return hasFiles; + } } From e1a59535dff9bc0c1c80de5269bccfcaf4196416 Mon Sep 17 00:00:00 2001 From: Yoki Lam Date: Tue, 17 Oct 2017 21:36:13 -0400 Subject: [PATCH 02/16] added_token --- src/nyc/c4q/ramonaharrison/Main.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 933e92b..579af75 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -14,6 +14,8 @@ public static void main(String[] args) { myBot.listMessages(Slack.BOTS_CHANNEL_ID); + System.out.println("testing"); + // Post "Hello, world!" to the #bots channel //myBot.sendMessage("Hello, world!"); From c6ba7bc67c84d5fb4a5bb3145d2769d5c22bceaf Mon Sep 17 00:00:00 2001 From: Ackochanski Date: Wed, 18 Oct 2017 11:48:41 -0400 Subject: [PATCH 03/16] adding api key --- nano.save | 2 ++ src/nyc/c4q/ramonaharrison/model/User.java | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) create mode 100644 nano.save diff --git a/nano.save b/nano.save new file mode 100644 index 0000000..a5cb6b9 --- /dev/null +++ b/nano.save @@ -0,0 +1,2 @@ +xoxb-256619381650-4fYFTrN2thrUnnk0D74tXRT9 + diff --git a/src/nyc/c4q/ramonaharrison/model/User.java b/src/nyc/c4q/ramonaharrison/model/User.java index a1f11f0..2c87259 100644 --- a/src/nyc/c4q/ramonaharrison/model/User.java +++ b/src/nyc/c4q/ramonaharrison/model/User.java @@ -2,16 +2,6 @@ import org.json.simple.JSONObject; - -/** - * Created by Ramona Harrison - * on 8/26/16 - * - * A class representing a user. - * See https://api.slack.com/types/user - * - */ - public class User { private String id; From 2278c7764a3b3e5b7759d4630f75082b3285d4e4 Mon Sep 17 00:00:00 2001 From: Ackochanski <30937177+Ackochanski@users.noreply.github.com> Date: Thu, 19 Oct 2017 13:10:35 -0400 Subject: [PATCH 04/16] Delete nano.save --- nano.save | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 nano.save diff --git a/nano.save b/nano.save deleted file mode 100644 index a5cb6b9..0000000 --- a/nano.save +++ /dev/null @@ -1,2 +0,0 @@ -xoxb-256619381650-4fYFTrN2thrUnnk0D74tXRT9 - From 9df445c099df033689d33f079593c10560912377 Mon Sep 17 00:00:00 2001 From: Ackochanski <30937177+Ackochanski@users.noreply.github.com> Date: Thu, 19 Oct 2017 22:02:30 -0400 Subject: [PATCH 05/16] Delete nano.save --- nano.save | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 nano.save diff --git a/nano.save b/nano.save deleted file mode 100644 index a5cb6b9..0000000 --- a/nano.save +++ /dev/null @@ -1,2 +0,0 @@ -xoxb-256619381650-4fYFTrN2thrUnnk0D74tXRT9 - From d38cdafb219af199a43e9d110c70d4581cd28c30 Mon Sep 17 00:00:00 2001 From: Ackochanski Date: Thu, 19 Oct 2017 22:13:36 -0400 Subject: [PATCH 06/16] minor changes --- src/nyc/c4q/ramonaharrison/Bot.java | 1 + src/nyc/c4q/ramonaharrison/Main.java | 6 ++++++ src/nyc/c4q/ramonaharrison/network/Slack.java | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Bot.java b/src/nyc/c4q/ramonaharrison/Bot.java index 6a52dd4..ad1e41c 100644 --- a/src/nyc/c4q/ramonaharrison/Bot.java +++ b/src/nyc/c4q/ramonaharrison/Bot.java @@ -82,6 +82,7 @@ public void sendMessageToBotsChannel(String text) { } else { System.err.print("Error sending message: " + sendMessageResponse.getError()); } + } /** diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 933e92b..c77117f 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -1,5 +1,7 @@ package nyc.c4q.ramonaharrison; +import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion; +import nyc.c4q.ramonaharrison.model.Message; import nyc.c4q.ramonaharrison.network.Slack; public class Main { @@ -14,6 +16,10 @@ public static void main(String[] args) { myBot.listMessages(Slack.BOTS_CHANNEL_ID); +// myBot.sendMessageToBotsChannel(" testing " ); + + + // Post "Hello, world!" to the #bots channel //myBot.sendMessage("Hello, world!"); diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index 87521bd..5040f73 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -27,8 +27,9 @@ public class Slack { private static final String ENDPOINT_LIST_MESSAGES = "channels.history"; private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; + private static String asUser = "true"; - public static final String BOTS_CHANNEL_ID = "C2ABKERFT"; + public static final String BOTS_CHANNEL_ID = "C7KE0KTM4"; /** * Static method to test the Slack API. @@ -82,7 +83,7 @@ public static SendMessageResponse sendMessage(String messageText) { throw new RuntimeException(e); } - URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText); + URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText + "&as_user="+ asUser); return new SendMessageResponse(HTTPS.get(sendMessageUrl)); } From c5d9738648c172c67d5a0c97e0c6dede2a44bfdf Mon Sep 17 00:00:00 2001 From: Yoki Lam Date: Fri, 20 Oct 2017 12:10:02 -0400 Subject: [PATCH 07/16] name_and_random --- src/nyc/c4q/ramonaharrison/Bot.java | 18 +++ src/nyc/c4q/ramonaharrison/Main.java | 13 ++- .../c4q/ramonaharrison/model/Attachment.java | 107 +++++++++++++++--- src/nyc/c4q/ramonaharrison/network/HTTPS.java | 3 + src/nyc/c4q/ramonaharrison/network/Slack.java | 8 +- 5 files changed, 130 insertions(+), 19 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Bot.java b/src/nyc/c4q/ramonaharrison/Bot.java index 6a52dd4..2240412 100644 --- a/src/nyc/c4q/ramonaharrison/Bot.java +++ b/src/nyc/c4q/ramonaharrison/Bot.java @@ -5,7 +5,9 @@ import nyc.c4q.ramonaharrison.network.*; import nyc.c4q.ramonaharrison.network.response.*; +import java.util.ArrayList; import java.util.List; +import java.util.Random; /** * Created by Ramona Harrison @@ -16,7 +18,10 @@ public class Bot { // TODO: implement your bot logic! + ArrayList tips = new ArrayList<>(); + public Bot() { +// randomTip(); } @@ -98,4 +103,17 @@ public void deleteMessageInBotsChannel(String messageTs) { System.err.print("Error sending message: " + deleteMessageResponse.getError()); } } + + public String randomTip () { + tips.add("Arrays have fixed size but ArrayLists have variable sizes. \n Since the size of Array is fixed, the memory gets allocated at the time of declaration of Array type variable. \n Hence, Arrays are very fast. "); + tips.add("To compute power (^), one way is to use the Math.pow"); + + Random r= new Random(); + + + String tip=tips.get(r.nextInt(tips.size())); + return tip; + } + + } diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 579af75..2c3c5a0 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -1,7 +1,10 @@ package nyc.c4q.ramonaharrison; +import jdk.nashorn.internal.parser.JSONParser; import nyc.c4q.ramonaharrison.network.Slack; + + public class Main { public static void main(String[] args) { @@ -9,12 +12,18 @@ public static void main(String[] args) { Bot myBot = new Bot(); myBot.testApi(); - myBot.listChannels(); +// JSONParser parser = new JSONParser(); + myBot.listMessages(Slack.BOTS_CHANNEL_ID); - System.out.println("testing"); + + + + myBot.sendMessageToBotsChannel(myBot.randomTip()); + myBot.sendMessageToBotsChannel("Yum yum!"); + myBot.sendMessageToBotsChannel("So does this one: "); // Post "Hello, world!" to the #bots channel //myBot.sendMessage("Hello, world!"); diff --git a/src/nyc/c4q/ramonaharrison/model/Attachment.java b/src/nyc/c4q/ramonaharrison/model/Attachment.java index 8b9d1ef..b982e97 100644 --- a/src/nyc/c4q/ramonaharrison/model/Attachment.java +++ b/src/nyc/c4q/ramonaharrison/model/Attachment.java @@ -14,26 +14,103 @@ public class Attachment { // TODO: implement private fields for each of the following attachment JSON keys: - // "fallback" - // "color" - // "pretext" - // "author_name" - // "author_link" - // "author_icon" - // "title" - // "title_link" - // "text" - // "fields" - // "image_url" - // "thumb_url" - // "footer" - // "footer_icon" - // "ts" +// private String fallback; +// private String color; +// private String pretext; +// private String author_name; +// private String author_link; +// private String author_icon; +// private String title; +// private String title_link; +// private String text; +// private String image_url; +// private String thumb_url; +// private String footer; +// private String footer_icon; +// private String ts; + public Attachment(JSONObject json) { // TODO: parse an attachment from the incoming json +// if (json.get("fallback") != null) { +// this.fallback = (String) json.get("fallback"); +// } +// if(json.get("color")!=null){ +// this.color=(String) json.get(color); +// } +// if(json.get("pretext")!=null){ +// this.pretext=(String) json.get("pretext"); +// } +// if(json.get("author_name")!=null){ +// this.author_name=(String)json.get("author_name"); +// } +// if(json.get("author_link")!=null){ +// this.author_link=(String) json.get("author_link"); +// } +// if(json.get("author_icon")!=null){ +// this.author_icon=(String) json.get("author_icon"); +// } +// if(json.get("title")!=null){ +// this.title=(String) json.get("title"); +// }if(json.get("title_link")!=null){ +// this.title_link=(String) json.get("title_link"); +// }if(json.get("text")!=null){ +// this.text=(String) json.get("text");// +// }if(json.get("image_url")!=null){ +// this.image_url=(String) json.get("image_url"); +// }if(json.get("thumb_url")!=null){ +// this.thumb_url=(String) json.get("thumb_url"); +// }if(json.get("footer")!=null){ +// this.footer=(String) json.get("footer"); +// }if(json.get("footer_icon")!=null){ +// this.footer_icon=(String) json.get("footer_icon"); +// }if(json.get("ts")!=null){ +// this.ts=(String) json.get("ts"); +// } } // TODO add getters to access private fields +// public String getFallback() { +// return fallback; +// } +// public String getColor() { +// return color; +// } +// public String getPretext() { +// return pretext; +// } +// public String getAuthor_name() { +// return author_name; +// } +// public String getAuthor_link() { +// return author_link; +// } +// public String getAuthor_icon() { +// return author_icon; +// } +// public String getTitle() { +// return title; +// } +// public String getTitle_link() { +// return title_link; +// } +// public String getText() { +// return text; +// } +// public String getImage_url() { +// return image_url; +// } +// public String getThumb_url() { +// return thumb_url; +// } +// public String getFooter() { +// return footer; +// } +// public String getFooter_icon() { +// return footer_icon; +// } +// public String getTs() { +// return ts; +// } } diff --git a/src/nyc/c4q/ramonaharrison/network/HTTPS.java b/src/nyc/c4q/ramonaharrison/network/HTTPS.java index 7da0c8d..2f3f8e2 100644 --- a/src/nyc/c4q/ramonaharrison/network/HTTPS.java +++ b/src/nyc/c4q/ramonaharrison/network/HTTPS.java @@ -18,7 +18,10 @@ public class HTTPS { /** * Reads from 'reader' by 'blockSize' until end-of-stream, and returns its complete contents. + * */ + + private static String readAll(InputStreamReader reader, int blockSize) throws IOException { final char buffer[] = new char[blockSize]; StringBuilder builder = new StringBuilder(); diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index 87521bd..aeaf199 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -20,6 +20,7 @@ public class Slack { + public static final boolean as_user= true; private static final String API_KEY = Token.findApiToken(); private static final String BASE_URL = "https://slack.com/api/"; private static final String ENDPOINT_TEST = "api.test"; @@ -28,7 +29,10 @@ public class Slack { private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; - public static final String BOTS_CHANNEL_ID = "C2ABKERFT"; + public static final String BOTS_CHANNEL_ID = "C7M51NP4K"; + //"C7KE0KTM4" + //C7M51NP4K + //C7M6UM4LA /** * Static method to test the Slack API. @@ -82,7 +86,7 @@ public static SendMessageResponse sendMessage(String messageText) { throw new RuntimeException(e); } - URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText); + URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText+"&as_user="+as_user); return new SendMessageResponse(HTTPS.get(sendMessageUrl)); } From 93031f05b3bd2d0d848ac20912788cbad98351c1 Mon Sep 17 00:00:00 2001 From: Darnell O Date: Fri, 20 Oct 2017 12:14:50 -0400 Subject: [PATCH 08/16] attachment --- src/nyc/c4q/ramonaharrison/Main.java | 4 +- .../c4q/ramonaharrison/model/Attachment.java | 120 ++++++++++++++++++ src/nyc/c4q/ramonaharrison/network/Slack.java | 2 +- 3 files changed, 123 insertions(+), 3 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 933e92b..867ccaa 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -12,10 +12,10 @@ public static void main(String[] args) { myBot.listChannels(); - myBot.listMessages(Slack.BOTS_CHANNEL_ID); + // myBot.listMessages(Slack.BOTS_CHANNEL_ID); // Post "Hello, world!" to the #bots channel - //myBot.sendMessage("Hello, world!"); + myBot.sendMessageToBotsChannel("Testing, Testing"); // Post a pineapple photo to the #bots channel //myBot.sendMessage("http://weknowyourdreams.com/images/pineapple/pineapple-07.jpg"); diff --git a/src/nyc/c4q/ramonaharrison/model/Attachment.java b/src/nyc/c4q/ramonaharrison/model/Attachment.java index 8b9d1ef..53830c5 100644 --- a/src/nyc/c4q/ramonaharrison/model/Attachment.java +++ b/src/nyc/c4q/ramonaharrison/model/Attachment.java @@ -15,25 +15,145 @@ public class Attachment { // TODO: implement private fields for each of the following attachment JSON keys: // "fallback" + private String fallback; // "color" + private String color; // "pretext" + private String pretext; // "author_name" + private String author_name; // "author_link" + private String author_link; // "author_icon" + private String author_icon; // "title" + private String title; // "title_link" + private String title_link; // "text" + private String text; // "fields" + private String fields; // "image_url" + private String image_url; // "thumb_url" + private String thumb_url; // "footer" + private String footer; // "footer_icon" + private String footer_icon; // "ts" + private String ts; public Attachment(JSONObject json) { // TODO: parse an attachment from the incoming json + if (json.get("fallback") != null) { + this.fallback = (String) json.get("fallback"); + } + if (json.get("color") !=null) { + this.color = (String) json.get("color"); + } + if (json.get("pretext") != null) { + this.pretext = (String) json.get("pretext"); + } + if (json.get("author name")!=null){ + this.author_name = (String) json.get("author name"); + } + if (json.get("author link")!=null){ + this.author_link = (String) json.get("author link"); + } + if (json.get("author icon")!=null){ + this.author_icon =(String) json.get("author icon"); + } + if (json.get("title")!=null){ + this.title = (String) json.get ("title"); + } + if (json.get("title link")!=null){ + this.title_link = (String) json.get ("title link"); + } + if (json.get("text")!=null){ + this.text = (String) json.get ("text"); + } + if (json.get("fields")!=null){ + this.fields = (String) json.get ("fields"); + } + if (json.get("image url")!=null){ + this.image_url = (String) json.get ("image url"); + } + if (json.get("thumb url")!=null){ + this.thumb_url = (String) json.get (" thumb url"); + } + if (json.get("footer")!=null){ + this.footer= (String) json.get ("footer"); + } + if (json.get("ts")!=null){ + this.ts = (String) json.get ("ts"); + } + + + } // TODO add getters to access private fields + + public String getFallback() { + return fallback; + } + + public String getColor() { + return color; + } + + public String getPretext() { + return pretext; + } + + public String getAuthor_name() { + return author_name; + } + + public String getAuthor_link() { + return author_link; + } + + public String getAuthor_icon() { + return author_icon; + } + + public String getTitle() { + return title; + } + + public String getTitle_link() { + return title_link; + } + + public String getText() { + return text; + } + + public String getFields() { + return fields; + } + + public String getImage_url() { + return image_url; + } + + public String getThumb_url() { + return thumb_url; + } + + public String getFooter() { + return footer; + } + + public String getFooter_icon() { + return footer_icon; + } + + public String getTs() { + return ts; + } } diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index 87521bd..a61a2e7 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -28,7 +28,7 @@ public class Slack { private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; - public static final String BOTS_CHANNEL_ID = "C2ABKERFT"; + public static final String BOTS_CHANNEL_ID = "C7KE0KTM4"; /** * Static method to test the Slack API. From 567d7c80f43000fb1ab844644b586af227900a13 Mon Sep 17 00:00:00 2001 From: Yoki Lam Date: Fri, 20 Oct 2017 12:20:44 -0400 Subject: [PATCH 09/16] removes_conflict --- src/nyc/c4q/ramonaharrison/Main.java | 5 +- .../c4q/ramonaharrison/model/Attachment.java | 93 +------------------ 2 files changed, 3 insertions(+), 95 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 2c3c5a0..e802692 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -14,11 +14,8 @@ public static void main(String[] args) { myBot.testApi(); myBot.listChannels(); -// JSONParser parser = new JSONParser(); - - myBot.listMessages(Slack.BOTS_CHANNEL_ID); - +// myBot.listMessages(Slack.BOTS_CHANNEL_ID); myBot.sendMessageToBotsChannel(myBot.randomTip()); diff --git a/src/nyc/c4q/ramonaharrison/model/Attachment.java b/src/nyc/c4q/ramonaharrison/model/Attachment.java index b982e97..d875174 100644 --- a/src/nyc/c4q/ramonaharrison/model/Attachment.java +++ b/src/nyc/c4q/ramonaharrison/model/Attachment.java @@ -14,103 +14,14 @@ public class Attachment { // TODO: implement private fields for each of the following attachment JSON keys: -// private String fallback; -// private String color; -// private String pretext; -// private String author_name; -// private String author_link; -// private String author_icon; -// private String title; -// private String title_link; -// private String text; -// private String image_url; -// private String thumb_url; -// private String footer; -// private String footer_icon; -// private String ts; public Attachment(JSONObject json) { // TODO: parse an attachment from the incoming json -// if (json.get("fallback") != null) { -// this.fallback = (String) json.get("fallback"); -// } -// if(json.get("color")!=null){ -// this.color=(String) json.get(color); -// } -// if(json.get("pretext")!=null){ -// this.pretext=(String) json.get("pretext"); -// } -// if(json.get("author_name")!=null){ -// this.author_name=(String)json.get("author_name"); -// } -// if(json.get("author_link")!=null){ -// this.author_link=(String) json.get("author_link"); -// } -// if(json.get("author_icon")!=null){ -// this.author_icon=(String) json.get("author_icon"); -// } -// if(json.get("title")!=null){ -// this.title=(String) json.get("title"); -// }if(json.get("title_link")!=null){ -// this.title_link=(String) json.get("title_link"); -// }if(json.get("text")!=null){ -// this.text=(String) json.get("text");// -// }if(json.get("image_url")!=null){ -// this.image_url=(String) json.get("image_url"); -// }if(json.get("thumb_url")!=null){ -// this.thumb_url=(String) json.get("thumb_url"); -// }if(json.get("footer")!=null){ -// this.footer=(String) json.get("footer"); -// }if(json.get("footer_icon")!=null){ -// this.footer_icon=(String) json.get("footer_icon"); -// }if(json.get("ts")!=null){ -// this.ts=(String) json.get("ts"); -// } + } // TODO add getters to access private fields -// public String getFallback() { -// return fallback; -// } -// public String getColor() { -// return color; -// } -// public String getPretext() { -// return pretext; -// } -// public String getAuthor_name() { -// return author_name; -// } -// public String getAuthor_link() { -// return author_link; -// } -// public String getAuthor_icon() { -// return author_icon; -// } -// public String getTitle() { -// return title; -// } -// public String getTitle_link() { -// return title_link; -// } -// public String getText() { -// return text; -// } -// public String getImage_url() { -// return image_url; -// } -// public String getThumb_url() { -// return thumb_url; -// } -// public String getFooter() { -// return footer; -// } -// public String getFooter_icon() { -// return footer_icon; -// } -// public String getTs() { -// return ts; -// } + } From d31e8bedb2700e1c1914c102c6f857df189bf77b Mon Sep 17 00:00:00 2001 From: Yoki Lam Date: Fri, 20 Oct 2017 12:36:41 -0400 Subject: [PATCH 10/16] resolved... --- src/nyc/c4q/ramonaharrison/Bot.java | 1 - src/nyc/c4q/ramonaharrison/model/User.java | 47 ------------------- src/nyc/c4q/ramonaharrison/network/Slack.java | 6 +-- 3 files changed, 2 insertions(+), 52 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Bot.java b/src/nyc/c4q/ramonaharrison/Bot.java index 2240412..ffdedd9 100644 --- a/src/nyc/c4q/ramonaharrison/Bot.java +++ b/src/nyc/c4q/ramonaharrison/Bot.java @@ -21,7 +21,6 @@ public class Bot { ArrayList tips = new ArrayList<>(); public Bot() { -// randomTip(); } diff --git a/src/nyc/c4q/ramonaharrison/model/User.java b/src/nyc/c4q/ramonaharrison/model/User.java index a1f11f0..a4159b7 100644 --- a/src/nyc/c4q/ramonaharrison/model/User.java +++ b/src/nyc/c4q/ramonaharrison/model/User.java @@ -30,53 +30,6 @@ public class User { public User(JSONObject json) { - if (json.get("id") != null) { - this.id = (String) json.get("id"); - } - - if (json.get("name") != null) { - this.name = (String) json.get("name"); - } - - if (json.get("deleted") != null) { - this.deleted = (Boolean) json.get("deleted"); - } - - if (json.get("color") != null) { - this.color = (String) json.get("color"); - } - - if (json.get("profile") != null) { - this.profile = (String) json.get("profile"); - } - - if (json.get("is_admin") != null) { - this.isAdmin = (Boolean) json.get("is_admin"); - } - - if (json.get("is_owner") != null) { - this.isOwner = (Boolean) json.get("is_owner"); - } - - if (json.get("is_primary_owner") != null) { - this.isPrimaryOwner = (Boolean) json.get("is_primary_owner"); - } - - if (json.get("is_restricted") != null) { - this.isRestricted = (Boolean) json.get("is_restricted"); - } - - if (json.get("has_2fa") != null) { - this.has2fa = (Boolean) json.get("has_2fa"); - } - - if (json.get("two_factor_type") != null) { - this.twoFactorType = (Boolean) json.get("two_factor_type"); - } - - if (json.get("has_files") != null) { - this.hasFiles = (Boolean) json.get("has_file"); - } } public String getId() { diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index aeaf199..fa2ed3d 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -29,10 +29,8 @@ public class Slack { private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; - public static final String BOTS_CHANNEL_ID = "C7M51NP4K"; - //"C7KE0KTM4" - //C7M51NP4K - //C7M6UM4LA + public static final String BOTS_CHANNEL_ID = "C7KE0KTM4"; + /** * Static method to test the Slack API. From 4d84236f7a482b53c997580890f274301f20cc94 Mon Sep 17 00:00:00 2001 From: Darnell O Date: Fri, 20 Oct 2017 12:48:11 -0400 Subject: [PATCH 11/16] Again --- src/nyc/c4q/ramonaharrison/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 867ccaa..5f9d178 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -12,7 +12,7 @@ public static void main(String[] args) { myBot.listChannels(); - // myBot.listMessages(Slack.BOTS_CHANNEL_ID); + myBot.listMessages(Slack.BOTS_CHANNEL_ID); // Post "Hello, world!" to the #bots channel myBot.sendMessageToBotsChannel("Testing, Testing"); From 0e2db8b3e753a523ea4b3d122c7f63948cf3dfe7 Mon Sep 17 00:00:00 2001 From: Darnell O Date: Fri, 20 Oct 2017 13:41:30 -0400 Subject: [PATCH 12/16] againagain --- .../c4q/ramonaharrison/model/Attachment.java | 140 ++++++++++++++++-- 1 file changed, 124 insertions(+), 16 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/model/Attachment.java b/src/nyc/c4q/ramonaharrison/model/Attachment.java index f6f1523..63c9d1b 100644 --- a/src/nyc/c4q/ramonaharrison/model/Attachment.java +++ b/src/nyc/c4q/ramonaharrison/model/Attachment.java @@ -11,24 +11,132 @@ * */ -public class Attachment { + public class Attachment { + // TODO: implement private fields for each of the following attachment JSON keys: + // “fallback” + private String fallback; + // “color” + private String color; + // “pretext” + private String pretext; + // “author_name” + private String author_name; + // “author_link” + private String author_link; + // “author_icon” + private String author_icon; + // “title” + private String title; + // “title_link” + private String title_link; + // “text” + private String text; + // “fields” + private String fields; + // “image_url” + private String image_url; + // “thumb_url” + private String thumb_url; + // “footer” + private String footer; + // “footer_icon” + private String footer_icon; + // “ts” + private String ts; - // TODO: implement private fields for each of the following attachment JSON keys: + public Attachment(JSONObject json) { + // TODO: parse an attachment from the incoming json + if (json.get("fallback") != null) { + this.fallback = (String) json.get("fallback"); + } + if (json.get("color") !=null) { + this.color = (String) json.get("color"); + } + if (json.get("pretext") != null) { + this.pretext = (String) json.get("pretext"); + } + if (json.get("author name")!=null){ + this.author_name = (String) json.get("author name"); + } + if (json.get("author link")!=null){ + this.author_link = (String) json.get("author link"); + } + if (json.get("author icon")!=null){ + this.author_icon =(String) json.get("author icon"); + } + if (json.get("title")!=null){ + this.title = (String) json.get ("title"); + } + if (json.get("title link")!=null){ + this.title_link = (String) json.get ("title link"); + } + if (json.get("text")!=null){ + this.text = (String) json.get ("text"); + } + if (json.get("fields")!=null){ + this.fields = (String) json.get ("fields"); + } + if (json.get("image url")!=null){ + this.image_url = (String) json.get ("image url"); + } + if (json.get("thumb url")!=null){ + this.thumb_url = (String) json.get ("thumb url"); + } + if (json.get("footer")!=null){ + this.footer= (String) json.get ("footer"); + } + if (json.get("ts")!=null){ + this.ts = (String) json.get ("ts"); + } + } + // TODO add getters to access private fields + public String getFallback() { + return fallback; + } + public String getColor() { + return color; + } + public String getPretext() { + return pretext; + } + public String getAuthor_name() { + return author_name; + } + public String getAuthor_link() { + return author_link; + } + public String getAuthor_icon() { + return author_icon; + } + public String getTitle() { + return title; + } + public String getTitle_link() { + return title_link; + } + public String getText() { + return text; + } + public String getFields() { + return fields; + } + public String getImage_url() { + return image_url; + } + public String getThumb_url() { + return thumb_url; + } + public String getFooter() { + return footer; + } + public String getFooter_icon() { + return footer_icon; + } + public String getTs() { + return ts; + } + } - public Attachment(JSONObject json) { - // TODO: parse an attachment from the incoming json - - public Attachment(JSONObject json) { - // TODO: parse an attachment from the incoming json - - - } - - // TODO add getters to access private fields - - - -} From 4898ddb482ae16e8259b127f6be5e5929f3d8ab6 Mon Sep 17 00:00:00 2001 From: Bobby Bah Date: Fri, 20 Oct 2017 16:29:15 -0400 Subject: [PATCH 13/16] added inspirational quotes --- src/nyc/c4q/ramonaharrison/Bot.java | 56 +++++++++++++++++-- src/nyc/c4q/ramonaharrison/Main.java | 3 +- src/nyc/c4q/ramonaharrison/network/Slack.java | 2 +- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Bot.java b/src/nyc/c4q/ramonaharrison/Bot.java index ffdedd9..78000d1 100644 --- a/src/nyc/c4q/ramonaharrison/Bot.java +++ b/src/nyc/c4q/ramonaharrison/Bot.java @@ -18,7 +18,7 @@ public class Bot { // TODO: implement your bot logic! - ArrayList tips = new ArrayList<>(); + ArrayList inspirationQuotes = new ArrayList<>(); public Bot() { @@ -103,15 +103,59 @@ public void deleteMessageInBotsChannel(String messageTs) { } } - public String randomTip () { - tips.add("Arrays have fixed size but ArrayLists have variable sizes. \n Since the size of Array is fixed, the memory gets allocated at the time of declaration of Array type variable. \n Hence, Arrays are very fast. "); - tips.add("To compute power (^), one way is to use the Math.pow"); + public String randomQuote() { + inspirationQuotes.add("If you have the opportunity to play this game of life \n " + + "you need to appreciate every moment. \n" + + "A lot of people don't appreciate the moment until it's passed.\n" + + "-Kanye West"); + inspirationQuotes.add("Do not dwell in the past, do not dream of the future.\n" + + "Concentrate the mind on the present moment\n" + + "-Buddha"); + inspirationQuotes.add("Try to be a rainbow in someone's cloud\n -Maya Angelou"); + inspirationQuotes.add("Sometimes when you innovate, you make mistakes.\n" + + "It is best to admit them quickly, and get on with improving your other innovations\n" + + "-Steve Jobs"); + inspirationQuotes.add("People say nothing is impossible, but I do nothing everyday.\n" + + "-A.A. Milne"); + inspirationQuotes.add("A diamond is merely a lump of coal that did well under pressure\n" + + "-Unknown"); + inspirationQuotes.add("No one can make you feel inferior without your consent\n" + + "-Eleanor Roosevelt"); + inspirationQuotes.add("Believe you can and you're halfway there\n" + + "-T. Roosevelt"); + inspirationQuotes.add("Don't sweat the petty things and don't pet the sweaty things.\n" + + "-George Carlin"); + inspirationQuotes.add("There isn't a way things should be. There's just what happens and what we do.\n" + + "-Terry Pratchett"); + inspirationQuotes.add("More fuck yeah, less fuck that.\n" + + "-Unknown"); + inspirationQuotes.add("Turn your wounds into wisdom\n" + + "-Oprah"); + inspirationQuotes.add("Hope is a waking dream\n" + + "-Aristotle"); + inspirationQuotes.add("Life is trying things to see if they work\n" + + "-Ray Bradbury"); + inspirationQuotes.add("The obstacle is the path\n" + + "-Unknown"); + inspirationQuotes.add("We become what we think about\n" + + "-Earl Nightingale"); + inspirationQuotes.add("It does not matter how slowly you go as long as you do not stop\n" + + "-Confucius"); + inspirationQuotes.add("A jug fills drop by drop\n" + + "-Buddha"); + inspirationQuotes.add("Don't regret the past, just learn from it\n" + + "-Ben Ipock"); + inspirationQuotes.add("Action is the foundational key to all success\n" + + "-Pablo Picasso"); + inspirationQuotes.add("Whatever you are, be a good one\n" + + "-Abraham Lincoln"); + Random r= new Random(); - String tip=tips.get(r.nextInt(tips.size())); - return tip; + String quote= inspirationQuotes.get(r.nextInt(inspirationQuotes.size())); + return quote; } diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index b7141d8..72b3502 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -1,6 +1,5 @@ package nyc.c4q.ramonaharrison; -import jdk.nashorn.internal.parser.JSONParser; import nyc.c4q.ramonaharrison.network.Slack; @@ -17,7 +16,7 @@ public static void main(String[] args) { myBot.listMessages(Slack.BOTS_CHANNEL_ID); - myBot.sendMessageToBotsChannel(myBot.randomTip()); + myBot.sendMessageToBotsChannel(myBot.randomQuote()); myBot.sendMessageToBotsChannel("Yum yum!"); myBot.sendMessageToBotsChannel("So does this one: "); diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index fa2ed3d..a6833f8 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -29,7 +29,7 @@ public class Slack { private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; - public static final String BOTS_CHANNEL_ID = "C7KE0KTM4"; + public static final String BOTS_CHANNEL_ID = "C7M6UM4LA"; /** From 3af35a34103e04e627231944f6fcdb9b055a2b56 Mon Sep 17 00:00:00 2001 From: Yoki Lam Date: Fri, 20 Oct 2017 18:04:01 -0400 Subject: [PATCH 14/16] print method --- src/nyc/c4q/ramonaharrison/Bot.java | 54 +++++++++++++++---- src/nyc/c4q/ramonaharrison/Main.java | 13 +++-- src/nyc/c4q/ramonaharrison/network/Slack.java | 2 +- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Bot.java b/src/nyc/c4q/ramonaharrison/Bot.java index ffdedd9..51e8616 100644 --- a/src/nyc/c4q/ramonaharrison/Bot.java +++ b/src/nyc/c4q/ramonaharrison/Bot.java @@ -18,7 +18,7 @@ public class Bot { // TODO: implement your bot logic! - ArrayList tips = new ArrayList<>(); + ArrayList inspirationQuotes = new ArrayList<>(); public Bot() { @@ -59,6 +59,8 @@ public void listChannels() { public void listMessages(String channelId) { ListMessagesResponse listMessagesResponse = Slack.listMessages(channelId); + Bot myBot = new Bot(); + if (listMessagesResponse.isOk()) { List messages = listMessagesResponse.getMessages(); @@ -67,12 +69,42 @@ public void listMessages(String channelId) { System.out.println(); System.out.println("Timestamp: " + message.getTs()); System.out.println("Message: " + message.getText()); + + String saySomething = message.getText(); + + if(saySomething.contains("candy")) { + myBot.sendMessageToBotsChannel(randomTip()); + + } + + } } else { System.err.print("Error listing messages: " + listMessagesResponse.getError()); } } + public void respondGreeting(String channelId) { + ListMessagesResponse listMessagesResponse = Slack.listMessages(channelId); + + if (listMessagesResponse.isOk()) { + List messages = listMessagesResponse.getMessages(); + + Bot myBot = new Bot(); + + for (Message message : messages) { + + String saySomething = message.getText(); + + if (saySomething.contains("@U7JJ7B7K4") || saySomething.contains("candy")) { +// myBot.sendMessageToBotsChannel("Hello"); + System.out.println(randomTip()); + + } + } + } + } + /** * Sample method: sends a plain text message to the #bots channel. Prints a message indicating success or failure. * @@ -88,11 +120,11 @@ public void sendMessageToBotsChannel(String text) { } } - /** - * Sample method: deletes a message from the #bots channel. Prints a message indicating success or failure. - * - * @param messageTs unique timestamp of the message to be deleted. - */ + /** + * Sample method: deletes a message from the #bots channel. Prints a message indicating success or failure. + * + * @param messageTs unique timestamp of the message to be deleted. + */ public void deleteMessageInBotsChannel(String messageTs) { DeleteMessageResponse deleteMessageResponse = Slack.deleteMessage(messageTs); @@ -104,14 +136,16 @@ public void deleteMessageInBotsChannel(String messageTs) { } public String randomTip () { - tips.add("Arrays have fixed size but ArrayLists have variable sizes. \n Since the size of Array is fixed, the memory gets allocated at the time of declaration of Array type variable. \n Hence, Arrays are very fast. "); - tips.add("To compute power (^), one way is to use the Math.pow"); + + inspirationQuotes.add("cvbncn"); + inspirationQuotes.add("pwertiowert"); + inspirationQuotes.add("09645094609"); Random r= new Random(); - String tip=tips.get(r.nextInt(tips.size())); - return tip; + String quote= inspirationQuotes.get(r.nextInt(inspirationQuotes.size())); + return quote; } diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index b7141d8..e1423c9 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -14,16 +14,21 @@ public static void main(String[] args) { myBot.testApi(); myBot.listChannels(); +// myBot.respondGreeting("@C7M6UM4LA"); + myBot.respondGreeting("@C7M6UM4LA"); + myBot.randomTip(); myBot.listMessages(Slack.BOTS_CHANNEL_ID); - myBot.sendMessageToBotsChannel(myBot.randomTip()); - myBot.sendMessageToBotsChannel("Yum yum!"); - myBot.sendMessageToBotsChannel("So does this one: "); + +// myBot.sendMessageToBotsChannel(list); +// myBot.sendMessageToBotsChannel(myBot.randomTip()); +// myBot.sendMessageToBotsChannel("Yum yum!"); +// myBot.sendMessageToBotsChannel("So does this one: "); // Post "Hello, world!" to the #bots channel - myBot.sendMessageToBotsChannel("Testing, Testing"); +// myBot.sendMessageToBotsChannel("Testing, Testing"); // Post a pineapple photo to the #bots channel //myBot.sendMessage("http://weknowyourdreams.com/images/pineapple/pineapple-07.jpg"); diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index fa2ed3d..a6833f8 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -29,7 +29,7 @@ public class Slack { private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; - public static final String BOTS_CHANNEL_ID = "C7KE0KTM4"; + public static final String BOTS_CHANNEL_ID = "C7M6UM4LA"; /** From 7474fa9a4e5eba1b4fe26b7e93bab53e803da51c Mon Sep 17 00:00:00 2001 From: Yoki Lam Date: Sat, 21 Oct 2017 14:26:41 -0400 Subject: [PATCH 15/16] testing --- src/nyc/c4q/ramonaharrison/Bot.java | 108 +++++++----------- src/nyc/c4q/ramonaharrison/Main.java | 15 ++- src/nyc/c4q/ramonaharrison/network/Slack.java | 2 +- 3 files changed, 49 insertions(+), 76 deletions(-) diff --git a/src/nyc/c4q/ramonaharrison/Bot.java b/src/nyc/c4q/ramonaharrison/Bot.java index 9027f07..dc80c06 100644 --- a/src/nyc/c4q/ramonaharrison/Bot.java +++ b/src/nyc/c4q/ramonaharrison/Bot.java @@ -1,5 +1,6 @@ package nyc.c4q.ramonaharrison; +import nyc.c4q.ramonaharrison.model.Attachment; import nyc.c4q.ramonaharrison.model.Channel; import nyc.c4q.ramonaharrison.model.Message; import nyc.c4q.ramonaharrison.network.*; @@ -29,7 +30,7 @@ public Bot() { */ public void testApi() { Response apiTest = Slack.testApi(); - System.out.println("API OK: " +apiTest.isOk() + "\n"); + System.out.println("API OK: " + apiTest.isOk() + "\n"); } /** @@ -72,8 +73,10 @@ public void listMessages(String channelId) { String saySomething = message.getText(); - if(saySomething.contains("candy")) { - myBot.sendMessageToBotsChannel(randomTip()); + if (saySomething.contains("candy") || saySomething.contains("@U7JJ7B7K4")) { + myBot.sendMessageToBotsChannel("Random Quote: \n" + randomQuote()); + break; + } @@ -84,7 +87,7 @@ public void listMessages(String channelId) { } } - public void respondGreeting(String channelId) { + public void respond(String channelId) { ListMessagesResponse listMessagesResponse = Slack.listMessages(channelId); if (listMessagesResponse.isOk()) { @@ -98,7 +101,7 @@ public void respondGreeting(String channelId) { if (saySomething.contains("@U7JJ7B7K4") || saySomething.contains("candy")) { // myBot.sendMessageToBotsChannel("Hello"); - System.out.println(randomTip()); + System.out.println(randomQuote()); } } @@ -120,11 +123,11 @@ public void sendMessageToBotsChannel(String text) { } } - /** - * Sample method: deletes a message from the #bots channel. Prints a message indicating success or failure. - * - * @param messageTs unique timestamp of the message to be deleted. - */ + /** + * Sample method: deletes a message from the #bots channel. Prints a message indicating success or failure. + * + * @param messageTs unique timestamp of the message to be deleted. + */ public void deleteMessageInBotsChannel(String messageTs) { DeleteMessageResponse deleteMessageResponse = Slack.deleteMessage(messageTs); @@ -135,68 +138,39 @@ public void deleteMessageInBotsChannel(String messageTs) { } } -<<<<<<< HEAD - public String randomTip () { - inspirationQuotes.add("cvbncn"); - inspirationQuotes.add("pwertiowert"); - inspirationQuotes.add("09645094609"); -======= + public String randomQuote() { - inspirationQuotes.add("If you have the opportunity to play this game of life \n " + - "you need to appreciate every moment. \n" + - "A lot of people don't appreciate the moment until it's passed.\n" + - "-Kanye West"); - inspirationQuotes.add("Do not dwell in the past, do not dream of the future.\n" + - "Concentrate the mind on the present moment\n" + - "-Buddha"); + inspirationQuotes.add("If you have the opportunity to play this game of life \n " + "you need to appreciate every moment. \n" + "A lot of people don't appreciate the moment until it's passed.\n" + "-Kanye West"); + inspirationQuotes.add("Do not dwell in the past, do not dream of the future.\n" + "Concentrate the mind on the present moment\n" + "-Buddha"); inspirationQuotes.add("Try to be a rainbow in someone's cloud\n -Maya Angelou"); - inspirationQuotes.add("Sometimes when you innovate, you make mistakes.\n" + - "It is best to admit them quickly, and get on with improving your other innovations\n" + - "-Steve Jobs"); - inspirationQuotes.add("People say nothing is impossible, but I do nothing everyday.\n" + - "-A.A. Milne"); - inspirationQuotes.add("A diamond is merely a lump of coal that did well under pressure\n" + - "-Unknown"); - inspirationQuotes.add("No one can make you feel inferior without your consent\n" + - "-Eleanor Roosevelt"); - inspirationQuotes.add("Believe you can and you're halfway there\n" + - "-T. Roosevelt"); - inspirationQuotes.add("Don't sweat the petty things and don't pet the sweaty things.\n" + - "-George Carlin"); - inspirationQuotes.add("There isn't a way things should be. There's just what happens and what we do.\n" + - "-Terry Pratchett"); - inspirationQuotes.add("More fuck yeah, less fuck that.\n" + - "-Unknown"); - inspirationQuotes.add("Turn your wounds into wisdom\n" + - "-Oprah"); - inspirationQuotes.add("Hope is a waking dream\n" + - "-Aristotle"); - inspirationQuotes.add("Life is trying things to see if they work\n" + - "-Ray Bradbury"); - inspirationQuotes.add("The obstacle is the path\n" + - "-Unknown"); - inspirationQuotes.add("We become what we think about\n" + - "-Earl Nightingale"); - inspirationQuotes.add("It does not matter how slowly you go as long as you do not stop\n" + - "-Confucius"); - inspirationQuotes.add("A jug fills drop by drop\n" + - "-Buddha"); - inspirationQuotes.add("Don't regret the past, just learn from it\n" + - "-Ben Ipock"); - inspirationQuotes.add("Action is the foundational key to all success\n" + - "-Pablo Picasso"); - inspirationQuotes.add("Whatever you are, be a good one\n" + - "-Abraham Lincoln"); - ->>>>>>> cda13a2bd21a0090789c6efe97ba06dfc7e55298 - - Random r= new Random(); - - - String quote= inspirationQuotes.get(r.nextInt(inspirationQuotes.size())); + inspirationQuotes.add("Sometimes when you innovate, you make mistakes.\n" + "It is best to admit them quickly, and get on with improving your other innovations\n" + "-Steve Jobs"); + inspirationQuotes.add("People say nothing is impossible, but I do nothing everyday.\n" + "-A.A. Milne"); + inspirationQuotes.add("A diamond is merely a lump of coal that did well under pressure\n" + "-Unknown"); + inspirationQuotes.add("No one can make you feel inferior without your consent\n" + "-Eleanor Roosevelt"); + inspirationQuotes.add("Believe you can and you're halfway there\n" + "-T. Roosevelt"); + inspirationQuotes.add("Don't sweat the petty things and don't pet the sweaty things.\n" + "-George Carlin"); + inspirationQuotes.add("There isn't a way things should be. There's just what happens and what we do.\n" + "-Terry Pratchett"); + inspirationQuotes.add("More fuck yeah, less fuck that.\n" + "-Unknown"); + inspirationQuotes.add("Turn your wounds into wisdom\n" + "-Oprah"); + inspirationQuotes.add("Hope is a waking dream\n" + "-Aristotle"); + inspirationQuotes.add("Life is trying things to see if they work\n" + "-Ray Bradbury"); + inspirationQuotes.add("The obstacle is the path\n" + "-Unknown"); + inspirationQuotes.add("We become what we think about\n" + "-Earl Nightingale"); + inspirationQuotes.add("It does not matter how slowly you go as long as you do not stop\n" + "-Confucius"); + inspirationQuotes.add("A jug fills drop by drop\n" + "-Buddha"); + inspirationQuotes.add("Don't regret the past, just learn from it\n" + "-Ben Ipock"); + inspirationQuotes.add("Action is the foundational key to all success\n" + "-Pablo Picasso"); + inspirationQuotes.add("Whatever you are, be a good one\n" + "-Abraham Lincoln"); + + + Random r = new Random(); + + + String quote = inspirationQuotes.get(r.nextInt(inspirationQuotes.size())); return quote; } + } diff --git a/src/nyc/c4q/ramonaharrison/Main.java b/src/nyc/c4q/ramonaharrison/Main.java index 32ed5ab..0cf1323 100644 --- a/src/nyc/c4q/ramonaharrison/Main.java +++ b/src/nyc/c4q/ramonaharrison/Main.java @@ -14,22 +14,21 @@ public static void main(String[] args) { myBot.listChannels(); // myBot.respondGreeting("@C7M6UM4LA"); - myBot.respondGreeting("@C7M6UM4LA"); - myBot.randomTip(); + myBot.respond("@C7M6UM4LA"); + myBot.listMessages(Slack.BOTS_CHANNEL_ID); -<<<<<<< HEAD + // myBot.sendMessageToBotsChannel(list); // myBot.sendMessageToBotsChannel(myBot.randomTip()); // myBot.sendMessageToBotsChannel("Yum yum!"); // myBot.sendMessageToBotsChannel("So does this one: "); -======= - myBot.sendMessageToBotsChannel(myBot.randomQuote()); - myBot.sendMessageToBotsChannel("Yum yum!"); - myBot.sendMessageToBotsChannel("So does this one: "); ->>>>>>> cda13a2bd21a0090789c6efe97ba06dfc7e55298 + +// myBot.sendMessageToBotsChannel(myBot.randomQuote()); +// myBot.sendMessageToBotsChannel("Yum yum!"); +// myBot.sendMessageToBotsChannel("So does this one: "); // Post "Hello, world!" to the #bots channel diff --git a/src/nyc/c4q/ramonaharrison/network/Slack.java b/src/nyc/c4q/ramonaharrison/network/Slack.java index a6833f8..fa2ed3d 100644 --- a/src/nyc/c4q/ramonaharrison/network/Slack.java +++ b/src/nyc/c4q/ramonaharrison/network/Slack.java @@ -29,7 +29,7 @@ public class Slack { private static final String ENDPOINT_POST_MESSAGE = "chat.postMessage"; private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete"; - public static final String BOTS_CHANNEL_ID = "C7M6UM4LA"; + public static final String BOTS_CHANNEL_ID = "C7KE0KTM4"; /** From 6e8e17e953abda0e2aa74f3115fc6736729f6c9c Mon Sep 17 00:00:00 2001 From: Ackochanski Date: Sat, 21 Oct 2017 16:35:09 -0400 Subject: [PATCH 16/16] parsed User AGAIN --- src/nyc/c4q/ramonaharrison/model/User.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/nyc/c4q/ramonaharrison/model/User.java b/src/nyc/c4q/ramonaharrison/model/User.java index 6bab787..061b413 100644 --- a/src/nyc/c4q/ramonaharrison/model/User.java +++ b/src/nyc/c4q/ramonaharrison/model/User.java @@ -20,53 +20,113 @@ public class User { public User(JSONObject json) { + if(json.get("id") != null) { + this.id = (String) json.get("id"); + } + + if(json.get("name") != null) { + this.name = (String) json.get("name"); + } + + if(json.get("deleted") != null) { + this.deleted = (Boolean) json.get("deleted"); + } + + if(json.get("color") != null) { + this.color = (String) json.get("color"); + } + + if(json.get("profile") != null) { + this.profile = (String) json.get("profile"); + } + + if(json.get("isAdmin") != null) { + this.isAdmin = (Boolean) json.get("isAdmin"); + } + + if(json.get("isOwner") != null) { + this.isOwner = (Boolean) json.get("isOwner"); + } + + if(json.get("isPrimaryOwner") != null) { + this.isPrimaryOwner = (Boolean) json.get("isPrimaryOwner"); + } + + if(json.get("isRestricted") != null) { + this.isRestricted = (Boolean) json.get("isRestricted"); + } + + if(json.get("has2fa") != null) { + this.has2fa = (Boolean) json.get("has2fa"); + } + + if(json.get("twoFactorType") != null) { + this.twoFactorType = (Boolean) json.get("twoFactorType"); + } + + if(json.get("hasFile") != null) { + this.hasFiles = (Boolean) json.get("hasFiles"); + } + } public String getId() { + return id; } public String getName() { + return name; } public boolean deleted() { + return deleted; } public String getcolor() { + return color; } public String getProfile() { + return profile; } public boolean IsAdmin() { + return isAdmin; } public boolean isOwner() { + return isOwner; } public boolean isPrimaryOwner() { + return isPrimaryOwner; } public boolean isRestricted() { + return isRestricted; } public boolean has2fa() { + return has2fa; } public boolean twoFactorType() { + return twoFactorType; } public boolean hasFiles() { + return hasFiles; } }