aboutsummaryrefslogtreecommitdiff
path: root/src/commands/dev/syncAutomod.ts
blob: 7a0fb58d1c3464234a0dfc6401d60cd06870d500 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
import { BotCommand, clientSendAndPermCheck, emojis, Shared, type CommandMessage, type SlashMessage } from '#lib';
import typescript from 'typescript';
import { NodeVM } from 'vm2';

export default class SyncAutomodCommand extends BotCommand {
	public constructor() {
		super('syncAutomod', {
			aliases: ['sync-automod'],
			category: 'dev',
			description: 'Syncs automod info with the github repository.',
			usage: ['sync-automod'],
			examples: ['sync-automod'],
			slash: false,
			hidden: true,
			clientPermissions: (m) => clientSendAndPermCheck(m),
			userPermissions: []
		});
	}

	public override async exec(message: CommandMessage | SlashMessage) {
		if (!message.author.isOwner() && message.author.id !== '497789163555389441')
			return await message.util.reply(`${emojis.error} Only a very select few may use this command.`);

		const badLinks = await fetch('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/lib/badlinks.ts').then((p) =>
			p.ok ? p.text() : null
		);
		const badWords = await fetch('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/lib/badwords.ts').then((p) =>
			p.ok ? p.text() : null
		);

		if (!badLinks || !badWords) {
			return await message.util.reply(`${emojis.error} Failed to fetch bad links or bad words.`);
		}

		const transpiledBadLinks = typescript.transpileModule(badLinks, {}).outputText;
		const transpiledBadWords = typescript.transpileModule(badWords, {}).outputText;

		const badLinksParsed = new NodeVM({}).run(transpiledBadLinks).default;
		const badWordsParsed = new NodeVM({}).run(transpiledBadWords).default;

		const row = (await Shared.findByPk(0))!;
		row.badLinks = badLinksParsed;
		row.badWords = badWordsParsed;
		await row.save();

		return await message.util.reply(`${emojis.success} Automod info synced.`);
	}
}