Add ARs and decide.js and patch bugs

master
Kit Kasune 4 years ago
parent a459a39a2e
commit 8ba49a228b
  1. 3
      bot.js
  2. 6
      commands/eval.js
  3. 13
      commands/reload.js
  4. 29
      commands/warn.js
  5. 5
      events/message.js
  6. 16
      handle/response.js
  7. 22
      models/mod.js
  8. 29
      responses/decide.js

@ -10,7 +10,8 @@ async function init() {
client.config = auth; client.config = auth;
['commands', 'aliases'].forEach(x => client[x] = new Discord.Collection()); ['commands', 'aliases'].forEach(x => client[x] = new Discord.Collection());
['command', 'event'].forEach(x => require(`./handle/${x}`)(client)); client.responses = {triggers: [], commands: new Discord.Collection()};
['command', 'event', 'response'].forEach(x => require(`./handle/${x}`)(client));
client.developers = ["330547934951112705", "673477059904929802"]; client.developers = ["330547934951112705", "673477059904929802"];

@ -13,18 +13,18 @@ module.exports = {
const result = new Promise((resolve) => resolve(eval(args.join(' ')))); const result = new Promise((resolve) => resolve(eval(args.join(' '))));
return result.then((output) => { return result.then((output) => {
if (typeof output !== 'string') { if (typeof output !== 'string') {
output = require('util').inspect(output, { depth: 0 }); output = require('util').inspect(output, {depth: 0});
} }
output = output.replace(client.config.token, 'Client Token') output = output.replace(client.config.token, 'Client Token')
.replace(client.config.database.password, 'Database Password') .replace(client.config.database.password, 'Database Password')
.replace(client.config.database.cluster, 'Database Cluster') .replace(client.config.database.cluster, 'Database Cluster');
return message.channel.send(new Discord.MessageEmbed() return message.channel.send(new Discord.MessageEmbed()
.setTitle('Client Evaluation') .setTitle('Client Evaluation')
.setDescription(`\`\`\`js\n${output}\n\`\`\``) .setDescription(`\`\`\`js\n${output}\n\`\`\``)
.setColor('c375f0') .setColor('c375f0')
.setFooter(`Natsuki`, client.user.avatarURL()) .setFooter(`Natsuki`, client.user.avatarURL())
.setTimestamp()) .setTimestamp());
}).catch(error => {return message.channel.send(`Error: \`${error}\`.`);}); }).catch(error => {return message.channel.send(`Error: \`${error}\`.`);});
} catch (error) { } catch (error) {
let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6);

@ -39,13 +39,24 @@ module.exports = {
} }
console.log(`${chalk.gray('[LOG]')} >> ${chalk.blue('Loaded all Events')}`); console.log(`${chalk.gray('[LOG]')} >> ${chalk.blue('Loaded all Events')}`);
var responses = fs.readdirSync('./responses').filter(file => file.endsWith('.js'));
client.responses.triggers = [];
for (let responsef of responses) {
if (Object.keys(require.cache).includes(require.resolve(`../responses/${responsef}`))) {delete require.cache[require.resolve(`../responses/${responsef}`)];}
var response = require(`../responses/${responsef}`);
client.responses.triggers.push([response.name, response.condition]);
client.responses.commands.set(response.name, response);
}
console.log(`${chalk.gray('[LOG]')} >> ${chalk.blue('Loaded all Responses')}`);
console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`Client refresh successful`)}\n`); console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`Client refresh successful`)}\n`);
return message.channel.send("Done!") return message.channel.send("Done!")
} }
if (['l', 'log', 'ns', 'nosilent', 'notsilent'].includes(args[0].toLowerCase())) { if (['l', 'log', 'ns', 'nosilent', 'notsilent'].includes(args[0].toLowerCase())) {
['commands', 'aliases'].forEach(x => client[x] = new Discord.Collection()); ['commands', 'aliases'].forEach(x => client[x] = new Discord.Collection());
['command', 'event'].forEach(x => require(`../handle/${x}`)(client)); client.responses = {triggers: [], commands: new Discord.Collection()};
['command', 'event', 'response'].forEach(x => require(`./${x}`)(client));
return message.channel.send("Done!"); return message.channel.send("Done!");
} }
else {return message.channel.send("Oi! 'log' is the only valid arg to use. Use no args if you want a cleaner console output instead.");} else {return message.channel.send("Oi! 'log' is the only valid arg to use. Use no args if you want a cleaner console output instead.");}

