Skip to content

Commit

Permalink
randomememe prototype implementation of raw data return value
Browse files Browse the repository at this point in the history
  • Loading branch information
Supinic committed Oct 8, 2024
1 parent f1f81b8 commit 04fe1c8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
8 changes: 7 additions & 1 deletion commands/dankdebug/create-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,17 @@ module.exports = async function createDebugSandbox (context, scriptArgs) {

commandExecutionPending = false;

return {
const returnValue = {
success: result.success ?? true,
reason: result.reason ?? null,
reply: result.reply
};

if (result.data && typeof result.data === "object") {
returnValue.data = result.data;
}

return returnValue;
}
}),
get tee () { return Object.freeze([...context.tee]); },
Expand Down
11 changes: 10 additions & 1 deletion commands/randommeme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
{ name: "galleryLinks", type: "boolean" },
{ name: "ignoreFlair", type: "string" },
{ name: "linkOnly", type: "boolean" },
{ name: "rawData", type: "boolean" },
{ name: "showFlairs", type: "boolean" },
{ name: "skipGalleries", type: "boolean" },
{ name: "skipVideos", type: "boolean" }
Expand Down Expand Up @@ -247,7 +248,15 @@ module.exports = {
// And then splice off everything over the length of 3.
repeatedPosts.splice(config.repeats);

if (context.params.linkOnly) {
if (context.params.raw) {
return {
reply: "Data is available.",
data: {
post: post.toJSON()
}
}
}
else if (context.params.linkOnly) {
return {
reply: post.url
};
Expand Down
17 changes: 16 additions & 1 deletion commands/randommeme/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module.exports = class RedditPost {
this.#galleryLinks.push(link);
}
}

}

get id () { return this.#id; }
Expand Down Expand Up @@ -112,4 +111,20 @@ module.exports = class RedditPost {

return `${this.#title} ${fixedUrl} (Score: ${this.#score}, posted ${this.posted}${xpost})`;
}

toJSON () {
return {
id: this.#id,
url: this.#url,
created: new Date(this.#created),
author: this.#author,
nsfw: this.#nsfw,
stickied: this.#stickied,
isTextPost: this.#isTextPost,
score: this.#score,
commentsUrl: this.#commentsUrl,
flairs: [...this.#flairs],
galleryLinks: [...this.#galleryLinks]
};
}
};

0 comments on commit 04fe1c8

Please sign in to comment.