initial commit
This commit is contained in:
parent
d4df7078e8
commit
56d71a3d99
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
# Config
|
||||
config.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
17
config-template.json
Normal file
17
config-template.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"motd": "Bot is running...",
|
||||
"status": "your wishes",
|
||||
"statusType": "LISTENING",
|
||||
"guildId": "<YOUR_GUILD_ID>",
|
||||
"token": "<YOUR_BOT_TOKEN>",
|
||||
"checkTime": 7,
|
||||
"goods": {
|
||||
"PlayStation 5": [
|
||||
{"name": "<STORE_NAME>", "url": "<STORE_URL>", "delimiter": "<HTML_ELEMENT_CLASSNAME>", "elm": "<HTML_ELEMENT_NAME>", "text": "<SOLD_TEXT>"},
|
||||
{"name": "Amazon", "url": "https://www.amazon.com/PlayStation-5-Console/dp/B08FC5L3RG", "delimiter": "a-size-medium a-color-price", "elm": "span", "text": "Currently unavailable."}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"PlayStation 5": {"role": "<PS5_ROLE_ID>", "channel": "<CHANNEL_ID_TO_MENTION_IF_PS5_IS_IN_STORE>"}
|
||||
}
|
||||
}
|
66
index.js
Normal file
66
index.js
Normal file
@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const fetch = require('node-fetch');
|
||||
const bot = new Discord.Client();
|
||||
const cfg = require('./config.json');
|
||||
|
||||
bot.on('ready', () => {
|
||||
console.clear();
|
||||
console.log(cfg.motd);
|
||||
bot.user.setActivity(cfg.status, { type: cfg.statusType });
|
||||
initCheckout(bot);
|
||||
});
|
||||
|
||||
bot.login(cfg.token);
|
||||
|
||||
const initCheckout = (bot) => {
|
||||
bot.guilds.fetch(cfg.guildId)
|
||||
.then(guild => {
|
||||
doCheckout(bot, guild);
|
||||
setInterval(() => {
|
||||
doCheckout(bot, guild);
|
||||
}, cfg.checkTime*60000);
|
||||
});
|
||||
};
|
||||
|
||||
const doCheckout = (bot, guild) => {
|
||||
const goods = cfg.goods;
|
||||
const data = cfg.data;
|
||||
for (var k in goods) {
|
||||
if (goods.hasOwnProperty(k)) {
|
||||
goods[k].forEach((v) => {
|
||||
guild.roles.fetch(data[k].role)
|
||||
.then(role => {
|
||||
bot.channels.fetch(data[k].channel)
|
||||
.then(ch => {
|
||||
checkStock(ch, role, k, v.name, v.url, v.delimiter, v.elm, v.text);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const checkStock = (ch, role, good, name, url, delimiter, elm, text) => {
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
follow: 10,
|
||||
headers: {
|
||||
'User-Agent': 'GoodsGirl/OwO'
|
||||
}
|
||||
})
|
||||
.then(res => res.text())
|
||||
.then(body => {
|
||||
if (body.indexOf(delimiter) != -1) {
|
||||
var check = `</${elm}`;
|
||||
check = (body.split(delimiter)[1]).split(check)[0];
|
||||
if (check.indexOf(text) != -1) {
|
||||
console.log(`A ${good} is unavailable at ${name}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`A ${good} is available at ${name}`);
|
||||
ch.send(`${role} is available in store ${name}! Follow the link to buy it: ${url}`);
|
||||
}
|
||||
});
|
||||
};
|
107
package-lock.json
generated
Normal file
107
package-lock.json
generated
Normal file
@ -0,0 +1,107 @@
|
||||
{
|
||||
"name": "goods-girl",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@discordjs/collection": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
|
||||
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
|
||||
},
|
||||
"@discordjs/form-data": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
|
||||
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"requires": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"discord.js": {
|
||||
"version": "12.5.1",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz",
|
||||
"integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==",
|
||||
"requires": {
|
||||
"@discordjs/collection": "^0.1.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prism-media": "^1.2.2",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
}
|
||||
},
|
||||
"event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.46.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.46.0.tgz",
|
||||
"integrity": "sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.29",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz",
|
||||
"integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==",
|
||||
"requires": {
|
||||
"mime-db": "1.46.0"
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"prism-media": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz",
|
||||
"integrity": "sha512-UHCYuqHipbTR1ZsXr5eg4JUmHER8Ss4YEb9Azn+9zzJ7/jlTtD1h0lc4g6tNx3eMlB8Mp6bfll0LPMAV4R6r3Q=="
|
||||
},
|
||||
"setimmediate": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.4.4",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.4.tgz",
|
||||
"integrity": "sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw=="
|
||||
}
|
||||
}
|
||||
}
|
23
package.json
Normal file
23
package.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "goods-girl",
|
||||
"version": "1.0.0",
|
||||
"description": "A Discord bot that checks out if goods are in store or not",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Mestima/goods-girl.git"
|
||||
},
|
||||
"author": "Mestima",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Mestima/goods-girl/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Mestima/goods-girl#readme",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.1",
|
||||
"node-fetch": "^2.6.1"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user