Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete attempt #23

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
01e47e3
first commit to User.Java
Oct 17, 2017
0c7d0d4
Merge pull request #1 from Ackochanski/Anne
Ackochanski Oct 17, 2017
e1a5953
added_token
yokilam Oct 18, 2017
eee317a
Merge pull request #2 from Ackochanski/Yoki
Ackochanski Oct 18, 2017
c6ba7bc
adding api key
Oct 18, 2017
0eaf9a9
Merge pull request #3 from Ackochanski/Anne
Ackochanski Oct 18, 2017
2278c77
Delete nano.save
Ackochanski Oct 19, 2017
9df445c
Delete nano.save
Ackochanski Oct 20, 2017
d38cdaf
minor changes
Oct 20, 2017
e22f2da
Merge pull request #4 from Ackochanski/Anne
Ackochanski Oct 20, 2017
c5d9738
name_and_random
yokilam Oct 20, 2017
93031f0
attachment
Oct 20, 2017
20a399a
Merge pull request #5 from Ackochanski/Darnell
Ackochanski Oct 20, 2017
567d7c8
removes_conflict
yokilam Oct 20, 2017
d31e8be
resolved...
yokilam Oct 20, 2017
fe1d422
Merge branch 'master' into Yoki
Ackochanski Oct 20, 2017
91f67f1
Merge pull request #7 from Ackochanski/Yoki
Ackochanski Oct 20, 2017
4d84236
Again
Oct 20, 2017
8cc8159
Merge branch 'master' into Darnell
Ackochanski Oct 20, 2017
58e59bb
Merge pull request #8 from Ackochanski/Darnell
Ackochanski Oct 20, 2017
0e2db8b
againagain
Oct 20, 2017
012e8ed
Merge pull request #9 from Ackochanski/Darnell
Ackochanski Oct 20, 2017
4898ddb
added inspirational quotes
Oct 20, 2017
cda13a2
Merge pull request #10 from Ackochanski/Bobby
Ackochanski Oct 20, 2017
3af35a3
print method
yokilam Oct 20, 2017
386f187
something
yokilam Oct 20, 2017
acfc33a
Merge pull request #11 from Ackochanski/Yoki
Ackochanski Oct 20, 2017
b244493
Merge conflicts fixed
Oct 21, 2017
7474fa9
testing
yokilam Oct 21, 2017
7d1bafc
Merge pull request #12 from Ackochanski/Yoki
Ackochanski Oct 21, 2017
6e8e17e
parsed User AGAIN
Oct 21, 2017
9e5e324
Merge pull request #13 from Ackochanski/Anne
Ackochanski Oct 21, 2017
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
78 changes: 77 additions & 1 deletion src/nyc/c4q/ramonaharrison/Bot.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
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.*;
import nyc.c4q.ramonaharrison.network.response.*;

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

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

ArrayList<String> inspirationQuotes = new ArrayList<>();

public Bot() {

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

/**
Expand Down Expand Up @@ -55,6 +60,8 @@ public void listChannels() {
public void listMessages(String channelId) {
ListMessagesResponse listMessagesResponse = Slack.listMessages(channelId);

Bot myBot = new Bot();

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

Expand All @@ -63,12 +70,44 @@ 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") || saySomething.contains("@U7JJ7B7K4")) {
myBot.sendMessageToBotsChannel("Random Quote: \n" + randomQuote());
break;


}


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

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

if (listMessagesResponse.isOk()) {
List<Message> 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(randomQuote());

}
}
}
}

/**
* Sample method: sends a plain text message to the #bots channel. Prints a message indicating success or failure.
*
Expand All @@ -82,6 +121,7 @@ public void sendMessageToBotsChannel(String text) {
} else {
System.err.print("Error sending message: " + sendMessageResponse.getError());
}

}

/**
Expand All @@ -98,4 +138,40 @@ public void deleteMessageInBotsChannel(String messageTs) {
System.err.print("Error sending message: " + deleteMessageResponse.getError());
}
}



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 quote = inspirationQuotes.get(r.nextInt(inspirationQuotes.size()));
return quote;
}



}
21 changes: 19 additions & 2 deletions src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@

import nyc.c4q.ramonaharrison.network.Slack;



public class Main {

public static void main(String[] args) {

Bot myBot = new Bot();

myBot.testApi();

myBot.listChannels();

// myBot.respondGreeting("@C7M6UM4LA");
myBot.respond("@C7M6UM4LA");


myBot.listMessages(Slack.BOTS_CHANNEL_ID);



// myBot.sendMessageToBotsChannel(list);
// myBot.sendMessageToBotsChannel(myBot.randomTip());
// myBot.sendMessageToBotsChannel("Yum yum!");
// myBot.sendMessageToBotsChannel("So does this one: <http://www.foo.com|www.foo.com>");

// myBot.sendMessageToBotsChannel(myBot.randomQuote());
// myBot.sendMessageToBotsChannel("Yum yum!");
// myBot.sendMessageToBotsChannel("So does this one: <http://www.foo.com|www.foo.com>");


// 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");
Expand Down
155 changes: 129 additions & 26 deletions src/nyc/c4q/ramonaharrison/model/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,132 @@
*
*/

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"

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

// TODO add getters to access private fields

}
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;
}
}




Loading