Allow/Disallow Cleverbot

This commit is contained in:
Dragon Fire
2021-05-18 16:37:16 -04:00
parent d7be838434
commit 08235698e3
10 changed files with 110 additions and 3 deletions
+1
View File
@@ -16,6 +16,7 @@ config.json
command-leaderboard.json
command-last-run.json
blacklist.json
cleverbot.json
# Tensorflow Models
tf_models/
+12
View File
@@ -121,6 +121,18 @@ client.on('ready', async () => {
}
}, 1.8e+6);
// Import Cleverbot users
try {
const results = client.importCleverbotAllowed();
if (results) {
client.logger.info('[CLEVERBOT] cleverbot.json successfully loaded.');
} else {
client.logger.error('[CLEVERBOT] cleverbot.json is not formatted correctly.');
}
} catch (err) {
client.logger.error(`[CLEVERBOT] Could not parse cleverbot.json:\n${err.stack}`);
}
// Import blacklist
try {
const results = client.importBlacklist();
+3
View File
@@ -12,6 +12,9 @@ module.exports = class CleverbotEndCommand extends Command {
}
run(msg) {
if (!this.client.isOwner(msg.author) && !this.client.allowedUsers.includes(msg.author.id)) {
return msg.say('You are not currently allowed to use Cleverbot.');
}
const cleverbot = this.client.cleverbots.get(msg.channel.id);
if (!cleverbot) return msg.say('There is not a Cleverbot conversation in this channel.');
clearTimeout(cleverbot.timeout);
+3
View File
@@ -22,6 +22,9 @@ module.exports = class CleverbotCommand extends Command {
}
run(msg) {
if (!this.client.isOwner(msg.author) && !this.client.allowedUsers.includes(msg.author.id)) {
return msg.say('You are not currently allowed to use Cleverbot.');
}
if (this.client.cleverbots.has(msg.channel.id)) {
return msg.say('There is already a Cleverbot conversation in this channel.');
}
+30
View File
@@ -0,0 +1,30 @@
const Command = require('../../structures/Command');
module.exports = class AllowCleverbotCommand extends Command {
constructor(client) {
super(client, {
name: 'allow-cleverbot',
aliases: ['allow-clevs'],
group: 'util',
memberName: 'allow-cleverbot',
description: 'Allows a user to use Cleverbot.',
details: 'Only the bot owner(s) may use this command.',
ownerOnly: true,
guarded: true,
args: [
{
key: 'target',
prompt: 'Who do you want to allow? Use the ID.',
type: 'string'
}
]
});
}
async run(msg, { target }) {
if (this.client.allowedUsers.includes(target)) return msg.say(`🧠 \`${target}\` is already allowed.`);
this.client.allowedUsers.push(target);
this.client.exportCleverbotAllowed();
return msg.say(`🧠 Allowed \`${target}\` to use Cleverbot.`);
}
};
+1 -1
View File
@@ -22,7 +22,7 @@ module.exports = class BlacklistCommand extends Command {
},
{
key: 'target',
prompt: 'What do you want to blacklist? Use the ID.',
prompt: 'Who do you want to blacklist? Use the ID.',
type: 'string'
}
]
+31
View File
@@ -0,0 +1,31 @@
const Command = require('../../structures/Command');
const { removeFromArray } = require('../../util/Util');
module.exports = class DisallowCleverbotCommand extends Command {
constructor(client) {
super(client, {
name: 'disallow-cleverbot',
aliases: ['disallow-clevs'],
group: 'util',
memberName: 'disallow-cleverbot',
description: 'Disallows a user from using Cleverbot.',
details: 'Only the bot owner(s) may use this command.',
ownerOnly: true,
guarded: true,
args: [
{
key: 'target',
prompt: 'Who do you want to disallow? Use the ID.',
type: 'string'
}
]
});
}
async run(msg, { target }) {
if (!this.client.allowedUsers.includes(target)) return msg.say(`🧠 \`${target}\` is not allowed.`);
removeFromArray(this.client.allowedUsers, target);
this.client.exportCleverbotAllowed();
return msg.say(`🧠 Disallowed \`${target}\` from using Cleverbot.`);
}
};
+1 -1
View File
@@ -23,7 +23,7 @@ module.exports = class UnblacklistCommand extends Command {
},
{
key: 'target',
prompt: 'What do you want to unblacklist? Use the ID.',
prompt: 'Who do you want to unblacklist? Use the ID.',
type: 'string'
}
]
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "140.0.0",
"version": "140.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"private": true,
+27
View File
@@ -49,6 +49,7 @@ module.exports = class XiaoClient extends CommandoClient {
this.games = new Collection();
this.dispatchers = new Map();
this.cleverbots = new Map();
this.allowedUsers = [];
this.phone = new PhoneManager(this);
this.activities = activities;
this.leaveMessages = leaveMsgs;
@@ -194,6 +195,32 @@ module.exports = class XiaoClient extends CommandoClient {
return buf;
}
importCleverbotAllowed() {
const read = fs.readFileSync(path.join(__dirname, '..', 'cleverbot.json'), { encoding: 'utf8' });
const file = JSON.parse(read);
if (!Array.isArray(file)) return null;
for (const id of file) {
if (typeof id !== 'string') continue;
if (this.allowedUsers.includes(id)) continue;
this.allowedUsers.push(id);
}
return file;
}
exportCleverbotAllowed() {
let text = '[\n ';
if (this.allowedUsers.length) {
for (const id of this.allowedUsers.guild) {
text += `"${id}",\n `;
}
text = text.slice(0, -3);
}
text += '\n]\n';
const buf = Buffer.from(text);
fs.writeFileSync(path.join(__dirname, '..', 'cleverbot.json'), buf, { encoding: 'utf8' });
return buf;
}
importCommandLeaderboard(add = false) {
const read = fs.readFileSync(path.join(__dirname, '..', 'command-leaderboard.json'), {
encoding: 'utf8'