Skip to content

Commit

Permalink
chore: linting, deps
Browse files Browse the repository at this point in the history
  • Loading branch information
ljosberinn committed Nov 10, 2021
1 parent 1a30170 commit 7c087e8
Show file tree
Hide file tree
Showing 36 changed files with 445 additions and 894 deletions.
18 changes: 9 additions & 9 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ const {
const tsOverride = createTSOverride({
...getDependencies(),
rules: {
'inclusive-language/use-inclusive-words': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/no-misused-promises': 0,
},
});

module.exports = createConfig({
overrides: [tsOverride],
root: true,
rules: {
'no-empty': 0,
'no-void': 0,
'@typescript-eslint/no-misused-promises': 0,
// this shit isn't properly supported in TS or node, its too early
'unicorn/prefer-string-replace-all': 0,
'no-eq-null': 0,
eqeqeq: ['error', 'always', { null: 'ignore' }],
'no-bitwise': 0,
// stuff
'unicorn/import-index': 'off',
},
});

module.exports = {
...createConfig({
overrides: [tsOverride],
}),
ignorePatterns: ['src/v1/*.ts'],
};
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
safe-exact=true
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"engines": {
"node": "16.13.0"
"node": "16.13.0 || ^17.0.0"
},
"scripts": {
"dev": "TS_NODE_FILES=true TS_NODE_PROJECT=\"./tsconfig.json\" nodemon -r dotenv/config -x node --experimental-specifier-resolution=node --loader ts-node/esm ./src/index.ts",
Expand All @@ -16,44 +16,45 @@
"test:watch": "jest --watch",
"test:ci": "jest --ci",
"lint:fix": "eslint --fix src && prettier --write src",
"lint:types": "tsc --noEmit"
"lint:types": "tsc --noEmit",
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@mdn/browser-compat-data": "^4.0.9",
"@mdn/browser-compat-data": "4.0.10",
"@sentry/node": "6.14.1",
"compare-versions": "4.0.1",
"date-fns": "2.25.0",
"discord.js": "^13.3.1",
"discord.js": "13.3.1",
"dom-parser": "0.1.6",
"domyno": "^1.0.1",
"fuse.js": "^6.4.6",
"domyno": "1.0.1",
"fuse.js": "6.4.6",
"html-entities": "2.3.2",
"lodash-es": "4.17.21",
"mongoose": "6.0.12",
"node-cache": "5.1.2",
"node-fetch": "3.1.0",
"node-html-parser": "^5.1.0",
"ts-node": "^10.4.0",
"lodash-es": "^4.17.21",
"node-html-parser": "5.1.0",
"ts-node": "10.4.0",
"typescript": "4.4.4"
},
"devDependencies": {
"@sentry/types": "6.14.1",
"@types/dom-parser": "^0.1.1",
"@types/html-entities": "^1.3.3",
"@types/dom-parser": "0.1.1",
"@types/html-entities": "1.3.4",
"@types/jest": "27.0.2",
"@types/mongoose": "5.11.96",
"@types/mongoose": "^5.11.97",
"@types/node": "16.11.7",
"@types/node-fetch": "3.0.2",
"@types/node-fetch": "3.0.3",
"dotenv": "10.0.0",
"eslint": "8.2.0",
"eslint-config-galex": "3.2.1",
"eslint-config-galex": "3.3.3",
"husky": "7.0.4",
"jest": "27.3.1",
"lint-staged": "11.2.6",
"nodemon": "2.0.14",
"nodemon": "2.0.15",
"prettier": "2.4.1",
"ts-jest": "27.0.7"
},
Expand Down
2 changes: 1 addition & 1 deletion src/v2/autorespond/code_parsing/hasVarInSource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line import/no-namespace
import ts from 'typescript';

export function hasVarInSource(source: string): boolean {
Expand Down
3 changes: 2 additions & 1 deletion src/v2/autorespond/html_parsing/hasDeprecated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parse } from 'node-html-parser';

import { mapʹ } from '../../utils/map.js';

const deprecatedElementsMap = new Map([
Expand Down Expand Up @@ -124,7 +125,7 @@ export function hasDeprecatedHTMLElementInSource(str: string) {
const deprecatedElements = root.querySelectorAll(deprecatedElSelector)

const uniqueElements = new Set(deprecatedElements.map(item => item.rawTagName.toLowerCase()))
if(uniqueElements.size) {
if(uniqueElements.size > 0) {
return [...mapʹ(item => [item, deprecatedElementsMap.get(item)], uniqueElements)]
}
return false
Expand Down
2 changes: 1 addition & 1 deletion src/v2/autorespond/html_parsing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function detectDeprecatedHTML(msg: Message): boolean {
const { content, channel, author } = msg;

const deprecated = [...getDeprecatedElements(content)].flat(1);
if (deprecated.length) {
if (deprecated.length > 0) {
const deprecatedTags = deprecated.map(([item]) => `\`<${item}>\``);
const template = _`Hey <@!${author.id}>, I've noticed you're using ${
_.n
Expand Down
6 changes: 4 additions & 2 deletions src/v2/autorespond/thanks/createResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { MessageButton, User } from 'discord.js';
import { MessageButton } from 'discord.js';
import { MessageActionRow, MessageSelectMenu } from 'discord.js';
import { EmbedField, Collection } from 'discord.js';
import type { User } from 'discord.js';
import type { EmbedField, Collection } from 'discord.js';

import { clampLength } from '../../utils/clampStr.js';
import { createEmbed } from '../../utils/discordTools.js';

Expand Down
4 changes: 2 additions & 2 deletions src/v2/autorespond/thanks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { stripMarkdownQuote } from '../../utils/content_format.js';
import { createEmbed } from '../../utils/discordTools.js';
import { mapʹ } from '../../utils/map.js';
import { difference } from '../../utils/sets.js';
import { createResponse } from './createResponse.js';
import type { ThanksInteractionType } from './db_model.js';
import { ThanksInteraction } from './db_model.js';
import { handleThreadThanks } from './threadThanks.js';
import { createResponse } from './createResponse.js';

type CooldownUser = {
id: string;
Expand Down Expand Up @@ -62,7 +62,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
await ThanksInteraction.find({
thanker: msg.author.id,
createdAt: {
$gte: Date.now() - Number.parseInt(POINT_LIMITER_IN_MINUTES) * 60000,
$gte: Date.now() - Number.parseInt(POINT_LIMITER_IN_MINUTES) * 60_000,
},
}).exec();

Expand Down
18 changes: 10 additions & 8 deletions src/v2/autorespond/thanks/threadThanks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
Collection,
MessageSelectMenu,
} from 'discord.js';

import { POINT_LIMITER_IN_MINUTES } from '../../env.js';
import { asyncCatch } from '../../utils/asyncCatch.js';
import { createResponse } from './createResponse.js';
import { ThanksInteraction, ThanksInteractionType } from './db_model.js';
import { _ } from '../../utils/pluralize.js';
import { POINT_LIMITER_IN_MINUTES } from '../../env.js';
import { createResponse } from './createResponse.js';
import type { ThanksInteractionType } from './db_model.js';
import { ThanksInteraction } from './db_model.js';

const memoryCache = new Map<string, Message>();

Expand All @@ -28,7 +30,7 @@ export async function handleThreadThanks(msg: Message): Promise<void> {

const oldResponseId = [msg.author.id, msg.channel.id].join('|');
if (memoryCache.has(oldResponseId)) {
await memoryCache.get(oldResponseId).delete().catch(e => console.error("message already deleted")).finally(() => { memoryCache.delete(oldResponseId) });
await memoryCache.get(oldResponseId).delete().catch(error => { console.error("message already deleted"); }).finally(() => { memoryCache.delete(oldResponseId) });
}
// channel.members.fetch should return a collection
const [members, previousInteractions]: [
Expand All @@ -41,7 +43,7 @@ export async function handleThreadThanks(msg: Message): Promise<void> {
ThanksInteraction.find({
thanker: msg.author.id,
createdAt: {
$gte: Date.now() - Number.parseInt(POINT_LIMITER_IN_MINUTES) * 60000,
$gte: Date.now() - Number.parseInt(POINT_LIMITER_IN_MINUTES) * 60_000,
},
}),
]);
Expand Down Expand Up @@ -69,7 +71,7 @@ export async function handleThreadThanks(msg: Message): Promise<void> {
const response = await msg.reply({
content: [
"Hey, it looks like you're trying to thank one or many users, but haven't specified who. Who would you like to thank?",
alreadyThanked.length
alreadyThanked.length > 0
? _`There ${_.mapper({ 1: 'is' }, 'are')} **${_.n} user${
_.s
} that you can't thank as you've thanked them recently**, so they won't show up as an option.`(
Expand Down Expand Up @@ -113,7 +115,7 @@ export function attachThreadThanksHandler(client: Client): void {
if (!(interaction.isSelectMenu() || interaction.isButton())) {
return;
}
const channel = interaction.channel;
const {channel} = interaction;
const [category, msgId, type, userId] = interaction.customId.split('🤔');

if (category !== 'threadThanks') {
Expand Down Expand Up @@ -219,7 +221,7 @@ export function attachThreadClose(client: Client) {

const channel = activeThreads.threads.get(channelId);

if (!channel || channel.archived === true) {
if (!channel || channel.archived) {
interaction.reply({ content: '' });
}

Expand Down
20 changes: 8 additions & 12 deletions src/v2/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import type {
import { Collection } from 'discord.js';
import { filter } from 'domyno';
import { isEqual } from 'lodash-es';

import type { CommandDataWithHandler } from '../../types';
import { asyncCatch } from '../utils/asyncCatch.js';

import { map, mapʹ } from '../utils/map.js';
import { merge } from '../utils/merge.js';
import { normalizeApplicationCommandData } from '../utils/normalizeCommand.js';
Expand Down Expand Up @@ -111,8 +111,8 @@ export const registerCommands = async (client: Client): Promise<void> => {
content: "Couldn't recognize command.",
});
}
} catch (e) {
console.error(e);
} catch (error) {
console.error(error);
await interaction.reply({
ephemeral: true,
content: 'Something went wrong when trying to execute the command',
Expand All @@ -123,13 +123,13 @@ export const registerCommands = async (client: Client): Promise<void> => {

for (const { onAttach } of applicationCommands.values()) {
// We're attaching these so it's fine
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
onAttach?.(client);
}

for (const { onAttach } of guildCommands.values()) {
// We're attaching these so it's fine
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
onAttach?.(client);
}

Expand All @@ -139,8 +139,8 @@ export const registerCommands = async (client: Client): Promise<void> => {
guild = await oauth2Guild.fetch();
const cmds = await (guild as Guild).commands.fetch();
await addCommands(cmds, guildCommands, (guild as Guild).commands);
} catch (e) {
console.error(`Failed to add commands to guild: ${guild.name}`, e);
} catch (error) {
console.error(`Failed to add commands to guild: ${guild.name}`, error);
}
}
console.log('Guild specific commands added');
Expand Down Expand Up @@ -219,11 +219,7 @@ async function addCommands(

function getDestination(
commandManager:
| ApplicationCommandManager<
ApplicationCommand<{ guild: GuildResolvable }>,
{ guild: GuildResolvable },
null
>
| ApplicationCommandManager
| GuildApplicationCommandManager
) {
return 'guild' in commandManager
Expand Down
2 changes: 1 addition & 1 deletion src/v2/commands/mdn/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable unicorn/prefer-query-selector */
import type {
ButtonInteraction,
Client,
Expand Down
2 changes: 1 addition & 1 deletion src/v2/commands/npm/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from '@sentry/types';
import type { User } from '@sentry/types';
import { formatDistanceToNow } from 'date-fns';
import type {
EmbedField,
Expand Down
2 changes: 1 addition & 1 deletion src/v2/commands/please/handlers/format/exampleFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function formatFn(fn: Function) {
return fn
.toString()
.split(LINE_SEPARATOR)
.map(line => '> ' + line)
.map(line => `> ${ line}`)
.join(LINE_SEPARATOR);
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/commands/points/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const handleDecayRequest = async (interaction: CommandInteraction) => {
const { diff } = getTimeDiffToDecay();
const timer = Number.parseInt(POINT_DECAY_TIMER);

let [hours, minutes]: Array<string | number> = (timer - diff)
let [hours, minutes]: (string | number)[] = (timer - diff)
.toString()
.split('.');

Expand Down
16 changes: 9 additions & 7 deletions src/v2/commands/post/env.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
IS_PROD,
MOD_CHANNEL,
JOB_POSTINGS_CHANNEL,
MINIMAL_COMPENSATION,



POST_LIMITER_IN_HOURS, // Used for informing the user about the limiter
AWAIT_MESSAGE_TIMEOUT as AMT, // Renamed for shadowing
MINIMAL_AMOUNT_OF_WORDS as MAOW, // Renamed for shadowing as well
Expand All @@ -20,11 +20,13 @@ const POST_LIMITER = IS_PROD
const MINIMAL_AMOUNT_OF_WORDS = Number.parseInt(MAOW);

export {
MOD_CHANNEL,
JOB_POSTINGS_CHANNEL,
MINIMAL_COMPENSATION,



MINIMAL_AMOUNT_OF_WORDS,
POST_LIMITER,
POST_LIMITER_IN_HOURS,

AWAIT_MESSAGE_TIMEOUT,
};

export {MOD_CHANNEL, JOB_POSTINGS_CHANNEL, MINIMAL_COMPENSATION, POST_LIMITER_IN_HOURS} from '../../env.js';
6 changes: 3 additions & 3 deletions src/v2/commands/post/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-await-in-loop */
import type {
Message,
CollectorFilter,
Expand All @@ -17,8 +17,10 @@ import {
import { filter } from 'domyno';

import type { CommandDataWithHandler } from '../../../types';
import { SERVER_ID } from '../../env.js';
import { cache } from '../../spam_filter/index.js';
import { MultistepForm } from '../../utils/MultistepForm.js';
import { asyncCatch } from '../../utils/asyncCatch.js';
import { createEmbed, createMarkdownCodeBlock } from '../../utils/discordTools.js';
import { map } from '../../utils/map.js';
import { pipe } from '../../utils/pipe.js';
Expand All @@ -30,8 +32,6 @@ import {
POST_LIMITER_IN_HOURS,
} from './env.js';
import { questions } from './questions.v2.js';
import { asyncCatch } from '../../utils/asyncCatch.js';
import { SERVER_ID } from '../../env.js';

const dateFormatter = new Intl.DateTimeFormat('en-US', {
month: 'long',
Expand Down
2 changes: 1 addition & 1 deletion src/v2/commands/post/questions.v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const isNotTooLong = length => (str:string) => {
const and = <T,K>(...fns:((input:T) => K)[]) => (input:T):K | true=> {
for (const fn of fns) {
const item: unknown = fn(input)
if(item !== true) return item as K
if(item !== true) {return item as K}
}
return true
}
Expand Down
Loading

0 comments on commit 7c087e8

Please sign in to comment.