fixing random patch

This commit is contained in:
John Facey
2021-12-23 16:29:03 -06:00
parent f551fbcd63
commit e53a8245b1
5 changed files with 25 additions and 11 deletions

17
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
}
]
}

View File

@@ -5,22 +5,17 @@ module.exports = {
name: 'random',
description: 'Random',
execute(message, args) {
let category = "";
let catName = "All";
var category = "";
var catName = "All";
if (args.length == 1) {
category = args[0];
catName = category;
}
message.reply(
`Random article - loading...
Category: ${catName}
`
);
var feedArray = libFlayer.getFeeds(category);
var i = Math.floor(Math.random() * (feedArray.length - 0) + 0 );
message.reply(`Retrieving: [Link](${feedArray[i].link})`);
message.reply(`Retrieving: [${catName}](${feedArray[i].link})`);
}
};

View File

@@ -64,7 +64,7 @@ client.on('message', message => {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
//message.reply('there was an error trying to execute that command!');
}
});

View File

@@ -37,7 +37,7 @@ exports.loadFeeds = function() {
var linkData = {
title: `${unescape(item.title)}`,
link: `${unescape(item.link)}`,
category: `${unescape(item.category)}`
category: `${unescape(feedBlock.category)}`
}
linkFlayerMap.push(linkData);
});
@@ -60,10 +60,11 @@ exports.writeFeed = function (feeds) {
};
exports.getFeeds = function (feedType) {
var linkFlayerFilteredMap = [];
if (feedType == null || feedType == undefined || feedType == "") {
return linkFlayerMap;
} else {
var linkFlayerFilteredMap = [];
linkFlayerMap.forEach(linkFlay => {
if (linkFlay.category.toLowerCase().indexOf(feedType.toLowerCase()) > -1) {
linkFlayerFilteredMap.push(linkFlay);

View File

@@ -16,6 +16,7 @@
"start": "node index.js",
"push": "git push heroku main",
"restart": "heroku dyno:restart",
"stop": "heroku dyno:stop",
"tail": "heroku logs --tail",
"local": "heroku local web"
},