80 lines
2.6 KiB
JavaScript
80 lines
2.6 KiB
JavaScript
const Revolt = require('revolt.js');
|
|
const { client, logger, config, db } = require('..');
|
|
const getUser = require('../util/get_user');
|
|
|
|
module.exports.meta = {
|
|
name: 'blacklist',
|
|
aliases: [ 'block' ],
|
|
description: 'Blacklist or unblacklist users.',
|
|
devLevel: 1
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param { Revolt.Message } message
|
|
* @param { string[] } args
|
|
*/
|
|
module.exports.run = async (message, args) => new Promise(async (resolve, reject) => {
|
|
if (!args[0]) return client.channels.sendMessage(message.channel, ':x: No user specified');
|
|
let user = await getUser(args.shift());
|
|
if (!user) return client.channels.sendMessage(message.channel, ':x: User not found');
|
|
|
|
let blacklistStatus = db.blacklist.get(user._id);
|
|
if (!blacklistStatus) blacklistStatus = {
|
|
blacklisted: false,
|
|
silent: false,
|
|
nextWarning: Date.now() - 1,
|
|
lastBlacklistedBy: null
|
|
}
|
|
|
|
let removeFriend = () => client.users.removeFriend(user._id)
|
|
.catch(reject);
|
|
|
|
let block = () => client.users.blockUser(user._id)
|
|
.catch(reject);
|
|
|
|
let unblock = () => client.users.unblockUser(user._id)
|
|
.catch(reject);
|
|
|
|
if (args[0]) {
|
|
switch (args[0]?.toLowerCase()) {
|
|
case 'yes':
|
|
case 'true':
|
|
case 'on':
|
|
case 'normal':
|
|
blacklistStatus.blacklisted = true;
|
|
blacklistStatus.silent = false;
|
|
blacklistStatus.lastBlacklistedBy = message.author;
|
|
await removeFriend();
|
|
await block();
|
|
break;
|
|
|
|
case 'no':
|
|
case 'false':
|
|
case 'off':
|
|
blacklistStatus.blacklisted = false;
|
|
blacklistStatus.silent = false;
|
|
await unblock();
|
|
break;
|
|
|
|
case 'silent':
|
|
blacklistStatus.blacklisted = true;
|
|
blacklistStatus.silent = true;
|
|
blacklistStatus.lastBlacklistedBy = message.author;
|
|
await removeFriend();
|
|
await block();
|
|
break;
|
|
|
|
default:
|
|
return client.channels.sendMessage(message.channel, `Unknown argument, must be either \`true\`, \`false\` or \`silent\``);
|
|
}
|
|
}
|
|
|
|
await client.channels.sendMessage(message.channel,
|
|
`>##${args[0] ? ' Blacklist updated:' : ''} <@${user._id}>\n>\u200b\n` +
|
|
`>Blacklisted: \`${blacklistStatus.blacklisted}\`\n` +
|
|
`>Silent: \`${blacklistStatus.silent}\`\n` +
|
|
`>Last blacklisted by: ${blacklistStatus.lastBlacklistedBy != null ? `<@${blacklistStatus.lastBlacklistedBy}>` : '`None`'}`);
|
|
|
|
db.blacklist.set(user._id, blacklistStatus);
|
|
}); |