Add !debug command

This commit is contained in:
Jordan Eldredge 2020-12-02 15:18:18 -05:00
parent 70095fe88f
commit 5ddb7833ec
4 changed files with 46 additions and 1 deletions

View file

@ -6,6 +6,10 @@ import { knex } from "../db";
const IA_URL = /^(https:\/\/)?archive.org\/details\/([^/]+)\/?/;
export type IaItemDebugData = {
row: IaItemRow;
};
export default class IaItemModel {
constructor(readonly ctx: UserContext, readonly row: IaItemRow) {}
@ -65,6 +69,12 @@ export default class IaItemModel {
}
return identifier;
}
async debug(): Promise<IaItemDebugData> {
return {
row: this.row,
};
}
}
const getIaItemLoader = ctxWeakMapMemoize<DataLoader<string, IaItemRow>>(

View file

@ -2,7 +2,7 @@ import { getScreenshotUrl, getSkinUrl } from "./skins";
import { TweetStatus, SkinRow, ReviewRow } from "../types";
import UserContext, { ctxWeakMapMemoize } from "./UserContext";
import TweetModel, { TweetDebugData } from "./TweetModel";
import IaItemModel from "./IaItemModel";
import IaItemModel, { IaItemDebugData } from "./IaItemModel";
import FileModel, { FileDebugData } from "./FileModel";
import { MD5_REGEX } from "../utils";
import DataLoader from "dataloader";
@ -136,14 +136,17 @@ export default class SkinModel {
reviews: ReviewRow[];
tweets: TweetDebugData[];
files: FileDebugData[];
iaItem: IaItemDebugData | null;
}> {
const tweets = await this.getTweets();
const files = await this.getFiles();
const iaItem = await this.getIaItem();
return {
row: this.row,
reviews: await this.getReviews(),
tweets: await Promise.all(tweets.map((tweet) => tweet.debug())),
files: await Promise.all(files.map((file) => file.debug())),
iaItem: iaItem == null ? null : await iaItem.debug(),
};
}
}

View file

@ -0,0 +1,31 @@
import { Message } from "discord.js";
import UserContext from "../../data/UserContext";
import SkinModel from "../../data/SkinModel";
const TRIPPLE = "```";
async function handler(message: Message, args: [string]) {
const ctx = new UserContext();
const [anything] = args;
if (anything == null) {
message.channel.send(`<md5-skin> is required.`);
return;
}
const skin = await SkinModel.fromAnything(ctx, anything);
if (skin == null) {
message.channel.send(`Could not find a skin matching ${anything}`);
return;
}
const data = await skin.debug();
await message.channel.send(
[TRIPPLE, JSON.stringify(data, null, 2), TRIPPLE].join("")
);
}
module.exports = {
usage: "<md5-skin>",
description: "Show debug information about a skin",
command: "debug",
handler,
};

View file

@ -12,6 +12,7 @@ const commands = [
require("./commands/review"),
require("./commands/screenshot"),
require("./commands/skin"),
require("./commands/debug"),
require("./commands/stats"),
require("./commands/tweet"),
];