Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/nyc/c4q/ramonaharrison/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import nyc.c4q.ramonaharrison.model.Channel;
import nyc.c4q.ramonaharrison.model.Message;
import nyc.c4q.ramonaharrison.model.User;
import nyc.c4q.ramonaharrison.network.*;
import nyc.c4q.ramonaharrison.network.response.*;

Expand All @@ -15,6 +16,8 @@

public class Bot {
// TODO: implement your bot logic!
public String botName = "messybot";


public Bot() {

Expand All @@ -25,7 +28,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");
}

/**
Expand Down Expand Up @@ -69,13 +72,30 @@ public void listMessages(String channelId) {
}
}

public void readMessages(String channelId){
ListMessagesResponse listMessagesResponse = Slack.listMessages(channelId);

if (listMessagesResponse.isOk()) {
List<Message> messages = listMessagesResponse.getMessages();

System.out.println("\nMessages: ");

// for (Message message : messages) { /* Searches ALL messages in channel for string */
//
// if(message.getText().equalsIgnoreCase(botName /* text you want to search for here*/)) {
// sendMessageToBotsChannel("https://www.hallaminternet.com/assets/https.jpg");
// }
}
}


/**
* Sample method: sends a plain text message to the #bots channel. Prints a message indicating success or failure.
*
* @param text message text.
*/
public void sendMessageToBotsChannel(String text) {
SendMessageResponse sendMessageResponse = Slack.sendMessage(text);
SendMessageResponse sendMessageResponse = Slack.sendMessage(text);

if (sendMessageResponse.isOk()) {
System.out.println("Message sent successfully!");
Expand Down
29 changes: 20 additions & 9 deletions src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
package nyc.c4q.ramonaharrison;

import java.util.*;
import nyc.c4q.ramonaharrison.model.Message;
import nyc.c4q.ramonaharrison.network.Slack;
import sun.misc.resources.Messages;

import java.util.List;

public class Main {

public static void main(String[] args) {
while(true) {
Bot aBot = new Bot();
// aBot.listChannels();
// aBot.testApi();
// aBot.readMessages("C2BLV9LV6");
Slack.getHolidaysForToday();
if (Slack.giphySearch() != null) {
aBot.sendMessageToBotsChannel("You have entered the guessing game command! Type 'hint' for another gif related to the next holiday, or 'give up' for the answer. Good luck!");
aBot.sendMessageToBotsChannel(Slack.giphySearch());
}
Slack.guessingGame();
}

Bot myBot = new Bot();

myBot.testApi();

myBot.listChannels();

myBot.listMessages(Slack.BOTS_CHANNEL_ID);

// Post "Hello, world!" to the #bots channel
//myBot.sendMessage("Hello, world!");

// Post a pineapple photo to the #bots channel
//myBot.sendMessage("http://weknowyourdreams.com/images/pineapple/pineapple-07.jpg");

// myBot.sendMessage(");
// myBot.sendMessage("someString");
}
}
}
159 changes: 142 additions & 17 deletions src/nyc/c4q/ramonaharrison/model/Attachment.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package nyc.c4q.ramonaharrison.model;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Ramona Harrison
* on 8/26/16
Expand All @@ -13,27 +17,148 @@

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 pretext;
private String authorName;
private String authorLink;
private String authorIcon;
private String title;
private String titleLink;
private String text;
private List<Field> fields;
private String imageUrl;
private String thumbUrl;
private String footer;
private String footerIcon;
private long ts;

public Attachment(JSONObject json) {
// TODO: parse an attachment from the incoming json

if(json.containsKey("fallback")){
this.fallback = (String) json.get("fallback");
}

if(json.containsKey("pretext")){
this.pretext = (String) json.get("pretext");
}

if(json.containsKey("authorName")){
this.authorName = (String) json.get("authorName");
}

if(json.containsKey("authorLink")){
this.authorLink = (String) json.get("authorLink");
}

if(json.containsKey("authorIcon")){
this.authorIcon = (String) json.get("authorIcon");
}

if(json.containsKey("authorIcon")){
this.authorIcon = (String) json.get("author");
}

if(json.containsKey("title")){
this.title = (String) json.get("title");
}

if (json.containsKey("titleLink")) {
this.titleLink = (String) json.get("titleLink");
}

if(json.containsKey("text")){
this.text = (String) json.get("text");
}

if(json.containsKey("fields")){
JSONArray jsonFields = (JSONArray) json.get("fields");
this.fields = new ArrayList<Field>();
for (int i = 0; i < jsonFields.size(); i++){
Field field = new Field((JSONObject) jsonFields.get(i));
this.fields.add(field);
}
}

if(json.containsKey("imageUrl")){
this.imageUrl = (String) json.get("imageUrl");
}

if(json.containsKey("thumbUrl")){
this.thumbUrl = (String) json.get("thumbUrl");
}

if(json.containsKey("footer")){
this.footer = (String) json.get("footer");
}

if(json.containsKey("footerIcon")){
this.footerIcon = (String) json.get("footerIcon");
}

if (json.containsKey("ts")){
this.ts = (long) json.get("ts");
}

}

// oTODO add getters to access private fields

public String getFallback() {
return fallback;
}

public String getPretext() {
return pretext;
}

public String getAuthorName() {
return authorName;
}

public String getAuthorLink() {
return authorLink;
}

public String getAuthorIcon() {
return authorIcon;
}

public String getTitle() {
return title;
}

public String getTitleLink() {
return titleLink;
}

public String getText() {
return text;
}

public List<Field> getFields() {
return fields;
}

public String getImageUrl() {
return imageUrl;
}

public String getThumbUrl() {
return thumbUrl;
}

public String getFooter() {
return footer;
}

public String getFooterIcon() {
return footerIcon;
}

public long getTs() {
return ts;
}

// TODO add getters to access private fields

}
38 changes: 38 additions & 0 deletions src/nyc/c4q/ramonaharrison/model/Field.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package nyc.c4q.ramonaharrison.model;

import org.json.simple.JSONObject;

/**
* Created by shawnspeaks on 9/11/16.
*/
public class Field {
private String title;
private String value;
private boolean isShort;

public Field(JSONObject json) {
if (json.containsKey("title")) {
this.title = (String) json.get("title");
}

if (json.containsKey("value")) {
this.value = (String) json.get("value");
}

if (json.containsKey("isShort")){
this.isShort = (boolean) json.get("isShort");
}

}
public String getTitle() {
return title;
}

public String getValue() {
return value;
}

public boolean isShort() {
return isShort;
}
}
Loading