linter pass

This commit is contained in:
Erik 2021-10-22 10:35:04 +03:00
parent 775b063c42
commit 4bfcc8c737
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589
19 changed files with 200 additions and 180 deletions

View File

@ -1,24 +1,30 @@
module.exports = { module.exports = {
'env': { "env": {
'commonjs': true, "es6": true,
'es2021': true, "node": true
'node': true
}, },
'extends': 'eslint:recommended', "extends": "eslint:recommended",
'parserOptions': { "globals": {
'ecmaVersion': 12 "Atomics": "readonly",
"SharedArrayBuffer": "readonly"
}, },
'rules': { "parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"accessor-pairs": "warn", "accessor-pairs": "warn",
"array-callback-return": "warn", "array-callback-return": "warn",
"arrow-parens": "warn", "array-bracket-newline": [ "warn", "consistent" ],
"array-bracket-spacing": [ "warn", "always", { "objectsInArrays": false, "arraysInArrays": false }],
// "arrow-parens": "warn",
"arrow-spacing": "warn", "arrow-spacing": "warn",
"block-scoped-var": "warn", "block-scoped-var": "warn",
"block-spacing": "warn", "block-spacing": [ "warn", "always" ],
"brace-style": "warn", "brace-style": [ "warn", "1tbs" ],
"callback-return": "warn", "callback-return": "warn",
"camelcase": "warn", "camelcase": "warn",
"comma-dangle": "warn", "comma-dangle": [ "warn", "only-multiline" ],
"comma-spacing": [ "comma-spacing": [
"warn", "warn",
{ {
@ -38,6 +44,10 @@ module.exports = {
"allowKeywords": true "allowKeywords": true
} }
], ],
"dot-location": [
"error",
"property"
],
"eol-last": [ "eol-last": [
"warn", "warn",
"never" "never"
@ -55,18 +65,13 @@ module.exports = {
"id-blacklist": "warn", "id-blacklist": "warn",
"id-match": "warn", "id-match": "warn",
"implicit-arrow-linebreak": "warn", "implicit-arrow-linebreak": "warn",
"indent": [ "indent": "warn",
"warn",
4,
{
"SwitchCase": 1
}
],
"init-declarations": "warn", "init-declarations": "warn",
"jsx-quotes": "warn", "jsx-quotes": [ "warn", "prefer-single" ],
"key-spacing": "warn", "key-spacing": [ "warn", { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [ "warn", { "after": true, "before": true }],
"linebreak-style": [ "linebreak-style": [
"warn", "error",
"windows" "windows"
], ],
"lines-around-comment": "warn", "lines-around-comment": "warn",
@ -98,13 +103,14 @@ module.exports = {
"no-floating-decimal": "warn", "no-floating-decimal": "warn",
"no-implicit-coercion": "warn", "no-implicit-coercion": "warn",
"no-implicit-globals": "warn", "no-implicit-globals": "warn",
"no-implied-eval": "warn", "no-implied-eval": "error",
"no-import-assign": "warn", "no-import-assign": "warn",
"no-invalid-this": "warn", "no-invalid-this": "warn",
"no-iterator": "warn", "no-iterator": "warn",
"no-label-var": "warn", "no-label-var": "warn",
// "no-labels": "warn", // "no-labels": "warn",
"no-lone-blocks": "warn", "no-lone-blocks": "warn",
"no-lonely-if": "warn",
"no-loop-func": "warn", "no-loop-func": "warn",
"no-mixed-requires": "warn", "no-mixed-requires": "warn",
"no-multi-assign": "warn", "no-multi-assign": "warn",
@ -113,6 +119,7 @@ module.exports = {
"no-multiple-empty-lines": "warn", "no-multiple-empty-lines": "warn",
"no-native-reassign": "warn", "no-native-reassign": "warn",
"no-negated-in-lhs": "warn", "no-negated-in-lhs": "warn",
"no-negated-condition": "error",
"no-nested-ternary": "warn", "no-nested-ternary": "warn",
"no-new": "warn", "no-new": "warn",
"no-new-func": "warn", "no-new-func": "warn",
@ -135,14 +142,16 @@ module.exports = {
"no-sequences": "warn", "no-sequences": "warn",
"no-setter-return": "warn", "no-setter-return": "warn",
"no-spaced-func": "warn", "no-spaced-func": "warn",
"no-shadow": "error",
"no-tabs": "warn", "no-tabs": "warn",
"no-template-curly-in-string": "warn", "no-template-curly-in-string": "error",
"no-throw-literal": "warn", "no-throw-literal": "warn",
"no-undef-init": "warn", "no-undef-init": "error",
"no-undefined": "error",
"no-unmodified-loop-condition": "warn", "no-unmodified-loop-condition": "warn",
"no-unneeded-ternary": "warn", "no-unneeded-ternary": "error",
"no-unused-expressions": "warn", "no-unused-expressions": "warn",
"no-use-before-define": "warn", "no-use-before-define": "error",
"no-useless-call": "warn", "no-useless-call": "warn",
"no-useless-computed-key": "warn", "no-useless-computed-key": "warn",
"no-useless-concat": "warn", "no-useless-concat": "warn",
@ -151,22 +160,25 @@ module.exports = {
"no-useless-return": "warn", "no-useless-return": "warn",
"no-var": "warn", "no-var": "warn",
"no-void": "warn", "no-void": "warn",
"no-whitespace-before-property": "warn", "no-whitespace-before-property": "error",
"nonblock-statement-body-position": "warn", "nonblock-statement-body-position": "warn",
"object-curly-spacing": [ "object-curly-spacing": [
"warn", "warn",
"always" "always"
], ],
"object-property-newline": [ "warn", { "allowAllPropertiesOnSameLine": true }],
"object-shorthand": "warn", "object-shorthand": "warn",
"one-var-declaration-per-line": "warn", "one-var-declaration-per-line": "warn",
"operator-assignment": "warn", "operator-assignment": "warn",
"operator-linebreak": [ "warn", "before" ],
"padding-line-between-statements": "warn", "padding-line-between-statements": "warn",
"padded-blocks": [ "warn", { "switches": "never" }, { "allowSingleLineBlocks": true }],
"prefer-arrow-callback": "warn", "prefer-arrow-callback": "warn",
"prefer-const": "warn", "prefer-const": "warn",
"prefer-destructuring": "warn", "prefer-destructuring": "warn",
"prefer-exponentiation-operator": "warn", "prefer-exponentiation-operator": "warn",
"prefer-numeric-literals": "warn", "prefer-numeric-literals": "warn",
"prefer-object-spread": "warn", "prefer-object-spread": "error",
"prefer-promise-reject-errors": "warn", "prefer-promise-reject-errors": "warn",
"prefer-regex-literals": "warn", "prefer-regex-literals": "warn",
"prefer-rest-params": "warn", "prefer-rest-params": "warn",
@ -174,17 +186,20 @@ module.exports = {
"require-jsdoc": "warn", "require-jsdoc": "warn",
"require-unicode-regexp": "warn", "require-unicode-regexp": "warn",
"rest-spread-spacing": "warn", "rest-spread-spacing": "warn",
"semi": "warn", "semi": "error",
"semi-spacing": "warn", "semi-spacing": "warn",
"semi-style": [ "semi-style": [
"warn", "warn",
"last" "last"
], ],
"space-before-blocks": "warn", "space-before-blocks": "warn",
"space-before-function-paren": [ "error", "always" ],
"space-in-parens": [ "space-in-parens": [
"warn", "warn",
"never" "never"
], ],
"spaced-comment": [ "warn", "always" ],
"strict": "warn",
"switch-colon-spacing": "warn", "switch-colon-spacing": "warn",
"symbol-description": "warn", "symbol-description": "warn",
"template-curly-spacing": [ "template-curly-spacing": [
@ -198,7 +213,7 @@ module.exports = {
], ],
"vars-on-top": "warn", "vars-on-top": "warn",
"wrap-iife": "warn", "wrap-iife": "warn",
"wrap-regex": "warn", "wrap-regex": "error",
"yield-star-spacing": "warn", "yield-star-spacing": "warn",
"yoda": [ "yoda": [
"warn", "warn",

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ modmail_cache
persistent_cache.json persistent_cache.json
canned_replies.json canned_replies.json
config - server.js config - server.js
old.eslintrc.js

View File

@ -1,11 +1,13 @@
const fs = require('fs'); const fs = require('fs');
const CacheHandler = require('./abstractions/CacheHandler');
class Cache { class JsonCache extends CacheHandler {
constructor (client) { constructor (client) {
super(client);
const opts = client._options; const opts = client._options;
this.client = client;
this.logger = client.logger; this.logger = client.logger;
this.saveInterval = opts.saveInterval; this.saveInterval = opts.saveInterval;
@ -34,16 +36,16 @@ class Cache {
for (const [ key, val ] of entries) this[key] = val; for (const [ key, val ] of entries) this[key] = val;
} else { } else {
this.logger.info('Cache file missing, creating...'); this.logger.info('Cache file missing, creating...');
this.save(); this.savePersistentCache();
} }
this.cacheSaveInterval = setInterval(this.save.bind(this), 10 * 60 * 1000); this.cacheSaveInterval = setInterval(this.savePersistentCache.bind(this), 10 * 60 * 1000);
this.modmailSaveInterval = setInterval(this.saveModmailHistory.bind(this), this.saveInterval * 60 * 1000, this.client.modmail); this.modmailSaveInterval = setInterval(this.saveModmailHistory.bind(this), this.saveInterval * 60 * 1000, this.client.modmail);
this._ready = true; this._ready = true;
} }
save() { savePersistentCache () {
this.logger.debug('Saving cache'); this.logger.debug('Saving cache');
fs.writeFileSync('./persistent_cache.json', JSON.stringify(this.json)); fs.writeFileSync('./persistent_cache.json', JSON.stringify(this.json));
} }
@ -101,4 +103,4 @@ class Cache {
} }
module.exports = Cache; module.exports = JsonCache;

View File

@ -135,8 +135,8 @@ class ChannelHandler {
fields: [ fields: [
{ {
name: '__User Data__', name: '__User Data__',
value: `**User:** <@${user.id}>\n` + value: `**User:** <@${user.id}>\n`
`**Account created:** ${user.createdAt.toDateString()}\n`, + `**Account created:** ${user.createdAt.toDateString()}\n`,
inline: false inline: false
} }
], ],
@ -151,9 +151,9 @@ class ChannelHandler {
} else embed.description = `**__USER IS IN APPEAL SERVER__**`; } else embed.description = `**__USER IS IN APPEAL SERVER__**`;
} else if (member) embed.fields.push({ } else if (member) embed.fields.push({
name: '__Member Data__', name: '__Member Data__',
value: `**Nickname:** ${member.nickname || 'N/A'}\n` + value: `**Nickname:** ${member.nickname || 'N/A'}\n`
`**Server join date:** ${member.joinedAt.toDateString()}\n` + + `**Server join date:** ${member.joinedAt.toDateString()}\n`
`**Roles:** ${member.roles.cache.filter((r) => r.id !== guild.roles.everyone.id).map((r) => `<@&${r.id}>`).join(' ')}`, + `**Roles:** ${member.roles.cache.filter((r) => r.id !== guild.roles.everyone.id).map((r) => `<@&${r.id}>`).join(' ')}`,
inline: false inline: false
}); });
@ -166,10 +166,12 @@ class ChannelHandler {
if (!entry) continue; if (!entry) continue;
if ([ 'read', 'unread' ].includes(entry.readState)) continue; if ([ 'read', 'unread' ].includes(entry.readState)) continue;
// eslint-disable-next-line no-shadow
const user = await this.client.resolveUser(entry.author).catch(this.client.logger.error.bind(this.client.logger)); const user = await this.client.resolveUser(entry.author).catch(this.client.logger.error.bind(this.client.logger));
const mem = await this.modmail.getMember(user.id).catch(this.client.logger.error.bind(this.client.logger)); const mem = await this.modmail.getMember(user.id).catch(this.client.logger.error.bind(this.client.logger));
if (!user) return reject(new Error(`Failed to find user`)); if (!user) return reject(new Error(`Failed to find user`));
// eslint-disable-next-line no-shadow
const embed = { const embed = {
footer: { footer: {
text: user.id text: user.id

View File

@ -51,7 +51,7 @@ class ModmailClient extends Client {
process.on('exit', () => { process.on('exit', () => {
this.logger.warn('process exiting'); this.logger.warn('process exiting');
this.cache.save(); this.cache.savePersistentCache();
this.cache.saveModmailHistory(this.modmail); this.cache.saveModmailHistory(this.modmail);
}); });
process.on('SIGINT', () => { process.on('SIGINT', () => {

View File

@ -117,8 +117,7 @@ class Modmail {
// Anti spam // Anti spam
if (!this.spammers[author.id]) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false }; if (!this.spammers[author.id]) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false };
else { else if (this.spammers[author.id].timeout) {
if (this.spammers[author.id].timeout) {
if (now - this.spammers[author.id].start > 5 * 60) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false }; if (now - this.spammers[author.id].start > 5 * 60) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false };
else return; else return;
} else if (this.spammers[author.id].count > 5 && now - this.spammers[author.id].start < 15) { } else if (this.spammers[author.id].count > 5 && now - this.spammers[author.id].start < 15) {
@ -128,11 +127,8 @@ class Modmail {
await author.send(`I've blocked you for spamming, please try again in 5 minutes`); await author.send(`I've blocked you for spamming, please try again in 5 minutes`);
if (cache._channels[author.id]) await cache._channels[author.id].send(`I've blocked ${author.tag} from DMing me as they were spamming.`); if (cache._channels[author.id]) await cache._channels[author.id].send(`I've blocked ${author.tag} from DMing me as they were spamming.`);
} }
} else { } else if (now - this.spammers[author.id].start > 15) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false };
if (now - this.spammers[author.id].start > 15) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false };
else this.spammers[author.id].count++; else this.spammers[author.id].count++;
}
}
const pastModmail = await this.cache.loadModmailHistory(author.id) const pastModmail = await this.cache.loadModmailHistory(author.id)
.catch((err) => { .catch((err) => {

View File

@ -104,6 +104,7 @@ class Resolver {
const match = resolveable.match(id); const match = resolveable.match(id);
const [ , ch ] = match; const [ , ch ] = match;
// eslint-disable-next-line no-shadow
const channel = await this.client.channels.fetch(ch).catch((e) => { }); // eslint-disable-line no-empty, no-empty-function, no-unused-vars const channel = await this.client.channels.fetch(ch).catch((e) => { }); // eslint-disable-line no-empty, no-empty-function, no-unused-vars
if (channel && filter(channel)) resolved.push(channel); if (channel && filter(channel)) resolved.push(channel);
@ -112,6 +113,7 @@ class Resolver {
const match = resolveable.match(name); const match = resolveable.match(name);
const ch = match[1].toLowerCase(); const ch = match[1].toLowerCase();
// eslint-disable-next-line no-shadow
const channel = CM.cache.sort((a, b) => a.name.length - b.name.length).filter(filter).filter((c) => { const channel = CM.cache.sort((a, b) => a.name.length - b.name.length).filter(filter).filter((c) => {
if (!strict) return c.name.toLowerCase().includes(ch); if (!strict) return c.name.toLowerCase().includes(ch);
return c.name.toLowerCase() === ch; return c.name.toLowerCase() === ch;

View File

@ -28,6 +28,7 @@ class CannedReply extends Command {
const list = Object.entries(this.client.modmail.replies); const list = Object.entries(this.client.modmail.replies);
let str = ''; let str = '';
// eslint-disable-next-line no-shadow
for (const [ name, content ] of list) { for (const [ name, content ] of list) {
if (str.length + content.length > 2000) { if (str.length + content.length > 2000) {
await channel.send(str).catch(this.client.logger.error.bind(this.client.logger)); await channel.send(str).catch(this.client.logger.error.bind(this.client.logger));

View File

@ -43,6 +43,7 @@ class Logs extends Command {
}; };
for (const entry of page.items) { for (const entry of page.items) {
// eslint-disable-next-line no-shadow
const user = await this.client.resolveUser(entry.author); const user = await this.client.resolveUser(entry.author);
embed.fields.push({ embed.fields.push({
name: `${user.tag}${entry.anon ? ' (ANON)' : ''} @ ${new Date(entry.timestamp).toUTCString()}`, name: `${user.tag}${entry.anon ? ' (ANON)' : ''} @ ${new Date(entry.timestamp).toUTCString()}`,