You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Luno/commands/social/afk.js

45 lines
2.4 KiB

4 years ago
const Discord = require('discord.js');
const mongoose = require('mongoose');
const Status = require('../../models/status');
const UserData = require('../../models/user');
module.exports = {
name: "afk",
aliases: ['setafk'],
help: new Discord.MessageEmbed()
.setTitle("Help -> AFK")
.setDescription("Set your status within the bot as AFK and specify a reason. Then, when other people ping you, I can let them know that you're not available!")
.addField("Syntax", "`afk [clearMode] <reason>`")
.addField("Notice","Your status clear mode can be set to either 'auto' or 'manual'. If not specified, it will clear next time you send a message (auto)."),
meta: {
category: 'Social',
description: "Tell others that you're AFK so that they'll be notified when you ping them.",
syntax: '`afk [clearMode] <reason>`',
extra: null
},
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}afk [clearMode] <reason>\``);}
let tu = await UserData.findOne({uid: message.author.id})
? await UserData.findOne({uid: message.author.id})
: new UserData({uid: message.author.id});
if (['m', 'manual', 'a', 'auto'].includes(args[0])) {
tu.statusclearmode = ['m', 'manual'].includes(args[0]) ? 'manual' : 'auto';
args.shift();
} else {tu.statusclearmode = 'auto';}
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}afk [clearMode] <reason>\``);}
let reason = args.join(" ");
if (reason.length > 150) {return message.reply("That status a bit long; keep it under 150 characters.");}
4 years ago
if (reason.match(/<@&\d+>|@everyone/gm)) {return message.reply("I won't ping any roles or @ everyone!");}
4 years ago
tu.statustype = 'afk';
tu.statusmsg = reason.trim();
tu.statussetat = new Date();
let tempDate = new Date();
tu.statusclearat = tempDate.setHours(tempDate.getHours() + 12);
tu.markModified("statussetat");
tu.markModified("statusclearat");
4 years ago
tu.save();
require('../../util/cachestatus')(message.author.id, tempDate.setHours(tempDate.getHours() + 12));
return message.reply(`I set your ${tu.statusclearmode === 'auto' ? 'automatically' : 'manually'}-clearing AFK message to: ${reason.trim()}`);
}
};