From 0442ccbe8dd434f4f8364c38c81eeb03c40d18d4 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sat, 5 Jun 2021 18:16:13 +0000 Subject: [PATCH] I'm really questioning life rn --- Main.js | 49 ++++++--- cmds/fun/chat.js | 12 ++- cmds/moderation/eventlog.js | 192 ++++++++++++++++++++++++++++++++++++ cmds/owner/update.js | 18 ++++ cmds/utility/embmaker.js | 58 +++++++++-- cmds/utility/fixchat.js | 24 ----- cmds/utility/send.js | 1 - package.json | 4 +- resources/functions.js | 69 +++++++++---- resources/shaChat.js | 33 ++++--- resources/structures.js | 26 +++-- 11 files changed, 394 insertions(+), 92 deletions(-) create mode 100644 cmds/moderation/eventlog.js create mode 100644 cmds/owner/update.js delete mode 100644 cmds/utility/fixchat.js diff --git a/Main.js b/Main.js index fe66c00..d26a78d 100644 --- a/Main.js +++ b/Main.js @@ -9,9 +9,9 @@ const client = new Commando.Client({ }); const sqlite = require('sqlite'); let configFile = require('./config.json'); -const { errLog, trySend } = require('./resources/functions'); +const { errLog, trySend, noPerm } = require('./resources/functions'); const { join } = require('path'); -//const { chatAnswer } = require("./resources/shaChat"); +const { chatAnswer } = require("./resources/shaChat"); const { timestampAt } = require("./resources/debug"); client.registry @@ -20,7 +20,8 @@ client.registry 'moderation', 'experiment', 'image', - 'fun' + 'fun', + "owner" ]) .registerDefaults() .registerCommandsIn(join(__dirname, 'cmds')); @@ -41,19 +42,43 @@ client.on('ready', async () => { }); client.on("message", async msg => { - if (msg.guild?.dbLoaded === false && !msg.author.bot) { - await msg.guild.dbLoad(); - } if (msg.author.dbLoaded === false && !msg.author.bot) { - await msg.author.dbLoad(); - }/* - if (msg.channel.id === "837178237322919966" && !msg.author.bot && !msg.content.toLowerCase().startsWith(client.commandPrefix+"chat")) { - chatAnswer(client, msg); + msg.author.dbLoad(); + } + if (msg.channel.id === "837178237322919966" && !msg.author.bot && !msg.isCommand) { + msg.channel.startTyping().then(trySend(client, msg, await chatAnswer(msg.cleanContent)) + ).then(msg.channel.stopTyping()).catch(msg.channel.stopTyping()); } 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}`); + } else { + if (/(? { + if (r) { + trySend(client, msg, "YES! <3 <3"); + }; + }) + .catch(noPerm(msg)); + } + } + if (/(dont|don't|no).*giv.*(heart|nick).*(nick|heart)/i.test(msg.content)) { + if (msg.member.displayName?.endsWith(" <3")) { + msg.member.setNickname(msg.member.displayName.slice(0, -3)) + .then(r => { + if (r) { + trySend(client, msg, "okay <3"); + }; + }) + .catch(noPerm(msg)); + } + } + if (msg.guild.dbLoaded === false) { + msg.guild.dbLoad(); + } + } }); client.on("guildMemberRemove", memberLeave => { diff --git a/cmds/fun/chat.js b/cmds/fun/chat.js index 55554c0..7c22ed2 100644 --- a/cmds/fun/chat.js +++ b/cmds/fun/chat.js @@ -1,7 +1,8 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -//const { chatAnswer } = require("../../resources/shaChat"); +const { trySend } = require("../../resources/functions"); +const { chatAnswer } = require("../../resources/shaChat"); module.exports = class chat extends commando.Command { constructor(client) { @@ -13,6 +14,13 @@ module.exports = class chat extends commando.Command { }); } async run(msg) { - //chatAnswer(this.client, msg); + return msg.channel.startTyping().then( + trySend(this.client, msg, await chatAnswer(msg.cleanContent.slice((msg.guild.commandPrefix + msg.command.name).length + 1))).then(r => { + msg.channel.stopTyping(); + return r; + }).catch( + msg.channel.stopTyping() + ) + ); } }; \ No newline at end of file diff --git a/cmds/moderation/eventlog.js b/cmds/moderation/eventlog.js new file mode 100644 index 0000000..3a5b886 --- /dev/null +++ b/cmds/moderation/eventlog.js @@ -0,0 +1,192 @@ +'use strict'; + +const commando = require("@iceprod/discord.js-commando"); +const { getChannelProchedure, trySend, defaultImageEmbed } = require("../../resources/functions"); + +module.exports = class eventlog extends commando.Command { + constructor(client) { + super(client, { + name: "eventlog", + aliases: ["eventlogs"], + memberName: "eventlog", + group: "moderation", + description: "Configure server's Event Log Channels.", + guildOnly: true, + userPermissions: ["MANAGE_GUILD"] + }); + } + async run(msg, arg) { + const set = arg.split(/(? 0 && /(? 0) { + for (const ign of ignoreArgs) { + if (ign.length === 0) { + continue; + } + const chan = getChannelProchedure(this.client, msg, ign); + if (chan) { + if (messagelog.ignore.includes(chan.id)) { + report += "**[MESSAGE_CHANNELIGNORE]** Duplicate result: <#" + chan.id + + `> with keyword: **${ign.trim()}**\n`; + } else { + messagelog.ignore.push(chan.id); + } + } else { + report += "**[MESSAGE_CHANNELIGNORE]** Unknown channel: **" + ign.trim() + "**\n"; + } + } + } + } + } + } + messagelog.channel = getChannelProchedure(this.client, msg, args.slice("messages".length).replace(/(? \`\`\`**Categories:** \`\`\`js\n[MESSAGE [-ignore ], JOINLEAVE, MEMBER, MEMBERROLE, BANUNBAN, GUILD, ROLE, CHANNEL, EMOJI, INVITE]\`\`\``) + .addField(`Message Edit and Delete`, eventChannels?.message?.channel ? `<#${eventChannels?.message.channel}>\n**Ignores:** ${eventChannels?.message?.ignore?.length > 0 ? + "<#" + eventChannels?.message.ignore.join(">, <#") + ">" : "None"}` + : "Not set", true) + .addField(`Member Join and Leave`, eventChannels?.joinLeave ? `<#${eventChannels?.joinLeave}>` : "Not set", true) + .addField(`Member Profile Updates`, eventChannels?.member ? `<#${eventChannels?.member}>` : "Not set", true) + .addField(`Member Role Updates`, eventChannels?.memberRole ? `<#${eventChannels?.memberRole}>` : "Not set", true) + .addField(`Member Ban and Unban`, eventChannels?.banUnban ? `<#${eventChannels?.banUnban}>` : "Not set", true) + .addField(`Server Updates`, eventChannels?.guild ? `<#${eventChannels?.guild}>` : "Not set", true) + .addField(`Server Role Updates`, eventChannels?.role ? `<#${eventChannels?.role}>` : "Not set", true) + .addField(`Server Channels Updates`, eventChannels?.channel ? `<#${eventChannels?.channel}>` : "Not set", true) + .addField(`Server Emoji Updates`, eventChannels?.emote ? `<#${eventChannels?.emote}>` : "Not set", true) + .addField(`Server Invites`, eventChannels?.invite ? `<#${eventChannels?.invite}>` : "Not set", true); + return emb; + } + eventChannels = { + joinLeave: joinleavelog ?? eventChannels?.joinLeave, + channel: channellog ?? eventChannels?.channel, + banUnban: banunbanlog ?? eventChannels?.banUnban, + message: { + channel: messagelog.channel ?? eventChannels?.message?.channel, + ignore: setMessageIgnore ? messagelog.ignore : eventChannels?.message?.ignore + }, + invite: invitelog ?? eventChannels?.invite, + role: rolelog ?? eventChannels?.role, + guild: guildlog ?? eventChannels?.guild, + member: membernicklog ?? eventChannels?.member, + emote: emotelog ?? eventChannels?.emote, + memberRole: memberroleslog ?? eventChannels?.memberRole + } + await msg.guild.setEventChannels(eventChannels); + if (msg.guild.eventChannels === eventChannels) { + report += "Event Log Channels set!\n"; + } + report += "\n**SUMMARY:**"; + if (report.length > 0) { + return trySend(this.client, msg, (await resultEmbed(this)).setDescription(report.slice(0, 2048))); + } + } +}; \ No newline at end of file diff --git a/cmds/owner/update.js b/cmds/owner/update.js new file mode 100644 index 0000000..9f5a8a0 --- /dev/null +++ b/cmds/owner/update.js @@ -0,0 +1,18 @@ +'use strict'; + +const commando = require("@iceprod/discord.js-commando"); + +module.exports = class update extends commando.Command { + constructor(client) { + super(client, { + name: "update", + memberName: "update", + group: "owner", + description: "Update Shasha.", + ownerOnly: true + }); + } + run(msg) { + + } +}; \ No newline at end of file diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index 4354059..df9f2cc 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -13,9 +13,7 @@ module.exports = class embmaker extends commando.Command { aliases: ["embedmaker","createmb","creatembed"], group: "utility", description: "Embed creator.", - details:`Embed creator: You can just copy this template and remove unneeded argument. Every argument is optional.\`\`\`\n--title [text]\n--description [text]\n--author:\n -name [text]\n -icon [url]\n -url [url]\n--color [hex, number, name of color]\n--image [url]\n--thumbnail [url]\n--url [url]\n--newfield:\n -name [text]\n -desc [text]\n -inline (true if provided)\n--footer:\n -text [text]\n -icon [url]\n--content [text]\n--channel [channel_[mention, ID]]\n--timestamp [ISO 8601, UNIX Timestamp (Milliseconds)] - Use https://time.lol \n--attachments [url] - You can put [-copy] when editing to copy all the message attachments (Cannot remove existing attachment unless [--channel] provided) \`\`\`Embed editor: You can put \`\`\`--edit <[message_ID, channel_[mention, ID] message_ID]>\`\`\` as first argument to edit the embed in a message. All existing property will be replaced with provided argument. Put \`\`\`--remove [author, fields, footer]\`\`\` to remove all existing property of the provided argument in the embed.\n\nOther arguments:\`\`\`\n--quote <[message_ID, channel_[mention, ID] message_ID]> - Quote a message\`\`\``, - ownerOnly:false, - hidden:false + details:`Embed creator: You can just copy this template and remove unneeded argument. Every argument is optional.\`\`\`\n--title [text]\n--description [text]\n--author:\n -name [text]\n -icon [url]\n -url [url]\n--color [hex, number, name of color]\n--image [url]\n--thumbnail [url]\n--url [url]\n--newfield:\n -name [text]\n -desc [text]\n -inline (true if provided)\n--footer:\n -text [text]\n -icon [url]\n--content [text]\n--channel [channel_[mention, ID]]\n--timestamp [ISO 8601, UNIX Timestamp (Milliseconds)] - Use https://time.lol \n--attachments [url] - You can put [-copy] when editing to copy all the message attachments (Cannot remove existing attachment unless [--channel] provided) \`\`\`Embed editor: You can put \`\`\`--edit <[message_ID, channel_[mention, ID] message_ID]>\`\`\` as first argument to edit the embed in a message. All existing property will be replaced with provided argument. Put \`\`\`--remove [author, fields, footer]\`\`\` to remove all existing property of the provided argument in the embed.\n\nOther arguments:\`\`\`\n--quote <[message_ID, channel_[mention, ID] message_ID]> - Quote a message\`\`\`` }); } /** @@ -25,6 +23,9 @@ module.exports = class embmaker extends commando.Command { * @returns */ async run(msg, arg) { + if (msg.guild && !this.client.owners.includes(msg.author) && !msg.member.hasPermission("EMBED_LINKS")) { + return trySend(this.client, msg, "LMFAO no"); + } const args = arg.trim().split(/(? 0) { editSrc = await getChannelMessage(this.client, msg, editArg[0], editArg[1]); @@ -72,6 +78,7 @@ module.exports = class embmaker extends commando.Command { } else { reportMessage += "**[EDIT]** No argument provided.\n"; } + continue; } if (value.toLowerCase().startsWith('quote')) { const quoteargs = value.slice('quote'.length).toLowerCase().trim().split(/ +/); @@ -104,6 +111,7 @@ module.exports = class embmaker extends commando.Command { } else { reportMessage += "**[QUOTE]** No argument provided.\n"; } + continue; } if (value.toLowerCase().startsWith('remove')) { const remove = value.slice('remove'.length).toLowerCase().trim().split(/ +/); @@ -123,21 +131,26 @@ module.exports = class embmaker extends commando.Command { embed.footer = null; } } + continue; } if (value.toLowerCase().startsWith('title')) { embed.setTitle(value.slice('title'.length).trim().replace(/\\(?!\\)/g,'')); + continue; } if (value.toLowerCase().startsWith('desc')) { embed.setDescription(value.slice('desc'.length).trim().replace(/\\(?!\\)/g,'')); + continue; } if (value.toLowerCase().startsWith('description')) { embed.setDescription(value.slice('description'.length).trim().replace(/\\(?!\\)/g,'')); + continue; } if (value.toLowerCase().startsWith("author")) { const autData = value.trim().split(/( \-)+/); for(const autVal of autData) { if (autVal.toLowerCase().startsWith('name')) { autName = autVal.slice('name'.length).trim().replace(/\\(?!\\)/g,''); + continue; } if (autVal.toLowerCase().startsWith('icon')) { if (/^https?:\/\/\w+\.\w\w/.test(autVal.slice('icon'.length).trim())) { @@ -146,6 +159,7 @@ module.exports = class embmaker extends commando.Command { reportMessage += "**[AUTHOR]** Invalid icon URL.\n"; autIcon = null; } + continue; } if (autVal.toLowerCase().startsWith('url')) { if (/^https?:\/\/\w+\.\w\w/.test(autVal.slice('url'.length).trim())) { @@ -154,8 +168,10 @@ module.exports = class embmaker extends commando.Command { reportMessage += "**[AUTHOR]** Invalid URL.\n"; autUrl = null; } + continue; } } + continue; } if (value.toLowerCase().startsWith("color")) { const colorName = value.slice("color".length).trim(); @@ -163,6 +179,7 @@ module.exports = class embmaker extends commando.Command { if (color) { embed.setColor(color); } + continue; } if (value.toLowerCase().startsWith("image")) { if (/^https?:\/\/\w+\.\w\w/.test(value.slice("image".length).trim())) { @@ -171,6 +188,7 @@ module.exports = class embmaker extends commando.Command { reportMessage += "**[IMAGE]** Invalid URL.\n"; embed.setImage(null); } + continue; } if (value.toLowerCase().startsWith("thumbnail")) { if (/^https?:\/\/\w+\.\w\w/.test(value.slice("thumbnail".length).trim())) { @@ -179,6 +197,7 @@ module.exports = class embmaker extends commando.Command { reportMessage += "**[THUMBNAIL]** Invalid URL.\n"; embed.setThumbnail(null); } + continue; } if (value.toLowerCase().startsWith('url')) { if (/^https?:\/\/\w+\.\w\w/.test(value.slice("url".length).trim())) { @@ -187,6 +206,7 @@ module.exports = class embmaker extends commando.Command { reportMessage += "**[URL]** Invalid URL.\n"; embed.setURL(null); } + continue; } if (value.toLowerCase().startsWith('attachment')) { const attach = value.slice("attachments".length).trim().split(/ +/); @@ -210,6 +230,7 @@ module.exports = class embmaker extends commando.Command { } } } + continue; } if (value.toLowerCase().startsWith("timestamp")) { if(!/\D/.test(value.slice("timestamp".length).trim())) { @@ -224,6 +245,7 @@ module.exports = class embmaker extends commando.Command { if (!embed.timestamp) { reportMessage += "**[TIMESTAMP]** Invalid format.\n"; } + continue; } if (value.toLowerCase().startsWith('footer')) { const footerData = value.trim().split(/( \-)+/); @@ -240,6 +262,7 @@ module.exports = class embmaker extends commando.Command { } } } + continue; } if (value.toLowerCase().startsWith('newfield')) { const fieldData = value.trim().split(/( \-)+/); @@ -265,9 +288,11 @@ module.exports = class embmaker extends commando.Command { fieldValue = '​'; } embed.addField(fieldName,fieldValue,inline); + continue; } if (value.toLowerCase().startsWith('content')) { content = value.slice('content'.length).trim().replace(/\\(?!\\)/g,''); + continue; } if (value.toLowerCase().startsWith('channel')) { let ID = cleanMentionID(value.slice('channel'.length).trim()); @@ -279,13 +304,21 @@ module.exports = class embmaker extends commando.Command { if (!channel && this.client.owners.includes(msg.author.id)) { channel = this.client.channels.cache.get(ID); } - } else { + } + if (!channel) { channel = findChannelRegEx(msg, ID, ["category", "voice"])[0]; } if (!channel) { reportMessage += "**[CHANNEL]** Unknown channel.\n"; + } else { + const p = msg.guild?.channels.cache.get(channel)?.permissionsFor(msg.author); + if (!p || p.missing("SEND_MESSAGES") || p.missing("EMBED_LINKS") || p.missing("VIEW_CHANNEL")) { + channel = undefined; + reportMessage += "**[CHANNEL]** Missing permission.\n"; + } } } + continue; } } if(autIcon === false) { @@ -315,18 +348,29 @@ module.exports = class embmaker extends commando.Command { if (embed.description === '​' && (content || newAttach.length > 0)) { embed = null; } - if (newAttach.length > 0) { - reportMessage += "**[ATTACHMENT]** Uploading attachments....\n"; - } let sent = []; if (reportMessage.length > 0) { sent.push(trySend(this.client, msg, reportMessage)); } if (editSrc) { if (channel) { + if (msg.guild?.channels.cache.get(channel)?.permissionsFor(msg.author).has("ATTACH_FILES") && newAttach.length > 0) { + reportMessage += "**[ATTACHMENT]** Uploading attachments....\n"; + } else { + if (newAttach.length > 0) { + newAttach = []; + reportMessage += "**[ATTACHMENT]** Missing permission.\n"; + } + } sent.push(channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg))); } else { channel = msg.channel; + if (msg.guild && channel.permissionsFor(msg.author).missing("ATTACH_FILES")) { + if (newAttach.length > 0) { + newAttach = []; + reportMessage += "**[ATTACHMENT]** Missing permission.\n"; + } + } if (editSrc.author === this.client.user) { sent.push(editSrc.edit({content:content,embed:embed,files:newAttach}).catch(e => { errLog(e, msg, this.client); diff --git a/cmds/utility/fixchat.js b/cmds/utility/fixchat.js deleted file mode 100644 index 5f1d975..0000000 --- a/cmds/utility/fixchat.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -const commando = require("@iceprod/discord.js-commando"), -{ fixChat } = require("../../resources/shaChat"); -const { trySend } = require("../../resources/functions"); - -module.exports = class fixchat extends commando.Command { - constructor(client) { - super(client, { - name: "fixchat", - memberName: "fixchat", - group: "utility", - description: "Fix broken chat." - }); - } - async run(msg) { - //const r = await fixChat(); - if (r === 3) { - return trySend(this.client, msg, "Fixed!"); - } else { - return trySend(this.client, msg, "Oopsie somethin's wrong..."); - } - } -}; \ No newline at end of file diff --git a/cmds/utility/send.js b/cmds/utility/send.js index 10694b6..6bc4c50 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -15,7 +15,6 @@ module.exports = class send extends commando.Command { } async run(msg, args ) { const comarg = args.trim().split(/ +/); - let at = comarg[0]; if (!comarg[0]) { return trySend(this.client, msg, 'Where?!?'); } diff --git a/package.json b/package.json index 35429db..e5262a9 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "dependencies": { "@iceprod/discord.js-commando": "^0.14.3", + "axios": "^0.21.1", "bree": "^6.2.0", "bufferutil": "^4.0.3", "cabin": "^9.0.4", - "cleverbot-node": "^0.3.11", "discord.js": "^12.5.2", "discord.js-commando": "^0.12.3", "erlpack": "github:discord/erlpack", @@ -12,8 +12,6 @@ "lodash": "^4.17.21", "mongodb": "^3.6.6", "node": "^15.12.0", - "node-fetch": "^2.6.1", - "puppeteer": "^9.0.0", "sqlite": "^4.0.21", "sqlite3": "^5.0.2", "utf-8-validate": "^5.0.4", diff --git a/resources/functions.js b/resources/functions.js index dbde6ec..9407ad7 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -1,6 +1,6 @@ 'use strict'; -const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, Channel } = require('discord.js'); +const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, TextChannel, DMChannel } = require('discord.js'); const { defaultErrorLogChannel, ranLogger } = require("../config.json"); const { database } = require("../database/mongo"); const { timestampAt } = require('./debug'); @@ -172,26 +172,25 @@ function noPerm(msg) { /** * Send message - * @param {Client} client - (this.client) - * @param {Message | String | Channel} msg Message object | channel_ID + * @param {CommandoClient} client - (this.client) + * @param {Message | String | TextChannel | DMChannel} msg Message object | channel_ID * @param {MessageOptions} content - ({content:content,optionblabla}) * @param {Boolean} adCheck - Check source for Discord invite link (true) * @returns {Promise} Sent message object */ -async function trySend(client, msg, content, adCheck = true) { +function trySend(client, msg, content, adCheck = true) { if (!client || !msg) { return; } - let msgOf; - if (msg?.channel) { - msgOf = msg.channel; - } else { - if (typeof msg === "string") { - msgOf = client.channels.cache.get(msg); - } else { - msgOf = msg; + if (client.owners.includes(msg.author)) { + adCheck = false; + if (content.disableMentions) { + content.disableMentions = "none"; } } + if (typeof msg === "string") { + msg = client.channels.cache.get(msg); + } if (adCheck) { if (content.content) { content.content = sentAdCheck(content.content); @@ -201,15 +200,15 @@ async function trySend(client, msg, content, adCheck = true) { } } } - const sentMes = await msgOf.send(content) - .catch((e) => { - console.error(e); - if (msg?.channel) { - noPerm(msg); + if (msg instanceof Message) { + return msg.channel.send(content).catch(() => {}); + } else { + if (msg instanceof TextChannel || msg instanceof DMChannel) { + return msg.send(content).catch(() => {}); + } else { + console.error("[TRYSEND] Unknown {msg} type.", msg); } - return - }); - return sentMes; + } } /** @@ -403,6 +402,34 @@ function multipleChannelsFound(client, msg, arr, key, max = 4, withID) { } } +/** + * Standard + * @param {Client} client this.client + * @param {Message} msg - Message object + * @param {String} key - Channel ID | Mention | Name + * @returns + */ +function getChannelProchedure(client, msg, key) { + if (key.length === 0) { + return; + } + const search = cleanMentionID(key); + if (search.length === 0) { + return; + } + let channel; + if (/^\d{17,19}$/.test(search)) { + channel = msg.guild.channels.cache.get(search); + if (!channel && client.owners.includes(msg.author)) { + channel = client.channels.cache.get(search); + } + } + if (!channel) { + channel = findChannelRegEx(msg, search, ["category", "voice"])[0]; + } + return channel; +} + module.exports = { cleanMentionID, multipleMembersFound, multipleRolesFound, multipleChannelsFound, @@ -410,5 +437,5 @@ module.exports = { getChannelMessage, errLog, execCB, ranLog, noPerm, trySend, tryDelete, tryReact, - sentAdCheck, defaultImageEmbed + sentAdCheck, defaultImageEmbed, getChannelProchedure } \ No newline at end of file diff --git a/resources/shaChat.js b/resources/shaChat.js index 9d6a169..5d0ab34 100644 --- a/resources/shaChat.js +++ b/resources/shaChat.js @@ -1,12 +1,13 @@ 'use strict'; -const puppeteer = require('puppeteer'); -const { trySend, noPerm } = require('./functions'); +//const puppeteer = require('puppeteer'); +const axios = require("axios").default; +const { errLog } = require('./functions'); const Commando = require("@iceprod/discord.js-commando"); -require("discord.js"); +//require("discord.js"); //'4, 15, 10, 11, 14, 17, 18' - +/* const URL = [ 'https://rebot.me/simsimi', 'https://rebot.me/ryuko-matoi',//1 'https://rebot.me/xmonikax', 'https://rebot.me/futa-nun',//3 @@ -20,7 +21,7 @@ const URL = [ 'https://rebot.me/zacharie-1', 'https://rebot.me/natsuki-41',//19 'https://rebot.me/lea-7062078', 'https://rebot.me/bunny-exe',//21 'https://rebot.me/just-monika-56' -]; +];/* const browser = puppeteer.launch(); const page1 = browser.then(r => r.newPage()); page1.then(r => r.goto(URL[1]).catch(console.error)); @@ -31,7 +32,7 @@ page1.then(r => r.goto(URL[1]).catch(console.error)); * @param {Number} index - Index of answer * @param {Commando.Message} question - Message object * @returns {Promise} Reply - */ + * async function shaChat(client, index, question) { if (page1) { let query = question.content.trim(); @@ -55,7 +56,7 @@ async function shaChat(client, index, question) { * @param {puppeteer.Page} page * @param {Number} index * @returns {String} - */ + * async function fetchAnswer(page, index) { try { await page.waitForSelector(`#answer > div:nth-child(${index})`).catch(() => {}); @@ -70,13 +71,15 @@ async function fetchAnswer(page, index) { } let chatIndex = 3; - +*/ /** - * @param {Commando.Client} client - * @param {Commando.CommandoMessage} message - * @returns + * @param {String} message - Query + * @returns {Promise} Answers */ - async function chatAnswer(client, message) { + async function chatAnswer(message) { + const r = await axios.post("https://rebot.me/ask", { username: "muffin-6", question: message }).catch(() => {}); + return r.data; + } /* { //console.log(message.content); //console.log(chatIndex); if (message.content.trim().length === 0) { @@ -106,10 +109,10 @@ let chatIndex = 3; message.channel.stopTyping(); } } -} +} async function fixChat() { return page1.then(r => r.reload()).then(() => {return chatIndex = 3}).catch(e => {return console.log(e)}); -} +} */ -module.exports = { chatAnswer, fixChat } +module.exports = { chatAnswer } diff --git a/resources/structures.js b/resources/structures.js index 701c292..6ef66db 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -1,8 +1,8 @@ 'use strict'; const { Structures } = require("discord.js"), -{ database } = require("../database/mongo"); -const { errLog } = require("./functions"); +{ database } = require("../database/mongo"), +{ errLog } = require("./functions"); Structures.extend("Guild", g => { return class Guild extends g { @@ -16,6 +16,9 @@ Structures.extend("Guild", g => { this.infractions = r?.moderation?.infractions; this.moderation = r?.moderation?.settings; this.defaultEmbed = r?.settings?.defaultEmbed; + + this.eventChannels = r?.settings?.eventChannels; + return this.dbLoaded = true; }); return ret; @@ -42,6 +45,8 @@ Structures.extend("Guild", g => { if (found.length > 0) { return found; } + } else { + return; } } catch (e) { } } @@ -49,16 +54,22 @@ Structures.extend("Guild", g => { 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) => { + const ret = database.collection("Guild").updateOne({document: this.id}, {$push:{"moderation.infractions":add}}, (e) => { if (e) return errLog(e, null, this.client); - if (r) { - this.infractions.push(add); - return true; - }; + this.infractions.push(add); + return true; }); return ret; } catch (e) { } } + setEventChannels(set) { + const ret = database.collection("Guild").updateOne({document: this.id}, {$set: {"settings.eventChannels": set}}, {upsert: true}, (e) => { + if (e) return errLog(e, null, this.client); + this.eventChannels = set; + return true; + }); + return ret; + } 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); @@ -83,6 +94,7 @@ Structures.extend("User", u => { constructor(client, data) { super(client, data); this.dbLoaded = false; + this.giveHeart = "yes"; } async dbLoad() { const ret = await database.collection("User").findOne({document: this.id}).then((r, j) => {