summaryrefslogtreecommitdiff
path: root/src/commands/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/server')
-rw-r--r--src/commands/server/goodbye.ts88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/commands/server/goodbye.ts b/src/commands/server/goodbye.ts
new file mode 100644
index 0000000..2300fe2
--- /dev/null
+++ b/src/commands/server/goodbye.ts
@@ -0,0 +1,88 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import emoji from 'emoji-random';
+import Goodbye from '../../models/goodbye.js';
+import mongo from 'mongoose';
+mongo.connect('mongodb://sin:[email protected]:47107/heroku_4qrjvmb9', { useNewUrlParser: true, useUnifiedTopology: true })
+
+module.exports = class GoodbyeServer extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'goodbye',
+ group: 'server',
+ memberName: 'goodbye',
+ description: 'Allows you to set, change or delete a server goodbye message.',
+ userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ examples: [
+ 'uwu!goodbye',
+ 'uwu!goodbye set',
+ 'uwu!goodbye remove'
+ ],
+ args: [
+ {
+ key: 'wType',
+ prompt: 'Would you like to set, remove or change the current goodbye channel?',
+ type: 'string',
+ default: ''
+ }
+ ],
+ throttling: {
+ usages: 5,
+ duration: 30
+ },
+ guildOnly: true
+ });
+ }
+ async run(msg: CommandoMessage, { wType }) {
+ const goodbye = new Goodbye({
+ _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
+ })
+ const guildExist = await Goodbye.findOne({ guildID: msg.guild.id })
+
+ if (msg.member.hasPermission('MANAGE_GUILD')) {
+ Goodbye.findOne({ guildID: msg.guild.id }, async (error, guild) => {
+ if (error) {
+ console.log(error)
+ } else if (guild && wType == 'remove') {
+ await Goodbye.findOneAndDelete({ guildID: msg.guild.id })
+ msg.say('The current goodbye channel has been unset! ' + emoji.random()).then(mnotif => {
+ mnotif.delete({ timeout: 2000 })
+ msg.delete({ timeout: 2000 })
+ })
+ } else if (!guild && wType == 'remove') {
+ msg.reply('There is no current goodbye channel set for this guild! ' + emoji.random()).then(mnotif => {
+ mnotif.delete({ timeout: 2000 })
+ msg.delete({ timeout: 2000 })
+ })
+ } else if (guild && wType == 'set') {
+ msg.reply(`There already is a goodbye channel set! It's ${guild.channelname}! ` + emoji.random()).then(mnotif => {
+ mnotif.delete({ timeout: 2000 })
+ msg.delete({ timeout: 2000 })
+ })
+ } else if (!guild && wType == 'set') {
+ await goodbye.save()
+ .then(result => console.log(result))
+ .catch(err => console.log(err))
+
+ msg.reply(`The goodbye channel has been set to ${msg.channel}! ` + emoji.random()).then(mnotif => {
+ mnotif.delete({ timeout: 2000 })
+ msg.delete({ timeout: 2000 })
+ })
+ } else if (!guild) {
+ msg.reply('There is no current goodbye channel set for this guild! To set one, do `uwu!goodbye set` in the channel you want to set it in. ' + emoji.random())
+ } else if (guild) {
+ msg.reply(`The current goodbye channel is ${guild.channelname}. ` + emoji.random())
+ }
+ })
+ } else {
+ msg.reply('Insufficent permissions! ' + emoji.random())
+ }
+ }
+}; \ No newline at end of file