Merge pull request #1 from Neko-Life/main

Update repository 1
This commit is contained in:
Daniel Bulant 2021-05-16 11:30:13 +02:00 committed by GitHub
commit 65496b0554
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 375 additions and 72 deletions

4
.gitignore vendored
View file

@ -1,5 +1,6 @@
config.json
package-lock.json
*.sqlite3
# Logs
logs
@ -43,6 +44,7 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
exp/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
@ -117,3 +119,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
settings.sqlite3
settings.sqlite3

View file

@ -2,7 +2,7 @@
const Commando = require('@iceprod/discord.js-commando');
const client = new Commando.Client({
owner: '750335181285490760',
owner: ['820696421912412191', '750335181285490760'],
partials: ["CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION", "USER"]
});
const sqlite = require('sqlite');

View file

@ -0,0 +1,22 @@
'use strict';
const { trySend } = require("../../resources/functions");
const commando = require("@iceprod/discord.js-commando"),
{ database } = require("../../database/mongo"),
col = database.collection("Experiment");
module.exports = class dropexp extends commando.Command {
constructor(client) {
super(client, {
name: "dropexp",
memberName: "dropexp",
group: "experiment",
description: "description",
ownerOnly:true
});
}
run(msg, arg) {
col.drop().then(trySend(this.client, msg, "cleared")).catch(e => trySend(this.client, msg, `\`\`\`js\n${e.stack}\`\`\``));
}
};

View file

