Logs -> Setting, caching, mdelete logs

master
Kit Kasune 4 years ago
parent 8ba49a228b
commit dc4fa00fd2
  1. 1
      bot.js
  2. 12
      commands/anime.js
  3. 65
      commands/logs.js
  4. 27
      events/messageDelete.js
  5. 15
      events/ready.js
  6. 3
      models/anime.js
  7. 48
      models/log.js

@ -26,5 +26,6 @@ async function init() {
client.guildconfig = {}; client.guildconfig = {};
client.guildconfig.prefixes = new Map(); client.guildconfig.prefixes = new Map();
client.guildconfig.logs = new Map();
} }
init(); init();

@ -36,9 +36,11 @@ module.exports = {
new Tag(['genres', 'g'], 'genres', 'listAppend'), new Tag(['genres', 'g'], 'genres', 'listAppend'),
new Tag(['tags', 'ta', 'tgs', 'tg', 'tag'], 'tags', 'listAppend'), new Tag(['tags', 'ta', 'tgs', 'tg', 'tag'], 'tags', 'listAppend'),
new Tag(['cs', 'characters', 'chars', 'chs'], 'characters', 'listAppend'), new Tag(['cs', 'characters', 'chars', 'chs'], 'characters', 'listAppend'),
new Tag(['streams', 'streamat', 'sa'], 'streamAt', 'listAppend') new Tag(['streams', 'streamat', 'sa'], 'streamAt', 'listAppend'),
new Tag(['img', 'thumb', 'thumbnail', 'image'])
]).test(args.join(' ')); ]).test(args.join(' '));
if (Object.keys(options).length) {
var foptions = {}; var foptions = {};
let option; for (option of Object.keys(options)) { let option; for (option of Object.keys(options)) {
if (Array.isArray(options[option])) { if (Array.isArray(options[option])) {
@ -51,6 +53,14 @@ module.exports = {
foptions[option] = s; foptions[option] = s;
} }
} }
} else {
if (client.misc.activeDMs.has(message.author.id)) {return message.channel.send("I'm already asking you questions in a DM! Finish that first, then try this command again.");}
client.misc.activeDMs.set(message.author.id, 'anime-add');
await message.author.send("I'm going to ask you some questions about the anime's info. Just reply with the answer and use good grammar and spelling and be as accurate as possible. To cancel the process, just leave the question unanswered for a few minutes and I'll let you know that the question timed out and is not longer answerable.")
.catch(() => {return message.reply("Something went wrong there! Most likely, your DMs are closed.");});
}
message.channel.send(new Discord.MessageEmbed() message.channel.send(new Discord.MessageEmbed()
.setTitle(`New Anime -> ${options.name}`) .setTitle(`New Anime -> ${options.name}`)

@ -1,17 +1,72 @@
const Discord = require("discord.js"); const Discord = require("discord.js");
const GuildData = require('../models/guild');
const LogData = require('../models/log');
const ObjLogTypes = {
mdelete: ['md', 'messagedelete', 'deletemessage', 'deletemsg', 'msgdelete'],
medit: ['me', 'messageedit', 'editmessage', 'msgedit', 'editmsg'],
chnew: ['chn', 'chc', 'newch', 'newchannel', 'chcreate', 'channelcreate'],
//chedit: ['channeledit'],
chdelete: ['chd', 'channeldelete', 'deletechannel', 'deletech', 'chdelete'],
//vcjoin: [],
//vcleave: [],
//servervcmute: [],
//servervcdeafen: [],
//kick: [],
//ban: [],
//mute: [],
//warn: [],
//giverole: [],
//takerole: [],
//addrole: [],
//editrole: [],
//deleterole: [],
//serverjoin: [],
//serverleave: [],
//nickname: [],
//username: [],
//avatar: []
}; const LogTypes = new Map();
let keys = Object.keys(ObjLogTypes);
let key; for (key of keys) {let vs = ObjLogTypes[key]; let v; for (v of vs) {LogTypes.set(v, key);}}
module.exports = { module.exports = {
name: "logs", name: "logs",
aliases: ["log", "l", "modlog", "modlogs"], aliases: ["log", "l", "modlog", "modlogs"],
help: new Discord.MessageEmbed() help: new Discord.MessageEmbed()
.setTitle("Help -> Server Logs") .setTitle("Help -> Server Logs")
.setDescription("Comfigure your server's log settings.\n\nLogs will update you on what ") .setDescription("Configure your server's log settings.\n\nLogs will update you on events in your server that have the potential to require moderator intervention, like someone deleting a hateful message before you can see it or a misbehaving moderator kicking/banning a member when they aren't supposed to.")
.addField("Syntax", "`vip <add|remove|check>`") .addField("Syntax", "`log <set|list|view|clear> [logType] [#channel]`")
.addField("Notice", "This command is **developer-only**."), .addField("Notice", "You must be an admin or have the specified staff role in order to use this command."),
async execute(message, msg, args, cmd, prefix, mention, client) { async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.reply("This command is server-only!");} if (!message.guild) {return message.reply("This command is server-only!");}
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}vip <add|remove|check>\``);} let tg = await GuildData.findOne({gid: message.guild.id});
const GuildSettings = require('../models/guild'); if ((!message.member.permissions.has("ADMINISTRATOR")) && (!tg || !tg.staffrole || !tg.staffrole.length || !message.member.roles.cache.has(tg.staffrole))) {return message.reply("You must be an administrator or have the specified staff role in this server in order to edit or view log settings.");}
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}log <set|list|view|clear> [logType] [#channel]\``);}
if (['s', 'set'].includes(args[0].toLowerCase())) {
if (args.length < 3) {return message.channel.send(`You must specify the log type and the channel to send the log to. Use \`${prefix}log list\` to see a list of valid log types.`);}
if (!LogTypes.has(args[1].toLowerCase())) {return message.channel.send("That's not a valid log type. Use \`${prefix}log list\` to see a list of valid log types.");}
let lt = LogTypes.get(args[1].toLowerCase());
let ch = args[2].match(/<\#(?:\d+)>/m) && message.guild.channels.cache.has(message.mentions.channels.first().id) ? message.mentions.channels.first() : message.guild.channels.cache.has(args[2]) ? message.guild.channels.cache.get(args[2]) : null;
if (!ch) {return message.channel.send("I can't find that channel! Make sure that you've mentioned one, or that the ID you provided is correct, and that I can see it.");}
if (!ch.permissionsFor(client.user.id).has("SEND_MESSAGES")) {return message.reply("I don't have permissions to send messages in that channel. Please give me access and try again.");}
let tl = await LogData.findOne({gid: message.guild.id}) || new LogData({gid: message.guild.id});
tl[lt] = ch.id;
tl.save();
if (!client.guildconfig.logs.has(message.guild.id)) {client.guildconfig.logs.set(message.guild.id, new Map());}
client.guildconfig.logs.get(message.guild.id).set(lt, ch.id);
return message.channel.send("Log settings updated!");
}
if (['l', 'list'].includes(args[0].toLowerCase())) {}
if (['v', 'view'].includes(args[0].toLowerCase())) {}
if (['c', 'clear'].includes(args[0].toLowerCase())) {}
} }
}; };

