// Global Discord // custom command const SequelizeGlobal = new Sequelize('Global', 'user', 'password', { host: 'localhost', dialect: 'sqlite', logging: false, operatorsAliases: false, // SQLite only storage: './database/.Global.sqlite' }) const Global = SequelizeGlobal.define('global', { name: Sequelize.STRING, description: Sequelize.TEXT, username: Sequelize.STRING, usage_count: { type: Sequelize.INTEGER, defaultValue: 0, allowNull: false }, guildname: Sequelize.STRING, guildid: Sequelize.STRING }) Global.sync() client.on('message', async msg => { if (msg.author.bot) return if (!msg.content.startsWith(GlobalPrefix)) return const input = msg.content.slice(GlobalPrefix.length).split(' ') const command = input.shift() const commandArgs = input.join(' ') if (command === 'ac') { if (!msg.member.hasPermission('ADMINISTRATOR')) { return msg.channel.send('You do not have permission to add commands.') } const splitArgs = commandArgs.split(' ') const tagName = splitArgs.shift() const tagDescription = splitArgs.join(' ') if (!tagName) { return msg.channel.send('Specify a new command.') } if (!tagDescription) { return msg.channel.send('Specify the answer.') } const tag = await Global.findOne({ where: { name: tagName, guildid: msg.guild.id } }) if (tag) { return msg.channel.send(`The сommand '${tagName}' is already there.`) } const tag2 = await Global.create({ name: tagName, description: tagDescription, username: msg.author.username, guildname: msg.guild.name, guildid: msg.guild.id }) return msg.channel.send(`The command '${tag2.name}' has been added.`) } else if (command === 'ec') { if (!msg.member.hasPermission('ADMINISTRATOR')) { return msg.channel.send('You do not have permission to change commands.') } const splitArgs = commandArgs.split(' ') const tagName = splitArgs.shift() const tagDescription = splitArgs.join(' ') if (!tagName) { return msg.channel.send('Specify the command.') } if (!tagDescription) { return msg.channel.send('Specify a new answer.') } const affectedRows = await Global.update({ description: tagDescription }, { where: { name: tagName, guildid: msg.guild.id } }) if (affectedRows > 0) { return msg.channel.send(`The command '${tagName}' has been changed.`) } return msg.channel.send(`Could not find the '${tagName}' command.`) } else if (command === 'ic') { if (!msg.member.hasPermission('ADMINISTRATOR')) { return msg.channel.send('You do not have permission to view command information.') } const tagName = commandArgs if (!tagName) { return msg.channel.send('Specify the command.') } const tag = await Global.findOne({ where: { name: tagName, guildid: msg.guild.id } }) if (tag) { return msg.channel.send(`Command: ${tagName}\nAuthor: ${tag.username}\nUsage: ${tag.usage_count}\nGuild: ${tag.guildname}`) } return msg.channel.send(`Could not find the '${tagName}' command.`) } else if (command === 'lc') { const tagList = await Global.findAll({ attributes: [ 'name' ], where: { guildid: msg.guild.id } }) if (tagList) { const tagString = tagList.map(t => t.name).join(', ').sort() || 'No commands added' return msg.channel.send(`${tagString}.`) } } else if (command === 'rc') { if (!msg.member.hasPermission('ADMINISTRATOR')) { return msg.channel.send('You do not have permission to delete commands.') } const tagName = commandArgs const rowCount = await Global.destroy({ where: { name: tagName, guildid: msg.guild.id } }) if (!tagName) { return msg.channel.send('Specify the command.') } if (!rowCount) return msg.channel.send(`The command '${tagName}' does not exist.`) return msg.channel.send(`The command '${tagName}' has been deleted.`) } else if (command) { const tagName = command const tag = await Global.findOne({ where: { name: tagName, guildid: msg.guild.id } }) if (tag) { tag.increment('usage_count') return msg.channel.send(tag.get('description')) } } })