2021-09-12 00:17:26 +03:00
|
|
|
import moment from "moment-timezone";
|
|
|
|
import { GuildArchives } from "../../../data/GuildArchives";
|
2023-04-01 12:58:17 +01:00
|
|
|
import { getBaseUrl, sendSuccessMessage } from "../../../pluginUtils";
|
|
|
|
import { getRateLimitStats } from "../../../rateLimitStats";
|
|
|
|
import { botControlCmd } from "../types";
|
2021-09-12 00:17:26 +03:00
|
|
|
|
|
|
|
export const RateLimitPerformanceCmd = botControlCmd({
|
|
|
|
trigger: ["rate_limit_performance"],
|
|
|
|
permission: "can_performance",
|
|
|
|
|
|
|
|
signature: {},
|
|
|
|
|
2023-05-08 22:58:51 +03:00
|
|
|
async run({ pluginData, message: msg }) {
|
2021-09-12 00:17:26 +03:00
|
|
|
const logItems = getRateLimitStats();
|
|
|
|
if (logItems.length === 0) {
|
2023-04-01 12:58:17 +01:00
|
|
|
sendSuccessMessage(pluginData, msg.channel, `No rate limits hit`);
|
2021-09-12 00:17:26 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
logItems.reverse();
|
|
|
|
const formatted = logItems.map((item) => {
|
|
|
|
const formattedTime = moment.utc(item.timestamp).format("YYYY-MM-DD HH:mm:ss.SSS");
|
2021-09-12 02:02:48 +03:00
|
|
|
const items: string[] = [`[${formattedTime}]`];
|
|
|
|
if (item.data.global) items.push("GLOBAL");
|
|
|
|
items.push(item.data.method.toUpperCase());
|
|
|
|
items.push(item.data.route);
|
2023-04-01 12:58:17 +01:00
|
|
|
items.push(`stalled for ${item.data.timeToReset}ms`);
|
2021-09-12 02:02:48 +03:00
|
|
|
items.push(`(max requests ${item.data.limit})`);
|
|
|
|
return items.join(" ");
|
2021-09-12 00:17:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const fullText = `Last ${logItems.length} rate limits hit:\n\n${formatted.join("\n")}`;
|
|
|
|
|
|
|
|
const archives = GuildArchives.getGuildInstance("0");
|
|
|
|
const archiveId = await archives.create(fullText, moment().add(1, "hour"));
|
|
|
|
const archiveUrl = archives.getUrl(getBaseUrl(pluginData), archiveId);
|
|
|
|
msg.channel.send(`Link: ${archiveUrl}`);
|
|
|
|
},
|
|
|
|
});
|