Merge branch 'Neko-Life:main' into main

This commit is contained in:
Daniel Bulant 2021-05-20 16:34:24 +02:00
commit bca8ed27ff
12 changed files with 95 additions and 241 deletions

3
.gitignore vendored
View file

@ -45,6 +45,7 @@ build/Release
node_modules/
jspm_packages/
exp/
cmds/experiment/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
@ -119,5 +120,3 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
settings.sqlite3
settings.sqlite3

View file

@ -68,6 +68,10 @@ client.on("guildMemberAdd", newMember => {
//console.log(`New member ${newMember.displayName} (${newMember.user.tag}) (${newMember.id}) joined ${newMember.guild.name} (${newMember.guild.id})! Now it has ${newMember.guild.memberCount} total members count.`);
});
process.on("uncaughtException", e => errLog(e, null, client));
process.on("unhandledRejection", e => errLog(e, null, client));
process.on("warning", e => errLog(e, null, client));
// client.on("debug", (...args) => console.log(...args));
client.login(configFile.token);

View file

@ -1,22 +0,0 @@
'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

@ -1,35 +0,0 @@
'use strict';
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) {
super(client, {
name: "mydatabase",
memberName: "mydatabase",
group: "experiment",
description: "Show all document collection.",
ownerOnly:true
});
}
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,
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)}\`\`\`` + `\`\`\`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);
});
}
};

View file

@ -1,32 +0,0 @@
'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

@ -1,29 +0,0 @@
'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

@ -1,40 +0,0 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const { ranLog, trySend, errLog } = require("../../resources/functions");
const { database } = require("../../database/mongo");
module.exports = class resetdatabase extends commando.Command {
constructor(client) {
super(client, {
name: "resetdatabase",
memberName: "resetdatabase",
group: "experiment",
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.");
const confirm = msg.channel.createMessageCollector(() => true, {time:30000});
confirm.on("collect", h => {
if (h.author === msg.author) {
if (h.content.trim() === "yes") {
col.findOneAndDelete({document: doc})
.then(
trySend(this.client, msg, "Wiped!"))
.catch(e => errLog(e, msg, this.client));
} else {
trySend(this.client, msg, "Request aborted.");
}
confirm.stop();
return ranLog(msg, "resetdatabase", h.content);
}
});
}
};

View file

@ -1,28 +0,0 @@
'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

@ -1,32 +0,0 @@
'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

@ -115,10 +115,10 @@ module.exports = class mute extends commando.Command {
const found = findChannelRegEx(msg, key);
logChannel = found[0];
}
if (/^none$/.test(key)) {
if (/^none$/i.test(key)) {
logChannel = undefined;
}
if (logChannel || /^none$/.test(key)) {
if (logChannel || /^none$/i.test(key)) {
theSettingUp.logChannel = logChannel?.id;
} else {
resultMsg += `No channel found for: **${argument}**\n`;
@ -134,10 +134,10 @@ module.exports = class mute extends commando.Command {
const found = findRoleRegEx(msg, key);
role = found[0]?.id;
}
if (/^none$/.test(key)) {
if (/^none$/i.test(key)) {
role = undefined;
}
if (role || /^none$/.test(key)) {
if (role || /^none$/i.test(key)) {
theSettingUp.role = role;
} else {
resultMsg += `No role found for: **${argument}**\n`;
@ -251,10 +251,8 @@ module.exports = class mute extends commando.Command {
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 {
if (!settingUp && mentions.length === 1 && mentions[0].length === 0) {
return trySend(this.client, msg, "Who do you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`");
}
}
}

View file

@ -1,6 +1,6 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const { ranLog, errLog, trySend, sentAdCheck, tryReact } = require("../../resources/functions");
const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions");
module.exports = class send extends commando.Command {
constructor(client) {
@ -9,36 +9,37 @@ module.exports = class send extends commando.Command {
memberName: "send",
group: "utility",
description: "Send message to designated channel.",
userPermissions:["MANAGE_MESSAGES"]
guildOnly:true
});
}
async run(msg, args ) {
const comarg = args.trim().split(/ +/);
const bot = this.client;
let at = comarg[0];
if (!comarg[0]) {
return trySend(this.client, msg, 'Where?!?');
}
if (comarg[0].startsWith('<#') && comarg[0].endsWith('>')) {
at = comarg[0].slice(2, -1);
}
const channel = bot.channels.cache.get(at);
const sendTheMes = args.slice(comarg[0].length).trim();
const search = cleanMentionID(comarg[0]),
channel = findChannelRegEx(msg, search)[0],
sendTheMes = args.slice(comarg[0].length).trim();
if (!channel) {
return trySend(this.client, msg, "Give me the right `channel_[mention, ID]` bruh");
return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>");
} else {
if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES")) {
return trySend(this.client, msg, "No <:cathmmLife:772716381874946068>");
}
}
try {
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>`);
return trySend(this.client, channel, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`);
}
const sendThis = {content:sendTheMes, disableMentions:"all"};
if (msg.member?.hasPermission("ADMINISTRATOR")) {
if (msg.member?.hasPermission("MENTION_EVERYONE")) {
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});
const filter = () => true,
collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true});
collector.on('collect', r => {
try {
msg.react(r.emoji);

70
resources/structures.js Normal file
View file

@ -0,0 +1,70 @@
'use strict';
const { Structures } = require("discord.js");
class Settings {
constructor(client, type, id) {
this.client = client;
this.type = type;
this.id = id;
}
get(setting) {
collection(this.type).findOne({ id: this.id })[setting];
}
}
Structures.extend("Guild", Guild => {
return class GuildSettings extends Guild {
constructor(client, data) {
super(client, data);
this.settings = new Settings(client, "Guild", this.id);
}
embed = {
footer: {
text: undefined,
icon: undefined
},
timestamp: false
};
moderation = {
mute: {
role: undefined,
duration: {
date: undefined,
string: undefined
},
log: undefined,
publicLog: undefined
},
ban: {
duration: {
date: undefined,
string: undefined
},
log: undefined,
publicLog: undefined
},
kick: {
log: undefined,
publicLog: undefined
}
}
}
});
Structures.extend("User", User => {
return class Settings extends User {
constructor(client, data) {
super(client, data);
this.settings = new Settings(client, User, this.id);
}
embed = {
footer: {
text: undefined,
icon: undefined
},
timestamp: false
};
}
});