-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (30 loc) · 1.04 KB
/
index.ts
File metadata and controls
37 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { Message } from 'discord.js';
import { createCodeBlockCapturer } from '../../utils/codeBlockCapturer.js';
import { pipe } from '../../utils/pipe.js';
import { pluck } from '../../utils/pluck.js';
import { some } from '../../utils/some.js';
import { hasVarInSource } from './hasVarInSource.js';
const jsCodeBlocks = createCodeBlockCapturer([
'js',
'javascript',
'ts',
'typescript',
]);
const tap = <T>(x: T): T => {
console.log(x)
return x
}
const getFirstVar = pipe([jsCodeBlocks, pluck('code'), some(hasVarInSource)]);
const messageFor = (userId: string) => `
Hey <@${userId}>, I've noticed you're using \`var\` in a code snippet.
Unless you've got a very good reason to, it's highly recommended that you use \`let\` or \`const\`. Preferably \`const\` if it won't be reassigned.`;
export function detectVar(msg: Message): boolean {
if (msg.author.id === msg.client.user.id) {
return;
}
const { content, channel, author } = msg;
if (getFirstVar(content)) {
channel.send(messageFor(author.id));
return true;
}
}