Implement Discord CnC Server into Emmelia
This commit is contained in:
55
libCore.js
55
libCore.js
@@ -4,6 +4,9 @@ const axios = require('axios');
|
||||
let parser = new Parser();
|
||||
const storageHandler = require("./libStorage");
|
||||
|
||||
const { DebugBuilder } = require("./utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "libCore");
|
||||
|
||||
/* OpenAI config
|
||||
const { Configuration, OpenAIApi } = require('openai');
|
||||
const configuration = new Configuration({
|
||||
@@ -48,11 +51,11 @@ exports.addSource = function (title, link, category, callback) {
|
||||
}
|
||||
}], function (err, record) {
|
||||
if (err) {
|
||||
console.error("Error in create:", err);
|
||||
log.ERROR("Error in create:", err);
|
||||
callback(err, undefined);
|
||||
}
|
||||
|
||||
console.log("Record ID:", record.getId());
|
||||
log.DEBUG("Record ID:", record.getId());
|
||||
|
||||
var linkData = {
|
||||
title: `${title}`,
|
||||
@@ -61,11 +64,11 @@ exports.addSource = function (title, link, category, callback) {
|
||||
id: record.getId()
|
||||
}
|
||||
|
||||
console.log("Link Data:", linkData);
|
||||
log.DEBUG("Link Data:", linkData);
|
||||
|
||||
feeds.push(linkData);
|
||||
|
||||
console.log("pushed item to feeds");
|
||||
log.DEBUG("pushed item to feeds");
|
||||
callback(undefined, true);
|
||||
});
|
||||
|
||||
@@ -85,10 +88,10 @@ exports.deleteSource = function (title, callback) {
|
||||
}
|
||||
storageSource.destroy(deleteRecord, function (err, deletedRecord) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
log.ERROR(err);
|
||||
callback(err, undefined);
|
||||
}
|
||||
console.log(deletedRecord.id);
|
||||
log.DEBUG(deletedRecord.id);
|
||||
callback(undefined, deletedRecord);
|
||||
});
|
||||
}
|
||||
@@ -124,9 +127,9 @@ exports.loadFeeds = function () {
|
||||
storageSource.getAllRecords(function (err, records) {
|
||||
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'));
|
||||
log.DEBUG('Retrieved title: ', record.get('title'));
|
||||
log.DEBUG('Retrieved link:', record.get('link'));
|
||||
log.DEBUG('Retrieved category:', record.get('category'));
|
||||
|
||||
var feedData = {
|
||||
title: `${unescape(record.get('title'))}`,
|
||||
@@ -158,7 +161,7 @@ exports.loadFeeds = function () {
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -167,7 +170,7 @@ exports.loadFeeds = function () {
|
||||
try {
|
||||
const feed = parser.parseURL(feedBlock.link, function (err, feed) {
|
||||
if (err) {
|
||||
console.log(err + " " + feedBlock.link);
|
||||
log.DEBUG(err + " " + feedBlock.link);
|
||||
//return;
|
||||
}
|
||||
|
||||
@@ -191,19 +194,19 @@ exports.loadFeeds = function () {
|
||||
|
||||
});
|
||||
} else {
|
||||
console.log('error parsing :' + feedBlock.link);
|
||||
log.DEBUG('error parsing :' + feedBlock.link);
|
||||
}
|
||||
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
}
|
||||
})().then();
|
||||
});
|
||||
return;
|
||||
//fetchNextPage();
|
||||
}, function done(error) {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -216,7 +219,7 @@ exports.loadFeeds = function () {
|
||||
exports.weatherAlert = async function (state) {
|
||||
|
||||
var answerURL = `https://api.weather.gov/alerts/active?area=${state}`;
|
||||
console.log(answerURL);
|
||||
log.DEBUG(answerURL);
|
||||
answerData = [];
|
||||
|
||||
await axios.get(answerURL)
|
||||
@@ -228,7 +231,7 @@ exports.weatherAlert = async function (state) {
|
||||
return answerData;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
});
|
||||
return answerData;
|
||||
}
|
||||
@@ -241,15 +244,15 @@ exports.weatherAlert = async function (state) {
|
||||
exports.getFood = async function () {
|
||||
|
||||
var answerURL = `https://www.themealdb.com/api/json/v1/1/random.php`;
|
||||
console.log(answerURL);
|
||||
log.DEBUG(answerURL);
|
||||
answerData = {
|
||||
text: `No answer found try using a simpler search term`,
|
||||
source: ``
|
||||
}
|
||||
await axios.get(answerURL)
|
||||
.then(response => {
|
||||
//console.log(response.data.RelatedTopics[0].Text);
|
||||
//console.log(response.data.RelatedTopics[0].FirstURL);
|
||||
//log.DEBUG(response.data.RelatedTopics[0].Text);
|
||||
//log.DEBUG(response.data.RelatedTopics[0].FirstURL);
|
||||
|
||||
// if (response.data.meals.length != 0) {
|
||||
|
||||
@@ -274,7 +277,7 @@ exports.getFood = async function () {
|
||||
return answerData;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
});
|
||||
return answerData;
|
||||
}
|
||||
@@ -288,14 +291,14 @@ exports.getFood = async function () {
|
||||
exports.getSlang = async function (question) {
|
||||
|
||||
var answerURL = `https://api.urbandictionary.com/v0/define?term=${question}`;
|
||||
console.log(answerURL);
|
||||
log.DEBUG(answerURL);
|
||||
slangData = {
|
||||
definition: `No answer found try using a simpler search term`,
|
||||
example: ``
|
||||
}
|
||||
await axios.get(answerURL)
|
||||
.then(response => {
|
||||
console.log(response.data.list[0]);
|
||||
log.DEBUG(response.data.list[0]);
|
||||
|
||||
slangData = {
|
||||
definition: `${unescape(response.data.list[0].definition) ? unescape(response.data.list[0].definition) : ''}`,
|
||||
@@ -307,7 +310,7 @@ exports.getSlang = async function (question) {
|
||||
return slangData;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
});
|
||||
return slangData;
|
||||
}
|
||||
@@ -349,14 +352,14 @@ exports.getQuotes = async function (quote_url) {
|
||||
var data = [];
|
||||
await axios.get(quote_url)
|
||||
.then(response => {
|
||||
console.log(response.data[0].q);
|
||||
console.log(response.data[0].a);
|
||||
log.DEBUG(response.data[0].q);
|
||||
log.DEBUG(response.data[0].a);
|
||||
data = response.data;
|
||||
|
||||
return data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
log.DEBUG(error);
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user