Skip to content

Commit

Permalink
Create 0.5.1c issue detector (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szedann authored Jul 30, 2023
1 parent fd973de commit d60313e
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN corepack prepare pnpm@latest --activate

WORKDIR /app

COPY package.json pnpm-lock.yaml .
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile

COPY . .
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"name": "snrbot",
"version": "1.0.0",
"license": "GPL-3.0",
"scripts": {
"dev": "cross-env NODE_ENV=development tsx watch src/index.ts",
"start": "tsx src/index.ts",
Expand All @@ -10,6 +13,7 @@
"colorette": "^2.0.20",
"discord.js": "14.11.0",
"express": "^4.18.2",
"gray-matter": "^4.0.3",
"tsx": "3.12.7"
},
"devDependencies": {
Expand All @@ -20,7 +24,6 @@
"cross-env": "^7.0.3",
"dotenv": "16.3.1",
"eslint": "8.43.0",
"gray-matter": "4.0.3",
"prettier": "2.8.8",
"typescript": "5.1.3"
},
Expand Down
166 changes: 90 additions & 76 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 29 additions & 8 deletions src/handlers/log.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { EmbedBuilder, Events } from 'discord.js';

// log providers
import logProviders from '../logProviders/_logProviders';
import logAnalyzers from '../logAnalyzers/_logAnalyzers';
import logAnalyzers from '../logIssueAnalyzers/_logIssueAnalyzers';

import { Handler } from '..';
import { analyzers } from '../logs/Analyzer';

export type LogAnalyzer = (
url: string
Expand All @@ -14,6 +15,10 @@ export interface LogProvider {
parse: (url: string) => Promise<void | string>;
}

export type Analyzer = (
log: string
) => Promise<{ name: string; value: string } | null>;

const hostnameMap = new Map<string, (text: string) => Promise<void | string>>();

for (const provider of logProviders) {
Expand Down Expand Up @@ -77,22 +82,38 @@ export const logHandler: Handler = (client) => {

if (!regexPasses.find((reg) => log.match(reg))) return;

const logInfo: { name: string; value: string }[] = [];

for (const analyzer of analyzers) {
const info = await analyzer(log);
if (info) logInfo.push(info);
}

const logInfoEmbed = new EmbedBuilder()
.setTitle('Log File')
.setDescription('__Environment info__')
.setColor('Green')
.setFields(...logInfo);

const issues = await findIssues(log);

const embed = new EmbedBuilder()
if (!issues.length) {
message.reply({ embeds: [logInfoEmbed] });
return;
}

const issuesEmbed = new EmbedBuilder()
.setTitle('Log analysis')
.setDescription(
`${issues.length || 'No'} issue${
`${issues.length} issue${
issues.length == 1 ? '' : 's'
} found automatically`
)
.setFields(...issues)
.setColor(issues.length ? 'Red' : 'Green');
.setColor('Red');

if (log != null) {
message.reply({ embeds: [embed] });
return;
}
message.reply({ embeds: [logInfoEmbed, issuesEmbed] });
return;
} catch (error) {
console.error('Unhandled exception on MessageCreate', error);
}
Expand Down
6 changes: 0 additions & 6 deletions src/logAnalyzers/_logAnalyzers.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/logIssueAnalyzers/_logIssueAnalyzers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Analyzer } from '../handlers/log.handler';
import { createVersionAnalyzer } from './createVersion';
import { minecraftVersionAnalyzer } from './minecraftVersion';
import { optifineAnalyzer } from './optifine';

export const logAnalyzers: Analyzer[] = [
optifineAnalyzer,
minecraftVersionAnalyzer,
createVersionAnalyzer,
];

export default logAnalyzers;
12 changes: 12 additions & 0 deletions src/logIssueAnalyzers/createVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Analyzer } from '../handlers/log.handler';

export const createVersionAnalyzer: Analyzer = async (text) => {
const matchesCreate = text.match(/create-(.)+-0\.5\.1\.c/);
if (matchesCreate) {
return {
name: 'Incompatible with Create 0.5.1',
value: "Create: Steam 'n' Rails is currently incompatible with `Create 0.5.1c`. Downgrade to `Create 0.5.1b`.",
};
}
return null;
};
15 changes: 15 additions & 0 deletions src/logIssueAnalyzers/minecraftVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Analyzer } from '../handlers/log.handler';
import { getMinecraftVersion } from '../logs/Analyzer';

export const minecraftVersionAnalyzer: Analyzer = async (log) => {
const minecraftVersion = getMinecraftVersion(log);
console.log(minecraftVersion);
if (!minecraftVersion) return null;
const incompatibleVersions = new Set(['1.19.3', '1.19.4']);
if (incompatibleVersions.has(minecraftVersion))
return {
name: 'Incompatible with that version of Minecraft',
value: "Steam 'n' Rails is currently only compatible with MC 1.18.2 and 1.19.2.",
};
return null;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LogAnalyzer } from '../handlers/log.handler';
import { Analyzer } from '../handlers/log.handler';

export const optifineAnalyzer: LogAnalyzer = async (text) => {
export const optifineAnalyzer: Analyzer = async (text) => {
const matchesOptifine = text.match(/f_174747_/);
if (matchesOptifine) {
return {
Expand Down
Loading

0 comments on commit d60313e

Please sign in to comment.