@ -24,21 +24,20 @@ module.exports = {
if (['check', 'c', 'list', 'l'].includes(args[0].toLowerCase())) { if (['check', 'c', 'list', 'l'].includes(args[0].toLowerCase())) {
user = user ? user : message.member; user = user ? user : message.member;
let mh = await Mod.findOne({gid: message.guild.id}); let mh = await Mod.findOne({gid: message.guild.id});
if (!mh || !mh.warnings.size) {return message.reply("There are no warnings available in this server.");} if (!mh || !Object.keys(mh.warnings).length) {return message.reply("There are no warnings available in this server.");}
if (!mh.warnings.has(user.id) || !mh.warnings.get(user.id).length) {return message.reply(`${user.id === message.author.id ? 'You have' : 'That user has'} never been warned in this server.`);} if (!mh.warnings[user.id] || !mh.warnings[user.id].length) {return message.reply(`${user.id === message.author.id ? 'You have' : 'That user has'} never been warned in this server.`);}
console.log(mh.cases, mh.warnings); //console.log(mh.cases, mh.warnings);
let ws = ''; let ws = '';
let cwc = 0; let cwc = 0;
let warning; for (warning of mh.warnings.get(user.id)) { let warning; for (warning of mh.warnings[user.id]) {
let tcase = mh.cases.get(`${warning}`); let tcase = mh.cases[warning - 1];
console.log(tcase.status, warning);
if (tcase.status !== "Cleared") { if (tcase.status !== "Cleared") {
ws += `\`Case #${warning}\` - Issued by <@${tcase.moderators[0]}>\n${tcase.reason}\n\n`; ws += `\`Case #${warning}\` - Issued by <@${tcase.moderators[0]}>\n${tcase.reason}\n\n`;
} else {cwc++;} } else {cwc++;}
} }
if (cwc > 0) {ws += '*Plus ' + cwc + ' other warnings that have been cleared.*';} if (cwc > 0) {ws += '*Plus ' + cwc + ' other warnings that have been cleared.*';}
if (cwc === mh.warnings.get(user.id).length) {return message.reply("That user has no uncleared warnings.");} if (cwc === mh.warnings[user.id].length) {return message.reply("That user has no uncleared warnings.");}
return message.channel.send(new Discord.MessageEmbed() return message.channel.send(new Discord.MessageEmbed()
.setTitle("User Warnings") .setTitle("User Warnings")
.setThumbnail(client.users.cache.get(user.id).avatarURL({size: 1024})) .setThumbnail(client.users.cache.get(user.id).avatarURL({size: 1024}))
@ -97,7 +96,7 @@ module.exports = {
let mh = await Mod.findOne({gid: message.guild.id}) || new Mod({gid: message.guild.id}); let mh = await Mod.findOne({gid: message.guild.id}) || new Mod({gid: message.guild.id});
let mhcases = mh.cases; let mhcases = mh.cases;
mhcases.set(`${mh.cases.size + 1}`, { mhcases.push({
members: [user.id], members: [user.id],
punishment: "Warned", punishment: "Warned",
reason: reason, reason: reason,
@ -109,14 +108,20 @@ module.exports = {
}); });
let mhwarnings = mh.warnings; let mhwarnings = mh.warnings;
let mhwarningsk = Object.keys(mhwarnings);
console.log(mhwarnings); console.log(mhwarnings);
console.log(mhcases.size);
if (mhwarnings.has(user.id)) {var uw = mhwarnings.get(user.id); uw[mhcases.size - 1] = mhcases.size;} if (mhwarningsk.includes(user.id)) {let tw = mhwarnings[user.id]; tw.push(mhcases.length); mhwarnings[user.id] = tw;}
mhwarnings.set(user.id, mhwarnings.has(user.id) ? uw : [mhcases.size]); else {mhwarnings[user.id] = [mhcases.length];}
console.log(mhwarnings);
mh.warnings = mhwarnings; mh.warnings = mhwarnings;
mh.warnings[user.id] = mhwarnings[user.id];
mh.cases = mhcases; mh.cases = mhcases;
if (!options.silent) {message.channel.send(`Case ${mh.cases.size} - Member has been warned. Reason: \`${reason}\``);} if (!options.silent) {message.channel.send(`Case ${mh.cases.length} - Member has been warned. Reason: \`${reason}\``);}
if (!options.silent && !options.nodm) {client.users.cache.get(user.id).send(`\`${message.author.username}\` has warned you in \`${message.guild.name}\`. Reason: **${reason}**`);} if (!options.silent && !options.nodm) {client.users.cache.get(user.id).send(`\`${message.author.username}\` has warned you in \`${message.guild.name}\`. Reason: **${reason}**`);}
mh.save(); mh.save();

@ -49,13 +49,14 @@ module.exports = async (client, message) => {
try { try {
if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) { if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) {
let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd)); let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));
if (!command) {return;} if (!command) {let trigger; for (trigger of client.responses.triggers) {if (await trigger[1](message, msg, args, cmd, prefix, mention, client)) {await client.responses.commands.get(trigger[0]).execute(message, msg, args, cmd, prefix, mention, client); break;}} return;}
message.channel.startTyping(); message.channel.startTyping();
await wait(800); await wait(800);
message.channel.stopTyping(); message.channel.stopTyping();
require('../util/oncommand')(message, msg, args, cmd, prefix, mention, client); require('../util/oncommand')(message, msg, args, cmd, prefix, mention, client);
command.execute(message, msg, args, cmd, prefix, mention, client); return command.execute(message, msg, args, cmd, prefix, mention, client);
} }
let trigger; for (trigger of client.responses.triggers) {if (await trigger[1](message, msg, args, cmd, prefix, mention, client)) {await client.responses.commands.get(trigger[0]).execute(message, msg, args, cmd, prefix, mention, client); break;}}
} catch (e) { } catch (e) {
var date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); var date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6);
console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | In ${message.guild.name}\n`)}`, e); console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | In ${message.guild.name}\n`)}`, e);

