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 fs = require('fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { prefix } = require('./config.json');
|
const {
|
||||||
|
prefix
|
||||||
|
} = require('./config.json');
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
token = process.env.TOKEN;
|
token = process.env.TOKEN;
|
||||||
const { Routes } = require('discord-api-types/v9');
|
const {
|
||||||
const { quotes } = require('./quotes.json');
|
Routes
|
||||||
|
} = require('discord-api-types/v9');
|
||||||
|
const {
|
||||||
|
quotes
|
||||||
|
} = require('./quotes.json');
|
||||||
//const Discord = require('discord.js');Client, Collection, Intents
|
//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 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 PORT = process.env.PORT || 3000;
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const server = express();
|
const server = express();
|
||||||
@@ -18,12 +32,12 @@ var libTrivia = require("./libTrivia.js");
|
|||||||
|
|
||||||
let linkFlayerMap = [];
|
let linkFlayerMap = [];
|
||||||
|
|
||||||
server.all("/",(req, res) => {
|
server.all("/", (req, res) => {
|
||||||
var htmlOutput = "LinkFlayer Bot is Ready - Sources loading <br />";
|
var htmlOutput = "LinkFlayer Bot is Ready - Sources loading <br />";
|
||||||
|
|
||||||
var sources = libFlayer.getSources();
|
var sources = libFlayer.getSources();
|
||||||
sources.forEach(source => {
|
sources.forEach(source => {
|
||||||
htmlOutput +=`
|
htmlOutput += `
|
||||||
<div style='margin-bottom:15px;'>
|
<div style='margin-bottom:15px;'>
|
||||||
|
|
||||||
<div> Title: ${source.title} </div>
|
<div> Title: ${source.title} </div>
|
||||||
@@ -36,21 +50,21 @@ server.all("/",(req, res) => {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
res.send(htmlOutput);
|
res.send(htmlOutput);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function keepAlive() {
|
function keepAlive() {
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log("Keep Alive Server Running");
|
console.log("Keep Alive Server Running");
|
||||||
try {
|
try {
|
||||||
libFlayer.loadFeeds();
|
libFlayer.loadFeeds();
|
||||||
libFlayer.feedArray = libFlayer.getFeeds();
|
libFlayer.feedArray = libFlayer.getFeeds();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +91,7 @@ for (const file of commandFiles) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(`Logged in as ${client.user.tag}!`);
|
console.log(`Logged in as ${client.user.tag}!`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('interactionCreate', async interaction => {
|
client.on('interactionCreate', async interaction => {
|
||||||
@@ -85,8 +99,11 @@ client.on('interactionCreate', async interaction => {
|
|||||||
if (!interaction.isSelectMenu()) return;
|
if (!interaction.isSelectMenu()) return;
|
||||||
|
|
||||||
let aaa = interaction.values[0];
|
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 {
|
try {
|
||||||
//await command.execute(interaction);
|
//await command.execute(interaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -113,13 +130,9 @@ client.on('message', message => {
|
|||||||
|
|
||||||
console.log("Link Flayer Bot Activating");
|
console.log("Link Flayer Bot Activating");
|
||||||
keepAlive();
|
keepAlive();
|
||||||
client.login(token); //Load Client Discord Token
|
client.login(token); //Load Client Discord Token
|
||||||
try {
|
try {
|
||||||
libFlayer.loadFeeds();
|
libFlayer.loadFeeds();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
98
libFlayer.js
98
libFlayer.js
@@ -124,8 +124,8 @@ exports.loadFeeds = function () {
|
|||||||
|
|
||||||
base(userTable)
|
base(userTable)
|
||||||
.select().firstPage(function (err, records) {
|
.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 title: ', record.get('title'));
|
||||||
console.log('Retrieved link:', record.get('link'));
|
console.log('Retrieved link:', record.get('link'));
|
||||||
console.log('Retrieved category:', record.get('category'));
|
console.log('Retrieved category:', record.get('category'));
|
||||||
@@ -144,6 +144,7 @@ exports.loadFeeds = function () {
|
|||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!foundMatch) {
|
if (!foundMatch) {
|
||||||
feeds.push(feedData);
|
feeds.push(feedData);
|
||||||
}
|
}
|
||||||
@@ -159,48 +160,47 @@ exports.loadFeeds = function () {
|
|||||||
linkFlayerCats.push(record.get('category'));
|
linkFlayerCats.push(record.get('category'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
});
|
console.log(error);
|
||||||
} catch (error) {
|
}
|
||||||
console.log(error);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
feeds.forEach(feedBlock => {
|
feeds.forEach(feedBlock => {
|
||||||
(async () => {
|
(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 (feed != undefined && feed.items != undefined) {
|
||||||
if (err) {
|
feed.items.forEach(item => {
|
||||||
console.log(err + " " + feedBlock.link);
|
var foundFeed = false;
|
||||||
//return;
|
linkFlayerMap.forEach(linkFlay => {
|
||||||
}
|
if (linkFlay.link == item.link) {
|
||||||
|
foundFeed = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (feed != undefined && feed.items != undefined) {
|
if (!foundFeed) {
|
||||||
feed.items.forEach(item => {
|
var linkData = {
|
||||||
var foundFeed = false;
|
title: `${unescape(item.title)}`,
|
||||||
linkFlayerMap.forEach(linkFlay => {
|
link: `${unescape(item.link)}`,
|
||||||
if (linkFlay.link == item.link) {
|
category: `${unescape(feedBlock.category)}`
|
||||||
foundFeed = true;
|
}
|
||||||
|
linkFlayerMap.push(linkData);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log('error parsing :' + feedBlock.link);
|
||||||
|
}
|
||||||
|
|
||||||
if (!foundFeed) {
|
})
|
||||||
var linkData = {
|
} catch (error) {
|
||||||
title: `${unescape(item.title)}`,
|
console.log(error);
|
||||||
link: `${unescape(item.link)}`,
|
}
|
||||||
category: `${unescape(feedBlock.category)}`
|
|
||||||
}
|
|
||||||
linkFlayerMap.push(linkData);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log('error parsing :' + feedBlock.link);
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
})().then();
|
})().then();
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -219,7 +219,7 @@ exports.weatherAlert = async function (state) {
|
|||||||
|
|
||||||
await axios.get(answerURL)
|
await axios.get(answerURL)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
response.data.features.forEach(feature => {
|
response.data.features.forEach(feature => {
|
||||||
answerData.push(feature);
|
answerData.push(feature);
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -290,6 +290,30 @@ exports.getSlang = async function (question) {
|
|||||||
return slangData;
|
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) {
|
exports.getStock = async function (stock) {
|
||||||
|
|
||||||
var answerURL = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${stock}&interval=5min&apikey=${stockKey}`;
|
var answerURL = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${stock}&interval=5min&apikey=${stockKey}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user