This commit is contained in:
Neko Life 2021-05-30 22:39:46 +00:00
parent 81c0ea6a7b
commit b338b6622f
12 changed files with 47 additions and 48 deletions

View file

@ -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);
}
};

View file

@ -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")

View file

@ -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);

View file

@ -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) {

View file

@ -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) {

View file

@ -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 `[<channel_[mention, ID]> <message_ID>, message_link]` if it\'s in another channel.');
} catch (e) {
noPerm(msg);

View file

@ -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]\``);

View file

@ -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;
}
};

View file

@ -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);

View file

@ -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) {

View file

@ -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~");
}

View file

@ -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<MessageEmbed>}
*/
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);
}
/**