@ -0,0 +1,16 @@
const Discord = require('discord.js');
const fs = require('fs');
const chalk = require('chalk');
module.exports = client => {
var responses = fs.readdirSync('./responses').filter(file => file.endsWith('.js'));
console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Responses...')}\n`);
for (let responsef of responses) {
if (Object.keys(require.cache).includes(require.resolve(`../responses/${responsef}`))) {delete require.cache[require.resolve(`../responses/${responsef}`)];}
var response = require(`../responses/${responsef}`);
client.responses.triggers.push([response.name, response.condition]);
client.responses.commands.set(response.name, response);
console.log(`${chalk.gray('[LOG] ')} >> ${chalk.blueBright('Loaded Response')} ${chalk.white(response.name)}`);
}
console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Loaded all Responses')}`);
};

@ -2,10 +2,24 @@ const mongoose = require('mongoose');
const ModModel = new mongoose.Schema({ const ModModel = new mongoose.Schema({
gid: {type: String, unique: true}, gid: {type: String, unique: true},
cases: {type: Map, default: new Map()}, cases: {type: [{
rules: {type: Map, default: new Map()}, members: [String],
auto: {type: Map, default: new Map()}, punishment: String,
warnings: {type: Map, default: new Map()}, reason: String,
status: String,
moderators: [String],
notes: [String],
history: [String],
issued: Date
}], default: []},
rules: {type: [{
name: String,
description: String,
punishment: String,
automod: String
}], default: []},
auto: {type: Object, default: {}},
warnings: {type: Object, default: {}},
maxWarnings: {type: Number, default: 0}, maxWarnings: {type: Number, default: 0},
onMaxWarn: {type: String, default: 'kick'} onMaxWarn: {type: String, default: 'kick'}
}); });

@ -0,0 +1,29 @@
const Discord = require('discord.js');
module.exports = {
name: "decide",
meta: {
category: "",
perms: "",
staff: false,
vip: "",
serverPerms: [],
writtenBy: "",
serverOnly: false
},
tags: [],
help: new Discord.MessageEmbed()
.setTitle("Help -> ")
.setDescription("")
.addField("Syntax", "``"),
async condition (message, msg, args, cmd, prefix, mention, client) {return msg.split(/\s+/gm).length > 3 && (msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`));},
async execute(message, msg, args, cmd, prefix, mention, client) {
let e = message.content.split(/\s+/g); e.shift();
let options = e.join(" ").split(/(?:(?:\s+)[oO][rR] [sS][hH][oO][uU][lL][dD] [iI](?:\s+)|,(?:\s*)[oO][rR] [sS][hH][oO][uU][lL][dD] [iI](?:\s+)|(?:\s+)[oO][rR] [dD][oO] [iI](?:\s+)|,(?:\s*)[dD][oO] [iI](?:\s+)|,(?:\s*)[sS][hH][oO][uU][lL][dD] [iI](?:\s+)|,(?:\s*)[oO][rR] [dD][oO] [iI](?:\s+)|,(?:\s*)[oO][rR](?:\s+)|(?:\s+)[oO][rR](?:\s+)|,(?:\s*))/gm);
//console.log(e, options);
if (options.length < 2) {return;}
let cleanups = ['should i ', 'do i '];
let option; for (option of options) {let c; for (c of cleanups) {if (option.trim().toLowerCase().startsWith(c)) {options[options.indexOf(option)] = option.trim().slice(c.length);}}}
return message.channel.send(`${['You should', 'How about', 'Hmmm... I pick', 'How about you', 'I think you should'][Math.floor(Math.random() * 5)]} ${options[Math.floor(Math.random() * options.length)]}.`);
}
};
Loading…
Cancel
Save