Removed Twitter bot
This commit is contained in:
parent
8c760a527d
commit
03aa3b3a2b
11 changed files with 1 additions and 185 deletions
12
.env.example
12
.env.example
|
@ -51,14 +51,4 @@ TMP_DOMAIN=
|
|||
# Set this to true if you're using PM2 to manage the bot
|
||||
PMTWO=false
|
||||
# Set this to true if you want to use the image API
|
||||
API=false
|
||||
|
||||
# Enable/disable Twitter bot (true/false)
|
||||
TWITTER=false
|
||||
# Put Twitter username here
|
||||
HANDLE=
|
||||
# Put consumer key, consumer secret, access token, and access secret here
|
||||
TWITTER_KEY=
|
||||
CONSUMER_SECRET=
|
||||
ACCESS_TOKEN=
|
||||
ACCESS_SECRET=
|
||||
API=false
|
|
@ -1,20 +0,0 @@
|
|||
const { writeFile } = require("fs");
|
||||
const { promisify } = require("util");
|
||||
const tweets = require("../tweets.json");
|
||||
const twitter = require("../utils/twitter.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can add tweets!`;
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to add to the tweet database!`;
|
||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the content you want to add!`;
|
||||
tweets[args[0]].push(args.slice(1).join(" "));
|
||||
twitter.tweets = tweets;
|
||||
await promisify(writeFile)("../tweets.json", JSON.stringify(tweets, null, 2));
|
||||
return `${message.author.mention}, the content has been added.`;
|
||||
};
|
||||
|
||||
exports.aliases = ["add"];
|
||||
exports.category = 8;
|
||||
exports.help = "Adds a tweet to the database";
|
||||
exports.requires = "twitter";
|
||||
exports.params = "[category] [message]";
|
|
@ -1,15 +0,0 @@
|
|||
const twitter = require("../utils/twitter.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can tweet!`;
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to tweet!`;
|
||||
const info = await twitter.client.statuses.update(args.join(" "));
|
||||
//if (info.resp.statusCode !== 200) return `Something happened when trying to post this tweet: ${info.resp.statusCode} ${info.resp.statusMessage}`;
|
||||
return `https://twitter.com/${process.env.HANDLE}/status/${info.id_str}`;
|
||||
// with status code ${info.resp.statusCode} ${info.resp.statusMessage}.
|
||||
};
|
||||
|
||||
exports.category = 8;
|
||||
exports.help = "Tweets a message";
|
||||
exports.requires = "twitter";
|
||||
exports.params = "[message]";
|
|
@ -6,8 +6,6 @@ const misc = require("../utils/misc.js");
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
const helpGenerator =
|
||||
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
|
||||
const twitter =
|
||||
process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
|
||||
const first = process.env.PMTWO === "true" ? process.env.NODE_APP_INSTANCE === "0" : true;
|
||||
|
||||
// run when ready
|
||||
|
@ -28,46 +26,6 @@ module.exports = async () => {
|
|||
setTimeout(activityChanger, 900000);
|
||||
})();
|
||||
|
||||
// tweet stuff
|
||||
if (twitter !== null && twitter.active === false && first) {
|
||||
const blocks = await twitter.client.blocks.ids();
|
||||
const tweet = async () => {
|
||||
const tweetContent = await misc.getTweet(twitter.tweets);
|
||||
try {
|
||||
const info = await twitter.client.statuses.update(tweetContent);
|
||||
logger.log(`Tweet with id ${info.id_str} has been posted.`);
|
||||
// with status code ${info.resp.statusCode} ${info.resp.statusMessage}
|
||||
} catch (e) {
|
||||
const error = JSON.stringify(e);
|
||||
if (error.includes("Status is a duplicate.")) {
|
||||
logger.log("Duplicate tweet, will retry in 30 minutes");
|
||||
} else {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
tweet();
|
||||
setInterval(tweet, 1800000);
|
||||
twitter.active = true;
|
||||
try {
|
||||
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
|
||||
stream.on("data", async (tweet) => {
|
||||
if (tweet.user.screen_name !== "esmBot_" && !blocks.ids.includes(tweet.user.id_str)) {
|
||||
const tweetContent = await misc.getTweet(twitter.tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
|
||||
const payload = {
|
||||
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
||||
in_reply_to_status_id: tweet.id_str,
|
||||
};
|
||||
const info = await twitter.client.statuses.update(payload);
|
||||
logger.log(`Reply with id ${info.id_str} has been posted.`);
|
||||
// with status code ${info.resp.statusCode} ${info.resp.statusMessage}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error(`The Twitter streaming API ran into an error: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.PMTWO === "true") process.send("ready");
|
||||
logger.log(`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
|
||||
};
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
const fs = require("fs");
|
||||
const mongoose = require("mongoose");
|
||||
mongoose.connect("mongodb://localhost/esmBot");
|
||||
|
||||
const tweetSchema = new mongoose.Schema({
|
||||
tweets: [String],
|
||||
replies: [String],
|
||||
media: [String],
|
||||
phrases: [String],
|
||||
games: [String],
|
||||
characters: [String],
|
||||
download: [String],
|
||||
enabled: Boolean
|
||||
});
|
||||
|
||||
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);
|
||||
|
||||
TweetCollection.findOne({}, (err, res) => {
|
||||
if (err) throw err;
|
||||
fs.writeFileSync("tweets.json", JSON.stringify(res));
|
||||
console.log("Migrated!");
|
||||
mongoose.connection.close();
|
||||
});
|
11
package-lock.json
generated
11
package-lock.json
generated
|
@ -24,7 +24,6 @@
|
|||
"node-addon-api": "^3.1.0",
|
||||
"node-emoji": "^1.10.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"node-tweet": "^0.1.4",
|
||||
"puppeteer": "^5.5.0",
|
||||
"puppeteer-extra": "^3.1.15",
|
||||
"puppeteer-extra-plugin-stealth": "^2.6.5",
|
||||
|
@ -2312,11 +2311,6 @@
|
|||
"node-gyp-build-test": "build-test.js"
|
||||
}
|
||||
},
|
||||
"node_modules/node-tweet": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/node-tweet/-/node-tweet-0.1.4.tgz",
|
||||
"integrity": "sha512-ywKfBwLFCFnPKH8QxK/bxfVeaR6SadeDh4YqhW+HixvfP/KxLxs08RA1vfnshswdlJRYh6dAq3jQ7FN2BeAqfA=="
|
||||
},
|
||||
"node_modules/noop-logger": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
|
||||
|
@ -5825,11 +5819,6 @@
|
|||
"integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==",
|
||||
"optional": true
|
||||
},
|
||||
"node-tweet": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/node-tweet/-/node-tweet-0.1.4.tgz",
|
||||
"integrity": "sha512-ywKfBwLFCFnPKH8QxK/bxfVeaR6SadeDh4YqhW+HixvfP/KxLxs08RA1vfnshswdlJRYh6dAq3jQ7FN2BeAqfA=="
|
||||
},
|
||||
"noop-logger": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
"node-addon-api": "^3.1.0",
|
||||
"node-emoji": "^1.10.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"node-tweet": "^0.1.4",
|
||||
"puppeteer": "^5.5.0",
|
||||
"puppeteer-extra": "^3.1.15",
|
||||
"puppeteer-extra-plugin-stealth": "^2.6.5",
|
||||
|
|
29
tweets.json
29
tweets.json
|
@ -1,29 +0,0 @@
|
|||
{
|
||||
"tweets": [
|
||||
"{{media}}",
|
||||
"This is an example tweet!",
|
||||
"{{characters}}: {{phrases}}",
|
||||
"I'm personally a pretty big fan of {{games}}.",
|
||||
"This is another example tweet!"
|
||||
],
|
||||
"replies": [
|
||||
"This is an example reply!",
|
||||
"Put some more replies in here!"
|
||||
],
|
||||
"media": [
|
||||
"<Put some media URLs in here!>",
|
||||
"pic.twitter.com/v8NSW2mC95"
|
||||
],
|
||||
"phrases": [
|
||||
"Here is a phrase that I can say!"
|
||||
],
|
||||
"games": [
|
||||
"Discord"
|
||||
],
|
||||
"characters": [
|
||||
"esmBot"
|
||||
],
|
||||
"download": [
|
||||
"I really do not like downloader bots."
|
||||
]
|
||||
}
|
|
@ -7,7 +7,6 @@ exports.load = async (command, soundStatus) => {
|
|||
if (props.requires === "google" && process.env.GOOGLE === "") return logger.log("info", `Google info not provided in config, skipped loading command ${command}...`);
|
||||
if (props.requires === "cat" && process.env.CAT === "") return logger.log("info", `Cat API info not provided in config, skipped loading command ${command}...`);
|
||||
if (props.requires === "mashape" && process.env.MASHAPE === "") return logger.log("info", `Mashape/RapidAPI info not provided in config, skipped loading command ${command}...`);
|
||||
if (props.requires === "twitter" && process.env.TWITTER === "false") return logger.log("info", `Twitter bot disabled, skipped loading command ${command}...`);
|
||||
if (props.requires === "sound" && soundStatus) return logger.log("info", `Failed to connect to some Lavalink nodes, skipped loading command ${command}...`);
|
||||
collections.commands.set(command.split(".")[0], props.run);
|
||||
collections.info.set(command.split(".")[0], {
|
||||
|
|
|
@ -34,28 +34,6 @@ exports.clean = async (text) => {
|
|||
return text;
|
||||
};
|
||||
|
||||
// get random tweet to post
|
||||
exports.getTweet = async (tweets, reply = false, isDownload = false) => {
|
||||
const randomTweet = this.random(reply ? (isDownload ? tweets.download : tweets.replies) : tweets.tweets);
|
||||
if (randomTweet.match("{{message}}")) {
|
||||
return randomTweet.replaceAll("{{message}}", await this.getRandomMessage());
|
||||
} else {
|
||||
return randomTweet
|
||||
.replaceAll("{{media}}", () => {
|
||||
return this.random(tweets.media);
|
||||
})
|
||||
.replaceAll("{{games}}", () => {
|
||||
return this.random(tweets.games);
|
||||
})
|
||||
.replaceAll("{{phrases}}", () => {
|
||||
return this.random(tweets.phrases);
|
||||
})
|
||||
.replaceAll("{{characters}}", () => {
|
||||
return this.random(tweets.characters);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.getRandomMessage = async () => {
|
||||
const messages = await client.guilds.get("631290275456745502").channels.get("631290275888627713").getMessages(50);
|
||||
const randomMessage = this.random(messages);
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
const Twitter = require("node-tweet");
|
||||
const client = new Twitter({
|
||||
consumerKey: process.env.TWITTER_KEY,
|
||||
consumerSecret: process.env.CONSUMER_SECRET,
|
||||
accessToken: process.env.ACCESS_TOKEN,
|
||||
accessSecret: process.env.ACCESS_SECRET
|
||||
});
|
||||
exports.client = client;
|
||||
exports.active = false;
|
||||
exports.tweets = require("../tweets.json");
|
Loading…
Reference in a new issue