diff --git a/.gitignore b/.gitignore index bbe3211..11e51e6 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ build/Release node_modules/ jspm_packages/ exp/ +cmds/experiment/ # Snowpack dependency directory (https://snowpack.dev/) web_modules/ diff --git a/Main.js b/Main.js index a0c8951..6317c62 100644 --- a/Main.js +++ b/Main.js @@ -52,7 +52,7 @@ client.on("message", async msg => { } if (!msg.guild) { - //console.log(`(${msg.channel.recipient.id}) ${msg.channel.recipient.tag}: (${msg.author.id}) ${msg.author.tag}: ${msg.content}`); + console.log(`(${msg.channel.recipient.id}) ${msg.channel.recipient.tag}: (${msg.author.id}) ${msg.author.tag}: ${msg.content}`); } }); @@ -78,6 +78,6 @@ 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, timestampAt())); +client.on("debug", (...args) => console.log(...args, timestampAt())); client.login(configFile.token); \ No newline at end of file diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index 0734a3c..2e1d69a 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -7,6 +7,38 @@ const col = database.collection("Guild"); const schedule = database.collection("Schedule"); const { scheduler } = require("../../resources/scheduler"); +/*{ + footer: { + text: undefined, + icon: undefined + }, + timestamp: false + }; + { + 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 + } + } +*/ + module.exports = class mute extends commando.Command { constructor(client) { super(client, { @@ -30,7 +62,7 @@ module.exports = class mute extends commando.Command { defaultDurationDoc = muteSettingsDoc?.defaultDuration, infractionsDoc = modDoc?.infractions, args = arg.trim().split(/(?> [--duration -- | --log --]\` to set it up.`); + return trySend(this.clientPermissions, msg, `No mute role configured! Run \`${msg.guild.commandPrefix}${this.name} --settings <--role --> [--duration -- | --log --]\` 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() && !settingDuration) { + 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), @@ -251,8 +283,8 @@ module.exports = class mute extends commando.Command { resultMsg += `Can't find user: **${usermention.trim()}**\n`; } } 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]]>`"); + if (!settingUp && mentions[0].length === 0) { + return trySend(this.client, msg, "Who do you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`. Use `,` to provide more than one user. Use `--` to split arguments.\nExample:```js\n" + `${msg.guild.commandPrefix}${this.name} 832423842785623423, @Shasha#1234, retard wanna get muted, #6969, ^fuck (ur)? .{5}#\\d\\d69$--69y69mo69w420d420h420m420s--Saying "joe"`); } } } diff --git a/cmds/moderation/src/duration.js b/cmds/moderation/src/duration.js new file mode 100644 index 0000000..eb109ab --- /dev/null +++ b/cmds/moderation/src/duration.js @@ -0,0 +1,2 @@ +'use strict'; + diff --git a/cmds/utility/send.js b/cmds/utility/send.js index ed67185..bb6a837 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); const emoteMessage = require("../../resources/emoteMessage"); -const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions"); +const { ranLog, errLog, trySend, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions"); module.exports = class send extends commando.Command { constructor(client) { @@ -48,7 +48,6 @@ module.exports = class send extends commando.Command { sendThis.disableMentions = "none"; } const send = await trySend(this.client, channel, sendThis); - sentAdCheck(send); const filter = () => true, collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); collector.on('collect', r => { diff --git a/resources/functions.js b/resources/functions.js index 2f76ba9..cb15a4a 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -187,7 +187,7 @@ function noPerm(msg) { * @param {MessageOptions} content - ({content:content,optionblabla}) * @returns {Promise} Sent message object */ -async function trySend(client, msg, content) { +async function trySend(client, msg, content, adCheck = true) { //console.log(...content); let msgOf; if (msg?.channel) { @@ -199,6 +199,15 @@ async function trySend(client, msg, content) { msgOf = msg; } } + if (adCheck) { + if (content.content) { + content.content = sentAdCheck(content.content); + } else { + if (typeof content === "string") { + content = sentAdCheck(content); + } + } + } const sentMes = await msgOf.send(content) .catch((e) => { console.error(e); @@ -207,7 +216,6 @@ async function trySend(client, msg, content) { } return }); - sentAdCheck(sentMes); return sentMes; } @@ -234,13 +242,13 @@ function tryReact(msg, reaction) { /** * Check a message sent by client for ads - * @param {Message} sent - Sent message object (await msg.channel.send("discord.gg/banana")) + * @param {String} content - Sent message object (await msg.channel.send("discord.gg/banana")) */ -function sentAdCheck(sent) { - if (sent) { - if (/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/.test(sent.content)) { - let newCont = sent.content.replace(/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/, '`Some invite link goes here`'); - sent.edit(newCont, `Command abuse: Contain server invite link.`); +function sentAdCheck(content) { + if (content.length > 5) { + if (/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/.test(content)) { + let newCont = content.replace(/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/, '`Some invite link goes here`'); + return newCont; } } } diff --git a/resources/scheduler/unmute.js b/resources/scheduler/unmute.js new file mode 100644 index 0000000..0fedcb2 --- /dev/null +++ b/resources/scheduler/unmute.js @@ -0,0 +1,5 @@ +'use strict'; + +require("@iceprod/discord.js-commando"); + +module.exports.unmuteExec = async function () {} \ No newline at end of file diff --git a/resources/shaChat.js b/resources/shaChat.js index daa61fd..f745a4d 100644 --- a/resources/shaChat.js +++ b/resources/shaChat.js @@ -24,7 +24,7 @@ const URL = [ ]; const browser = puppeteer.launch(); const page1 = browser.then(r => r.newPage()); -page1.then(r => r.goto(URL[10]).catch(console.error)); +page1.then(r => r.goto(URL[1]).catch(console.error)); /** * Chat with Shasha @@ -59,7 +59,7 @@ async function shaChat(client, index, question) { */ async function fetchAnswer(page, index) { try { - await page.waitForSelector(`#answer > div:nth-child(${index})`, {timeout:5000}).catch(() => {}); + await page.waitForSelector(`#answer > div:nth-child(${index})`).catch(() => {}); const result = await page.evaluate((index) => { const res = document.querySelector(`#answer > div:nth-child(${index})`).childNodes[4].textContent; return res; diff --git a/resources/structures.js b/resources/structures.js index d89d0d9..701c292 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -45,6 +45,20 @@ Structures.extend("Guild", g => { } } catch (e) { } } + async addInfraction(add) { + try { + const r = await database.collection("Guild").findOne({ document: this.id }); + this.infractions = r?.moderation?.infractions; + const ret = database.collection("Guild").updateOne({document: this.id}, {$push:{"moderation.infractions":add}}, (e, r) => { + if (e) return errLog(e, null, this.client); + if (r) { + this.infractions.push(add); + return true; + }; + }); + return ret; + } catch (e) { } + } setDefaultEmbed(set) { const ret = database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}, (e) => { if (e) return errLog(e, null, this.client);