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
82 changes: 81 additions & 1 deletion src/nyc/c4q/ramonaharrison/Bot.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -14,7 +15,40 @@
*/

public class Bot {
// TODO: implement your bot logic!

public static int money = 0;
public void checkMessagesAndRespond(String channelId) {
ListMessagesResponse listMessagesResponse = Slack.listMessages(channelId);

if (listMessagesResponse.isOk()) {
List<Message> messages = listMessagesResponse.getMessages();
for (Message message : messages) {
if (message.getText().contains("hamburger")) {
Slack.sendMessage("I love hamburgers");
Slack.sendMessage("https://media.giphy.com/media/yYc5L3vhTWeBi/giphy.gif");
break;
}else if(message.getText().contains("cat")){
Slack.sendMessage("Cats are meh");
Slack.sendMessage("https://media.giphy.com/media/MVQLSJt38RKJG/giphy.gif");
break;
}else if (message.getText().contains("alien")){
Slack.sendMessage("Aliens are scary");
Slack.sendMessage("https://media.giphy.com/media/l3V0ma60jQqGCoJyM/giphy.gif");
break;
}else if (message.getText().contains("ufo")){
Slack.sendMessage("OMG UFOS");
Slack.sendMessage("https://media.giphy.com/media/dKVvUk2oH8x2g/giphy.gif");
break;
}else {
Slack.sendMessage("life is hard could you lend me some money?");
break;
}


}

}
}

public Bot() {

Expand Down Expand Up @@ -69,6 +103,31 @@ public void listMessages(String channelId) {
}
}

public String lastMessageText() {
ListMessagesResponse listMessagesResponse = Slack.listMessages(Slack.BOTS_CHANNEL_ID);

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

Message message = messages.get(0);

return message.getText();
} else {
System.err.print("Error listing messages: " + listMessagesResponse.getError());
}
return "";
}

public Message lastMessage() {
ListMessagesResponse lmr = Slack.listMessages(Slack.BOTS_CHANNEL_ID);
if (lmr.isOk()) {
List<Message> messages = lmr.getMessages();
return messages.get(0);
} else {
System.err.print("Error listing messages: " + lmr.getError());
}
return null;
}
/**
* Sample method: sends a plain text message to the #bots channel. Prints a message indicating success or failure.
*
Expand All @@ -84,6 +143,27 @@ public void sendMessageToBotsChannel(String text) {
}
}


public void sendMessageToBotsChannelAsPolice(String text) {
SendMessageResponse sendMessageResponse = Slack.sendMessageAsPolice(text);

if (sendMessageResponse.isOk()) {
System.out.println("Message sent successfully!");
} else {
System.err.print("Error sending message: " + sendMessageResponse.getError());
}
}

public void sendMessageWithAttachmentsToBotsChannel(String text, List<Attachment> attachments) {
SendMessageResponse sendMessageResponse = Slack.sendMessageWithAttachments(text,attachments);

if (sendMessageResponse.isOk()) {
System.out.println("Message sent successfully!");
} else {
System.err.print("Error sending message: " + sendMessageResponse.getError());
}
}

/**
* Sample method: deletes a message from the #bots channel. Prints a message indicating success or failure.
*
Expand Down
76 changes: 66 additions & 10 deletions src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,80 @@
package nyc.c4q.ramonaharrison;

import nyc.c4q.ramonaharrison.model.Attachment;
import nyc.c4q.ramonaharrison.model.Message;
import nyc.c4q.ramonaharrison.network.Slack;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

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

public class Main {

public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {

Bot myBot = new Bot();

myBot.testApi();

myBot.listChannels();
List<Attachment> listOfAttachments = new ArrayList<>();
Attachment attachment = new Attachment("Required plain-text summary of the attachment.","%230099ff","Do%20you%20haz%20MONEY","C4Q%20Stuff","http://flickr.com/bobby/","http://flickr.com/icons/bobby.jpg","Not%20C4Q%20API%20Documentation","https://api.slack.com/","I%20Love%20Money","http://my-website.com/path/to/image.jpg","http://example.com/path/to/thumb.png","Not%20C4Q%20API","https://platform.slack-edge.com/img/default_application_icon.png");
Attachment attachment2 = new Attachment("Required plain-text summary of the attachment.","%23ff9900","Another%20attachment","More%20C4Q%20Stuff","http://flickr.com/bobby/","http://flickr.com/icons/bobby.jpg","Not%20C4Q%20API%20Documentation","https://api.slack.com/","I%20Love%20More%20Mulah","http://my-website.com/path/to/image.jpg","http://example.com/path/to/thumb.png","Not%20C4Q%20API","https://platform.slack-edge.com/img/default_application_icon.png");
listOfAttachments.add(attachment);
listOfAttachments.add(attachment2);
myBot.sendMessageWithAttachmentsToBotsChannel("I'm%20BeggarBot",listOfAttachments);

myBot.listMessages(Slack.BOTS_CHANNEL_ID);

// Post "Hello, world!" to the #bots channel
//myBot.sendMessage("Hello, world!");
// while(true) {
// Message message = myBot.lastMessage();
// String user = message.getUser();
// String lastMessage = myBot.lastMessageText().toLowerCase();
// if(lastMessage.contains("poor")){
// myBot.sendMessageToBotsChannel("*POOR??*");
// myBot.sendMessageToBotsChannel("...");
// myBot.sendMessageToBotsChannel("...");
// myBot.sendMessageToBotsChannel("Ugh Here's a dollar, Bye");
// Bot.money--;
// myBot.sendMessageToBotsChannel("_beggarbot escapes with " + Bot.money + " dollars!_");
// Thread.sleep(6000);
// myBot.sendMessageToBotsChannelAsPolice("WHERE DID HE GO! :police_car:");
// break;
// }
// if(!user.equals("beggarbot"))
// stringCheck(lastMessage);
// }
}

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

}
// public static void stringCheck(String lastMessage){
// Bot myBot = new Bot();
// if(lastMessage.contains("Trump".toLowerCase())){
// myBot.sendMessageToBotsChannel("Trump? How about giving me a dollar and make Beggarbot rich again!");
// Bot.money++;
// }
//
// else if(lastMessage.contains("Happy".toLowerCase())){
// myBot.sendMessageToBotsChannel("Feeling happy today? How about spreading the good vibes and give me a dollar?");
// Bot.money++;
// }
//
// else if(lastMessage.contains("Money".toLowerCase())){
// myBot.sendMessageToBotsChannel("I could use some money, give me a dollar!");
// Bot.money++;
// }
//
// else if(lastMessage.contains("Sad".toLowerCase())){
// myBot.sendMessageToBotsChannel("I’m feeling down too. Giving me a dollar would make me feel better.");
// Bot.money++;
// }
//
// else if(lastMessage.contains("Clinton".toLowerCase())){
// myBot.sendMessageToBotsChannel("I know where Hillary’s secret emails are. Give me a dollar and I’ll tell you where.");
// Bot.money++;
// }
// else if(lastMessage.equalsIgnoreCase("sure")||lastMessage.equalsIgnoreCase("fine")||lastMessage.equalsIgnoreCase("okay")){
// myBot.sendMessageToBotsChannel("SURE?? You agree to give me a dollar!");
// Bot.money++;
// }
// else
// myBot.sendMessageToBotsChannel("Give me a dollar, cmon");
// }
}
Loading