Added proper license, removed unused stuff, more twitter bot work
This commit is contained in:
parent
143319a7e2
commit
e1347fcf52
14 changed files with 81 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -38,3 +38,4 @@ todo.txt
|
|||
tweets.json
|
||||
.vscode/
|
||||
migratedb.js
|
||||
migratetweets.js
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Essem
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
13
commands/addtweet.js
Normal file
13
commands/addtweet.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const db = require("../utils/database.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!`;
|
||||
const tweets = (await db.tweets.find({ enabled: true }).exec())[0];
|
||||
tweets[args[0]].push(args.slice(1).join(" "));
|
||||
await tweets.save();
|
||||
return `${message.author.mention}, the content has been added.`;
|
||||
};
|
||||
|
||||
exports.aliases = ["add"];
|
|
@ -30,7 +30,7 @@ module.exports = async (message) => {
|
|||
await xp.save();
|
||||
} else {
|
||||
let newLevel;
|
||||
const newAmount = info.xpAmount + 1;
|
||||
const newAmount = info.xpAmount + 10;
|
||||
//xp.members[message.author.id].xpAmount++;
|
||||
const level = Math.floor(0.1 * Math.sqrt(newAmount));
|
||||
if (info.level < level) {
|
||||
|
|
|
@ -44,24 +44,27 @@ module.exports = async () => {
|
|||
|
||||
// set activity (a.k.a. the gamer code)
|
||||
(async function activityChanger() {
|
||||
client.editStatus("dnd", { name: `${misc.random(messages)} | @esmBot help`, url: "https://essem.space/esmBot/commands.html?dev=true" });
|
||||
client.editStatus("dnd", { name: `${misc.random(messages)} | @esmBot help` });
|
||||
setTimeout(activityChanger, 900000);
|
||||
})();
|
||||
|
||||
// tweet stuff
|
||||
if (twitter !== null) {
|
||||
(async function tweet() {
|
||||
const tweetContent = await misc.getTweet(twitter);
|
||||
const tweet = async () => {
|
||||
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
|
||||
const tweetContent = await misc.getTweet(tweets);
|
||||
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}`);
|
||||
setTimeout(tweet, 1800000);
|
||||
})();
|
||||
};
|
||||
tweet();
|
||||
setInterval(tweet, 1800000);
|
||||
const stream = twitter.client.stream("statuses/filter", {
|
||||
track: `@${process.env.HANDLE}`
|
||||
});
|
||||
stream.on("tweet", async (tweet) => {
|
||||
if (tweet.user.screen_name !== "esmBot_") {
|
||||
const tweetContent = await misc.getTweet(twitter, true);
|
||||
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
|
||||
const tweetContent = await misc.getTweet(tweets, true);
|
||||
const payload = {
|
||||
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
||||
in_reply_to_status_id: tweet.id_str
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
"type": "git",
|
||||
"url": "git+https://github.com/TheEssem/esmBot.git"
|
||||
},
|
||||
"scripts": {
|
||||
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
|
||||
},
|
||||
"dependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"cowsay": "^1.4.0",
|
||||
|
|
|
@ -2,3 +2,4 @@ const { Collection } = require("eris");
|
|||
|
||||
exports.commands = new Collection();
|
||||
exports.aliases = new Collection();
|
||||
exports.voiceConnections = new Collection();
|
||||
|
|
|
@ -15,5 +15,17 @@ const xpSchema = new mongoose.Schema({
|
|||
});
|
||||
const XP = mongoose.model("XP", xpSchema);
|
||||
|
||||
const tweetSchema = new mongoose.Schema({
|
||||
tweets: [String],
|
||||
replies: [String],
|
||||
media: [String],
|
||||
phrases: [String],
|
||||
games: [String],
|
||||
characters: [String],
|
||||
enabled: Boolean
|
||||
});
|
||||
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);
|
||||
|
||||
exports.guilds = Guild;
|
||||
exports.xp = XP;
|
||||
exports.tweets = TweetCollection;
|
|
@ -29,15 +29,16 @@ exports.clean = async (text) => {
|
|||
};
|
||||
|
||||
// get random tweet to post
|
||||
exports.getTweet = async (twitter, reply = false) => {
|
||||
const randomTweet = this.random(reply ? twitter.tweets.replies : twitter.tweets.tweets);
|
||||
exports.getTweet = async (tweets, reply = false) => {
|
||||
const randomTweet = this.random(reply ? tweets.replies : tweets.tweets);
|
||||
if (randomTweet.match("{{message}}")) {
|
||||
const randomMessage = await this.getRandomMessage();
|
||||
return randomTweet.replace("{{message}}", randomMessage);
|
||||
} else {
|
||||
return randomTweet.replace("{{media}}", this.random(twitter.tweets.media))
|
||||
.replace("{{games}}", this.random(twitter.tweets.games))
|
||||
.replace("{{phrases}}", this.random(twitter.tweets.phrases));
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,27 +1,32 @@
|
|||
const client = require("./client.js");
|
||||
const fs = require("fs");
|
||||
const logger = require("./logger.js");
|
||||
const connections = require("./collections.js").voiceConnections;
|
||||
|
||||
module.exports = async (sound, message) => {
|
||||
if (message.member.voiceState.channelID) {
|
||||
if (!message.channel.guild.members.get(client.user.id).permission.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return client.createMessage(message.channel.id, `${message.author.mention}, I can't join this voice channel!`);
|
||||
const voiceChannel = message.channel.guild.channels.get(message.member.voiceState.channelID);
|
||||
if (!voiceChannel.permissionsOf(client.user.id).has("voiceConnect")) return client.createMessage(message.channel.id, `${message.author.mention}, I don't have permission to join this voice channel!`);
|
||||
const checkConnection = connections.get(message.channel.guild.id);
|
||||
const connection = checkConnection ? checkConnection : await voiceChannel.join();
|
||||
const playingMessage = await client.createMessage(message.channel.id, "🔊 Playing sound...");
|
||||
const connection = await client.joinVoiceChannel(voiceChannel.id);
|
||||
console.log(connection.current);
|
||||
connections.set(message.channel.guild.id, connection);
|
||||
if (connection.playing) {
|
||||
connection.stopPlaying();
|
||||
connection.play(fs.createReadStream(sound));
|
||||
} else {
|
||||
connection.play(fs.createReadStream(sound));
|
||||
}
|
||||
connection.play(fs.createReadStream(sound));
|
||||
connection.on("error", (error) => {
|
||||
connections.delete(message.channel.guild.id);
|
||||
voiceChannel.leave();
|
||||
playingMessage.delete();
|
||||
logger.error(error);
|
||||
});
|
||||
connection.on("warn", (warn) => {
|
||||
logger.warn(warn);
|
||||
});
|
||||
connection.once("end", () => {
|
||||
connections.delete(message.channel.guild.id);
|
||||
voiceChannel.leave();
|
||||
playingMessage.delete();
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const Twit = require("twit");
|
||||
const tweets = require("../tweets.json");
|
||||
const T = new Twit({
|
||||
consumer_key: process.env.TWITTER_KEY,
|
||||
consumer_secret: process.env.CONSUMER_SECRET,
|
||||
access_token: process.env.ACCESS_TOKEN,
|
||||
access_token_secret: process.env.ACCESS_SECRET
|
||||
});
|
||||
module.exports = {
|
||||
client: T,
|
||||
tweets: tweets
|
||||
};
|
||||
exports.client = T;
|
||||
require("../utils/database.js").tweets.find({ enabled: true }, (error, docs) => {
|
||||
if (error) throw error;
|
||||
exports.tweets = docs[0];
|
||||
});
|
Loading…
Reference in a new issue