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
27 changes: 27 additions & 0 deletions Attachment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#ff0066",
"pretext": "Optional text that appears above the attachment block",
"author_name": "Mila Urakhchinskaya",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://static5.depositphotos.com/1043279/481/i/950/depositphotos_4812581-Banyan-or-ficus-bonsai-tree.jpg",
"title": "Polite Words and Expressions",
"title_link": "http://www.macmillandictionary.com/us/thesaurus-category/american/polite-words-and-expressions",
"text": "Please, familiarize yourself with Dictionary of Polite word ",
"fields": [
{
"title": "Priority",
"value": "High",
"short": false
}
],
"image_url": "http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2016/04/preview.gif",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Educational Opportunity",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789
}
]


78 changes: 77 additions & 1 deletion src/nyc/c4q/ramonaharrison/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

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.*;
import nyc.c4q.ramonaharrison.util.Words;

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

/**
* Created by Ramona Harrison
Expand All @@ -16,7 +20,62 @@
public class Bot {
// TODO: implement your bot logic!

public Bot() {

Words words = new Words();
public Bot() {}



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

if (listMessagesResponse.isOk()) {


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


for(int i=messages.size()-1;i>=0;i--){//for (Message message : messages) {

for(String replaceable: words.getmWord().keySet()){
if( messages.get(i).getText().contains(replaceable.toLowerCase())){
String output= messages.get(i).getText().replace(replaceable,words.getmWord().get(replaceable));
sendMessageToBotsChannel(output);
// System.out.println("\nMessages: ");
// System.out.println();
// System.out.println("Timestamp: " + message.getTs());
// System.out.println("Message: " + output);

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

}

public void pleaseBotv2(){
while (true){
ListMessagesResponse listMessagesResponse = Slack.listMessages(Slack.BOTS_CHANNEL_ID);
if (listMessagesResponse.isOk()) {
Bot bot = new Bot();
List<Message> messages = listMessagesResponse.getMessages();
String originalMessage = messages.get(0).getText();
if(originalMessage.toLowerCase().contains("please")){
bot.sendMessageToBotsChannel("Someone said please. Here's a cat gif");
bot.sendMessageToBotsChannel(CatGifs.catPics());
}


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

}


}

}

Expand Down Expand Up @@ -98,4 +157,21 @@ public void deleteMessageInBotsChannel(String messageTs) {
System.err.print("Error sending message: " + deleteMessageResponse.getError());
}
}

public void listUsers(String channelId) {
ListUsers listUsers = Slack.listUsers(channelId);

if (listUsers.isOk()) {
List<User> users = listUsers.getUser();

System.out.println("\nUsers: ");
for (User user : users) {
System.out.println();

System.out.println("User: " + user.getName());
}
} else {
System.err.print("Error listing messages: " + listUsers.getError());
}
}
}
50 changes: 50 additions & 0 deletions src/nyc/c4q/ramonaharrison/CatGifs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package nyc.c4q.ramonaharrison;

import java.util.Random;

/**
* Created by jordansmith on 9/16/16.
*/
public class CatGifs {


public static String catPics(){
String [] catPicsArray = new String [28];
catPicsArray [0] = "http://i.imgur.com/zcP8RYL.gif";
catPicsArray [1] = "http://i.imgur.com/4dSv0jH.gif";
catPicsArray [2] = "http://i.imgur.com/vmExtY7.gif";
catPicsArray [3] = "http://i.imgur.com/NIeyIQP.gif";
catPicsArray [4] = "http://i.imgur.com/sHQQJG5.gif";
catPicsArray [5] = "http://i.imgur.com/JKH5xBZ.gif";
catPicsArray [6] = "http://i.imgur.com/U0aCPSv.gif";
catPicsArray [7] = "http://i.imgur.com/FH8J8R3.gif";
catPicsArray [8] = "http://i.imgur.com/7AtUnqc.gif";
catPicsArray [9] = "http://i.imgur.com/OOVmdwa.gif";
catPicsArray [10] = "http://i.imgur.com/nfKM2dN.gif";
catPicsArray [11] = "http://i.imgur.com/nfKM2dN.gif";
catPicsArray [12] = "http://i.imgur.com/svQyujn.gif";
catPicsArray [13] = "http://i.imgur.com/fDiFnbO.gif";
catPicsArray [14] = "http://i.imgur.com/bPd4Kgh.gif";
catPicsArray [15] = "http://i.imgur.com/AOSdhQe.gif";
catPicsArray [16] = "http://i.imgur.com/nflEpRJ.gif";
catPicsArray [17] = "http://i.imgur.com/AOSdhQe.gif";
catPicsArray [18] = "http://i.imgur.com/JvyQd.gif";
catPicsArray [19] = "http://i.imgur.com/mMrUT.gif";
catPicsArray [20] = "http://i.imgur.com/2aJRS.gif";
catPicsArray [21] = "http://i.imgur.com/5xfNq82.gif";
catPicsArray [22] = "http://i.imgur.com/nLwiod0.gif";
catPicsArray [23] = "http://i.imgur.com/4nmgRLR.gif";
catPicsArray [24] = "http://i.imgur.com/KqgdiBH.gif";
catPicsArray [25] = "http://i.imgur.com/j3PYjtJ.gif";
catPicsArray [26] = "http://i.imgur.com/kNIBvRs.gif";
catPicsArray [27] = "http://i.imgur.com/EH7PhPo.gif";


Random rand = new Random();
int randomint = rand.nextInt(28);
return catPicsArray[randomint];

}


}
34 changes: 25 additions & 9 deletions src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
package nyc.c4q.ramonaharrison;

import com.sun.tools.classfile.Opcode;
import com.sun.tools.javac.util.List;
import nyc.c4q.ramonaharrison.model.Attachment;
import nyc.c4q.ramonaharrison.network.Slack;
import nyc.c4q.ramonaharrison.util.Words;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class Main {

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

Bot myBot = new Bot();

myBot.testApi();

myBot.listChannels();
JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader("Attachment.json"));
JSONArray jsonObject = (JSONArray) obj;

myBot.listMessages(Slack.BOTS_CHANNEL_ID);
//Slack.sendMessageWithAttachments(jsonObject);

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

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

}
}
Loading