@ -0,0 +1,27 @@
const Discord = require('discord.js');
module.exports = async (client, message) => {
if (message.channel.type != "text") {return;};
//if (!Object.keys(snipe.delete).includes(message.guild.id)) {snipe.delete[message.guild.id] = {};};
//snipe.delete[message.guild.id][message.channel.id] = message;
let ts = client.guildconfig.logs.has(message.guild.id) && client.guildconfig.logs.get(message.guild.id).has('mdelete') ? client.guildconfig.logs.get(message.guild.id).get('mdelete') : null;
if (ts) {if (message.guild.channels.cache.has(ts) && message.guild.channels.cache.get(ts).permissionsFor(client.user.id).has("SEND_MESSAGES")) {
let mde = new Discord.MessageEmbed()
.setTitle('Message Deleted')
.setDescription(`Sent by <@${message.author.id}> | In <#${message.channel.id}>`)
.setThumbnail(message.author.avatarURL({size: 1024}))
.setColor('ecff8f').setFooter("Natsuki", client.user.avatarURL()).setTimestamp();
if (message.content && message.content.length) {mde.addField("Message", "`-> `" + message.content.toString());}
if (message.attachments.size) {
if (message.attachments.first().url.includes(".png") || message.attachments.first().url.includes(".jpg") || message.attachments.first().url.includes(".gif")) {/*console.log('e');*/ try {mde.setImage(message.attachments.first().url);} catch {}}
let av = Array.from(message.attachments.values());
as = ''; for (let a of av) {
as += `[Att. ${av.indexOf(a) + 1}](${a.url})`;
if (av.indexOf(a) + 1 < av.length) {as += ' | ';}
}
if (as.length) {mde.addField('Attachments', as);}
}
message.guild.channels.cache.get(ts).send(mde);
}}
}

