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
+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'