adding npm commands
This commit is contained in:
39
commands/npm.js
Normal file
39
commands/npm.js
Normal file
@@ -0,0 +1,39 @@
|
||||
var libFlayer = require("../libFlayer.js");
|
||||
|
||||
module.exports = {
|
||||
name: 'npm',
|
||||
description: 'NPM',
|
||||
async execute(message, args) {
|
||||
try {
|
||||
if (args.length < 1) {
|
||||
message.reply(`Please use in !npm [npm-package] - ex !npm axios`);
|
||||
return;
|
||||
}
|
||||
var question = encodeURIComponent(args.join(" "));
|
||||
|
||||
var returnData = await libFlayer.getNPM(question);
|
||||
if (returnData.length > 1) {
|
||||
let npmList = ``;
|
||||
message.reply(`Please use exact name:`);
|
||||
returnData.forEach(npmResult => {
|
||||
npmList += `- ${npmResult.name}\n`;
|
||||
});
|
||||
message.reply(`Use !npm with exact name to match: \n` + npmList);
|
||||
} else {
|
||||
message.reply(
|
||||
`
|
||||
Name: **${returnData[0].name}** - *${returnData[0].description}*
|
||||
Version: **${returnData[0].version}**
|
||||
Date: **${returnData[0].date}**
|
||||
NPM: **${returnData[0].links.npm}**
|
||||
Homepage: **${returnData[0].links.homepage}**
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
message.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
65
index.js
65
index.js
@@ -1,14 +1,28 @@
|
||||
const fs = require('fs');
|
||||
const path = require('node:path');
|
||||
const { prefix } = require('./config.json');
|
||||
const {
|
||||
prefix
|
||||
} = require('./config.json');
|
||||
require('dotenv').config();
|
||||
token = process.env.TOKEN;
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const { quotes } = require('./quotes.json');
|
||||
const {
|
||||
Routes
|
||||
} = require('discord-api-types/v9');
|
||||
const {
|
||||
quotes
|
||||
} = require('./quotes.json');
|
||||
//const Discord = require('discord.js');Client, Collection, Intents
|
||||
const { Client, Collection, Intents, MessageActionRow, MessageButton } = require('discord.js');
|
||||
const {
|
||||
Client,
|
||||
Collection,
|
||||
Intents,
|
||||
MessageActionRow,
|
||||
MessageButton
|
||||
} = require('discord.js');
|
||||
//const client = new Discord.Client();
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS] });
|
||||
const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS]
|
||||
});
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const express = require("express");
|
||||
const server = express();
|
||||
@@ -18,12 +32,12 @@ var libTrivia = require("./libTrivia.js");
|
||||
|
||||
let linkFlayerMap = [];
|
||||
|
||||
server.all("/",(req, res) => {
|
||||
server.all("/", (req, res) => {
|
||||
var htmlOutput = "LinkFlayer Bot is Ready - Sources loading <br />";
|
||||
|
||||
var sources = libFlayer.getSources();
|
||||
sources.forEach(source => {
|
||||
htmlOutput +=`
|
||||
htmlOutput += `
|
||||
<div style='margin-bottom:15px;'>
|
||||
|
||||
<div> Title: ${source.title} </div>
|
||||
@@ -36,21 +50,21 @@ server.all("/",(req, res) => {
|
||||
|
||||
</div>
|
||||
|
||||
`
|
||||
});
|
||||
res.send(htmlOutput);
|
||||
`
|
||||
});
|
||||
res.send(htmlOutput);
|
||||
|
||||
});
|
||||
|
||||
function keepAlive() {
|
||||
server.listen(PORT, () => {
|
||||
server.listen(PORT, () => {
|
||||
console.log("Keep Alive Server Running");
|
||||
try {
|
||||
libFlayer.loadFeeds();
|
||||
libFlayer.feedArray = libFlayer.getFeeds();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
libFlayer.loadFeeds();
|
||||
libFlayer.feedArray = libFlayer.getFeeds();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,7 +91,7 @@ for (const file of commandFiles) {
|
||||
}
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
@@ -85,8 +99,11 @@ client.on('interactionCreate', async interaction => {
|
||||
if (!interaction.isSelectMenu()) return;
|
||||
|
||||
let aaa = interaction.values[0];
|
||||
await interaction.channel.send({ content: 'You picked something', ephemeral: true });
|
||||
|
||||
await interaction.channel.send({
|
||||
content: 'You picked something',
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
try {
|
||||
//await command.execute(interaction);
|
||||
} catch (error) {
|
||||
@@ -113,13 +130,9 @@ client.on('message', message => {
|
||||
|
||||
console.log("Link Flayer Bot Activating");
|
||||
keepAlive();
|
||||
client.login(token); //Load Client Discord Token
|
||||
client.login(token); //Load Client Discord Token
|
||||
try {
|
||||
libFlayer.loadFeeds();
|
||||
libFlayer.loadFeeds();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
98
libFlayer.js
98
libFlayer.js
@@ -124,8 +124,8 @@ exports.loadFeeds = function () {
|
||||
|
||||
base(userTable)
|
||||
.select().firstPage(function (err, records) {
|
||||
try {
|
||||
records.forEach(function (record) {
|
||||
records.forEach(function (record) {
|
||||
try {
|
||||
console.log('Retrieved title: ', record.get('title'));
|
||||
console.log('Retrieved link:', record.get('link'));
|
||||
console.log('Retrieved category:', record.get('category'));
|
||||
@@ -144,6 +144,7 @@ exports.loadFeeds = function () {
|
||||
foundMatch = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!foundMatch) {
|
||||
feeds.push(feedData);
|
||||
}
|
||||
@@ -159,48 +160,47 @@ exports.loadFeeds = function () {
|
||||
linkFlayerCats.push(record.get('category'));
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
|
||||
feeds.forEach(feedBlock => {
|
||||
(async () => {
|
||||
try {
|
||||
const feed = parser.parseURL(feedBlock.link, function (err, feed) {
|
||||
if (err) {
|
||||
console.log(err + " " + feedBlock.link);
|
||||
//return;
|
||||
}
|
||||
|
||||
const feed = parser.parseURL(feedBlock.link, function (err, feed) {
|
||||
if (err) {
|
||||
console.log(err + " " + feedBlock.link);
|
||||
//return;
|
||||
}
|
||||
if (feed != undefined && feed.items != undefined) {
|
||||
feed.items.forEach(item => {
|
||||
var foundFeed = false;
|
||||
linkFlayerMap.forEach(linkFlay => {
|
||||
if (linkFlay.link == item.link) {
|
||||
foundFeed = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (feed != undefined && feed.items != undefined) {
|
||||
feed.items.forEach(item => {
|
||||
var foundFeed = false;
|
||||
linkFlayerMap.forEach(linkFlay => {
|
||||
if (linkFlay.link == item.link) {
|
||||
foundFeed = true;
|
||||
if (!foundFeed) {
|
||||
var linkData = {
|
||||
title: `${unescape(item.title)}`,
|
||||
link: `${unescape(item.link)}`,
|
||||
category: `${unescape(feedBlock.category)}`
|
||||
}
|
||||
linkFlayerMap.push(linkData);
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
console.log('error parsing :' + feedBlock.link);
|
||||
}
|
||||
|
||||
if (!foundFeed) {
|
||||
var linkData = {
|
||||
title: `${unescape(item.title)}`,
|
||||
link: `${unescape(item.link)}`,
|
||||
category: `${unescape(feedBlock.category)}`
|
||||
}
|
||||
linkFlayerMap.push(linkData);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log('error parsing :' + feedBlock.link);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
})().then();
|
||||
});
|
||||
return;
|
||||
@@ -219,7 +219,7 @@ exports.weatherAlert = async function (state) {
|
||||
|
||||
await axios.get(answerURL)
|
||||
.then(response => {
|
||||
response.data.features.forEach(feature => {
|
||||
response.data.features.forEach(feature => {
|
||||
answerData.push(feature);
|
||||
})
|
||||
|
||||
@@ -290,6 +290,30 @@ exports.getSlang = async function (question) {
|
||||
return slangData;
|
||||
}
|
||||
|
||||
exports.getNPM = async function (question) {
|
||||
|
||||
var answerURL = `https://www.npmjs.com/search/suggestions?q=${question}`;
|
||||
console.log(answerURL);
|
||||
let returnData = [];
|
||||
|
||||
await axios.get(answerURL)
|
||||
.then(response => {
|
||||
console.log(response.data);
|
||||
|
||||
if (response.data.length != 0) {
|
||||
response.data.forEach(npmResult => {
|
||||
returnData.push(npmResult);
|
||||
});
|
||||
}
|
||||
|
||||
return returnData;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
return returnData;
|
||||
}
|
||||
|
||||
exports.getStock = async function (stock) {
|
||||
|
||||
var answerURL = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${stock}&interval=5min&apikey=${stockKey}`;
|
||||
|
||||
Reference in New Issue
Block a user