2021-09-11 21:14:47 +03:00
|
|
|
import { TextChannel } from "discord.js";
|
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
|
|
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|
|
|
import { createChunkedMessage, formatNumber, resolveInvite, sorter, verboseUserMention } from "../../../utils";
|
|
|
|
import { botControlCmd } from "../types";
|
|
|
|
import { getTopRestCallStats } from "../../../restCallStats";
|
|
|
|
|
|
|
|
const leadingPathRegex = /(?<=\().+\/backend\//g;
|
|
|
|
|
|
|
|
export const RestPerformanceCmd = botControlCmd({
|
|
|
|
trigger: ["rest_performance"],
|
|
|
|
permission: "can_performance",
|
|
|
|
|
2021-09-11 21:44:01 +03:00
|
|
|
signature: {
|
|
|
|
count: ct.number({ required: false }),
|
|
|
|
},
|
2021-09-11 21:14:47 +03:00
|
|
|
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
2021-09-11 21:44:01 +03:00
|
|
|
const count = Math.max(1, Math.min(25, args.count || 5));
|
2021-09-11 21:14:47 +03:00
|
|
|
const stats = getTopRestCallStats(5);
|
|
|
|
const formatted = stats.map((callStats) => {
|
|
|
|
const cleanSource = callStats.source.replace(leadingPathRegex, "");
|
|
|
|
return `**${callStats.count} calls**\n${callStats.method.toUpperCase()} ${callStats.path}\n${cleanSource}`;
|
|
|
|
});
|
|
|
|
createChunkedMessage(msg.channel as TextChannel, formatted.join("\n"));
|
|
|
|
},
|
|
|
|
});
|