Improved twitter bot a bit more, replaced all indexOf checks, fixed xp message bug
This commit is contained in:
parent
e1347fcf52
commit
0920c459d5
9 changed files with 52 additions and 43 deletions
|
@ -52,7 +52,7 @@ exports.run = async (message, args) => {
|
||||||
];
|
];
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
return `${message.author.mention}, you need to provide some text for the cow to say!`;
|
return `${message.author.mention}, you need to provide some text for the cow to say!`;
|
||||||
} else if (cowList.indexOf(args[0].toLowerCase()) > -1) {
|
} else if (cowList.includes(args[0].toLowerCase())) {
|
||||||
const cow = args.shift().toLowerCase();
|
const cow = args.shift().toLowerCase();
|
||||||
return `\`\`\`\n${cowsay.say({
|
return `\`\`\`\n${cowsay.say({
|
||||||
text: args.join(" "),
|
text: args.join(" "),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
if (args.length === 0) return `${message.author.mention}, you need to provide what you want to spam!`;
|
if (args.length === 0) return `${message.author.mention}, you need to provide what you want to spam!`;
|
||||||
if (message.content.indexOf("@everyone") > -1 || message.content.indexOf("@here") > -1) return "I don't know about you, but that seems like a bad idea.";
|
if (message.content.includes("@everyone") || message.content.includes("@here")) return "I don't know about you, but that seems like a bad idea.";
|
||||||
return args.join(" ").repeat(500).substring(0, 500);
|
return args.join(" ").repeat(500).substring(0, 500);
|
||||||
};
|
};
|
|
@ -10,7 +10,7 @@ exports.run = async (message, args) => {
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "add":
|
case "add":
|
||||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to add!`;
|
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to add!`;
|
||||||
if (blacklist.indexOf(args[1].toLowerCase()) > -1) return `${message.author.mention}, you can't make a tag with that name!`;
|
if (blacklist.includes(args[1].toLowerCase())) return `${message.author.mention}, you can't make a tag with that name!`;
|
||||||
if (tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
|
if (tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
|
||||||
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
|
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
|
||||||
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`;
|
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`;
|
||||||
|
|
|
@ -2,18 +2,22 @@ const fetch = require("node-fetch");
|
||||||
|
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
const url = args.length > 0 && args[0].match(/^\d+$/) ? `http://xkcd.com/${args[0]}/info.0.json` : "http://xkcd.com/info.0.json";
|
const url = args.length > 0 && args[0].match(/^\d+$/) ? `http://xkcd.com/${args[0]}/info.0.json` : "http://xkcd.com/info.0.json";
|
||||||
const request = await fetch(url);
|
try {
|
||||||
const json = await request.json();
|
const request = await fetch(url);
|
||||||
const embed = {
|
const json = await request.json();
|
||||||
"embed": {
|
const embed = {
|
||||||
"title": json.safe_title,
|
"embed": {
|
||||||
"url": `https://xkcd.com/${json.num}`,
|
"title": json.safe_title,
|
||||||
"color": 16711680,
|
"url": `https://xkcd.com/${json.num}`,
|
||||||
"description": json.alt,
|
"color": 16711680,
|
||||||
"image": {
|
"description": json.alt,
|
||||||
"url": json.img
|
"image": {
|
||||||
|
"url": json.img
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
return message.channel.createMessage(embed);
|
||||||
return message.channel.createMessage(embed);
|
} catch {
|
||||||
|
return `${message.author.mention}, I couldn't find that XKCD!`;
|
||||||
|
}
|
||||||
};
|
};
|
|
@ -17,25 +17,20 @@ module.exports = async (message) => {
|
||||||
|
|
||||||
// xp stuff
|
// xp stuff
|
||||||
const xp = (await database.xp.find({ id: message.channel.guild.id }).exec())[0];
|
const xp = (await database.xp.find({ id: message.channel.guild.id }).exec())[0];
|
||||||
if (xp.enabled === true) {
|
if (xp.enabled === true && !message.member.roles.includes("631290345824714762")) {
|
||||||
//console.log(xp.members);
|
|
||||||
const info = xp.members.get(message.author.id);
|
const info = xp.members.get(message.author.id);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
logger.log("Member not in XP database, adding");
|
logger.log("Member not in XP database, adding");
|
||||||
const memberInfo = {
|
const memberInfo = {
|
||||||
xpAmount: 1,
|
xpAmount: 10,
|
||||||
level: 0
|
level: 0
|
||||||
};
|
};
|
||||||
xp.members.set(message.author.id, memberInfo);
|
xp.members.set(message.author.id, memberInfo);
|
||||||
await xp.save();
|
await xp.save();
|
||||||
} else {
|
} else {
|
||||||
let newLevel;
|
|
||||||
const newAmount = info.xpAmount + 10;
|
const newAmount = info.xpAmount + 10;
|
||||||
//xp.members[message.author.id].xpAmount++;
|
|
||||||
const level = Math.floor(0.1 * Math.sqrt(newAmount));
|
const level = Math.floor(0.1 * Math.sqrt(newAmount));
|
||||||
if (info.level < level) {
|
if (info.level < level) {
|
||||||
newLevel = info.level++;
|
|
||||||
//xp.members[message.author.id].level++;
|
|
||||||
logger.log(`${message.author.username} has leveled up`);
|
logger.log(`${message.author.username} has leveled up`);
|
||||||
if (message.channel.guild.id === "631290275456745502" && level === 5) {
|
if (message.channel.guild.id === "631290275456745502" && level === 5) {
|
||||||
await message.author.addRole("638759280752853022", "level 5");
|
await message.author.addRole("638759280752853022", "level 5");
|
||||||
|
@ -52,14 +47,14 @@ module.exports = async (message) => {
|
||||||
}
|
}
|
||||||
xp.members.set(message.author.id, {
|
xp.members.set(message.author.id, {
|
||||||
xpAmount: newAmount,
|
xpAmount: newAmount,
|
||||||
level: newLevel ? newLevel : info.level
|
level: level
|
||||||
});
|
});
|
||||||
await xp.save();
|
await xp.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore other stuff
|
// ignore other stuff
|
||||||
if (message.content.startsWith(prefix) === false && message.mentions.indexOf(client.user) <= -1 && message.channel.id !== "573553254575898626" && (!message.content.match(/https?:\/\/(media|cdn)\.discordapp\.(net|com)\/attachments\/596766080014221373\/606176845871972383\/1561668913236-3.gif/))) return;
|
if (message.content.startsWith(prefix) === false && !message.mentions.includes(client.user) && message.channel.id !== "573553254575898626") return;
|
||||||
|
|
||||||
// funny stuff
|
// funny stuff
|
||||||
if (message.channel.id === "573553254575898626" && message.channel.guild.id === "433408970955423765") {
|
if (message.channel.id === "573553254575898626" && message.channel.guild.id === "433408970955423765") {
|
||||||
|
@ -75,12 +70,6 @@ module.exports = async (message) => {
|
||||||
await client.createMessage(generalChannel.id, message.content);
|
await client.createMessage(generalChannel.id, message.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// || (message.attachments && message.attachments[0].filename === "1561668913236-3.gif")
|
|
||||||
if (message.channel.guild.id === "322114245632327703" && (message.content.match(/https?:\/\/(media|cdn)\.discordapp\.(net|com)\/attachments\/596766080014221373\/606176845871972383\/1561668913236-3.gif/))) {
|
|
||||||
const odyMessages = ["Nope!", "No jojo gif here", "sorry ody, this gif is illegal", "get owned"];
|
|
||||||
await message.delete("anti-jojo mechanism");
|
|
||||||
await client.createMessage(message.channel.id, misc.random(odyMessages));
|
|
||||||
}
|
|
||||||
|
|
||||||
// separate commands and args
|
// separate commands and args
|
||||||
const escapedPrefix = misc.regexEscape(prefix);
|
const escapedPrefix = misc.regexEscape(prefix);
|
||||||
|
|
|
@ -49,22 +49,37 @@ module.exports = async () => {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// tweet stuff
|
// tweet stuff
|
||||||
if (twitter !== null) {
|
if (twitter !== null && twitter.active === false) {
|
||||||
const tweet = async () => {
|
const tweet = async () => {
|
||||||
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
|
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
|
||||||
const tweetContent = await misc.getTweet(tweets);
|
const tweetContent = await misc.getTweet(tweets);
|
||||||
const info = await twitter.client.post("statuses/update", { status: tweetContent });
|
try {
|
||||||
logger.log(`Tweet with id ${info.data.id_str} has been tweeted with status code ${info.resp.statusCode} ${info.resp.statusMessage}`);
|
const info = await twitter.client.post("statuses/update", { status: tweetContent });
|
||||||
|
logger.log(`Tweet with id ${info.data.id_str} has been tweeted 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();
|
tweet();
|
||||||
setInterval(tweet, 1800000);
|
setInterval(tweet, 1800000);
|
||||||
|
twitter.active = true;
|
||||||
const stream = twitter.client.stream("statuses/filter", {
|
const stream = twitter.client.stream("statuses/filter", {
|
||||||
track: `@${process.env.HANDLE}`
|
track: `@${process.env.HANDLE}`
|
||||||
});
|
});
|
||||||
stream.on("tweet", async (tweet) => {
|
stream.on("tweet", async (tweet) => {
|
||||||
if (tweet.user.screen_name !== "esmBot_") {
|
if (tweet.user.screen_name !== "esmBot_") {
|
||||||
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
|
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
|
||||||
const tweetContent = await misc.getTweet(tweets, true);
|
let tweetContent;
|
||||||
|
if (tweet.text.includes("@this_vid") || tweet.text.includes("@DownloaderBot") || tweet.text.includes("@GetVideoBot") || tweet.text.includes("@DownloaderB0t") || tweet.text.includes("@thisvid_")) {
|
||||||
|
tweetContent = await misc.getTweet(tweet, true, true);
|
||||||
|
} else {
|
||||||
|
tweetContent = await misc.getTweet(tweets, true);
|
||||||
|
}
|
||||||
const payload = {
|
const payload = {
|
||||||
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
||||||
in_reply_to_status_id: tweet.id_str
|
in_reply_to_status_id: tweet.id_str
|
||||||
|
|
|
@ -22,6 +22,7 @@ const tweetSchema = new mongoose.Schema({
|
||||||
phrases: [String],
|
phrases: [String],
|
||||||
games: [String],
|
games: [String],
|
||||||
characters: [String],
|
characters: [String],
|
||||||
|
download: [String],
|
||||||
enabled: Boolean
|
enabled: Boolean
|
||||||
});
|
});
|
||||||
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);
|
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);
|
||||||
|
|
|
@ -29,16 +29,15 @@ exports.clean = async (text) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// get random tweet to post
|
// get random tweet to post
|
||||||
exports.getTweet = async (tweets, reply = false) => {
|
exports.getTweet = async (tweets, reply = false, isDownload = false) => {
|
||||||
const randomTweet = this.random(reply ? tweets.replies : tweets.tweets);
|
const randomTweet = this.random(reply ? (isDownload ? tweets.download : tweets.replies) : tweets.tweets);
|
||||||
if (randomTweet.match("{{message}}")) {
|
if (randomTweet.match("{{message}}")) {
|
||||||
const randomMessage = await this.getRandomMessage();
|
return randomTweet.replace(/{{message}}/g, await this.getRandomMessage());
|
||||||
return randomTweet.replace("{{message}}", randomMessage);
|
|
||||||
} else {
|
} else {
|
||||||
return randomTweet.replace("{{media}}", this.random(tweets.media))
|
return randomTweet.replace(/{{media}}/g, this.random(tweets.media))
|
||||||
.replace("{{games}}", this.random(tweets.games))
|
.replace(/{{games}}/g, this.random(tweets.games))
|
||||||
.replace("{{phrases}}", this.random(tweets.phrases))
|
.replace(/{{phrases}}/g, this.random(tweets.phrases))
|
||||||
.replace("{{characters}}", this.random(tweets.characters));
|
.replace(/{{characters}}/g, this.random(tweets.characters));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ const T = new Twit({
|
||||||
access_token_secret: process.env.ACCESS_SECRET
|
access_token_secret: process.env.ACCESS_SECRET
|
||||||
});
|
});
|
||||||
exports.client = T;
|
exports.client = T;
|
||||||
|
exports.active = false;
|
||||||
require("../utils/database.js").tweets.find({ enabled: true }, (error, docs) => {
|
require("../utils/database.js").tweets.find({ enabled: true }, (error, docs) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
exports.tweets = docs[0];
|
exports.tweets = docs[0];
|
||||||
|
|
Loading…
Reference in a new issue