2020-02-19 22:46:50 +00:00
|
|
|
const util = require("util");
|
|
|
|
const client = require("./client.js");
|
|
|
|
|
2019-09-13 20:02:41 +00:00
|
|
|
// random(array) to select a random entry in array
|
|
|
|
exports.random = (array) => {
|
|
|
|
return array[Math.floor(Math.random() * array.length)];
|
|
|
|
};
|
|
|
|
|
|
|
|
// clean(text) to clean message of any private info or mentions
|
|
|
|
exports.clean = async (text) => {
|
|
|
|
if (text && text.constructor.name == "Promise")
|
|
|
|
text = await text;
|
2019-11-13 00:09:06 +00:00
|
|
|
if (typeof text !== "string")
|
2020-02-19 22:46:50 +00:00
|
|
|
text = util.inspect(text, { depth: 1 });
|
2019-09-13 20:02:41 +00:00
|
|
|
|
|
|
|
text = text
|
|
|
|
.replace(/`/g, `\`${String.fromCharCode(8203)}`)
|
|
|
|
.replace(/@/g, `@${String.fromCharCode(8203)}`)
|
2019-11-13 00:09:06 +00:00
|
|
|
.replace(process.env.TOKEN, "<redacted>")
|
|
|
|
.replace(process.env.MASHAPE, "<redacted>")
|
|
|
|
.replace(process.env.CAT, "<redacted>")
|
|
|
|
.replace(process.env.GOOGLE, "<redacted>")
|
|
|
|
.replace(process.env.DBL, "<redacted>")
|
2019-11-15 16:59:50 +00:00
|
|
|
.replace(process.env.MONGO, "<redacted>")
|
|
|
|
.replace(process.env.TWITTER_KEY, "<redacted>")
|
|
|
|
.replace(process.env.CONSUMER_SECRET, "<redacted>")
|
|
|
|
.replace(process.env.ACCESS_TOKEN, "<redacted>")
|
|
|
|
.replace(process.env.ACCESS_SECRET, "<redacted>");
|
2019-09-13 20:02:41 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2019-11-15 16:59:50 +00:00
|
|
|
// get random tweet to post
|
2019-11-23 23:23:28 +00:00
|
|
|
exports.getTweet = async (tweets, reply = false, isDownload = false) => {
|
|
|
|
const randomTweet = this.random(reply ? (isDownload ? tweets.download : tweets.replies) : tweets.tweets);
|
2019-11-15 16:59:50 +00:00
|
|
|
if (randomTweet.match("{{message}}")) {
|
2019-11-30 02:00:14 +00:00
|
|
|
return randomTweet.replace(/{{message}}/gm, await this.getRandomMessage());
|
2019-11-15 16:59:50 +00:00
|
|
|
} else {
|
2019-11-30 02:00:14 +00:00
|
|
|
return randomTweet
|
|
|
|
.replace(/{{media}}/gm, () => {
|
|
|
|
return this.random(tweets.media);
|
|
|
|
})
|
|
|
|
.replace(/{{games}}/gm, () => {
|
|
|
|
return this.random(tweets.games);
|
|
|
|
})
|
|
|
|
.replace(/{{phrases}}/gm, () => {
|
|
|
|
return this.random(tweets.phrases);
|
|
|
|
})
|
|
|
|
.replace(/{{characters}}/gm, () => {
|
|
|
|
return this.random(tweets.characters);
|
|
|
|
});
|
2019-11-15 16:59:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getRandomMessage = async () => {
|
2020-02-19 22:46:50 +00:00
|
|
|
const messages = await client.guilds.get("631290275456745502").channels.get("631290275888627713").getMessages(50);
|
2019-11-15 16:59:50 +00:00
|
|
|
const randomMessage = this.random(messages);
|
|
|
|
if (randomMessage.content.length > 144) return await this.getRandomMessage();
|
|
|
|
if (randomMessage.content.match(/<@!?\d+>/g)) return await this.getRandomMessage();
|
|
|
|
return randomMessage.content;
|
|
|
|
};
|
|
|
|
|
2019-09-13 20:02:41 +00:00
|
|
|
// regexEscape(string) to escape characters in a string for use in a regex
|
|
|
|
exports.regexEscape = (string) => {
|
|
|
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
|
|
|
};
|
|
|
|
|
2020-02-06 15:00:10 +00:00
|
|
|
// decodeEntities(string)
|
|
|
|
exports.decodeEntities = (string) => {
|
|
|
|
var translate_re = /&(nbsp|amp|quot|lt|gt);/g;
|
|
|
|
var translate = {
|
|
|
|
"nbsp": " ",
|
|
|
|
"amp": "&",
|
|
|
|
"quot": "\"",
|
|
|
|
"lt": "<",
|
|
|
|
"gt": ">"
|
|
|
|
};
|
|
|
|
return string.replace(translate_re, function(match, entity) {
|
|
|
|
return translate[entity];
|
|
|
|
}).replace(/&#(\d+);/gi, function(match, numStr) {
|
|
|
|
var num = parseInt(numStr, 10);
|
|
|
|
return String.fromCharCode(num);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-09-13 20:02:41 +00:00
|
|
|
// define defaults for prefixes and tags
|
|
|
|
exports.defaults = {
|
|
|
|
prefix: "&"
|
|
|
|
};
|
|
|
|
exports.tagDefaults = {
|
|
|
|
help: {
|
2019-12-06 14:55:30 +00:00
|
|
|
content: "https://projectlounge.pw/esmBot/help.html",
|
2019-09-13 20:02:41 +00:00
|
|
|
author: "198198681982205953"
|
|
|
|
}
|
|
|
|
};
|