More tags and add paste providers. Also more analysis
This commit is contained in:
parent
86c545cb45
commit
c39ed8e49c
10 changed files with 240 additions and 89 deletions
|
@ -14,7 +14,7 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
import { SuccessfulParsedMessage } from 'discord-command-parser';
|
||||
import * as dotenv from 'dotenv';
|
||||
import { parseLog } from './mclogs';
|
||||
import { parseLog } from './logs';
|
||||
dotenv.config();
|
||||
|
||||
export interface Command {
|
||||
|
|
19
src/logproviders/0x0.ts
Normal file
19
src/logproviders/0x0.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
const reg = /https\:\/\/0x0.st\/[^ ]*/;
|
||||
|
||||
export async function read0x0(s: string): Promise<null | string> {
|
||||
const r = s.match(reg);
|
||||
if (r == null || !r[0]) return null;
|
||||
const link = r[0];
|
||||
let log: string;
|
||||
try {
|
||||
const f = await fetch(link);
|
||||
if (f.status != 200) {
|
||||
throw 'nope';
|
||||
}
|
||||
log = await f.text();
|
||||
} catch (err) {
|
||||
console.log('Log analyze fail', err);
|
||||
return null;
|
||||
}
|
||||
return log;
|
||||
}
|
21
src/logproviders/haste.ts
Normal file
21
src/logproviders/haste.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
const reg = /https\:\/\/hst.sh\/[\w]*/;
|
||||
|
||||
export async function readHastebin(s: string): Promise<string | null> {
|
||||
const r = s.match(reg);
|
||||
if (r == null || !r[0]) return null;
|
||||
const link = r[0];
|
||||
const id = link.replace('https://hst.sh/', '');
|
||||
if (!id) return null;
|
||||
let log: string;
|
||||
try {
|
||||
const f = await fetch(`https://hst.sh/raw/${id}`);
|
||||
if (f.status != 200) {
|
||||
throw 'nope';
|
||||
}
|
||||
log = await f.text();
|
||||
} catch (err) {
|
||||
console.log('Log analyze fail', err);
|
||||
return null;
|
||||
}
|
||||
return log;
|
||||
}
|
22
src/logproviders/mclogs.ts
Normal file
22
src/logproviders/mclogs.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
const reg = /https\:\/\/mclo.gs\/[^ ]*/;
|
||||
|
||||
export async function readMcLogs(s: string): Promise<null | string> {
|
||||
const r = s.match(reg);
|
||||
if (r == null || !r[0]) return null;
|
||||
const link = r[0];
|
||||
const id = link.replace('https://mclo.gs/', '');
|
||||
if (!id) return null;
|
||||
const apiUrl = 'https://api.mclo.gs/1/raw/' + id;
|
||||
let log: string;
|
||||
try {
|
||||
const f = await fetch(apiUrl);
|
||||
if (f.status != 200) {
|
||||
throw 'nope';
|
||||
}
|
||||
log = await f.text();
|
||||
} catch (err) {
|
||||
console.log('Log analyze fail', err);
|
||||
return null;
|
||||
}
|
||||
return log;
|
||||
}
|
30
src/logproviders/pastegg.ts
Normal file
30
src/logproviders/pastegg.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
const reg = /https\:\/\/paste.gg\/p\/[\w]*\/[\w]*/;
|
||||
|
||||
export async function readPasteGG(s: string): Promise<null | string> {
|
||||
const r = s.match(reg);
|
||||
if (r == null || !r[0]) return null;
|
||||
const link = r[0];
|
||||
const id = link.replace(/https\:\/\/paste.gg\/p\/[\w]*\//, '');
|
||||
if (!id) return null;
|
||||
let log: string;
|
||||
try {
|
||||
const pasteJson = await (
|
||||
await fetch('https://api.paste.gg/v1/pastes/' + id)
|
||||
).json();
|
||||
if (pasteJson.status != 'success') throw 'up';
|
||||
const pasteData = await (
|
||||
await fetch(
|
||||
'https://api.paste.gg/v1/pastes/' +
|
||||
id +
|
||||
'/files/' +
|
||||
pasteJson.result.files[0].id
|
||||
)
|
||||
).json();
|
||||
if (pasteData.status != 'success') throw 'up';
|
||||
return pasteData.result.content.value;
|
||||
} catch (err) {
|
||||
console.log('Log analyze fail', err);
|
||||
return null;
|
||||
}
|
||||
return log;
|
||||
}
|
143
src/logs.ts
Normal file
143
src/logs.ts
Normal file
|
@ -0,0 +1,143 @@
|
|||
import { getLatest } from './version';
|
||||
import { MessageEmbed } 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';
|
||||
|
||||
const reg = /https\:\/\/mclo.gs\/[^ ]*/g;
|
||||
|
||||
type analyzer = (text: string) => Promise<Array<string> | null>;
|
||||
type logProvider = (text: string) => Promise<null | string>;
|
||||
|
||||
const javaAnalyzer: analyzer = async (text) => {
|
||||
if (text.includes('This instance is not compatible with Java version')) {
|
||||
const xp =
|
||||
/Please switch to one of the following Java versions for this instance:[\r\n]+([^\r\n]+)/g;
|
||||
|
||||
let ver: string;
|
||||
const m = text.match(xp);
|
||||
if (!m || !m[0]) {
|
||||
ver = '';
|
||||
} else {
|
||||
ver = m[0].split('\n')[1];
|
||||
}
|
||||
|
||||
return [
|
||||
'Wrong Java Version',
|
||||
`Please switch to the following: \`${ver}\`\nFor more information, type \`!java\``,
|
||||
];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const versionAnalyzer: analyzer = async (text) => {
|
||||
const vers = text.match(/PolyMC version: [0-9].[0-9].[0-9]/g);
|
||||
if (vers && vers[0]) {
|
||||
const latest = await getLatest();
|
||||
const current = vers[0].replace('PolyMC version: ', '');
|
||||
if (latest != current) {
|
||||
return [
|
||||
'Outdated PolyMC',
|
||||
`Your installed version is ${current}, while the newest version is ${latest}.\nPlease update, for more info see https://polymc.org/download/`,
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const flatpakNvidiaAnalyzer: analyzer = async (text) => {
|
||||
if (
|
||||
text.includes('org.lwjgl.LWJGLException: Could not choose GLX13 config')
|
||||
) {
|
||||
return [
|
||||
'Outdated Nvidia Flatpak Driver',
|
||||
`The Nvidia driver for flatpak is outdated.\nPlease run \`flatpak update\` to fix this issue. If that does not solve it, please wait until the driver is added to Flathub and run it again.`,
|
||||
];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const forgeJavaAnalyzer: analyzer = async (text) => {
|
||||
if (
|
||||
text.includes(
|
||||
'java.lang.NoSuchMethodError: sun.security.util.ManifestEntryVerifier.<init>(Ljava/util/jar/Manifest;)V'
|
||||
)
|
||||
) {
|
||||
return [
|
||||
'Forge Java Bug',
|
||||
'Old versions of Forge crash with Java 8u321+. For this reason, using Java 8u312 or lower is reccomended.\nYou can also update Forge via the Versions tab.',
|
||||
];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const intelHDAnalyzer: analyzer = async (text) => {
|
||||
if (text.includes('org.lwjgl.LWJGLException: Pixel format not accelerated')) {
|
||||
return [
|
||||
'Intel HD Windows 10',
|
||||
"Your drivers don't support windows 10 officially\nSee https://polymc.org/wiki/getting-started/installing-java/#a-note-about-intel-hd-20003000-on-windows-10 for more info",
|
||||
];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const macOSNSWindowAnalyzer: analyzer = async (text) => {
|
||||
if (
|
||||
text.includes(
|
||||
"Terminating app due to uncaught exception 'NSInternalInconsistencyException'"
|
||||
)
|
||||
) {
|
||||
return [
|
||||
'MacOS NSInternalInconsistencyException',
|
||||
'You need to downgrade your Java 8 version. See https://polymc.org/wiki/getting-started/installing-java/#older-minecraft-on-macos',
|
||||
];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const analyzers: analyzer[] = [
|
||||
javaAnalyzer,
|
||||
versionAnalyzer,
|
||||
flatpakNvidiaAnalyzer,
|
||||
forgeJavaAnalyzer,
|
||||
intelHDAnalyzer,
|
||||
macOSNSWindowAnalyzer,
|
||||
];
|
||||
|
||||
const providers: logProvider[] = [
|
||||
readMcLogs,
|
||||
read0x0,
|
||||
readPasteGG,
|
||||
readHastebin,
|
||||
];
|
||||
|
||||
export async function parseLog(s: string): Promise<MessageEmbed | null> {
|
||||
let log: string = '';
|
||||
for (let i in providers) {
|
||||
const provider = providers[i];
|
||||
const res = await provider(s);
|
||||
if (res) {
|
||||
log = res;
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!log) return null;
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle('Log analysis')
|
||||
.setColor('DARK_GREEN');
|
||||
for (let i in analyzers) {
|
||||
const analyzer = analyzers[i];
|
||||
const out = await analyzer(log);
|
||||
if (out) embed.addField(out[0], out[1]);
|
||||
}
|
||||
if (embed.fields[0]) return embed;
|
||||
else {
|
||||
embed.addField('Analyze failed', 'No issues found automatically');
|
||||
return embed;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
import { getLatest } from './version';
|
||||
import { MessageEmbed } from 'discord.js';
|
||||
const reg = /https\:\/\/mclo.gs\/[^ ]*/g;
|
||||
|
||||
type analyzer = (text: string) => Promise<Array<string> | null>;
|
||||
const javaAnalyzer: analyzer = async (text) => {
|
||||
if (text.includes('This instance is not compatible with Java version')) {
|
||||
const xp =
|
||||
/Please switch to one of the following Java versions for this instance:[\r\n]+([^\r\n]+)/g;
|
||||
|
||||
let ver: string;
|
||||
const m = text.match(xp);
|
||||
if (!m || !m[0]) {
|
||||
ver = '';
|
||||
} else {
|
||||
ver = m[0].split('\n')[1];
|
||||
}
|
||||
|
||||
return [
|
||||
'WrongJavaVersion',
|
||||
`Please switch to the following: \`${ver}\`\nFor more information, type \`!java\``,
|
||||
];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const versionAnalyzer: analyzer = async (text) => {
|
||||
const vers = text.match(/PolyMC version: [0-9].[0-9].[0-9]/g);
|
||||
if (vers && vers[0]) {
|
||||
const latest = await getLatest();
|
||||
const current = vers[0].replace('PolyMC version: ', '');
|
||||
if (latest != current) {
|
||||
return [
|
||||
'OutdatedPolyMC',
|
||||
`Your installed version is ${current}, while the newest version is ${latest}.\nPlease update, for more info see https://polymc.org/download/`,
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const analyzers: analyzer[] = [javaAnalyzer, versionAnalyzer];
|
||||
|
||||
export async function parseLog(s: string): Promise<MessageEmbed | null> {
|
||||
const r = s.match(reg);
|
||||
if (r == null || !r[0]) return null;
|
||||
const link = r[0]; // for now only first url
|
||||
const id = link.replace('https://mclo.gs/', '');
|
||||
if (!id) return null;
|
||||
const apiUrl = 'https://api.mclo.gs/1/raw/' + id;
|
||||
|
||||
let log: string;
|
||||
try {
|
||||
const f = await fetch(apiUrl);
|
||||
if (f.status != 200) {
|
||||
throw 'nope';
|
||||
}
|
||||
log = await f.text();
|
||||
} catch (err) {
|
||||
console.log('Log analyze fail', err);
|
||||
return null;
|
||||
}
|
||||
console.log(apiUrl);
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle('Log analyzer')
|
||||
.setColor('DARK_GREEN')
|
||||
.setDescription(`Analysis of ${link} [${apiUrl}] [ID: ${id}]`);
|
||||
for (let i in analyzers) {
|
||||
const analyzer = analyzers[i];
|
||||
const out = await analyzer(log);
|
||||
if (out) embed.addField(out[0], out[1]);
|
||||
}
|
||||
if (embed.fields[0]) return embed;
|
||||
else {
|
||||
embed.addField('Analyze failed', 'No issues found automatically');
|
||||
return embed;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
"aliases": ["migr", "mmc"]
|
||||
},
|
||||
{
|
||||
"name": "matrix-space",
|
||||
"name": "thematrix",
|
||||
"text": "https://matrix.to/#/#polymc:matrix.org"
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue