diff --git a/commands/admin/autoresponse.js b/commands/admin/autoresponse.js index f2d2c27..2c6e8b6 100644 --- a/commands/admin/autoresponse.js +++ b/commands/admin/autoresponse.js @@ -13,10 +13,6 @@ class autoresponseCommand extends Command { prompt: { start: 'Do you want to **enable** or **disable** auto response?', } - }, - { - id: 'all', - type: 'string' } ], clientPermissions: ['SEND_MESSAGES'], @@ -24,8 +20,8 @@ class autoresponseCommand extends Command { channelRestriction: 'guild', description: { content: 'enable/disable autoresponse', - usage: '[enable/disable] (optional) [all]', - examples: ['enable all'] + usage: '[enable/disable]', + examples: ['enable'] } }); } diff --git a/commands/admin/quotation.js b/commands/admin/quotation.js new file mode 100644 index 0000000..0a35f34 --- /dev/null +++ b/commands/admin/quotation.js @@ -0,0 +1,45 @@ +const { Command } = require('discord-akairo'); +const quotationStat = require('../../models').quotationStat; + +class quotationCommand extends Command { + constructor() { + super('quotation', { + aliases: ['quotation'], + category: 'admin', + args: [ + { + id: 'stat', + type: 'string', + prompt: { + start: 'Do you want to **enable** or **disable** quotation?', + } + } + ], + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['MANAGE_MESSAGES'], + channelRestriction: 'guild', + description: { + content: 'enable/disable quotation', + usage: '[enable/disable]', + examples: ['enable'] + } + }); + } + + async exec(message, args) { + if (args.stat.toLowerCase() == 'enable' || args.stat.toLowerCase() == 'disable') { + const quotationstat = await quotationStat.findOne({where: {serverID: message.guild.id}}); + + if (!quotationstat) { + const body = {serverID: message.guild.id, stat: args.stat}; + quotationStat.create(body); + return message.channel.send(`Quotation has been ${args.stat}d`); + } else { + const body = {serverID: message.guild.id, stat: args.stat}; + quotationStat.update(body, {where: {serverID: message.guild.id}}); + return message.channel.send(`Quotation has been ${args.stat}d`); + } + } + } +} +module.exports = quotationCommand; \ No newline at end of file diff --git a/commands/fun/audio2image.js b/commands/fun/audio2image.js index 8627332..68c7101 100644 --- a/commands/fun/audio2image.js +++ b/commands/fun/audio2image.js @@ -11,15 +11,15 @@ class audio2imageCommand extends Command { category: 'fun', clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'], args: [ - { - id: 'link', - type: 'string', - }, { id: 'video_size', match: 'option', flag: '--size', default: '640x480' + }, + { + id: 'link', + type: 'string', } ], description: { diff --git a/commands/utility/download.js b/commands/utility/download.js index b247f29..a0460db 100644 --- a/commands/utility/download.js +++ b/commands/utility/download.js @@ -88,6 +88,8 @@ class DownloadCommand extends Command { fs.renameSync(`${os.tmpdir()}/${fileName}`, `${os.tmpdir()}/${fileName}.${ext}`); } else if (fs.existsSync(`${os.tmpdir()}/${fileName}.mkv`)) { // If it can't find the video assume it got merged and end with mkv fs.renameSync(`${os.tmpdir()}/${fileName}.mkv`, `${os.tmpdir()}/${fileName}.mp4`); // Discord play mkv just fine but it need to end with mp4 + } else if (fs.existsSync(`${os.tmpdir()}/${fileName}.webm`)) { // Same as mkv + ext = 'webm'; } let file = fs.statSync(`${os.tmpdir()}/${fileName}.${ext}`); diff --git a/commands/utility/userInfo.js b/commands/utility/userInfo.js index 22aa5dc..5c49cbe 100644 --- a/commands/utility/userInfo.js +++ b/commands/utility/userInfo.js @@ -30,8 +30,6 @@ class userInfoCommand extends Command { let member = message.guild.member(user); - console.log(member); - const Embed = this.client.util.embed() .setColor(member.displayHexColor) .setAuthor(`${user.tag} (${user.id})`, user.displayAvatarURL()) @@ -47,8 +45,11 @@ class userInfoCommand extends Command { Embed.addField('​', '​'); // Show user status - if (user.presence.activity) Embed.addField('Presence', user.presence.activities[0], true); - + if (user.presence.activities[0]) { + Embed.addField('Presence', user.presence.activities[0], true); + if (user.presence.activities[0].details) Embed.addField('​', user.presence.activities[0].details, true); + if (user.presence.activities[0].state) Embed.addField('​', user.presence.activities[0].state, true); + } // Is the user a bot? if (user.bot) Embed.addField('Is a bot?', '✅', true); diff --git a/event/listeners/guildCreate.js b/event/listeners/guildCreate.js index 7e44000..ae4b4a6 100644 --- a/event/listeners/guildCreate.js +++ b/event/listeners/guildCreate.js @@ -13,6 +13,7 @@ class guildCreateListener extends Listener { async exec(guild) { console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}`); const channel = this.client.channels.resolve(statsChannel); + let botCount = guild.members.cache.filter(member => member.user.bot).size; const addEmbed = this.client.util.embed() .setColor('#52e80d') .setTitle('New boiz in town') @@ -21,8 +22,8 @@ class guildCreateListener extends Listener { .addField('Guild name', guild.name, true) .addField('Guild ID', guild.id, true) .addField('Total number of members', guild.memberCount, true) - .addField('Number of users', guild.members.filter(member => !member.user.bot).size, true) - .addField('Number of bots', guild.members.filter(member => member.user.bot).size, true) + .addField('Number of users', guild.memberCount - botCount, true) + .addField('Number of bots', botCount, true) .addField('Owner', guild.owner.user.username, true) .addField('Owner ID', guild.owner.id, true) .setFooter(`I'm now in ${this.client.guilds.cache.size} servers!`) diff --git a/event/listeners/guildDelete.js b/event/listeners/guildDelete.js index 209cd32..3ce18bc 100644 --- a/event/listeners/guildDelete.js +++ b/event/listeners/guildDelete.js @@ -14,6 +14,8 @@ class guildCreateListener extends Listener { console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}\n***BOT KICKED***`); const channel = this.client.channels.resolve(statsChannel); + let botCount = guild.members.cache.filter(member => member.user.bot).size; + const kickEmbed = this.client.util.embed() .setColor('#FF0000') .setTitle('Some mofo just removed me from there guild :(') @@ -22,8 +24,8 @@ class guildCreateListener extends Listener { .addField('Guild name', guild.name, true) .addField('Guild ID', guild.id, true) .addField('Total number of members', guild.memberCount, true) - .addField('Number of users', guild.members.filter(member => !member.user.bot).size, true) - .addField('Number of bots', guild.members.filter(member => member.user.bot).size, true) + .addField('Number of users', guild.memberCount - botCount, true) + .addField('Number of bots', botCount, true) .addField('Owner', guild.owner.user.username, true) .addField('Owner ID', guild.owner.id, true) .setFooter(`I'm now in ${this.client.guilds.cache.size} servers!`) diff --git a/event/listeners/guildMemberAdd.js b/event/listeners/guildMemberAdd.js index 570e57d..23ae19c 100644 --- a/event/listeners/guildMemberAdd.js +++ b/event/listeners/guildMemberAdd.js @@ -10,13 +10,13 @@ class guildMemberAddListener extends Listener { }); } - async exec(guild) { - if (guild.guild.id == 240843640375607296) { - guild.setNickname('fart piss'); + async exec(member) { + if (member.guild.id == 240843640375607296) { + member.setNickname('fart piss'); } - const join = await joinChannel.findOne({where: {guildID: guild.guild.id}}); + const join = await joinChannel.findOne({where: {guildID: member.guild.id}}); if (join) { const channel = this.client.channels.resolve(join.get('channelID')); @@ -26,17 +26,18 @@ class guildMemberAddListener extends Listener { let invite = new RegExp(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g); - let username = guild.user.username; - let user = guild.user; + let username = member.user.username; + let user = member.user; if (username.match(invite)) { username = username.replace(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g, '[REDACTED]'); user = username; } - welcomeMessage = welcomeMessage.replace(/\[member\]/, username); - welcomeMessage = welcomeMessage.replace(/\[memberPing\]/, user); - welcomeMessage = welcomeMessage.replace(/\[server\]/, guild.guild.name); - + welcomeMessage = welcomeMessage.replace(/\[member\]/g, username); + welcomeMessage = welcomeMessage.replace(/\[memberPing\]/g, user); + welcomeMessage = welcomeMessage.replace(/\[server\]/g, member.guild.name); + + // add attachment let attach; if (welcomeMessage.includes('[attach:')) { attach = welcomeMessage.split(/(\[attach:.*?])/); diff --git a/event/listeners/guildMemberRemove.js b/event/listeners/guildMemberRemove.js index 967f18e..e798a5a 100644 --- a/event/listeners/guildMemberRemove.js +++ b/event/listeners/guildMemberRemove.js @@ -10,8 +10,8 @@ class guildMemberRemoveListener extends Listener { }); } - async exec(guild) { - const leave = await leaveChannel.findOne({where: {guildID: guild.guild.id}}); + async exec(member) { + const leave = await leaveChannel.findOne({where: {guildID: member.guild.id}}); if (leave) { const channel = this.client.channels.resolve(leave.get('channelID')); @@ -19,8 +19,8 @@ class guildMemberRemoveListener extends Listener { let invite = new RegExp(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g); - let username = guild.user.username; - let user = guild.user; + let username = member.user.username; + let user = member.user; if (username.match(invite)) { username = username.replace(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g, '[REDACTED]'); user = username; @@ -28,7 +28,7 @@ class guildMemberRemoveListener extends Listener { byeMessage = byeMessage.replace(/\[member\]/, username); byeMessage = byeMessage.replace(/\[memberPing\]/, user); - byeMessage = byeMessage.replace(/\[server\]/, guild.guild.name); + byeMessage = byeMessage.replace(/\[server\]/, member.guild.name); let attach; if (byeMessage.includes('[attach:')) { diff --git a/event/listeners/message.js b/event/listeners/message.js index d4b8896..da591d9 100644 --- a/event/listeners/message.js +++ b/event/listeners/message.js @@ -6,6 +6,7 @@ const autoResponse = require('../../models').autoresponse; const autoResponseStat = require('../../models').autoresponseStat; const BannedWords = require('../../models').bannedWords; const WhitelistWord = require('../../models').whitelistWord; +const quotationStat = require('../../models').quotationStat; class messageListener extends Listener { constructor() { @@ -25,6 +26,11 @@ class messageListener extends Listener { if (message.author.bot) return; + /* Banned words section + * + * This section contains code about the banned words features + * + */ // Banned words const bannedWords = await BannedWords.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content.replace(/\u200B/g, '').replace(/[\u0250-\ue007]/g, '')), Sequelize.Op.ne, 0), serverID: message.guild.id}}); @@ -55,8 +61,14 @@ class messageListener extends Listener { return message.delete({reason: `Deleted message: ${message.content}`}); } else { + /* Autoresponse feature & tag + * + * This section contains autoresponse and tag feature + * + */ + // auto responses - const autoresponseStat = await autoResponseStat.findOne({where: {serverID: message.guild.id}}); + const autoresponseStat = await autoResponseStat.findOne({where: {serverID: message.guild.id, stat: 'enable'}}); if (autoresponseStat) { // Infinit haha very yes if (message.content.toLowerCase().startsWith('haha very') && message.content.toLowerCase().endsWith('yes')) { @@ -68,28 +80,25 @@ class messageListener extends Listener { return message.channel.send('haha very yes'); } - // If autoresponse is enable send the response - if (autoresponseStat.get('stat') == 'enable' && autoresponseStat.get('serverID') == message.guild.id) { // Reply with images as attachement - const autoresponse = await autoResponse.findOne({where: {trigger: message.content.toLowerCase()}}); + const autoresponse = await autoResponse.findOne({where: {trigger: message.content.toLowerCase()}}); - if (autoresponse) { - autoResponse.findOne({where: {trigger: message.content.toLowerCase()}}); - let trigger = autoresponse.get('trigger'); - let type = autoresponse.get('type'); - let content = autoresponse.get('response'); + if (autoresponse) { + autoResponse.findOne({where: {trigger: message.content.toLowerCase()}}); + let trigger = autoresponse.get('trigger'); + let type = autoresponse.get('type'); + let content = autoresponse.get('response'); - if (trigger == message.content.toLowerCase() && type == 'text') { - return message.channel.send(content); - } else if (trigger == message.content.toLowerCase() && type == 'react') { - return message.react(content); - } else if (trigger == message.content.toLowerCase() && type == 'image') { - return message.channel.send({files: [content]}); - } + if (trigger == message.content.toLowerCase() && type == 'text') { + return message.channel.send(content); + } else if (trigger == message.content.toLowerCase() && type == 'react') { + return message.react(content); + } else if (trigger == message.content.toLowerCase() && type == 'image') { + return message.channel.send({files: [content]}); } - } } + // User autoresponse const tag = await Tag.findOne({where: {trigger: message.content.toLowerCase(), serverID: message.guild.id}}); if (tag) { @@ -222,6 +231,51 @@ class messageListener extends Listener { } } + + /* Quotation feature + * + * This section will contain the code for the quotation feature, it will detect link for it and send it as embed + * + */ + const quotationstat = await quotationStat.findOne({where: {serverID: message.guild.id, stat: 'enable'}}); + + if (quotationstat && message.content.includes('discordapp.com/channels/')) { + let url = message.content.split('/'); + let guildID = url[4]; + let channelID = url[5]; + let messageID = url[6]; + + + // Verify if the guild, channel and message exist + let guild = this.client.guilds.resolve(guildID); + if (!guild) return; + let channel = this.client.channels.resolve(channelID); + if (!channel) return; + let quote = await channel.messages.fetch(messageID) + .catch(() => { + return; + }); + if (!quote) return; + + let Embed = this.client.util.embed() + .setAuthor(quote.author.username, quote.author.displayAvatarURL()) + .addField('Jump to', `[message](https://discordapp.com/channels/${message.guild.id}/${channelID}/${messageID})`, true) + .addField('In channel', quote.channel.name, true) + .addField('Quoted by', message.author, true) + .setDescription(quote.content) + .setTimestamp(quote.createdTimestamp); + + if (quote.member) Embed.setColor(quote.member.displayHexColor); + + if (guild.id != message.guild.id) Embed.addField('In guild', guild.name, true); + let Attachment = (quote.attachments).array(); + if (Attachment[0]) Embed.setImage(Attachment[0].url); + + return message.channel.send(Embed) + .then(() => { + message.delete(); + }); + } } } } diff --git a/migrations/20200305204757-create-quotation-stat.js b/migrations/20200305204757-create-quotation-stat.js new file mode 100644 index 0000000..481bdf6 --- /dev/null +++ b/migrations/20200305204757-create-quotation-stat.js @@ -0,0 +1,30 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('quotationStats', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + serverID: { + type: Sequelize.BIGINT + }, + stat: { + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('quotationStats'); + } +}; \ No newline at end of file diff --git a/models/quotationstat.js b/models/quotationstat.js new file mode 100644 index 0000000..3314816 --- /dev/null +++ b/models/quotationstat.js @@ -0,0 +1,11 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const quotationStat = sequelize.define('quotationStat', { + serverID: DataTypes.BIGINT, + stat: DataTypes.STRING + }, {}); + quotationStat.associate = function(models) { + // associations can be defined here + }; + return quotationStat; +}; \ No newline at end of file