Skip to content

Commit

Permalink
Merge pull request #3 from brianwhaley/dev
Browse files Browse the repository at this point in the history
v3.0
  • Loading branch information
brianwhaley committed Jul 17, 2020
2 parents 7afe411 + 6a5fb21 commit 129490f
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 2,127 deletions.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
# nerdjokes.com

## About NerdJokes
View random science, technology, math, and nerd jokes, or schedule them to be delivered to specific channels in your workspace!

* Type '/nerdjokes' to get a random joke to immediately share with your teammates.
* Type '/nerdjokes help' to get information about nerdjokes slash commands.
* Type '/nerdjokes bug' to get more information about submitting a bug.
* Type '/nerdjokes support' to get more information on how to reach out for support.
* Type '/nerdjokes getjoke' to get a random joke sent immediately.
* Type '/nerdjokes addjoke' to recommend a new joke to be added to the collection.
* Type '/nerdjokes addschedule' to add or edit a schedule for delivering jokes to the current channel.
* Type '/nerdjokes deleteschedule' to delete a schedule for delivering jokes to the current channel.
* Type '/nerdjokes version' to to see what version of NerdJokes you are using.

### STEP 1: RANDOM JOKE ON DEMAND
* Type '/nerdjokes' or '/nerdjokes getjoke' to get a random joke to immediately share with your teammates.

### STEP 2: CREATE OR DELETE A SCHEDULE
* Type '/nerdjokes addschedule' to add or edit a schedule for delivering jokes to the current channel.
* Type '/nerdjokes deleteschedule' to delete a schedule for delivering jokes to the current channel.

### STEP 3: STEP 3: ADD A JOKE
* Type '/nerdjokes addjoke' to recommend a new joke to be added to the collection.

### STEP 4: HELP
* Type '/nerdjokes help' to get information about nerdjokes slash commands.
* Type '/nerdjokes bug' to get more information about submitting a bug.
* Type '/nerdjokes support' to get more information on how to reach out for support.
* Type '/nerdjokes version' to to see what version of NerdJokes you are using.

## How it Works
* NerdJokes uses all AWS services to implement its features.
* API Gateway to manage load and broker requests and responses
* Lambda for executing code in a serverless environment
* DynamoDB for jokes, settings, and token storage

## Learn More
[NerdJokes on Pixelated](https://pixelated.tech/nerdjokes.html)

### Install Stkr
[NerdJokes on Pixelated](https://pixelated.tech/nerdjokes.html)

### Terms of Service
[NerdJokes on Pixelated](https://pixelated.tech/nerdjokes.html)

### Privacy Policy
[NerdJokes on Pixelated](https://pixelated.tech/nerdjokes.html)
57 changes: 14 additions & 43 deletions aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class S3 {
constructor(){
if(log) console.log("AWS S3 CONSTRUCTOR");
this.S3 = new AWS.S3();
this.stkrS3Bucket = "stkr-bucket";
return this ;
}

Expand Down Expand Up @@ -288,66 +287,38 @@ class S3 {

}

async emptyS3Directory(data){
if(log) console.log("EMPTY S3 DIRECTORY");
async emptyS3Directory(data) {
const listParams = {
Bucket: data.bucket,
Prefix: data.team_id + "/"
};
const listedObjects = await this.S3.listObjectsV2(listParams).promise();
if(log) console.log("EMPTY S3 DIRECTORY - Listed Objects : ", listedObjects);
const listedObjects = await S3.listObjectsV2(listParams).promise();

if (listedObjects.Contents.length === 0) return null;
const deleteParams = {
Bucket: data.bucket,
Delete: { Objects: [] }
};
for(var key in listedObjects.Contents) {
var thisObj = listedObjects.Contents[key];
deleteParams.Delete.Objects.push({ Key : thisObj.Key });
}
/* listedObjects.Contents.forEach(({ Key }) => {
listedObjects.Contents.forEach(({ Key }) => {
deleteParams.Delete.Objects.push({ Key });
}); */
if(log) console.log("EMPTY S3 DIRECTORY - Delete Params : ", JSON.stringify(deleteParams));
return new Promise((resolve, reject) => {
this.S3.deleteObjects( deleteParams, async (error, retdata) => {
if (error) {
console.log("EMPTY S3 DIRECTORY - Error", JSON.stringify(error));
console.log("EMPTY S3 DIRECTORY - ERROR Code : ", JSON.stringify(error.code));
console.log("EMPTY S3 DIRECTORY - ERROR Message : ", JSON.stringify(error.message));
console.log("EMPTY S3 DIRECTORY - ERROR Stack : ", JSON.stringify(error.stack));
reject(error);
} else {
if(log) console.log("EMPTY S3 DIRECTORY - Successful ");
if (listedObjects.IsTruncated) await this.emptyS3Directory(data);
resolve(retdata);
}
});
});
await this.S3.deleteObjects(deleteParams).promise();
if (listedObjects.IsTruncated) await this.emptyS3Directory(data);
}

async getS3ItemCount(data){
if(log) console.log("GET S3 ITEM COUNT - Event : ", data);
if(log) console.log("getS3ItemCount - Event : ", data);

var params = {
Bucket: data.bucket,
Prefix: data.team_id + "/"
};
return new Promise((resolve, reject) => {
this.S3.listObjectsV2(params, (error, retdata) => {
if (error) {
console.log("GET S3 ITEM COUNT - Error", JSON.stringify(error));
console.log("GET S3 ITEM COUNT - ERROR Code : ", JSON.stringify(error.code));
console.log("GET S3 ITEM COUNT - ERROR Message : ", JSON.stringify(error.message));
console.log("GET S3 ITEM COUNT - ERROR Stack : ", JSON.stringify(error.stack));
reject(error);
} else {
if(log) console.log("GET S3 ITEM COUNT - Success");
var image_count = retdata.Contents.length ;
if(log) console.log("GET S3 ITEM COUNT - Image Count : ", image_count);
resolve(image_count);
}
});
});
let retdata;
let items = 0;
retdata = await this.S3.listObjectsV2(params).promise();
items = retdata.Contents.length ;
if(log) console.log("getS3ItemCount - Image Count : ", items);
return(items);
}

async getS3ItemList(data){
Expand Down
Loading

0 comments on commit 129490f

Please sign in to comment.