From 56d1d6b63e5b1ba0881a3c2894d1ec3b4f60a1a1 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 00:01:17 +0300 Subject: [PATCH 01/14] some lang bs --- language/languages/en_us/commands/en_us_information.lang | 3 +++ language/languages/en_us/en_us_general.lang | 3 +++ 2 files changed, 6 insertions(+) diff --git a/language/languages/en_us/commands/en_us_information.lang b/language/languages/en_us/commands/en_us_information.lang index a0d4a1f..6999718 100644 --- a/language/languages/en_us/commands/en_us_information.lang +++ b/language/languages/en_us/commands/en_us_information.lang @@ -61,8 +61,11 @@ View data about the server. **Owner:** <@{owner}> **Member count:** {members} +**Boost tier:** {tier} +**Boosters:** {boosters} **Date created:** {createdAt} **Server ID:** {id} +**Shard ID:** {shard} **Channels:** Text {tc} / Voice {vc} **Server voice region:** {region} diff --git a/language/languages/en_us/en_us_general.lang b/language/languages/en_us/en_us_general.lang index 8cdeb88..e85143d 100644 --- a/language/languages/en_us/en_us_general.lang +++ b/language/languages/en_us/en_us_general.lang @@ -154,6 +154,9 @@ The command **{command}** can only be run by developers. The command **{command}** is currently throttled. *You can use this command again in `{remaining}` seconds.* +[I_CHANNELIGNORE_ERROR] +This channel is ignored by the bot, this should not be sending. + //Moderation Manager [MODERATIONMANAGER_INFRACTION_MAXTARGETS] You can only specify up to `{maxTargets}` unique {type}s, try again. From a3cbe75fedd1c04043aee5c06efb57ed415a9b3c Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 00:01:58 +0300 Subject: [PATCH 02/14] setting priorities straight --- structure/client/Dispatcher.js | 2 +- structure/client/components/observers/CommandHandler.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/structure/client/Dispatcher.js b/structure/client/Dispatcher.js index 4e766ab..de95795 100644 --- a/structure/client/Dispatcher.js +++ b/structure/client/Dispatcher.js @@ -10,7 +10,7 @@ class Dispatcher { const observers = this.client.registry.components .filter((c) => c.type === 'observer' && !c.disabled) - .sort((a, b) => b.priority - a.priority); + .sort((a, b) => a.priority - b.priority); for(const observer of observers.values()) { for(const [hook, func] of observer.hooks) { diff --git a/structure/client/components/observers/CommandHandler.js b/structure/client/components/observers/CommandHandler.js index 4f36a61..c2453d9 100644 --- a/structure/client/components/observers/CommandHandler.js +++ b/structure/client/components/observers/CommandHandler.js @@ -366,6 +366,7 @@ class CommandHandler extends Observer { async handleCommand(message) { const inhibitor = await this._handleInhibitors(message); + //console.log(inhibitor); if(inhibitor.error) return this.handleError(message, { type: 'inhibitor', ...inhibitor }); const resolved = await message.resolve(); @@ -396,7 +397,7 @@ class CommandHandler extends Observer { const reasons = (await Promise.all(promises)).filter((p) => p.error); // Filters out inhibitors with only errors. if(reasons.length === 0) return { error: false }; - reasons.sort((a, b) => b.inhibitor.priority - a.inhibitor.priority); // Sorts inhibitor errors by most important. + reasons.sort((a, b) => a.inhibitor.priority - b.inhibitor.priority); // Sorts inhibitor errors by most important. return reasons[0]; } @@ -553,7 +554,8 @@ class CommandHandler extends Observer { } }; - return message.respond(await messages[error.type](error), { emoji: 'failure' }); + //return this.client.rateLimiter.limitSend(message.channel, await messages[error.type](error)); + return message.limitedRespond(await messages[error.type](error), { emoji: 'failure' }); } From 1384860bd5568882a8b2c06e1cbc46654c4df506 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 00:02:16 +0300 Subject: [PATCH 03/14] move to info cat --- .../commands/{utility => information}/Guild.js | 9 ++++++--- .../components/commands/{utility => information}/User.js | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) rename structure/client/components/commands/{utility => information}/Guild.js (81%) rename structure/client/components/commands/{utility => information}/User.js (97%) diff --git a/structure/client/components/commands/utility/Guild.js b/structure/client/components/commands/information/Guild.js similarity index 81% rename from structure/client/components/commands/utility/Guild.js rename to structure/client/components/commands/information/Guild.js index 0d986a7..442b17c 100644 --- a/structure/client/components/commands/utility/Guild.js +++ b/structure/client/components/commands/information/Guild.js @@ -1,4 +1,4 @@ -const { Command } = require('../../../../interfaces/'); +const { Command } = require('../../../../interfaces'); class GuildCommand extends Command { @@ -6,7 +6,7 @@ class GuildCommand extends Command { super(client, { name: 'guild', - module: 'utility', + module: 'information', aliases: [ 'server' ] @@ -40,7 +40,10 @@ class GuildCommand extends Command { id: guild.id, name: guild.name, region: guild.region, - members: guild.memberCount + members: guild.memberCount, + boosters: guild.premiumSubscriptionCount, + tier: guild.premiumTier, + shard: guild.shardID }), thumbnail: { url: guild.iconURL() diff --git a/structure/client/components/commands/utility/User.js b/structure/client/components/commands/information/User.js similarity index 97% rename from structure/client/components/commands/utility/User.js rename to structure/client/components/commands/information/User.js index a6bfdd9..ffff713 100644 --- a/structure/client/components/commands/utility/User.js +++ b/structure/client/components/commands/information/User.js @@ -1,4 +1,4 @@ -const { Command } = require('../../../../interfaces/'); +const { Command } = require('../../../../interfaces'); const similarity = require('similarity'); class UserCommand extends Command { @@ -7,7 +7,7 @@ class UserCommand extends Command { super(client, { name: 'user', - module: 'utility', + module: 'information', description: 'Display information about user.', guildOnly: true, arguments: [ From ffa5128af2cc480a2b843388c5b1128532344592 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 00:02:30 +0300 Subject: [PATCH 04/14] channel ignoring inhibitor --- .../components/inhibitors/ChannelIgnore.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 structure/client/components/inhibitors/ChannelIgnore.js diff --git a/structure/client/components/inhibitors/ChannelIgnore.js b/structure/client/components/inhibitors/ChannelIgnore.js new file mode 100644 index 0000000..97ddae3 --- /dev/null +++ b/structure/client/components/inhibitors/ChannelIgnore.js @@ -0,0 +1,35 @@ +const { Inhibitor } = require('../../../interfaces/'); + +class ChannelIgnore extends Inhibitor { + + constructor(client) { + + super(client, { + name: 'channelIgnore', + priority: 5, + guild: true + }); + + } + + execute(message, command) { + + if(message.member.admin) return super._succeed(); + + const { guild, member, channel } = message, + setting = guild._settings.ignore, + roles = member._roles; + + if(!setting.enabled) return super._succeed(); + if(setting.channels.includes(channel.id)) + for(const role of roles) { + if(setting.roleBypass.includes(role)) return super._succeed(); + return super._fail({ error: true, silent: true }); + } + return super._succeed(); + + } + +} + +module.exports = ChannelIgnore; \ No newline at end of file From 771f7c68753082149a6485d54b7cec652d077c70 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 00:02:59 +0300 Subject: [PATCH 05/14] cleanup --- structure/client/components/inhibitors/Restricted.js | 2 +- structure/extensions/GuildMember.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/structure/client/components/inhibitors/Restricted.js b/structure/client/components/inhibitors/Restricted.js index 12a89ce..b1cef87 100644 --- a/structure/client/components/inhibitors/Restricted.js +++ b/structure/client/components/inhibitors/Restricted.js @@ -13,7 +13,7 @@ class Restricted extends Inhibitor { } execute(message, command) { - if(command.restricted && !this.client._options.bot.owners.includes(message.author.id)) { + if(command.restricted && !message.author.developer) { return super._fail(); } return super._succeed(); diff --git a/structure/extensions/GuildMember.js b/structure/extensions/GuildMember.js index ca5f6ea..f63e365 100644 --- a/structure/extensions/GuildMember.js +++ b/structure/extensions/GuildMember.js @@ -32,6 +32,10 @@ const GuildMember = Structures.extend('GuildMember', (GuildMember) => { } + get admin() { + return this.user.developer || this.hasPermission('ADMINISTRATOR') || this.hasPermission('MANAGE_GUILD'); + } + get timeSinceCached() { return Date.now()-this._cached; } From 57fe0be1c8cc8325a5200d11deb402b0959191ff Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 00:03:09 +0300 Subject: [PATCH 06/14] limitedResponse --- structure/extensions/Message.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/structure/extensions/Message.js b/structure/extensions/Message.js index c76fbe6..74dcef1 100644 --- a/structure/extensions/Message.js +++ b/structure/extensions/Message.js @@ -1,7 +1,6 @@ const { Structures } = require('discord.js'); const escapeRegex = require('escape-string-regexp'); -const emojis = require('../../util/emojis.json'); const { Util, Emojis } = require('../../util/'); const { stripIndents } = require('common-tags') @@ -88,7 +87,7 @@ const Message = Structures.extend('Message', (Message) => { if(typeof str === 'string') { if(opts.emoji) { - const emoji = emojis[opts.emoji]; + const emoji = Emojis[opts.emoji]; if(!emoji) this.command.client.logger.warn(`Invalid emoji provided to command ${this.command.resolveable}: "${opts.emoji}".`); str = `${emoji} ${str}`; } @@ -101,10 +100,25 @@ const Message = Structures.extend('Message', (Message) => { } + async limitedRespond(str, opts = { attachments: [] }) { + + if(typeof str === 'string') { + if(opts.emoji) { + const emoji = Emojis[opts.emoji]; + if(!emoji) this.client.logger.warn(`Invalid emoji provided to command ${this.command.resolveable}: "${opts.emoji}".`); + str = `${emoji} ${str}`; + } + if(opts.reply) str = `<@!${this.author.id}> ${str}`; + } + + return this.client.rateLimiter.limitSend(this.channel, str, opts.limit, opts.utility); + + } + async edit(str, opts) { if(!this.editable) return null; if(typeof str === 'string') { - if(opts.emoji) str = `${emojis[opts.emoji]} ${str}`; + if(opts.emoji) str = `${Emojis[opts.emoji]} ${str}`; if(opts.reply) str = `<@!${this.author.id}> ${str}`; } return super.edit(str); @@ -112,7 +126,7 @@ const Message = Structures.extend('Message', (Message) => { async prompt(str, opts) { if(typeof str === 'string') { - if(opts.emoji) str = `${emojis[opts.emoji]} ${str}`; + if(opts.emoji) str = `${Emojis[opts.emoji]} ${str}`; if(opts.reply) str = `<@!${this.author.id}> ${str}`; } await this.channel.send(str); From b6bbfbd115c5370d1b7eac08638a1f55942a11fe Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:25:43 +0300 Subject: [PATCH 07/14] more lang stuff --- .../en_us/settings/en_us_moderation.lang | 9 +++++++++ .../en_us/settings/en_us_utility.lang | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/language/languages/en_us/settings/en_us_moderation.lang b/language/languages/en_us/settings/en_us_moderation.lang index e0d54b8..486cd77 100644 --- a/language/languages/en_us/settings/en_us_moderation.lang +++ b/language/languages/en_us/settings/en_us_moderation.lang @@ -105,6 +105,15 @@ Successfully set member nicknames to log to {emoji_text-channel}**{changed}**. [S_MEMBERLOG_DESCRIPTION] Configure member logging for your server. +**Usable tags:** +{mention} - mentions the user +{tag} - username#discriminator +{user} - username +{guildsize} - member count of the server +{guildname} - name of the server +{accage} - age of the account +{id} - ID of the account + [S_MEMBERLOGS_TOGGLE] Successfully turned member logging **{changed}**. diff --git a/language/languages/en_us/settings/en_us_utility.lang b/language/languages/en_us/settings/en_us_utility.lang index 04538b0..a1512e3 100644 --- a/language/languages/en_us/settings/en_us_utility.lang +++ b/language/languages/en_us/settings/en_us_utility.lang @@ -14,6 +14,26 @@ Successfully set the guild description to [S_INDEX_TOGGLE] Successfully toggled guild indexing `{toggle}` +//GUILD WELCOMER +[S_WELCOMER_DESCRIPTION] +Configure a message that is sent to new members upon join. + +**Usable tags:** +{mention} - mentions the user +{tag} - username#discriminator +{user} - username +{guildsize} - member count of the server +{guildname} - name of the server +{accage} - age of the account +{id} - ID of the account + +[S_WELCOMER_TOGGLE] +Successfully toggled the welcomer `{toggle}`. + +[S_WELCOMER_SET] +Successfully set the welcomer message to +`{change}` + //guildPrefix Setting [S_GUILDPREFIX_DESCRIPTION] From 84cfa7696ceab489ebbdfb6d2fc1b7592af13c99 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:26:02 +0300 Subject: [PATCH 08/14] another reset term --- structure/client/Resolver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structure/client/Resolver.js b/structure/client/Resolver.js index f8fad3c..f2d0d6c 100644 --- a/structure/client/Resolver.js +++ b/structure/client/Resolver.js @@ -80,7 +80,7 @@ class Resolver { add: ['add', '+'], set: ['set', '='], remove: ['remove', 'delete', '-'], - reset: ['clear', 'reset'], + reset: ['clear', 'reset', 'default'], off: ['off', 'disable', 'false', 'no', 'n', 'f'], on: ['on', 'enable', 'true', 'yes', 'y', 't'] }; From f9f43b233f113983b04ff76e9b62d1e2faafa96a Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:26:59 +0300 Subject: [PATCH 09/14] differentiated different responses in respond --- structure/client/components/observers/CommandHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structure/client/components/observers/CommandHandler.js b/structure/client/components/observers/CommandHandler.js index c2453d9..9f4dc66 100644 --- a/structure/client/components/observers/CommandHandler.js +++ b/structure/client/components/observers/CommandHandler.js @@ -555,7 +555,7 @@ class CommandHandler extends Observer { }; //return this.client.rateLimiter.limitSend(message.channel, await messages[error.type](error)); - return message.limitedRespond(await messages[error.type](error), { emoji: 'failure' }); + return message.limitedRespond(await messages[error.type](error), { emoji: 'failure', limit: 10, utility: error.type }); } From 46b374f2bb622260b7641051892abc13c4185ced Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:27:23 +0300 Subject: [PATCH 10/14] attachment storing --- .../components/observers/GuildLogging.js | 107 ++++++++++++++++-- 1 file changed, 99 insertions(+), 8 deletions(-) diff --git a/structure/client/components/observers/GuildLogging.js b/structure/client/components/observers/GuildLogging.js index 17ee66d..4d056fb 100644 --- a/structure/client/components/observers/GuildLogging.js +++ b/structure/client/components/observers/GuildLogging.js @@ -7,7 +7,18 @@ const CONSTANTS = { YELLOW: 15120384, // message edit LIGHT_BLUE: 11337726, // message pin BLUE: 479397 - } + }, + IMAGES: { + PREMIUM_LIMIT: 2, + UPLOAD_LIMIT: { + '0': 8, + '1': 8, + '2': 50, + '3': 100 + }, + MB_DIVIDER: 1024*1024 + }, + WEEK: 7 * 24 * 60 * 60 }; class GuildLogger extends Observer { @@ -36,6 +47,85 @@ class GuildLogger extends Observer { async storeAttachment(message) { + const { guild, member, author, channel } = message; + if(!guild || author.bot) return; + if(!message.attachments.size) return; + console.log('Store call') + + const settings = await guild.settings(), + setting = settings.messageLog, + roles = member._roles, + { ignoredRoles } = setting; + + //if(guild._settings.premium < CONSTANTS.IMAGES.PREMIUM_LIMIT) return; + if(!setting.attachments || setting.ignoredChannels.includes(channel.id)) return; + if(setting.ignoredRoles.length && roles.length) + for(const role of ignoredRoles) + if(roles.includes(role)) return; + + console.log('Can store') + + const attachments = message.attachments.values(); + for(const attachment of attachments) { + + const TH = this.client.transactionHandler; + const { size, name, id } = attachment; + const fsize = size/CONSTANTS.IMAGES.MB_DIVIDER // File size in MB + if(fsize > CONSTANTS.IMAGES.UPLOAD_LIMIT[guild.premiumTier]) continue; + + const buffer = await Util.downloadAsBuffer(attachment.url).catch(err => { this.client.logger.error(err); return null; }); + if(!buffer) return; + const data = { + buffer, + id + }; + + try { + //TODO: test this + //const start = Date.now(); + const result = await TH.send({ + provider: 'mongodb', + request: { + type: 'insertOne', + collection: 'attachment_logs', + data + } + }); + + //console.log(`Took ${Date.now()-start}ms to insert image.`); + //console.log(result); + + const metadata = { + database_ID: result.insertedId, + id, + guild: guild.id, + message: message.id, + author: author.id, + name, + size, + timestamp: Math.floor(Date.now()/1000), + removeAt: Math.floor(Date.now()/1000 + guild._settings.premium * CONSTANTS.WEEK * 0.25) + } + + //console.log(metadata); + + await TH.send({ + provider: 'mongodb', + request: { + type: 'insertOne', + collection: 'attachment_logs_index', + data: metadata + } + }); + + //console.log(`Took ${Date.now()-start}ms to insert entire entry.`); + + } catch (err) { + this.client.logger.error('Something went wrong with storing image to db:\n' + err.stack); + } + + } + } //TODO: Figure this thing out, this should be called from messageDelete and rawMessageDelete if any attachments are present @@ -66,7 +156,7 @@ class GuildLogger extends Observer { const perms = logChannel.permissionsFor(guild.me); if(!perms.has('SEND_MESSAGES') || !perms.has('VIEW_CHANNEL')) return; - if (ignoredRoles && member._roles.length) + if (ignoredRoles.length && member._roles.length) for (const role of ignoredRoles) if (member._roles.includes(role)) return; @@ -234,14 +324,15 @@ class GuildLogger extends Observer { } _replaceTags(text, member) { - const { user } = member; + const { user, guild } = member; return text .replace(/\{mention\}/g, `<@${member.id}>`) - .replace(/\{tag\}/g, `${Util.escapeMarkdown(user.tag)}`) - .replace(/\{user\}/g, `${user.username}`) - .replace(/\{guildsize\}/g, `${guild.memberCount}`) - .replace(/\{accage\}/g, `${this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)}`) //.replace(/a/, '1') - .replace(/\{id\}/g, `${user.id}`) + .replace(/\{tag\}/g, Util.escapeMarkdown(user.tag)) + .replace(/\{user\}/g, Util.escapeMarkdown(user.username)) + .replace(/\{guildsize\}/g, guild.memberCount) + .replace(/\{guildname\}/g, guild.name) + .replace(/\{accage\}/g, this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)) //.replace(/a/, '1') + .replace(/\{id\}/g, user.id) .trim(); } From 57dad51b5c4e9271175ccafbe7104eaddc10494d Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:27:42 +0300 Subject: [PATCH 11/14] welcomer and start for autorole --- .../components/observers/UtilityHook.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 structure/client/components/observers/UtilityHook.js diff --git a/structure/client/components/observers/UtilityHook.js b/structure/client/components/observers/UtilityHook.js new file mode 100644 index 0000000..ed47c46 --- /dev/null +++ b/structure/client/components/observers/UtilityHook.js @@ -0,0 +1,67 @@ +const { Observer } = require('../../../interfaces/'); + +const CONSTANTS = {}; + +class UtilityHook extends Observer { + + constructor(client) { + + super(client, { + name: 'utility', + priority: 3 + }); + + this.hooks = [ + ['guildMemberAdd', this.welcome.bind(this)], + ['guildMemberAdd', this.autorole.bind(this)] + ] + + } + + async stickyRole(member) { + + const { guild } = member; + const settings = await guild.settings(); + const setting = settings.stickyRole; + if(!setting.enabled) return; + + } + + async autorole(member) { + + const { guild } = member; + const settings = await guild.settings(); + const setting = settings.autorole; + if(!setting.enabled) return; + + } + + async welcome(member) { + + const { guild, user } = member; + const settings = await guild.settings(); + const setting = settings.welcomer; + if(!setting.enabled) return; + + const channel = await user.createDM(); + const message = this._replaceTags(setting.message, member); + await channel.send(message).catch(); + + } + + _replaceTags(text, member) { + const { user, guild } = member; + return text + .replace(/\{mention\}/g, `<@${member.id}>`) + .replace(/\{tag\}/g, Util.escapeMarkdown(user.tag)) + .replace(/\{user\}/g, Util.escapeMarkdown(user.username)) + .replace(/\{guildsize\}/g, guild.memberCount) + .replace(/\{guildname\}/g, guild.name) + .replace(/\{accage\}/g, this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)) //.replace(/a/, '1') + .replace(/\{id\}/g, user.id) + .trim(); + } + +} + +module.exports = UtilityHook; \ No newline at end of file From aa0e2c354f58f02e41abb6192c2d27aad0c3d6a8 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:28:26 +0300 Subject: [PATCH 12/14] cleaning up unnecessary assignment --- .../client/components/settings/moderation/DmInfraction.js | 2 -- .../client/components/settings/moderation/MemberLogs.js | 2 -- .../client/components/settings/moderation/MessageLog.js | 7 +++++-- .../client/components/settings/moderation/ModerationLog.js | 2 -- .../components/settings/moderation/ModerationPoints.js | 2 -- structure/client/components/settings/moderation/Mute.js | 2 -- .../client/components/settings/moderation/NicknameLogs.js | 2 -- .../client/components/settings/moderation/VoiceLogs.js | 2 -- structure/client/components/settings/utility/Autorole.js | 2 -- .../client/components/settings/utility/GuildIndexing.js | 2 -- .../client/components/settings/utility/GuildPrefix.js | 2 -- .../client/components/settings/utility/IgnoreChannels.js | 2 -- .../client/components/settings/utility/PermissionType.js | 2 -- 13 files changed, 5 insertions(+), 26 deletions(-) diff --git a/structure/client/components/settings/moderation/DmInfraction.js b/structure/client/components/settings/moderation/DmInfraction.js index 490aa4a..ff9145b 100644 --- a/structure/client/components/settings/moderation/DmInfraction.js +++ b/structure/client/components/settings/moderation/DmInfraction.js @@ -24,8 +24,6 @@ class DmInfractionSetting extends Setting { } }); - this.client = client; - } async handle(message, args) { diff --git a/structure/client/components/settings/moderation/MemberLogs.js b/structure/client/components/settings/moderation/MemberLogs.js index 7127833..bd91cb5 100644 --- a/structure/client/components/settings/moderation/MemberLogs.js +++ b/structure/client/components/settings/moderation/MemberLogs.js @@ -58,8 +58,6 @@ class MemberLogsSetting extends Setting { ] }); - this.client = client; - } async handle(message, args) { diff --git a/structure/client/components/settings/moderation/MessageLog.js b/structure/client/components/settings/moderation/MessageLog.js index 8b4de70..ca83515 100644 --- a/structure/client/components/settings/moderation/MessageLog.js +++ b/structure/client/components/settings/moderation/MessageLog.js @@ -36,8 +36,6 @@ class MessageLogsSetting extends Setting { } }); - this.client = client; - } async handle(message, params) { @@ -248,6 +246,11 @@ class MessageLogsSetting extends Setting { value: await guild.resolveChannel(setting?.channel) || '`N/A`', inline: true }, + { + name: '》Log attachments', + value: setting?.attachments || false, + inline: true + }, { name: '》Ignored Roles', value: roles?.map((r) => r.name).join(', ') || '`N/A`', diff --git a/structure/client/components/settings/moderation/ModerationLog.js b/structure/client/components/settings/moderation/ModerationLog.js index f384f08..7d527fa 100644 --- a/structure/client/components/settings/moderation/ModerationLog.js +++ b/structure/client/components/settings/moderation/ModerationLog.js @@ -32,8 +32,6 @@ class ModerationLogsSetting extends Setting { } }); - this.client = client; - } async handle(message, params) { diff --git a/structure/client/components/settings/moderation/ModerationPoints.js b/structure/client/components/settings/moderation/ModerationPoints.js index 69ef189..b01ac7e 100644 --- a/structure/client/components/settings/moderation/ModerationPoints.js +++ b/structure/client/components/settings/moderation/ModerationPoints.js @@ -51,8 +51,6 @@ class ModerationPointsSetting extends Setting { } }); - this.client = client; - } async handle(message, args) { diff --git a/structure/client/components/settings/moderation/Mute.js b/structure/client/components/settings/moderation/Mute.js index 0b5c8e1..60968de 100644 --- a/structure/client/components/settings/moderation/Mute.js +++ b/structure/client/components/settings/moderation/Mute.js @@ -88,8 +88,6 @@ class MuteSetting extends Setting { } } }); - - this.client = client; } diff --git a/structure/client/components/settings/moderation/NicknameLogs.js b/structure/client/components/settings/moderation/NicknameLogs.js index ee2451c..251e3a4 100644 --- a/structure/client/components/settings/moderation/NicknameLogs.js +++ b/structure/client/components/settings/moderation/NicknameLogs.js @@ -26,8 +26,6 @@ class NicknameLogs extends Setting { } }); - this.client = client; - } async handle(message, params) { diff --git a/structure/client/components/settings/moderation/VoiceLogs.js b/structure/client/components/settings/moderation/VoiceLogs.js index 1da5663..5040194 100644 --- a/structure/client/components/settings/moderation/VoiceLogs.js +++ b/structure/client/components/settings/moderation/VoiceLogs.js @@ -26,8 +26,6 @@ class VoiceLogSettings extends Setting { } }); - this.client = client; - } async handle(message, params) { diff --git a/structure/client/components/settings/utility/Autorole.js b/structure/client/components/settings/utility/Autorole.js index 76febbb..458dee2 100644 --- a/structure/client/components/settings/utility/Autorole.js +++ b/structure/client/components/settings/utility/Autorole.js @@ -26,8 +26,6 @@ class AutoroleSetting extends Setting { custom: true }); - this.client = client; - } async handle(message, params) { diff --git a/structure/client/components/settings/utility/GuildIndexing.js b/structure/client/components/settings/utility/GuildIndexing.js index b434f22..08c8798 100644 --- a/structure/client/components/settings/utility/GuildIndexing.js +++ b/structure/client/components/settings/utility/GuildIndexing.js @@ -29,8 +29,6 @@ class DescriptionSetting extends Setting { custom: true }); - this.client = client; - } async handle(message, params) { diff --git a/structure/client/components/settings/utility/GuildPrefix.js b/structure/client/components/settings/utility/GuildPrefix.js index b5c351d..5d0cb7f 100644 --- a/structure/client/components/settings/utility/GuildPrefix.js +++ b/structure/client/components/settings/utility/GuildPrefix.js @@ -20,8 +20,6 @@ class GuildPrefixSetting extends Setting { }, custom: true }); - - this.client = client; } diff --git a/structure/client/components/settings/utility/IgnoreChannels.js b/structure/client/components/settings/utility/IgnoreChannels.js index 57fa658..2fa91c4 100644 --- a/structure/client/components/settings/utility/IgnoreChannels.js +++ b/structure/client/components/settings/utility/IgnoreChannels.js @@ -30,8 +30,6 @@ class IgnoreSetting extends Setting { custom: true }); - this.client = client; - } async handle(message, params) { diff --git a/structure/client/components/settings/utility/PermissionType.js b/structure/client/components/settings/utility/PermissionType.js index 74c9a09..7c3349d 100644 --- a/structure/client/components/settings/utility/PermissionType.js +++ b/structure/client/components/settings/utility/PermissionType.js @@ -26,8 +26,6 @@ class PermissionTypeSetting extends Setting { 'permissiontype reset' ] }); - - this.client = client; } From d9aa6bb0e95e9feb7d627061b397ee0bf84d78e6 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:28:43 +0300 Subject: [PATCH 13/14] welcomer setting --- .../components/settings/utility/Welcomer.js | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 structure/client/components/settings/utility/Welcomer.js diff --git a/structure/client/components/settings/utility/Welcomer.js b/structure/client/components/settings/utility/Welcomer.js new file mode 100644 index 0000000..bdb5f42 --- /dev/null +++ b/structure/client/components/settings/utility/Welcomer.js @@ -0,0 +1,77 @@ +const { Setting } = require('../../../../interfaces/'); + +class WelcomerSetting extends Setting { + + constructor(client) { + + super(client, { + name: 'welcomer', + module: 'utility', + aliases: [ + + ], + usage: '', + examples: [ + 'welcomer Welcome to {guildname}!', + 'welcomer ', + 'welcomer reset' + ], + guarded: false, + resolve: 'GUILD', + default: { + welcomer: { + message: 'Welcome to {guildname}!', + enabled: false + } + }, + custom: true + }); + + } + + async handle(message, params) { + + const { guild } = message; + const setting = guild._settings[this.index] || this.default[this.index]; + const { resolver } = this.client; + const response = await resolver.resolveMethod(params); + const langParams = {}; + let index = null; + + if(resolver.resolveBoolean(params[0]) !== null) { + setting.enabled = resolver.resolveBoolean(params[0]); + index = 'S_WELCOMER_TOGGLE'; + langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: setting.enabled }, true) + } else { + setting.message = message.content.replace(guild.prefix, '').replace(message._caller, '').replace(message._settingCaller, '').trim(); + index = 'S_WELCOMER_SET'; + langParams.change = setting.message; + } + + await message.guild._updateSettings({ [this.index]: setting }); + return { + error: false, + msg: message.format(index, langParams) + }; + + } + + async fields(guild) { + const setting = guild._settings[this.index] || this.default[this.index]; + return [ + { + name: '》Enabled', + value: setting.enabled, + inline: false + }, + { + name: '》Message', + value: setting.message.substring(0,1021) + setting.message.length > 1021 ? '...' : '', + inline: false + } + ] + } + +} + +module.exports = WelcomerSetting; \ No newline at end of file From 33c6f57150e4727e216796dc63e8dd5ceb587070 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 Jun 2020 23:28:53 +0300 Subject: [PATCH 14/14] download as buffer --- util/Util.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/Util.js b/util/Util.js index 0b26f4e..8ce89ca 100644 --- a/util/Util.js +++ b/util/Util.js @@ -10,6 +10,15 @@ class Util { throw new Error("Class may not be instantiated."); } + static downloadAsBuffer(source) { + return new Promise((resolve, reject) => { + fetch(source).then(res => { + if(res.ok) resolve(res.buffer()); + else reject(res.statusText); + }); + }); + } + static readdirRecursive(directory) { const result = [];