diff --git a/cmds/image/neko.js b/cmds/image/neko.js index 44d8c05..90cf592 100644 --- a/cmds/image/neko.js +++ b/cmds/image/neko.js @@ -13,11 +13,9 @@ module.exports = class neko extends commando.Command { }); } async run(msg) { - const aut = msg.guild ? msg.guild.member(msg.author) : msg.author; - const title = `${msg.guild ? aut.displayName : aut.username}! ~Nyann~ (UwU) <3`; + const title = `${msg.guild ? msg.member.displayName : msg.author.username}! ~Nyann~ (UwU) <3`; const image = `https://nekos.best/nekos/${String(Math.floor(Math.random() * 314)).padStart(4, '0')}.png`; - const emb = await defaultImageEmbed(this.client, msg, aut, image, title); - trySend(this.client, msg, emb); - return ranLog(msg, "neko"); + const emb = await defaultImageEmbed(msg, image, title); + return trySend(this.client, msg, emb); } }; \ No newline at end of file diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index d9e2949..072263a 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -245,7 +245,7 @@ module.exports = class mute extends commando.Command { defaultDurationDoc = muteSettingsDoc?.defaultDuration, logChannelDoc = muteSettingsDoc?.logChannel, roleDoc = muteSettingsDoc?.role; - let settings = await defaultImageEmbed(this.client, msg, msg.member); + let settings = await defaultImageEmbed(msg); settings .setTitle("Mute Configuration") .addField("Role", roleDoc ? "<@&"+roleDoc+">" : "Not set") diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index d4cbc3a..4354059 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -355,6 +355,7 @@ module.exports = class embmaker extends commando.Command { if (sent.length > 0) { tryReact(msg, "a:yesLife:794788847996370945"); } + ranLog(this.client, msg, ("```js\n" + JSON.stringify(embed, null, 2) + "```").slice(0, 2048)); return sent; } catch (e) { return errLog(e, msg, this.client, true, "", true); diff --git a/cmds/utility/mesemb.js b/cmds/utility/mesemb.js index 2b0da9a..b5c5ea3 100644 --- a/cmds/utility/mesemb.js +++ b/cmds/utility/mesemb.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { getChannelMessage, ranLog, errLog, noPerm, trySend } = require("../../resources/functions"); +const { getChannelMessage, trySend } = require("../../resources/functions"); module.exports = class mesemb extends commando.Command { constructor(client) { diff --git a/cmds/utility/mesinfo.js b/cmds/utility/mesinfo.js index 581de16..303571b 100644 --- a/cmds/utility/mesinfo.js +++ b/cmds/utility/mesinfo.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { errLog, getChannelMessage, ranLog, noPerm, trySend } = require("../../resources/functions"); +const { getChannelMessage, trySend } = require("../../resources/functions"); module.exports = class mesinfo extends commando.Command { constructor(client) { diff --git a/cmds/utility/newquoteotd.js b/cmds/utility/newquoteotd.js index 3465b7e..6372e33 100644 --- a/cmds/utility/newquoteotd.js +++ b/cmds/utility/newquoteotd.js @@ -2,7 +2,7 @@ const commando = require("@iceprod/discord.js-commando"); const { MessageEmbed } = require("discord.js"); -const { getChannelMessage, ranLog, errLog, noPerm, tryReact, trySend } = require("../../resources/functions"); +const { getChannelMessage, errLog, noPerm, tryReact, trySend, ranLog } = require("../../resources/functions"); const { database } = require("../../database/mongo"); const col = database.collection("Guild"); @@ -57,6 +57,7 @@ module.exports = class newquoteotd extends commando.Command { } return sent; } + ranLog(this.client, msg, "New quote: " + msg.content + "\nBy: " + mes.author.tag + ` (${mes.author.id})`); return trySend(this.client, msg, 'No message with that ID from this channel. Use `[ , message_link]` if it\'s in another channel.'); } catch (e) { noPerm(msg); diff --git a/cmds/utility/quoteotd.js b/cmds/utility/quoteotd.js index d8e5f7a..5063d4a 100644 --- a/cmds/utility/quoteotd.js +++ b/cmds/utility/quoteotd.js @@ -1,9 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { writeJSONSync } = require("fs-extra"); -const { join } = require("path"); -const { ranLog, trySend } = require("../../resources/functions"); +const { trySend, ranLog } = require("../../resources/functions"); const { database } = require("../../database/mongo"); const col = database.collection("Guild"); @@ -56,6 +54,7 @@ module.exports = class quoteotd extends commando.Command { } } if (result.length > 0) { + ranLog(this.client, msg, result); return trySend(this.client, msg, result); } else { return trySend(this.client, msg, `Provide argument: \`--channel [mention, ID], --text [footer text], --icon [url footer icon]\``); diff --git a/cmds/utility/say.js b/cmds/utility/say.js index 992a876..a924915 100644 --- a/cmds/utility/say.js +++ b/cmds/utility/say.js @@ -13,7 +13,7 @@ module.exports = class say extends commando.Command { description: "Say." }); } - run(msg, args) { + async run(msg, args) { let noArgs = '​'; if (!args) { args = noArgs; @@ -23,10 +23,11 @@ module.exports = class say extends commando.Command { if (msg.member?.hasPermission('MENTION_EVERYONE')) { sendThis.disableMentions = "none"; } - const sent = trySend(this.client, msg, sendThis); + const sent = await trySend(this.client, msg, sendThis); if (args !== noArgs && msg.channel.guild && msg.member.hasPermission("MANAGE_MESSAGES")) { tryDelete(msg); } + ranLog(this.client, msg, sent.content); return sent; } }; \ No newline at end of file diff --git a/cmds/utility/send.js b/cmds/utility/send.js index f0a3867..40baff1 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -57,6 +57,7 @@ module.exports = class send extends commando.Command { if (send) { tryReact(msg, 'yeLife:796401669188354090'); } + ranLog(this.client, msg, send.content); return send; } catch (e) { return errLog(e, msg, this.client); diff --git a/cmds/utility/setfootq.js b/cmds/utility/setfootq.js index 63e2e02..2149c35 100644 --- a/cmds/utility/setfootq.js +++ b/cmds/utility/setfootq.js @@ -29,6 +29,7 @@ module.exports = class setfootq extends commando.Command { return errLog(e, msg, this.client); } const result = await trySend(this.client, msg, `Changed from \`${oldQ?.["settings"]?.defaultEmbed?.footerQuote}\` to \`${args.trim()}\``); + ranLog(this.client, msg, result.content); return result; }); } catch (e) { diff --git a/cmds/utility/uinfo.js b/cmds/utility/uinfo.js index 8717593..984fde0 100644 --- a/cmds/utility/uinfo.js +++ b/cmds/utility/uinfo.js @@ -39,7 +39,7 @@ module.exports = class uinfo extends commando.Command { result += 'Display color:```js\n'+member.displayColor+'```'; } } - return trySend(this.client, msg, result, {split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); + return trySend(this.client, msg, {content: result, split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); } catch (e) { return trySend(this.client, msg, "404 ERROR not found~"); } diff --git a/resources/functions.js b/resources/functions.js index e91f707..b1da318 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -1,15 +1,17 @@ 'use strict'; const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, Channel } = require('discord.js'); -const { defaultErrorLogChannel } = require("../config.json"); +const { defaultErrorLogChannel, ranLogger } = require("../config.json"); const { database } = require("../database/mongo"); const { timestampAt } = require('./debug'); const getColor = require('./getColor'); +const { randomColors } = require("../config.json"); +const { CommandoMessage, CommandoClient } = require('@iceprod/discord.js-commando'); /** * Log an error. If second argument, third argument is required * @param {Error} theError - Catched error (error) - * @param {Message} msg - Message object (msg) + * @param {CommandoMessage} msg - Message object (msg) * @param {Client} client - This client (this.client) * @param {Boolean} sendTheError - Add error content to notify message (true | false) * @param {String} errorMessage - Error message ("You don't have enough permission to use that command!") @@ -18,8 +20,7 @@ const getColor = require('./getColor'); async function errLog(theError, msg, client, sendTheError, errorMessage, notify) { let errLogPath, [logThis, inLogChannel, sendErr] = ['', '', '']; if (msg) { - const comErr = msg.content.trim().split(/ +/)[0]; - logThis = `\`${comErr}\` (${msg.id}) ${msg.url} in ${msg.guild ? `**${msg.channel.name}** (${msg.channel.id}) of **${msg.guild.name}** (${msg.guild.id})` : `**DM**`} ran by **${msg.author.tag}** (${msg.author.id}) \n\n`; + logThis = `\`${msg.command.name}\` (${msg.id}) ${msg.url} in ${msg.guild ? `**${msg.channel.name}** (${msg.channel.id}) of **${msg.guild.name}** (${msg.guild.id})` : `**DM**`} ran by **${msg.author.tag}** (${msg.author.id}) \n\n`; msg.guild ? errLogPath = `../Guilds/${msg.guild.id}/Log/` : errLogPath = '../Log/'; if (errorMessage) { if (errorMessage.length > 0) { @@ -96,17 +97,22 @@ function execCB(error, stdout, stderr) { console.log('stdout:\n'+stdout); console.log('stderr:\n'+stderr); } - -async function ranLog(msg, cmd, addition) { return /* - let errLogPath; - if (msg.guild) { - errLogPath = `../Guilds/${msg.guild.id}/Log/`; - } else { - errLogPath = '../Log/'; - } - let add = '\n'+addition; - const b = new Date().toUTCString(); - return //console.log(inLog); */ +/** + * Command usage logger + * @param {CommandoClient} client + * @param {CommandoMessage} msg + * @param {String} addition + */ +async function ranLog(client, msg, addition) { + const channel = client.channels.cache.get(ranLogger); + const embed = await defaultImageEmbed(msg, null, msg.command.name.toLocaleUpperCase() + ` (${msg.id})`); + embed.setAuthor(msg.author.tag + ` (${msg.author.id})`, msg.author.displayAvatarURL({"size": 4096, "dynamic": true})) + .setURL(msg.url) + .setDescription(addition) + .setFooter(timestampAt(), msg.guild?.iconURL({"size": 4096, "dynamic": true})) + .addField("Guild", `**${msg.guild?.name}** (${msg.guild?.id})`, true) + .addField("Channel", `**${msg.channel?.name}** (${msg.channel.id})`, true); + trySend(client, channel, {embed: embed}); } /** @@ -247,32 +253,23 @@ function sentAdCheck(content) { /** * Make default image embed - * @param {Client} client * @param {Message} msg - * @param {URL} image + * @param {String} image * @param {GuildMember | User} author * @param {String} title - * @param {String} footerText + * @param {String} footerQuote * @returns {Promise} */ -async function defaultImageEmbed(client, msg, author, image, title, footerText) { - const { randomColors } = require("../config.json"); - let footerQuote = footerText; +async function defaultImageEmbed(msg, image, title, footerQuote) { if (!footerQuote) { - const r = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id}); + const r = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id}).catch(() => {}); footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote || ""; } - let emb = new MessageEmbed(); - try { - emb - .setTitle(title) - .setImage(image) - .setColor(msg.guild ? getColor(author?.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)]) - .setFooter(footerQuote); - } catch (e) { - return errLog(e, msg, client); - } - return emb; + return new MessageEmbed() + .setTitle(title) + .setImage(image) + .setColor(msg.guild ? getColor(msg.member.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)]) + .setFooter(footerQuote); } /**