Improved twitter bot a bit more, replaced all indexOf checks, fixed xp message bug

This commit is contained in:
TheEssem 2019-11-23 17:23:28 -06:00
parent e1347fcf52
commit 0920c459d5
9 changed files with 52 additions and 43 deletions

View file

@ -22,6 +22,7 @@ const tweetSchema = new mongoose.Schema({
phrases: [String],
games: [String],
characters: [String],
download: [String],
enabled: Boolean
});
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);

View file

@ -29,16 +29,15 @@ exports.clean = async (text) => {
};
// get random tweet to post
exports.getTweet = async (tweets, reply = false) => {
const randomTweet = this.random(reply ? tweets.replies : tweets.tweets);
exports.getTweet = async (tweets, reply = false, isDownload = false) => {
const randomTweet = this.random(reply ? (isDownload ? tweets.download : tweets.replies) : tweets.tweets);
if (randomTweet.match("{{message}}")) {
const randomMessage = await this.getRandomMessage();
return randomTweet.replace("{{message}}", randomMessage);
return randomTweet.replace(/{{message}}/g, await this.getRandomMessage());
} else {
return randomTweet.replace("{{media}}", this.random(tweets.media))
.replace("{{games}}", this.random(tweets.games))
.replace("{{phrases}}", this.random(tweets.phrases))
.replace("{{characters}}", this.random(tweets.characters));
return randomTweet.replace(/{{media}}/g, this.random(tweets.media))
.replace(/{{games}}/g, this.random(tweets.games))
.replace(/{{phrases}}/g, this.random(tweets.phrases))
.replace(/{{characters}}/g, this.random(tweets.characters));
}
};

View file

@ -6,6 +6,7 @@ const T = new Twit({
access_token_secret: process.env.ACCESS_SECRET
});
exports.client = T;
exports.active = false;
require("../utils/database.js").tweets.find({ enabled: true }, (error, docs) => {
if (error) throw error;
exports.tweets = docs[0];