import { Command, CommandoMessage, CommandoClient } from 'discord.js-commando'; //@ts-ignore import emoji from 'emoji-random'; import { MessageEmbed } from 'discord.js'; import FanArt from '../../models/FanArt'; import mongo from 'mongoose'; import config from '../../config.json'; mongo.connect(config['mongodburi'], { useNewUrlParser: true, useUnifiedTopology: true }) module.exports = class ArtEmma extends Command { constructor(client: CommandoClient) { super(client, { name: 'art', aliases: ['artwork'], group: 'emma', memberName: 'art', description: 'Allows you to submit artwork to Emma\'s artwork channel.', args: [ { key: 'type', prompt: 'What type of interaction would you like to do?', type: 'string', default: 'submit' }, { key: 'comment', prompt: 'Would you like to leave a comment?', type: "string", default: '' } ], examples: [ 'uwu!art submit ', 'uwu!art set', 'uwu!art remove' ], throttling: { usages: 5, duration: 30 }, userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'] }); } //@ts-ignore not assignable bc async run(msg: CommandoMessage, { type, comment }: any) { const fanart = new FanArt({ _id: mongo.Types.ObjectId(), username: msg.author.username, userID: msg.author.id, guildname: msg.guild.name, guildID: msg.guild.id, channelname: msg.channel, channelID: msg.channel.id, time: msg.createdAt }) //let fanartServer = this.client.guilds.cache.get('663964105983393793'); //@ts-ignore if (msg.guild.id.toString() != '663964105983393793') return msg.reply(`You are not submitting from **Kat\'s Korner**! ${emoji.random()}`); if (type == 'submit') { FanArt.findOne({ guildID: msg.guild.id}, async (error, guild) => { if (error) return console.log(error); //@ts-ignore let fanartServer = this.client.guilds.cache.get(guild.guildID); //@ts-ignore let fanartChannel = guild.channelID; if (msg.attachments.size) { msg.attachments.forEach(fanart => { if (fanart.url) { //@ts-ignore return fanartServer?.channels.cache.get(fanartChannel)?.send(`**New fanart submitted!**\nFanart by <@${msg.author.id}>.\n\n**Comment**\n${comment ? comment : 'None'}\n\n**Video** ` + fanart.url).then(m => { msg.delete(); m.react('😍'); m.react('😂'); m.react('😁'); m.react('😳'); m.react('😱'); }) /* let emb = new MessageEmbed() .setDescription(`Fanart by <@${msg.author.id}>.`) .setTitle('New fanart submitted!') .setURL(fanart.url) .addField('Comment', `ok`, true) .setFooter('Do you want to submit and image or video? Do uwu!help art') fanartServer?.channels.cache.get('704032357640044556')?.send(emb); */ } else return msg.reply(`No attachment was submitted! If you need help, please do \`uwu!art help\`. ${emoji.random()}`); } ); } else { return msg.reply(`No attachment was submitted! If you need help, please do \`uwu!art help\`. ${emoji.random()}`); } }) } if (type == 'help') { // msg.guild.channels.cache.get("fanart")?.fetch().then(bool => console.log('get' + bool)) // msg.guild.channels.cache.find(c => c.name == 'fanart')?.fetch().then(bool => console.log(bool + 'ok')) /* msg.guild.channels.cache.find(c => c.name === 'fanart', (bool) => { if (!bool) { console.log('ok') msg.guild.channels.create('fanart', { type: 'text', reason: 'Initialize fanart channel. This is an automated action by the Uwufier bot.', nsfw: false }) console.log('made channel') } else { console.log('exists') } }) */ let emb = new MessageEmbed() .setTitle('Fanart - Help ' + emoji.random()) .setColor(0xFFCC4D) .setDescription(`How to submit fanart:`) //@ts-ignore .setThumbnail(msg.guild.iconURL()) .addFields([ { name: '#1', value: 'Go to the `#media` channel.' }, { name: '#2', value: 'Click on the add media button in the bottom left corner of your screen and select a video or image.' }, { name: '#3', value: 'In the message section, please put `uwu!art submit`.' }, { name: '#4 (Optional)', value: 'If you would like, you can also put a comment on your fanart, you can do this by adding an extra string to the end of your submit command. e.g. `uwu!art submit this is where the comment goes!`, if you followed the steps correctly, your comment should be `this is where the comment goes!` ' + emoji.random() }, { name: 'Admin Stuff', value: 'If you are an admin or moderator who would like to set/ remove a fanart channel, you can do this by going to to the channel you would like to set as the new fanart channel and doing `uwu!art set`, this will set the current channel as the fanart channel. To remove a fanart channel, just do `uwu!art remove`.' }, { name: 'More Admin Info', value: 'You can only have **ONE** fanart channel (I think, I haven\'t tested it lol. If you change the name of the fanart channel, you will have to re-register with the bot by simply removing and re-setting the fanart channel.' } ]) return msg.say(emb); } else if (type == 'set') { if (!msg.member.hasPermission('MANAGE_GUILD')) return msg.reply(`Insufficient permission! ${emoji.random()}`); FanArt.findOne({ guildID: msg.guild.id }, async (error, guild) => { if (error) return console.log(error); if (guild) { //@ts-ignore this exists return msg.reply(`There already is a welcome channel set! It's ${guild.channelname}! ` + emoji.random()).then(mnotif => { //@ts-ignore this exists mnotif.delete({ timeout: 2000 }) //@ts-ignore this exists msg.delete({ timeout: 2000 }) }) } else if (!guild) { await fanart.save() .then(result => console.log(result)) .catch(err => console.log(err)) return msg.reply(`The welcome channel has been set to ${msg.channel}! ${emoji.random()}`).then(mnotif => { //@ts-ignore this exists mnotif.delete({ timeout: 2000 }) //@ts-ignore this exists msg.delete({ timeout: 2000 }) }) } }) } else if (type == 'remove') { if (!msg.member.hasPermission('MANAGE_GUILD')) return msg.reply(`Insufficient permission! ${emoji.random()}`); FanArt.findOne({ guildID: msg.guild.id }, async (error, guild) => { if (error) return console.log(error); if (guild) { await FanArt.findOneAndDelete({ guildID: msg.guild.id }); return msg.say(`The current fanart channel has been unset! ${emoji.random()}`).then(mnotif => { //@ts-ignore mnotif.delete({ timeout: 2000 }); //@ts-ignore msg.delete({ timeout: 2000 }); }) } else if (!guild) { return msg.reply(`There is no current fanart channel set for this guild! ${emoji.random()}`).then(m => { //@ts-ignore m.delete({ timeout: 2000 }) //@ts-ignore msg.delete({ timeout: 2000 }) }) } }) } /* else { return msg.reply(`That is not a valid operation! ${emoji.random()}`); } */ } };