@ -5,6 +5,7 @@ const mongoose = require('mongoose');
const GuildSettings = require('../models/guild'); const GuildSettings = require('../models/guild');
const BotDataSchema = require('../models/bot'); const BotDataSchema = require('../models/bot');
const LogData = require('../models/log');
const siftStatuses = require('../util/siftstatuses'); const siftStatuses = require('../util/siftstatuses');
@ -56,14 +57,22 @@ module.exports = async client => {
setInterval(setR, 14400000); setInterval(setR, 14400000);
const setP = async () => {let tg; for (tg of Array.from(client.guilds.cache.values)) { const setPL = async () => {let tg; for (tg of Array.from(client.guilds.cache.values)) {
let tguild = await GuildSettings.findOne({gid: tg.id}); let tguild = await GuildSettings.findOne({gid: tg.id});
if (tguild && tguild.prefix && tguild.prefix.length) {client.guildconfig.prefixes.set(tg.id, tguild.prefix);} if (tguild && tguild.prefix && tguild.prefix.length) {client.guildconfig.prefixes.set(tg.id, tguild.prefix);}
let tl = await LogData.findOne({gid: tg.id});
if (tl) {
let keys = Object.keys(tl);
let k; for (k of keys) {if (typeof tl[k] === "string" && tl[k].length) {
if (!client.guildconfig.logs.has(tg.id)) {client.guildconfig.logs.set(tg.id, new Map());}
client.guildconfig.logs.get(tg.id).set(k, tl[k]);
}}
}
}}; }};
setP(); setPL();
siftStatuses(); siftStatuses();
setInterval(() => {setP(); siftStatuses(client, null);}, 120000); setInterval(() => {setPL(); siftStatuses(client, null);}, 120000);
let botData = await BotDataSchema.findOne({finder: 'lel'}) let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'}) ? await BotDataSchema.findOne({finder: 'lel'})

@ -20,7 +20,8 @@ const AniSchema = new mongoose.Schema({
listed: Number, listed: Number,
liked: Number, liked: Number,
rating: Number, rating: Number,
lastUpdate: Date lastUpdate: Date,
thumbnail: String
}); });
module.exports = mongoose.model('anime', AniSchema); module.exports = mongoose.model('anime', AniSchema);

@ -2,27 +2,29 @@ const mongoose = require('mongoose');
const logSchema = new mongoose.Schema({ const logSchema = new mongoose.Schema({
gid: {type: String, unique: true}, gid: {type: String, unique: true},
mdelete: {type: Boolean, default: true}, mdelete: {type: String, default: ''},
medit: {type: Boolean, default: true}, medit: {type: String, default: ''},
chnew: {type: Boolean, default: true}, chnew: {type: String, default: ''},
chedit: {type: Boolean, default: true}, chedit: {type: String, default: ''},
chdelete: {type: Boolean, default: true}, chdelete: {type: String, default: ''},
vcjoin: {type: Boolean, default: false}, vcjoin: {type: String, default: ''},
vcleave: {type: Boolean, default: false}, vcleave: {type: String, default: ''},
servervcmute: {type: Boolean, default: true}, servervcmute: {type: String, default: ''},
servervcdeafen: {type: Boolean, default: true}, servervcdeafen: {type: String, default: ''},
kick: {type: Boolean, default: true}, kick: {type: String, default: ''},
ban: {type: Boolean, default: true}, ban: {type: String, default: ''},
mute: {type: Boolean, default: true}, mute: {type: String, default: ''},
warn: {type: Boolean, default: true}, warn: {type: String, default: ''},
giverole: {type: Boolean, default: true}, giverole: {type: String, default: ''},
takerole: {type: Boolean, default: true}, takerole: {type: String, default: ''},
addrole: {type: Boolean, default: true}, addrole: {type: String, default: ''},
editrole: {type: Boolean, default: true}, editrole: {type: String, default: ''},
deleterole: {type: Boolean, default: true}, deleterole: {type: String, default: ''},
serverjoin: {type: Boolean, default: false}, serverjoin: {type: String, default: ''},
serverleave: {type: Boolean, default: false}, serverleave: {type: String, default: ''},
nickname: {type: Boolean, default: true}, nickname: {type: String, default: ''},
username: {type: Boolean, default: false}, username: {type: String, default: ''},
avatar: {type: Boolean, default: false}, avatar: {type: String, default: ''}
}); });
module.exports = mongoose.model('log', logSchema);
Loading…
Cancel
Save