diff --git a/Main.js b/Main.js index f308ecf..ae63f6e 100644 --- a/Main.js +++ b/Main.js @@ -16,7 +16,7 @@ if (process.argv.includes("-d")) { const sqlite = require('sqlite'); const configFile = require('./config.json'); -const { errLog, trySend, noPerm, getUTCComparison, defaultEventLogEmbed } = require('./resources/functions'); +const { errLog, trySend, noPerm, getUTCComparison, defaultEventLogEmbed, getChannel } = require('./resources/functions'); const { join } = require('path'); const getColor = require("./resources/getColor"); const { timestampAt } = require("./resources/debug"); @@ -102,6 +102,10 @@ client.on("guildMemberAdd", async (member) => { lgr.guildMemberAdd(member); }); +client.on("guildBanAdd", async (GUILD, USER) => { + lgr.guildBanAdd(GUILD, USER); +}); + client.on("messageDelete", async (msg) => { if (msg.author && !msg.author.dbLoaded && !msg.author.bot) await msg.author.dbLoad(); if (msg.guild) { diff --git a/cmds/owner/eval.js b/cmds/owner/eval.js index 895bc94..2074e33 100644 --- a/cmds/owner/eval.js +++ b/cmds/owner/eval.js @@ -16,6 +16,7 @@ module.exports = class EvalCommand extends Command { description: 'Executes JavaScript code.', details: 'Only the bot owner(s) may use this command.', ownerOnly: true, + hidden: true, args: [ { @@ -30,7 +31,7 @@ module.exports = class EvalCommand extends Command { Object.defineProperty(this, '_sensitivePattern', { value: null, configurable: true }); } - run(msg, args) { + async run(msg, args) { // Make a bunch of helpers /* eslint-disable no-unused-vars */ const message = msg; @@ -59,7 +60,7 @@ module.exports = class EvalCommand extends Command { let hrDiff; try { const hrStart = process.hrtime(); - this.lastResult = eval(args.script); + this.lastResult = await eval(args.script); hrDiff = process.hrtime(hrStart); } catch (err) { return msg.reply(`Error while evaluating: \`${err}\``); diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index 8b5a92d..ee4156d 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -319,20 +319,16 @@ module.exports = class embmaker extends commando.Command { } if (value.startsWith("ch ")) { let ID = cleanMentionID(value.slice("ch ".length).trim()); - if (ID === "here") { - channel = msg.channel; + channel = getChannel(msg, ID, ["category", "voice"]) + if (!channel) { + reportMessage += "**[CHANNEL]** Unknown channel.\n"; } else { - channel = getChannel(msg, ID, ["category", "voice"]) - if (!channel) { - reportMessage += "**[CHANNEL]** Unknown channel.\n"; - } else { - if ((channel instanceof GuildChannel) && !this.client.owners.includes(msg.author)) { - const p = channel.permissionsFor(msg.author).serialize(), - f = channel.permissionsFor(this.client.user).serialize(); - if (!p.EMBED_LINKS || !p.SEND_MESSAGES || !p.VIEW_CHANNEL || !f.EMBED_LINKS || !f.SEND_MESSAGES) { - channel = undefined; - reportMessage += "**[CHANNEL]** Missing permission.\n"; - } + if ((channel instanceof GuildChannel) && !this.client.owners.includes(msg.author)) { + const p = channel.permissionsFor(msg.author).serialize(), + f = channel.permissionsFor(this.client.user).serialize(); + if (!p.EMBED_LINKS || !p.SEND_MESSAGES || !p.VIEW_CHANNEL || !f.EMBED_LINKS || !f.SEND_MESSAGES) { + channel = undefined; + reportMessage += "**[CHANNEL]** Missing permission.\n"; } } } diff --git a/cmds/utility/perms.js b/cmds/utility/perms.js index c2ae9ba..df5fa50 100644 --- a/cmds/utility/perms.js +++ b/cmds/utility/perms.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"), -{ getMember, trySend, defaultImageEmbed, getChannel } = require("../../resources/functions"); + { getMember, trySend, defaultImageEmbed, getChannel } = require("../../resources/functions"); const { Message, GuildChannel } = require("discord.js"); const getColor = require("../../resources/getColor"); @@ -28,17 +28,13 @@ module.exports = class perms extends commando.Command { const forC = arg.match(/(? 0) { member = getMember(msg.guild, find)?.[0]; } else { @@ -46,7 +42,7 @@ module.exports = class perms extends commando.Command { } } else { member = msg.member; - mes += `Args:\n\`user_[mention|ID|name]\` \`--c\` \`[channel_[name|ID]|here]\`\n`; + mes += `Args:\n\`user_[mention|ID|name]\` \`--ch\` \`[channel_[name|ID]|here]\`\n\n`; } if (!member) { return trySend(this.client, msg, "Is that your gf?"); @@ -80,8 +76,8 @@ module.exports = class perms extends commando.Command { emb.addField(`In channel: \`${channel.name}\``, `\`\`\`js\n${chanres.join(", ")}\`\`\``); } emb.setDescription(mes) - .setColor(getColor(member.displayColor)) - .setThumbnail(member.user.displayAvatarURL({size: 4096, format: "png", dynamic: true})); + .setColor(getColor(member.displayColor)) + .setThumbnail(member.user.displayAvatarURL({ size: 4096, format: "png", dynamic: true })); return trySend(this.client, msg, emb); } }; \ No newline at end of file diff --git a/resources/eventsLogger/guildBanAdd.js b/resources/eventsLogger/guildBanAdd.js new file mode 100644 index 0000000..98856d0 --- /dev/null +++ b/resources/eventsLogger/guildBanAdd.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = async (GUILD, USER) => { + if (GUILD.eventChannels?.ban) { + if (USER.partial) USER = await USER.fetch(); + const log = getChannel(GUILD, GUILD.eventChannels.ban); + if (!log) return; + const emb = defaultEventLogEmbed(GUILD); + const rea = (await GUILD.fetchBan(USER)).reason; + emb.setDescription(rea ?? "No reason provided.") + .setTitle(`User \`${USER.tag}\` banned`) + .setColor(getColor("red")) + .setThumbnail(USER.displayAvatarURL({ size: 4096, format: "png", dynamic: true })) + .addField("User", `<@${USER.id}>\n(${USER.id})`); + return trySend(GUILD.client, log, emb); + } +} \ No newline at end of file diff --git a/resources/eventsLogger/guildMemberRemove.js b/resources/eventsLogger/guildMemberRemove.js index 5508b74..985efaa 100644 --- a/resources/eventsLogger/guildMemberRemove.js +++ b/resources/eventsLogger/guildMemberRemove.js @@ -1,7 +1,7 @@ 'use strict'; const { GuildMember } = require("discord.js"); -const { getChannel, defaultEventLogEmbed, trySend } = require("../functions"); +const { getChannel, defaultEventLogEmbed, trySend, splitOnLength } = require("../functions"); const getColor = require("../getColor"); /** @@ -15,14 +15,19 @@ module.exports = (member) => { if (!log) return; const days = Math.floor(new Date(new Date().valueOf() + member.client.matchTimestamp - member.joinedAt.valueOf()).valueOf() / 86400000), emb = defaultEventLogEmbed(member.guild); + const RO = member.roles.cache.sort((a, b) => b.position - a.position).map(r => r.id).slice(0, -1), + RU = splitOnLength(RO, 1010, ">, <@&"); emb .setTitle("Member `" + member.user.tag + "` left") .setThumbnail(member.user.displayAvatarURL({ format: "png", size: 4096, dynamic: true })) .setColor(getColor("yellow")) .addField("Registered", "**" + member.user.createdAt.toUTCString().slice(0, -4) + "**", true) .addField("Joined", "**" + member.joinedAt.toUTCString().slice(0, -4) + "**" + `\n(${days > 0 ? `${days} day${days > 1 ? "s" : ""} ago` : "Today"})`, true) - .addField("Roles", member.roles.cache.size > 1 ? "<@&" + member.roles.cache.sort((a, b) => b.position - a.position).map(r => r.id).slice(0, -1).join(">, <@&") + ">" : "`[NONE]`") + .addField("Nick", "`" + member.displayName + "`") .setDescription(`<@!${member.id}> (${member.id}) just left.\nWe have ${member.guild.memberCount} total members now.`); + for (const U of RU) { + emb.addField(emb.fields.length === 3 ? "Roles" : "", U.length > 0 ? "<@&" + U.join(">, <@&") + ">" : "`[NONE]`"); + } return trySend(member.client, log, emb); } } \ No newline at end of file diff --git a/resources/functions.js b/resources/functions.js index d9ecce4..0ad3ff5 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -366,6 +366,7 @@ function getChannel(msg, key, exclude) { if (!key || key.length === 0 || !msg) return; const search = cleanMentionID(key); if (search.length === 0) return; + if ((msg instanceof Message) && search === "here") return msg.channel; let channel; if (/^\d{17,19}$/.test(search)) { channel = (msg.guild || msg).channels.cache.get(search); @@ -382,10 +383,10 @@ function getChannel(msg, key, exclude) { * @returns {GuildMember[]} */ function getMember(guild, key) { - if (!guild) return; + if (!(guild || key)) return; const use = cleanMentionID(key); - let found = []; if (!use || use.length === 0) return; + let found = []; if (/^\d{17,19}$/.test(use)) { found.push(guild.member(use)); } else { @@ -476,10 +477,9 @@ const reValidURL = /^https?:\/\/\w+\.\w\w/; function getUser(msg, key) { if (!(msg || key)) return; const use = cleanMentionID(key); + if (!use || use.length === 0) return; let u; - if (/^\d{17,19}$/.test(use)) u = msg.client.users.cache.get(use); - console.log(u); - if (!u) u = getMember(msg.guild, use)?.[0].user; + if (/^\d{17,19}$/.test(use)) u = msg.client.users.cache.get(use); else u = getMember(msg.guild, use)?.[0].user; return u; } diff --git a/resources/shaChat.js b/resources/shaChat.js index 25942ae..7e907ff 100644 --- a/resources/shaChat.js +++ b/resources/shaChat.js @@ -1,6 +1,7 @@ 'use strict'; -const axios = require("axios").default; +const axios = require("axios").default, + U = ["Yo", "Yyo", "Hello my friend", "Hey cutie <3", "What", "Wat", "Watchu want", "Hewwo", "UwU hwee", "OwO whats this", "Yoooooooooo", "Supp", "Whats good mein frien", "Iyo", "Hows doin", "Wassup", "Whats good", "Wanna chat?"]; //'4, 15, 10, 11, 14, 17, 18' @@ -29,7 +30,7 @@ async function chatAnswer(message) { text: u, lang: "en" } - }).then(r => r.data.success.replace(/Sim doesn't know what you are talking about. Please teach me/, "Sorry but i don't speak gibberish")).catch(() => { }); + }).then(r => r.data.success.replace(/Sim doesn't know what you are talking about. Please teach me/, "Sorry but i don't speak gibberish").replace(/kemon acho babu/, U[Math.floor(Math.random() * U.length)])).catch(() => { }); } module.exports = { chatAnswer } diff --git a/resources/structures.js b/resources/structures.js index b5ad55f..4427c1d 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -196,4 +196,16 @@ Structures.extend("Message", e => { this.previousMessageID = channel.lastMessageID; }; } -}); \ No newline at end of file +}); + +Structures.extend("GuildMember", e => { + return class GuildMember extends e { + constructor(client, data, guild) { + super(client, data, guild); + } + + async getInfractions() { + return this.guild.getInfractions(this.id); + } + } +}) \ No newline at end of file diff --git a/resources/tCmd.js b/resources/tCmd.js index 35af304..9334b5e 100644 --- a/resources/tCmd.js +++ b/resources/tCmd.js @@ -4,7 +4,7 @@ const { join } = require("path"); const requireAll = require("require-all"); module.exports = (client) => { - client.tCmds = requireAll({dirname: join(__dirname, "tCmds")}); + client.tCmds = requireAll({ dirname: join(__dirname, "tCmds") }); delete client.tCmds.resources; process.stdin.on("data", stdinBuffer => { // console.log(stdinBuffer.toJSON().data[0]);