diff --git a/.gitignore b/.gitignore index 4f61abb..dd039c3 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ bannedusers.json todo.txt tweets.json .vscode/ -migratedb.js \ No newline at end of file +migratedb.js +migratetweets.js \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..808c06b --- /dev/null +++ b/LICENSE @@ -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. diff --git a/assets/audio/johnwick.opus b/assets/audio/johnwick.opus deleted file mode 100644 index c3869eb..0000000 Binary files a/assets/audio/johnwick.opus and /dev/null differ diff --git a/assets/audio/macandcheese.opus b/assets/audio/macandcheese.opus deleted file mode 100644 index b773759..0000000 Binary files a/assets/audio/macandcheese.opus and /dev/null differ diff --git a/assets/audio/upermario.opus b/assets/audio/upermario.opus deleted file mode 100644 index 5372ee3..0000000 Binary files a/assets/audio/upermario.opus and /dev/null differ diff --git a/commands/addtweet.js b/commands/addtweet.js new file mode 100644 index 0000000..f10220b --- /dev/null +++ b/commands/addtweet.js @@ -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"]; \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js index e2438ef..84b4f84 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -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) { diff --git a/events/ready.js b/events/ready.js index 32dc707..cc4763d 100644 --- a/events/ready.js +++ b/events/ready.js @@ -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 diff --git a/package.json b/package.json index c71b519..4ad57f3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/utils/collections.js b/utils/collections.js index edcd292..b9108cb 100644 --- a/utils/collections.js +++ b/utils/collections.js @@ -2,3 +2,4 @@ const { Collection } = require("eris"); exports.commands = new Collection(); exports.aliases = new Collection(); +exports.voiceConnections = new Collection(); diff --git a/utils/database.js b/utils/database.js index 7700ea0..eb8e885 100644 --- a/utils/database.js +++ b/utils/database.js @@ -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; \ No newline at end of file +exports.xp = XP; +exports.tweets = TweetCollection; \ No newline at end of file diff --git a/utils/misc.js b/utils/misc.js index a59129c..1a586c7 100644 --- a/utils/misc.js +++ b/utils/misc.js @@ -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)); } }; diff --git a/utils/soundplayer.js b/utils/soundplayer.js index b34dc65..49da38f 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -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(); }); diff --git a/utils/twitter.js b/utils/twitter.js index 1a9b287..79a4ca0 100644 --- a/utils/twitter.js +++ b/utils/twitter.js @@ -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 -}; \ No newline at end of file +exports.client = T; +require("../utils/database.js").tweets.find({ enabled: true }, (error, docs) => { + if (error) throw error; + exports.tweets = docs[0]; +}); \ No newline at end of file