import { Command, CommandoMessage, CommandoClient } from 'discord.js-commando'; //@ts-ignore no @types import emoji from 'emoji-random'; import Darling from '../../models/darling.js'; import mongo from 'mongoose'; import config from '../../config.json'; mongo.connect(config['mongodburi'], { useNewUrlParser: true, useUnifiedTopology: true }) module.exports = class DarlingZeroTwo extends Command { constructor(client: CommandoClient) { super(client, { name: 'darling', group: 'zerotwo', memberName: 'darling', description: 'Allows you to set, change or delete uwufier\'s darling.', userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], examples: [ 'uwu!darling', 'uwu!darling set', 'uwu!darling remove' ], args: [ { key: 'darlingName', prompt: 'Who should the darling be?', type: 'string', default: '' } ], throttling: { usages: 5, duration: 30 }, guildOnly: true }); } //TODO: this //@ts-ignore this is not asnc async run(msg: CommandoMessage, { darlingName }: any) { // this is actually a string const darling = new Darling({ _id: mongo.Types.ObjectId(), username: msg.author.username, userID: msg.author.id, guildname: msg.guild.name, guildID: msg.guild.id, time: msg.createdAt }) // const guildExist = await Darling.findOne({ guildID: msg.guild.id }) Darling.findOne({ guildID: msg.guild.id }, async (error, guild) => { if (error) { return console.log(error) } else if (guild && darlingName == 'remove') { // @ts-ignore linting error shows that channelID doesnt exist when it does if (msg.author.id == guild.userID || msg.author.id == msg.guild.owner.id) { await Darling.findOneAndDelete({ guildID: msg.guild.id }) return msg.say('The current darling has been removed. ' + emoji.random()) } else { return msg.reply('Only my darling or the guild owner can remove the current darling. ' + emoji.random()) } } else if (!guild && darlingName == 'remove') { return msg.reply('There is no darling set in this server. ' + emoji.random()) } else if (guild && darlingName == 'set') { // @ts-ignore linting error shows that channelID doesnt exist when it does return msg.reply(`I already have a darling! It\'s <@${guild.userID}>! To set a new darling, either the current darling or the guild owner has to do \`uwu!darling remove\`. ` + emoji.random()) } else if (!guild && darlingName == 'set') { await darling.save() .then(result => console.log(result)) .catch(err => console.log(err)) const quotes = [ 'I think I have taken a liking to you. Won\'t you be my darling?', 'I like the look in your eyes. It makes my heart race. You are now my darling!', 'Wow, your taste makes my heart race. It bites and lingers... The taste of danger. You are now my darling!' ] let quoteNum = quotes[Math.floor(Math.random() * quotes.length)] return msg.reply(quoteNum) } else if (!guild) { return msg.reply('I haven\'t found my darling yet! To set one, do `uwu!darling set`. ' + emoji.random()) } else if (guild) { // @ts-ignore linting error shows that channelID doesnt exist when it does return msg.reply(`My darling is <@${guild.userID}>. ` + emoji.random()) } }) // if (guildExist && darlingName == 'remove') { // await Darling.findOneAndDelete({ guildID: msg.guild.id }) // msg.say('The current darling has been removed.') // } else if (!guildExist && darlingName == 'remove') { // msg.reply('There is no darling set in this server.') // } else if (darlingName || darlingName == 'set') { // await darling.save().then(result => console.log(result)).catch(err => console.log(err)) // var quoteNum = Math.floor((Math.random() * 3) + 1); // switch (quoteNum) { // case 1: var quoteResult = 'I think I have taken a liking to you. Won\'t you be my darling?'; break // case 2: var quoteResult = 'I like the look in your eyes. It makes my heart race. You are now my darling!'; break // case 3: var quoteResult = 'Wow, your taste makes my heart race. It bites and lingers... The taste of danger. You are now my darling!'; break // default: var quoteResult = 'I think I have taken a liking to you. Won\'t you be my darling?'; break // } // msg.reply(quoteResult) // } else if (!guildExist) { // msg.reply('I haven\'t found my darling yet!') // } else if (guildExist) { // await Darling.findOne({ userID: msg.author.id }, (err) => { // if (err) console.log(err) // }).then(res => { // msg.reply(`My darling is <@${res.userID}>`) // }) // //msg.reply(`My darling is <@${result.userID}>`) // } else { // console.error() // } } };