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

1
.gitignore vendored
View File

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

View File

@ -1,11 +1,13 @@
const fs = require('fs');
const CacheHandler = require('./abstractions/CacheHandler');
class Cache {
class JsonCache extends CacheHandler {
constructor (client) {
super(client);
const opts = client._options;
this.client = client;
this.logger = client.logger;
this.saveInterval = opts.saveInterval;
@ -34,16 +36,16 @@ class Cache {
for (const [ key, val ] of entries) this[key] = val;
} else {
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._ready = true;
}
save() {
savePersistentCache () {
this.logger.debug('Saving cache');
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: [
{
name: '__User Data__',
value: `**User:** <@${user.id}>\n` +
`**Account created:** ${user.createdAt.toDateString()}\n`,
value: `**User:** <@${user.id}>\n`
+ `**Account created:** ${user.createdAt.toDateString()}\n`,
inline: false
}
],
@ -151,9 +151,9 @@ class ChannelHandler {
} else embed.description = `**__USER IS IN APPEAL SERVER__**`;
} else if (member) embed.fields.push({
name: '__Member Data__',
value: `**Nickname:** ${member.nickname || 'N/A'}\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(' ')}`,
value: `**Nickname:** ${member.nickname || 'N/A'}\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(' ')}`,
inline: false
});
@ -166,10 +166,12 @@ class ChannelHandler {
if (!entry) 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 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`));
// eslint-disable-next-line no-shadow
const embed = {
footer: {
text: user.id

View File

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

View File

@ -117,8 +117,7 @@ class Modmail {
// Anti spam
if (!this.spammers[author.id]) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false };
else {
if (this.spammers[author.id].timeout) {
else 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 };
else return;
} 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`);
if (cache._channels[author.id]) await cache._channels[author.id].send(`I've blocked ${author.tag} from DMing me as they were spamming.`);
}
} else {
if (now - this.spammers[author.id].start > 15) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false };
} else 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++;
}
}
const pastModmail = await this.cache.loadModmailHistory(author.id)
.catch((err) => {

View File

@ -104,6 +104,7 @@ class Resolver {
const match = resolveable.match(id);
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
if (channel && filter(channel)) resolved.push(channel);
@ -112,6 +113,7 @@ class Resolver {
const match = resolveable.match(name);
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) => {
if (!strict) return c.name.toLowerCase().includes(ch);
return c.name.toLowerCase() === ch;

View File

@ -28,6 +28,7 @@ class CannedReply extends Command {
const list = Object.entries(this.client.modmail.replies);
let str = '';
// eslint-disable-next-line no-shadow
for (const [ name, content ] of list) {
if (str.length + content.length > 2000) {
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) {
// eslint-disable-next-line no-shadow
const user = await this.client.resolveUser(entry.author);
embed.fields.push({
name: `${user.tag}${entry.anon ? ' (ANON)' : ''} @ ${new Date(entry.timestamp).toUTCString()}`,