upgrade to discord.js v14
This commit is contained in:
parent
35a64b4f25
commit
7c0b91e1be
12 changed files with 446 additions and 533 deletions
22
package.json
22
package.json
|
@ -10,22 +10,22 @@
|
|||
"dependencies": {
|
||||
"@cliqz/adblocker": "^1.23.8",
|
||||
"discord-command-parser": "^1.5.3",
|
||||
"discord.js": "^13.8.0",
|
||||
"discord.js": "^14.0.3",
|
||||
"just-random": "^3.0.1",
|
||||
"kleur": "^4.1.4",
|
||||
"node-fetch": "^3.2.5",
|
||||
"kleur": "^4.1.5",
|
||||
"node-fetch": "^3.2.9",
|
||||
"remove-markdown": "^0.5.0",
|
||||
"tsx": "^3.4.2",
|
||||
"tsx": "^3.8.0",
|
||||
"url-regex": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.41",
|
||||
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
||||
"@typescript-eslint/parser": "^5.27.1",
|
||||
"@types/node": "^18.6.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
||||
"@typescript-eslint/parser": "^5.31.0",
|
||||
"dotenv": "^16.0.1",
|
||||
"esbuild": "^0.14.43",
|
||||
"eslint": "^8.17.0",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "^4.6.4"
|
||||
"esbuild": "^0.14.50",
|
||||
"eslint": "^8.20.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import { MessageEmbed } from 'discord.js';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { commands } from '.';
|
||||
import { Command } from '..';
|
||||
import type { Command } from '..';
|
||||
import { COLORS } from '../constants';
|
||||
|
||||
export const cmd: Command = {
|
||||
name: 'help',
|
||||
desc: 'Shows this menu.',
|
||||
exec: async (e) => {
|
||||
const embed = new MessageEmbed()
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('Help Menu')
|
||||
.setColor('DARK_GREEN');
|
||||
.setColor(COLORS.green);
|
||||
|
||||
const comman = commands;
|
||||
comman.sort((x, y) => {
|
||||
|
@ -27,7 +28,7 @@ export const cmd: Command = {
|
|||
if (cmd.examples && cmd.examples[0]) {
|
||||
resp.push(`**Examples**: \n${cmd.examples.join('\n> ')}`);
|
||||
}
|
||||
embed.addField('!' + cmd.name, resp.join('\n'));
|
||||
embed.addFields({ name: '!' + cmd.name, value: resp.join('\n') });
|
||||
}
|
||||
|
||||
await e.reply({ embeds: [embed] });
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import type { Command } from '../index';
|
||||
import type { Command } from '..';
|
||||
import { COLORS } from '../constants';
|
||||
|
||||
export const cmd: Command = {
|
||||
name: 'members',
|
||||
|
@ -20,7 +21,7 @@ export const cmd: Command = {
|
|||
m.presence?.status === 'dnd'
|
||||
).length
|
||||
} online members`,
|
||||
color: 'GOLD',
|
||||
color: COLORS.blue,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { Command } from '../index';
|
||||
import type { Command } from '..';
|
||||
|
||||
export const cmd: Command = {
|
||||
name: 'ping',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { COLORS } from '../constants';
|
||||
import type { Command } from '../index';
|
||||
|
||||
export const cmd: Command = {
|
||||
|
@ -12,7 +13,7 @@ export const cmd: Command = {
|
|||
embeds: [
|
||||
{
|
||||
title: `⭐ ${count} total stars!`,
|
||||
color: 'GOLD',
|
||||
color: COLORS.yellow,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { MessageEmbed } from 'discord.js';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { getTags, type Command } from '..';
|
||||
import { COLORS } from '../constants';
|
||||
|
||||
export const cmd: Command = {
|
||||
name: 'tags',
|
||||
desc: 'Lists the tags available',
|
||||
exec: async (e) => {
|
||||
const em = new MessageEmbed().setTitle('tags').setColor('DARK_GREEN');
|
||||
const em = new EmbedBuilder().setTitle('tags').setColor(COLORS.green);
|
||||
|
||||
const tags = await getTags();
|
||||
|
||||
|
@ -23,7 +24,7 @@ export const cmd: Command = {
|
|||
text += '\n[embedded message]';
|
||||
}
|
||||
|
||||
em.addField('?' + tag.name, text);
|
||||
em.addFields({ name: '?' + tag.name, value: text });
|
||||
}
|
||||
|
||||
await e.reply({ embeds: [em] });
|
||||
|
|
|
@ -20,3 +20,10 @@ export const ETA_MESSAGES = [
|
|||
'Next week',
|
||||
'In PolyMC 2.0.0',
|
||||
];
|
||||
|
||||
export const COLORS = {
|
||||
red: 0xef4444,
|
||||
green: 0x22c55e,
|
||||
blue: 0x60a5fa,
|
||||
yellow: 0xfde047,
|
||||
} as const;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Message } from 'discord.js';
|
||||
import type { Message } from 'discord.js';
|
||||
import { isBad } from './badLinks';
|
||||
import urlRegex from 'url-regex';
|
||||
import { COLORS } from './constants';
|
||||
|
||||
// true if message is ok, false if filtered
|
||||
export async function filterMessage(e: Message): Promise<boolean> {
|
||||
|
@ -19,7 +20,7 @@ export async function filterMessage(e: Message): Promise<boolean> {
|
|||
title: 'Hold on!',
|
||||
description:
|
||||
'There seems to be a phishing / malware link in your message.',
|
||||
color: 'RED',
|
||||
color: COLORS.red,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
64
src/index.ts
64
src/index.ts
|
@ -1,10 +1,4 @@
|
|||
import {
|
||||
Client,
|
||||
Intents,
|
||||
Message,
|
||||
MessageEmbed,
|
||||
type MessageEmbedOptions,
|
||||
} from 'discord.js';
|
||||
import { Client, Message, EmbedBuilder, type EmbedData } from 'discord.js';
|
||||
|
||||
import * as BuildConfig from './constants';
|
||||
import { commands } from './commands';
|
||||
|
@ -20,7 +14,7 @@ import {
|
|||
import random from 'just-random';
|
||||
import { readFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { green, bold, blue, underline, yellow } from 'kleur/colors';
|
||||
import { green, bold, yellow } from 'kleur/colors';
|
||||
import 'dotenv/config';
|
||||
|
||||
export interface Command {
|
||||
|
@ -38,7 +32,7 @@ interface Tag {
|
|||
name: string;
|
||||
aliases?: Array<string>;
|
||||
text?: string;
|
||||
embed?: MessageEmbedOptions;
|
||||
embed?: EmbedData;
|
||||
}
|
||||
|
||||
export const getTags = async (): Promise<Tag[]> => {
|
||||
|
@ -49,13 +43,14 @@ export const getTags = async (): Promise<Tag[]> => {
|
|||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
Intents.FLAGS.GUILDS,
|
||||
Intents.FLAGS.GUILD_MESSAGES,
|
||||
Intents.FLAGS.DIRECT_MESSAGES,
|
||||
Intents.FLAGS.GUILD_MEMBERS,
|
||||
Intents.FLAGS.GUILD_PRESENCES,
|
||||
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
||||
Intents.FLAGS.GUILD_BANS,
|
||||
'Guilds',
|
||||
'GuildMessages',
|
||||
'MessageContent',
|
||||
'DirectMessages',
|
||||
'GuildMembers',
|
||||
'GuildPresences',
|
||||
'GuildMessageReactions',
|
||||
'GuildBans',
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -65,18 +60,6 @@ client.once('ready', async () => {
|
|||
if (process.env.NODE_ENV !== 'development')
|
||||
console.warn(yellow(bold('Running in production mode!')));
|
||||
|
||||
console.log(
|
||||
'Invite link:',
|
||||
blue(
|
||||
underline(
|
||||
client.generateInvite({
|
||||
scopes: ['bot'],
|
||||
permissions: ['ADMINISTRATOR'],
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
client.user?.presence.set({
|
||||
activities: [{ name: `Minecraft ${await getLatestMinecraftVersion()}` }],
|
||||
status: 'online',
|
||||
|
@ -84,7 +67,7 @@ client.once('ready', async () => {
|
|||
|
||||
client.on('messageCreate', async (e) => {
|
||||
if (!e.content) return;
|
||||
if (!e.channel.isText()) return;
|
||||
if (!e.channel.isTextBased()) return;
|
||||
if (e.author === client.user) return;
|
||||
|
||||
if (
|
||||
|
@ -138,9 +121,9 @@ async function parseMsgForCommands(e: Message) {
|
|||
try {
|
||||
await cmd.exec(e, parsed);
|
||||
} catch (err: unknown) {
|
||||
const em = new MessageEmbed()
|
||||
const em = new EmbedBuilder()
|
||||
.setTitle('Error')
|
||||
.setColor('RED')
|
||||
.setColor('Red')
|
||||
// @ts-expect-error no why
|
||||
.setDescription(err['message'] as string);
|
||||
|
||||
|
@ -161,12 +144,27 @@ async function parseMsgForTags(e: Message) {
|
|||
);
|
||||
|
||||
if (tag) {
|
||||
const requesterAvatarURL = e.author.avatar;
|
||||
const tagRequester = {
|
||||
text: `Requested by ${e.author.tag}`,
|
||||
...(requesterAvatarURL ? { icon_url: requesterAvatarURL } : null),
|
||||
};
|
||||
|
||||
if (tag.text) {
|
||||
e.reply(tag.text);
|
||||
e.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder({
|
||||
title: tag.name,
|
||||
description: tag.text,
|
||||
footer: tagRequester,
|
||||
}),
|
||||
],
|
||||
});
|
||||
} else if (tag.embed) {
|
||||
const em = new MessageEmbed(tag.embed);
|
||||
const em = new EmbedBuilder(tag.embed).setFooter(tagRequester);
|
||||
e.reply({ embeds: [em] });
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
32
src/logs.ts
32
src/logs.ts
|
@ -1,11 +1,12 @@
|
|||
import { getLatestPolyMCVersion } from './utils/remoteVersions';
|
||||
import { MessageEmbed } from 'discord.js';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
|
||||
// log providers
|
||||
import { readMcLogs } from './logproviders/mclogs';
|
||||
import { read0x0 } from './logproviders/0x0';
|
||||
import { readPasteGG } from './logproviders/pastegg';
|
||||
import { readHastebin } from './logproviders/haste';
|
||||
import { COLORS } from './constants';
|
||||
|
||||
type Analyzer = (text: string) => Promise<Array<string> | null>;
|
||||
type LogProvider = (text: string) => Promise<null | string>;
|
||||
|
@ -224,14 +225,14 @@ const providers: LogProvider[] = [
|
|||
readHastebin,
|
||||
];
|
||||
|
||||
export async function parseLog(s: string): Promise<MessageEmbed | null> {
|
||||
export async function parseLog(s: string): Promise<EmbedBuilder | null> {
|
||||
if (s.includes('https://pastebin.com/')) {
|
||||
const embed = new MessageEmbed()
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('pastebin.com detected')
|
||||
.setDescription(
|
||||
'Please use https://mclo.gs or another paste provider and send logs using the Log Upload feature in PolyMC. (See !log)'
|
||||
)
|
||||
.setColor('DARK_RED');
|
||||
.setColor(COLORS.red);
|
||||
return embed;
|
||||
}
|
||||
|
||||
|
@ -247,19 +248,28 @@ export async function parseLog(s: string): Promise<MessageEmbed | null> {
|
|||
}
|
||||
}
|
||||
if (!log) return null;
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle('Log analysis')
|
||||
.setColor('DARK_GREEN');
|
||||
const embed = new EmbedBuilder().setTitle('Log analysis');
|
||||
|
||||
let thereWasAnIssue = false;
|
||||
for (const i in analyzers) {
|
||||
const Analyzer = analyzers[i];
|
||||
const out = await Analyzer(log);
|
||||
if (out) embed.addField(out[0], out[1]);
|
||||
if (out) {
|
||||
embed.addFields({ name: out[0], value: out[1] });
|
||||
thereWasAnIssue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (embed.fields[0]) return embed;
|
||||
else {
|
||||
embed.addField('Analyze failed', 'No issues found automatically');
|
||||
if (thereWasAnIssue) {
|
||||
embed.setColor(COLORS.red);
|
||||
return embed;
|
||||
} else {
|
||||
embed.setColor(COLORS.green);
|
||||
embed.addFields({
|
||||
name: 'Analyze failed',
|
||||
value: 'No issues found automatically',
|
||||
});
|
||||
|
||||
return embed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
"name": "optifine",
|
||||
"aliases": ["of", "optimize", "opticrap", "notfine"],
|
||||
"embed": {
|
||||
"color": "DARK_GREEN",
|
||||
"title": "OptiFine",
|
||||
"description": "OptiFine is known to cause problems when paired with other mods.\nPlease see [Installing OptiFine Alternatives](https://polymc.org/wiki/getting-started/install-of-alternatives/).\nIf you really want to use OptiFine, see [Installing OptiFine](https://polymc.org/wiki/getting-started/installing-optifine/)"
|
||||
}
|
||||
|
@ -43,7 +42,7 @@
|
|||
"embed": {
|
||||
"title": "Data directories",
|
||||
"description": "Where PolyMC stores your data (e.g. instances)",
|
||||
"color": "AQUA",
|
||||
|
||||
"fields": [
|
||||
{
|
||||
"name": "Portable (Windows / Linux)",
|
||||
|
@ -86,8 +85,7 @@
|
|||
"name": "whyjava8",
|
||||
"embed": {
|
||||
"title": "Why does PolyMC ask me to change java version?",
|
||||
"description": "Minecraft versions before 1.17 required Java 8 and have issues with newer java, while newer versions require Java 17, so you need to change java version. Some people think Java 8 is very outdated, but it's actually an LTS, it's still getting updates. If one of your mods is weird and requires newer java, you can bypass this going to instance settings-Java and ticking 'Skip java compatibility checks', but be aware of potential issues, such as [random CMEs](https://bugs.mojang.com/browse/MC-149777).",
|
||||
"color": "ORANGE"
|
||||
"description": "Minecraft versions before 1.17 required Java 8 and have issues with newer java, while newer versions require Java 17, so you need to change java version. Some people think Java 8 is very outdated, but it's actually an LTS, it's still getting updates. If one of your mods is weird and requires newer java, you can bypass this going to instance settings-Java and ticking 'Skip java compatibility checks', but be aware of potential issues, such as [random CMEs](https://bugs.mojang.com/browse/MC-149777)."
|
||||
},
|
||||
"aliases": ["isjava8ancient", "whyispolyforcingme"]
|
||||
},
|
||||
|
@ -95,8 +93,7 @@
|
|||
"name": "update",
|
||||
"embed": {
|
||||
"title": "Does PolyMC auto-update?",
|
||||
"description": "PolyMC auto-updates for macOS using the Sparkle Framework.\n\nWindows auto-updating is WIP for now, you will need to download the installer and run it again. (You will not lose your instances.)\n\nFor Linux, just use your package manager!",
|
||||
"color": "BLUE"
|
||||
"description": "PolyMC auto-updates for macOS using the Sparkle Framework.\n\nWindows auto-updating is WIP for now, you will need to download the installer and run it again. (You will not lose your instances.)\n\nFor Linux, just use your package manager!"
|
||||
},
|
||||
"aliases": ["updating", "autoupdate"]
|
||||
},
|
||||
|
@ -104,8 +101,7 @@
|
|||
"name": "modupdater",
|
||||
"embed": {
|
||||
"title": "Mod updater",
|
||||
"description": "Mod updating has been introduced in PolyMC 1.4.0! Upgrade if you haven't and you'll be able to use it.",
|
||||
"color": "GREEN"
|
||||
"description": "Mod updating has been introduced in PolyMC 1.4.0! Upgrade if you haven't and you'll be able to use it."
|
||||
},
|
||||
"aliases": ["mod-update", "modupdate"]
|
||||
},
|
||||
|
@ -113,8 +109,7 @@
|
|||
"name": "curseforge",
|
||||
"embed": {
|
||||
"title": "What's wrong with CurseForge?",
|
||||
"description": "CurseForge added a new option to block third party clients like PolyMC from accessing mod files, and they started to enforce this option lately. We can't allow you to download those mods directly from PolyMC, but PolyMC 1.3.1 and higher have a workaround to let modpacks work: letting you to download those opted out mods manually. We highly encourage asking authors that opted out to stop doing so.",
|
||||
"color": "ORANGE"
|
||||
"description": "CurseForge added a new option to block third party clients like PolyMC from accessing mod files, and they started to enforce this option lately. We can't allow you to download those mods directly from PolyMC, but PolyMC 1.3.1 and higher have a workaround to let modpacks work: letting you to download those opted out mods manually. We highly encourage asking authors that opted out to stop doing so."
|
||||
},
|
||||
"aliases": ["cf", "curse", "cursed", "cursedfrog"]
|
||||
},
|
||||
|
@ -122,8 +117,7 @@
|
|||
"name": "piracy",
|
||||
"embed": {
|
||||
"title": "We don't tolerate piracy!",
|
||||
"description": "PolyMC has always been legal, legitimate & appropriate. We don't and never will have features such as offline login without an official account.",
|
||||
"color": "DARK_RED"
|
||||
"description": "PolyMC has always been legal, legitimate & appropriate. We don't and never will have features such as offline login without an official account."
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue