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

Modified pubsub command to use more subs #46

Closed
wants to merge 2 commits into from
Closed
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
49 changes: 39 additions & 10 deletions src/commands/pubSub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const yesResponses = [
"Get your butt to Publix!",
"Yes. Yes they are.",
"They are, until they aren't. Hurry!",
"chickentendersub.onSale = true",
"publixSub.onSale = true",
];
const noResponses = [
"Sorry to disappoint.",
Expand All @@ -19,22 +19,25 @@ const noResponses = [
"Outlook seems dim.",
"Maybe next week.",
];

/**
* Investigates wether or not Publix PubSubs are on sale and responds to the caller
* Util function to grab the specific sub and return data
* @param {Discord.Messaage} message
* @param {string} pubSubName
*/
export function pubSub(message: Discord.Message): Promise<void> {
return fetch("http://www.arepublixchickentendersubsonsale.com/")
.then((res) => res.text())
function pubsubSender(message: Discord.Message, pubSubName: string) {
return fetch("https://api.pubsub-api.dev/subs/?name=" + pubSubName)
.then((res) => res.json())
.then((body) => {
if (body.includes("onsale:no")) {
let subData = body[0]
let subName = subData["sub_name"].replace(/-/g, " ")
if (subData["status"] == "False") {
message.channel.send(
noResponses[Math.floor(Math.random() * noResponses.length)]
noResponses[Math.floor(Math.random() * noResponses.length)] + " " + subName + " hasn't been on sale since " + subData["last_sale"] + " for the price of " + subData["price"]
);
} else {
}
else if (subData["status"] == "True") {
message.channel.send(
yesResponses[Math.floor(Math.random() * noResponses.length)]
yesResponses[Math.floor(Math.random() * noResponses.length)] + " " + subName + " is on sale right now till " + subData["last_sale"] + " for the price of " + subData["price"]
);
}
})
Expand All @@ -43,3 +46,29 @@ export function pubSub(message: Discord.Message): Promise<void> {
message.channel.send("Shits broke, Im not fixing it. probably.");
});
}
/**
* Investigates wether or not Publix PubSubs are on sale and responds to the caller
* @param {Discord.Messaage} message
* @param {String[]} commandArgs
*/
export function pubSub(message: Discord.Message, commandArgs: String[]) {
/**
Cycles through random pubsubs
*/
if (commandArgs.length == 1) {
pubsubSender(message, "random")
}
/*
Grabs the info for the particular sub, images are optional to add.
*/
else if (commandArgs.length >= 2) {
let subName = commandArgs.slice(1, commandArgs.length).join("-")
return fetch("https://api.pubsub-api.dev/subs/?name=" + subName)
.then((res) => res.json())
.then((body) => {
let subData = body[0]
pubsubSender(message, subName)
}
)
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ client.on("message", (message: Discord.Message) => {
break;
case "pubsub":
//Are they on sale?
pubSub(message);
pubSub(message, args);
break;
case "image":
case "animate":
Expand All @@ -43,7 +43,7 @@ client.on("message", (message: Discord.Message) => {
ping(message);
break;
case "pubsub":
pubSub(message);
pubSub(message, args);
break;
case "image":
case "animate":
Expand Down