@ -3,6 +3,7 @@
const commando = require("@iceprod/discord.js-commando");
const { errLog, trySend, ranLog } = require("../../resources/functions");
const { database } = require("../../database/mongo");
const exp = database.collection("Experiment");
module.exports = class mydatabase extends commando.Command {
constructor(client) {
@ -10,19 +11,24 @@ module.exports = class mydatabase extends commando.Command {
name: "mydatabase",
memberName: "mydatabase",
group: "experiment",
description: "Show all document collection."
description: "Show all document collection.",
ownerOnly:true
});
}
run(msg) {
async run(msg) {
if (!msg.guild?.member(msg.author).hasPermission("MANAGE_GUILD")) {
return trySend(this.client, msg, "No");
}
const data = msg.guild ? "Guild" : "User";
const doc = msg.guild?.id ?? msg.author.id;
const doc = msg.guild?.id ?? msg.author.id,
dbExp = await exp.find({}).toArray();
database.collection(data).find({document: doc}).toArray(async (e, fetched) => {
if (e) {
return errLog(e, msg, this.client);
}
let mes = `Fetched documents for ${msg.guild ? `server **${msg.guild.name}**` : `**${msg.author.tag}**`}`;
mes = `${mes}\`\`\`js\n${JSON.stringify(fetched, null, 2)}\`\`\``;
trySend(this.client, msg, mes);
mes = `${mes}\`\`\`js\n${JSON.stringify(fetched, null, 2)}\`\`\`` + `\`\`\`js\n${JSON.stringify(dbExp, null, 2)}\`\`\``;
trySend(this.client, msg, {content:mes,split:{maxLength:2000,append:",```",prepend:"```js\n",char:","}});
return ranLog(msg, "mydatabase", fetched);
});
}

32
cmds/experiment/regive.js Normal file
View file

@ -0,0 +1,32 @@
'use strict';
const { trySend, cleanMentionID } = require("../../resources/functions");
const commando = require("@iceprod/discord.js-commando"),
{ database } = require("../../database/mongo"),
col = database.collection("Experiment");
module.exports = class regive extends commando.Command {
constructor(client) {
super(client, {
name: "regive",
memberName: "regive",
group: "experiment",
description: "description"
});
}
/**
*
* @param {commando.CommandoMessage} msg
* @param {*} arg
*/
async run(msg, arg ) {
const args = arg.split(" "),
member = msg.guild.member(cleanMentionID(args[0])),
doc = await col.findOne({"rolesScreenshot.name":member.id}).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")),
test = doc.rolesScreenshot.data;
await member.roles.add(test.map(r => r)).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```"));
await member.roles.remove("772114626720432128").catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```"))
trySend(this.client, msg, "Success!"+"```js\n"+JSON.stringify(test, null, 2)+"```");
}
};

View file

@ -0,0 +1,29 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const { cleanMentionID, trySend } = require("../../resources/functions");
module.exports = class replace extends commando.Command {
constructor(client) {
super(client, {
name: "replace",
memberName: "replace",
group: "experiment",
description: "replace test"
});
}
/**
*
* @param {commando.CommandoMessage} msg
* @param {*} arg
*/
async run(msg, arg) {
const args = arg.split(" "),
targetID = cleanMentionID(args[0]),
targetUser = msg.guild.member(targetID);
await targetUser.roles.remove(targetUser.roles.cache.array()).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```"));
await targetUser.roles.add("772114626720432128").catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```"));
//trySend(this.client, msg, "```js\n"+JSON.stringify(mes, null, 2)+"```");
trySend(this.client, msg, "Replaced!");
}
};

View file

@ -10,10 +10,14 @@ module.exports = class resetdatabase extends commando.Command {
name: "resetdatabase",
memberName: "resetdatabase",
group: "experiment",
description: "Reset your server/private database."
description: "Reset your server/private database.",
ownerOnly:true
});
}
async run(msg) {
if (!msg.guild?.member(msg.author).hasPermission("MANAGE_GUILD")) {
return trySend(this.client, msg, "No");
}
const doc = msg.guild?.id ?? msg.author.id;
const col = database.collection(msg.guild ? "Guild" : "User");
trySend(this.client, msg, "Are you sure? You will lose every saved settings. This process can't be undone. Type `yes` in 30 seconds to confirm.");

View file

@ -0,0 +1,28 @@
'use strict';
const commando = require("@iceprod/discord.js-commando"),
{ database } = require("../../database/mongo");
const { trySend } = require("../../resources/functions"),
col = database.collection("Guild");
module.exports = class resetinfractions extends commando.Command {
constructor(client) {
super(client, {
name: "resetinfractions",
memberName: "resetinfractions",
group: "experiment",
description: "description",
guildOnly:true,
ownerOnly:true
});
}
run(msg) {
col.updateOne({document:msg.guild.id}, {$set:{"moderation.infractions":[]}}, {upsert:true}, (e, r) => {
if (e) {
return trySend(this.client, msg, "```js\n"+e.stack+"```");
}
col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute": {}}});
return trySend(this.client, msg, "Wiped!");
});
}
};

View file

@ -0,0 +1,32 @@
'use strict';
const { cleanMentionID, trySend } = require("../../resources/functions");
const commando = require("@iceprod/discord.js-commando"),
{ database } = require("../../database/mongo"),
dbExp = database.collection("Experiment");
module.exports = class screenshot extends commando.Command {
constructor(client) {
super(client, {
name: "screenshot",
memberName: "screenshot",
group: "experiment",
description: "description"
});
}
/**
*
* @param {commando.CommandoMessage} msg
* @param {*} arg
*/
async run(msg, arg) {
const args = arg.split(" "),
targetID = cleanMentionID(args[0]),
targetUser = msg.guild.member(targetID),
test = targetUser.roles.cache.map(r => r.id);
//trySend(this.client,msg,{content:`\`\`\`js\n${test}\`\`\``,split:true})
await dbExp.insertOne({ rolesScreenshot: { name: targetUser.id, data: test }}).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```"));
trySend(this.client, msg, "Sceenshoted!")
}
};

View file

@ -16,7 +16,7 @@ module.exports = class neko extends commando.Command {
const aut = msg.guild ? msg.guild.member(msg.author) : msg.author;
const title = `${msg.guild ? aut.displayName : aut.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, image, aut, title);
const emb = await defaultImageEmbed(this.client, msg, aut, image, title);
trySend(this.client, msg, emb);
return ranLog(msg, "neko");
}

View file

@ -1,10 +1,10 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const { trySend, findMemberRegEx, cleanMentionID } = require("../../resources/functions");
const { trySend, findMemberRegEx, cleanMentionID, findChannelRegEx, findRoleRegEx, defaultImageEmbed } = require("../../resources/functions");
const { database } = require("../../database/mongo");
const col = database.collection("Guild");
const dbExp = database.collection("Experiment");
const schedule = database.collection("Schedule");
const { scheduler } = require("../../resources/scheduler");
module.exports = class mute extends commando.Command {
@ -25,9 +25,11 @@ module.exports = class mute extends commando.Command {
*/
async run(msg, arg) {
const doc = await col.findOne({document: msg.guild.id}),
moderationDoc = doc?.["moderation"],
infractionDoc = moderationDoc?.infractions,
args = arg.trim().split(/(?<!\\)(\-\-)+/, 5),
modDoc = doc?.["moderation"],
muteSettingsDoc = modDoc?.["settings"]?.mute,
defaultDurationDoc = muteSettingsDoc?.defaultDuration,
infractionsDoc = modDoc?.infractions,
args = arg.trim().split(/(?<!\\)(\-\-)+/),
mentions = args.shift().split(/(?<!\\),+/),
durationRegExp = /\d+(?![^ymwdhs])[ymwdhs]?o?/gi,
invokedAt = msg.createdAt,
@ -39,59 +41,127 @@ module.exports = class mute extends commando.Command {
minute: invokedAt.getMinutes(),
second: invokedAt.getSeconds()
};
let durationHasSet = false,
let theSettingUp = {
role: undefined,
defaultDuration: {
date: undefined,
string: undefined
},
logChannel: undefined
},
durationHasSet = false,
settingUp = false,
settingRole = false,
settingRoleHasSet = false,
settingDuration = false,
settingDurationHasSet = false,
settingLogChannel = false,
settingLogChannelHasSet = false,
[timeForMessage, targetUser] = [["Indefinite"], []],
reason = "No reason provided.",
resultMsg = "";
for (const argument of args) {
if (/^\d+(?![^ymwdhs])[ymwdhs]?o?/i.test(argument.trim()) && !durationHasSet) {
const setArg = argument.toLowerCase().trim();
if (/^settings?$/i.test(setArg)) {
settingUp = true;
}
if (settingUp && /^durations?$/i.test(setArg)) {
settingDuration = true;
}
if (settingUp && /^log$/i.test(setArg)) {
settingLogChannel = true;
}
if (settingUp && /^role$/i.test(setArg)) {
settingRole = true;
}
if (/^\d{1,16}(?![^ymwdhs])[ymwdhs]?o?/i.test(argument.trim()) && !durationHasSet) {
const durationArg = argument.match(durationRegExp);
//timeForMessage = [];
for (const value of durationArg) {
const val = parseInt(value.match(/\d+/)[0], 10);
if (value.endsWith("h") || value.endsWith("ho")) {
duration.hour = duration.hour + val;
//timeForMessage.push(val + " Hours");
}
if (value.endsWith("y")) {
duration.year = duration.year + val;
//timeForMessage.push(val + " Years");
}
if (value.endsWith("mo")) {
duration.month = duration.month + val;
//timeForMessage.push(val + " Months");
}
if (value.endsWith("w")) {
duration.date = duration.date + 7 * val;
//timeForMessage.push(val + " Weeks");
}
if (value.endsWith("d")) {
duration.date = duration.date + val;
//timeForMessage.push(val + " Days");
}
if (value.endsWith("m") || !/\D/.test(value)) {
duration.minute = duration.minute + val;
//timeForMessage.push(val + " Minutes");
}
if (value.endsWith("s")) {
duration.second = duration.second + val;
//timeForMessage.push(val + " Seconds");
}
}
durationHasSet = true;
} else {
if (argument.length > 0 && argument !== "--") {
if (!settingRole && !settingLogChannel && argument.length > 0 && argument !== "--") {
reason = argument.trim();
} else {
if (settingLogChannel && !settingLogChannelHasSet && argument.length > 0 && argument !== "--" && setArg !== "log") {
settingLogChannelHasSet = true;
const key = cleanMentionID(argument);
let logChannel;
if (/^\d{17,19}$/.test(key)) {
logChannel = msg.guild.channels.cache.get(argument);
} else {
const found = findChannelRegEx(msg, key);
logChannel = found[0];
}
if (/^none$/.test(key)) {
logChannel = undefined;
}
if (logChannel || /^none$/.test(key)) {
theSettingUp.logChannel = logChannel?.id;
} else {
resultMsg += `No channel found for: **${argument}**\n`;
}
}
if (settingRole && !settingRoleHasSet && argument.length > 0 && argument !== "--" && setArg !== "role") {
settingRoleHasSet = true;
const key = cleanMentionID(argument);
let role;
if (/^\d{17,19}$/.test(key)) {
role = msg.guild.roles.cache.get(argument);
} else {
const found = findRoleRegEx(msg, key);
role = found[0]?.id;
}
if (/^none$/.test(key)) {
role = undefined;
}
if (role || /^none$/.test(key)) {
theSettingUp.role = role;
} else {
resultMsg += `No role found for: **${argument}**\n`;
}
}
}
}
}
const roleConfCheck = msg.guild.roles.cache.get(muteSettingsDoc?.role);
if (!roleConfCheck && !settingUp) {
return trySend(this.clientPermissions, msg, `No mute role configured! Run \`${this.client.commandPrefix}mute --settings <--role --<role_[name | ID]>> [--duration --<duration> | --log --<channel_[name | ID]>]\` to set it up.`);
}
if (duration.year > 275500) {
duration.year = 275500;
}
let untilDate = new Date(String(duration.year), String(duration.month), String(duration.date), String(duration.hour), String(duration.minute), String(duration.second));
if (untilDate.toUTCString() === invokedAt.toUTCString()) {
untilDate = "Indefinite";
} else {
if (untilDate.toUTCString() === invokedAt.toUTCString() && !settingDuration) {
if (defaultDurationDoc?.date?.valueOf() > 0) {
untilDate = new Date(invokedAt.valueOf() + defaultDurationDoc.date.valueOf() - 1000);
} else {
untilDate = "Indefinite";
}
}
if (untilDate !== "Indefinite") {
timeForMessage = [];
const elapsedTime = new Date(untilDate.valueOf() - invokedAt.valueOf() + 1000),
elapsed = [
@ -110,19 +180,48 @@ module.exports = class mute extends commando.Command {
"minute",
"second"
];
for (let index = 0; index < elapsed.length; index++) {
if (elapsed[index] > 0) {
timeForMessage.push(`${elapsed[index]} ${elapsedName[index]}`);
let mes = `${elapsed[index]} ${elapsedName[index]}`;
if (elapsed[index] > 1) {
mes += "s";
} else {}
timeForMessage.push(mes);
} else {}
}
for (let index = 0; index < timeForMessage.length; index++) {
if (parseInt(timeForMessage[index].split(" ")[0], 10) > 1) {
timeForMessage[index] += "s";
}
}
if (timeForMessage.length > 1) {
timeForMessage[timeForMessage.length - 2] += " and";
}
if (settingDuration && !settingDurationHasSet && timeForMessage.length > 0) {
settingDurationHasSet = true;
theSettingUp.defaultDuration.date = elapsedTime,
theSettingUp.defaultDuration.string = timeForMessage.join(" ");
}
}
if (settingUp) {
if(settingRoleHasSet) {
await col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute.role":theSettingUp.role}}, {upsert:true}).catch(e => {return trySend(this.client, msg, "```js\n"+e.stack+"```")});
}
if (durationHasSet) {
await col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute.defaultDuration":theSettingUp.defaultDuration}}, {upsert:true}).catch(e => {return trySend(this.client, msg, "```js\n"+e.stack+"```")});
}
if (settingLogChannelHasSet) {
await col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute.logChannel":theSettingUp.logChannel}}, {upsert:true}).catch(e => {return trySend(this.client, msg, "```js\n"+e.stack+"```")});
}
const doc = await col.findOne({document: msg.guild.id}),
modDoc = doc?.["moderation"],
muteSettingsDoc = modDoc?.["settings"]?.mute,
defaultDurationDoc = muteSettingsDoc?.defaultDuration,
logChannelDoc = muteSettingsDoc?.logChannel,
roleDoc = muteSettingsDoc?.role;
let settings = await defaultImageEmbed(this.client, msg, msg.member);
settings
.setTitle("Mute Configuration")
.addField("Role", roleDoc ? "<@&"+roleDoc+">" : "Not set")
.addField("Duration", defaultDurationDoc?.string ?? "Not set")
.addField("Log", logChannelDoc ? "<#"+logChannelDoc+">" : "Not set");
return trySend(this.client, msg, {content:resultMsg, embed:settings});
}
for (const usermention of mentions) {
if (usermention.length > 0) {
@ -151,35 +250,62 @@ module.exports = class mute extends commando.Command {
} else {
resultMsg += `Can't find user: **${usermention.trim()}**\n`;
}
} else {
if (!settingUp) {
return trySend(this.client, msg, "Who are you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`");
} else {
}
}
}
let infractionToDoc;
if (targetUser.length > 0) {
const infractionCase = infractionDoc?.map(r => r.infraction)?.length;
let targetMember = [],
notInServer = [];
for (const user of targetUser) {
const member = msg.guild.member(user);
if (member) {
const pushIt = {
name:member.user.tag,
id:member.id,
roles:member.roles.cache.map(r => r.id)
}
targetMember.push(pushIt);
} else {
const pushIt = {
name: user.tag,
id:user.id
}
notInServer.push(pushIt);
}
}
const infractionCase = infractionsDoc?.map(r => r.infraction)?.length;
infractionToDoc = {
infraction: infractionCase ? infractionCase + 1 : 1,
by: targetUser,
moderator: `**${msg.author.tag}** <@${msg.author.id}> (${msg.author.id})`,
punishment: "**Mute**",
punishment: "mute",
at: invokedAt,
for: timeForMessage,
until: untilDate,
reason: reason,
scene: msg.url
scene: msg.url,
members: targetMember,
users: notInServer
}
await col.updateOne({document: msg.guild.id}, { $push:{"moderation.infractions": infractionToDoc}}, {upsert:true});
const newUnmuteSchedule = {
name: "unmute schedule " + targetUser?.id,
name: "unmute",
path: "./scheduler/unmute.js",
worker: {
argv: {
}
}
argv: [msg, infractionToDoc.infraction]
},
date: untilDate
}
}
resultMsg += `Result:\`\`\`js\nUsers: ${targetUser.map(r => r?.tag).join(", ")}\nReason: ${reason}\nAt: ${invokedAt.toUTCString()}\nFor: ${timeForMessage.join(" ")}\nUntil: ${typeof untilDate !== "string" ? untilDate.toUTCString() : untilDate}\`\`\`\n`;
trySend(this.client, msg, "```js\n" + JSON.stringify(infractionToDoc, null, 2) + "```");
return trySend(this.client, msg, resultMsg);
resultMsg += `Result:\`\`\`js\nUsers: ${targetUser.map(r => r?.tag).join(", ")}\nReason: ${reason}\nAt: ${invokedAt.toUTCString()}\nFor: ${timeForMessage.join(" ")}\nUntil: ${typeof untilDate !== "string" ? untilDate.toUTCString() : untilDate}\`\`\``;
trySend(this.client, msg, {content:resultMsg+"```js\n" + JSON.stringify(infractionToDoc, null, 2) + "```",split:{maxLength:2000,append:",```",prepend:"```js\n",char:","}});
return
}
};

View file

@ -43,7 +43,7 @@ module.exports = class avatar extends commando.Command {
if (ops.toLowerCase().startsWith("show")) {
const val = ops.trim().split(/ +/);
const theVal = val[1]?.match(/\d*/);
if (theVal[0]) {
if (theVal?.[0]) {
show = parseInt(theVal[0].trim(), 10);
}
}
@ -55,7 +55,7 @@ module.exports = class avatar extends commando.Command {
if (uID.length > 0) {
let ree = [];
if (/^\d{17,19}$/.test(uID)) {
const findmem = msg.guild.member(uID);
const findmem = msg.guild?.member(uID);
if (findmem) {
ree.push(findmem.user);
} else {

View file

@ -13,7 +13,8 @@ module.exports = class newquoteotd extends commando.Command {
memberName: "newquoteotd",
group: "utility",
description: "The Life exclusive command for Quote of the day.",
guildOnly: true
guildOnly: true,
userPermissions:["ADMINISTRATOR"]
});
}
async run(msg, arg) {

View file

@ -15,7 +15,8 @@ module.exports = class quoteotd extends commando.Command {
group: "utility",
description: "Set Quote of the day channel and settings.",
details:"```\n--channel\n--text\n--icon```",
guildOnly: true
guildOnly: true,
userPermissions:["ADMINISTRATOR"]
});
}
async run(msg, arg) {

View file

@ -17,8 +17,12 @@ module.exports = class say extends commando.Command {
if (!args) {
args = noArgs;
}
trySend(this.client, msg, args);
if (args !== noArgs && msg.channel.guild) {
const sendThis = {content:args, disableMentions:"all"};
if (msg.member?.hasPermission("ADMINISTRATOR")) {
sendThis.disableMentions = "none";
}
trySend(this.client, msg, sendThis);
if (args !== noArgs && msg.channel.guild && msg.member.hasPermission("MANAGE_MESSAGES")) {
tryDelete(msg);
}
return ranLog(msg,'say',`Content: ${args}`);

View file

@ -8,7 +8,8 @@ module.exports = class send extends commando.Command {
name: "send",
memberName: "send",
group: "utility",
description: "Send message to designated channel."
description: "Send message to designated channel.",
userPermissions:["MANAGE_MESSAGES"]
});
}
async run(msg, args ) {
@ -30,7 +31,11 @@ module.exports = class send extends commando.Command {
if (sendTheMes.length === 0) {
return trySend(this.client, at, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`);
}
const send = await channel.send(sendTheMes);
const sendThis = {content:sendTheMes, disableMentions:"all"};
if (msg.member?.hasPermission("ADMINISTRATOR")) {
sendThis.disableMentions = "none";
}
const send = await trySend(this.client, channel, sendThis);
sentAdCheck(send);
const filter = () => true;
const collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true});

View file

@ -9,13 +9,18 @@ const getColor = require("../../resources/getColor");
module.exports = class servav extends commando.Command {
constructor(client) {
super(client, {
name: "servav",
memberName: "servav",
aliases: ["serveravatar", "servavatar", "serverav"],
name: "serv-av",
memberName: "serv-av",
aliases: ["server-avatar", "serv-avatar", "server-av"],
group: "utility",
description: "Show server avatar."
});
}
/**
*
* @param {commando.CommandoMessage} msg
* @param {*} arg
*/
run(msg, arg) {
const server_ID = arg.split(/ +/)[0];
const doc = msg.guild?.id ?? msg.author.id;
@ -26,7 +31,7 @@ module.exports = class servav extends commando.Command {
}
const footerQuote = res?.["settings"]?.defaultEmbed?.footerQuote;
let icon, target;
if (server_ID) {
if (server_ID && this.client.owners.includes(msg.author.id)) {
if (!/\D/.test(server_ID)) {
target = this.client.guilds.cache.get(server_ID);
} else {

View file

@ -11,7 +11,8 @@ module.exports = class setfootq extends commando.Command {
aliases:["setfooterquote"],
memberName: "setfootq",
group: "utility",
description: "Set server embed footer text."
description: "Set server embed footer text.",
userPermissions: ["ADMINISTRATOR"]
});
}
async run(msg, args) {

View file

@ -1,8 +1,9 @@
'use strict';
const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions } = require('discord.js');
const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, Channel } = require('discord.js');
const { defaultErrorLogChannel } = require("../config.json");
const { database } = require("../database/mongo");
const getColor = require('./getColor');
/**
* Log an error. If second argument, third argument is required
@ -139,7 +140,6 @@ async function ranLog(msg, cmd, addition) {
* @returns {String}
*/
function multipleMembersFound(client, msg, arr, key, max = 4, withID) {
arr = arr.slice(1);
if (arr.length > 0) {
try {
let multipleFound = [];
@ -203,7 +203,7 @@ function noPerm(msg) {
/**
* Send message
* @param {Client} client - (this.client)
* @param {Message | String} msg Message object | channel_ID
* @param {Message | String | Channel} msg Message object | channel_ID
* @param {MessageOptions} content - ({content:content,optionblabla})
* @returns {Promise<Message>} Sent message object
*/
@ -213,10 +213,15 @@ async function trySend(client, msg, content) {
if (msg?.channel) {
msgOf = msg.channel;
} else {
msgOf = client.channels.cache.get(msg);
if (typeof msg === "string") {
msgOf = client.channels.cache.get(msg);
} else {
msgOf = msg;
}
}
const sentMes = await msgOf.send(content)
.catch(() => {
.catch((e) => {
console.error(e);
if (msg?.channel) {
noPerm(msg);
}
@ -270,23 +275,20 @@ function sentAdCheck(sent) {
* @param {String} footerText
* @returns {Promise<MessageEmbed>}
*/
async function defaultImageEmbed(client, msg, image, author, title, footerText) {
async function defaultImageEmbed(client, msg, author, image, title, footerText) {
const { randomColors } = require("../config.json");
let footerQuote = footerText;
if (!footerQuote) {
const doc = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id});
footerQuote = doc?.["settings"]?.defaultEmbed?.footerQuote || "";
const r = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id});
footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote || "";
}
let emb = new MessageEmbed();
try {
emb
.setTitle(title)
.setImage(image)
.setColor(msg.guild ? author?.displayColor : randomColors[Math.floor(Math.random() * randomColors.length)])
.setColor(msg.guild ? getColor(author?.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)])
.setFooter(footerQuote);
if (author?.displayColor === 16777215) {
emb.setColor(16777214);
}
} catch (e) {
return errLog(e, msg, client, false, "", false);
}
@ -363,7 +365,6 @@ function findRoleRegEx(msg, name) {
* @returns {String}
*/
function multipleChannelsFound(client, msg, arr, key, max = 4, withID) {
arr = arr.slice(1);
if (arr.length > 0) {
try {
let multipleFound = [];
@ -404,7 +405,6 @@ function multipleChannelsFound(client, msg, arr, key, max = 4, withID) {
* @returns {String}
*/
function multipleRolesFound(client, msg, arr, key, max = 4, withID) {
arr = arr.slice(1);
if (arr.length > 0) {
try {
let multipleFound = [];

View file

@ -6,6 +6,9 @@
* @returns {String | Number} Color hex | Color number
*/
module.exports = function getColor(name) {
if (!name) {
return
}
if (typeof name === "string") {
name = name.toLowerCase();
}

View file

@ -2,7 +2,7 @@
const puppeteer = require('puppeteer');
const { trySend, errLog, ranLog, noPerm } = require('./functions');
const { trySend, ranLog, noPerm } = require('./functions');
const Commando = require("@iceprod/discord.js-commando");
require("discord.js");

Binary file not shown.