3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Add rate limit logging

This commit is contained in:
Dragory 2021-09-12 00:17:26 +03:00
parent 0a00be7a72
commit 57ed43b018
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 67 additions and 0 deletions

View file

@ -22,6 +22,7 @@ import { PluginPerformanceCmd } from "./commands/PluginPerformanceCmd";
import { AddServerFromInviteCmd } from "./commands/AddServerFromInviteCmd";
import { ChannelToServerCmd } from "./commands/ChannelToServerCmd";
import { RestPerformanceCmd } from "./commands/RestPerformanceCmd";
import { RateLimitPerformanceCmd } from "./commands/RateLimitPerformanceCmd";
const defaultOptions = {
config: {
@ -54,6 +55,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
EligibleCmd,
PluginPerformanceCmd,
RestPerformanceCmd,
RateLimitPerformanceCmd,
AddServerFromInviteCmd,
ChannelToServerCmd,
],

View file

@ -0,0 +1,36 @@
import { botControlCmd } from "../types";
import { getRateLimitStats } from "../../../rateLimitStats";
import moment from "moment-timezone";
import { GuildArchives } from "../../../data/GuildArchives";
import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { TextChannel } from "discord.js";
export const RateLimitPerformanceCmd = botControlCmd({
trigger: ["rate_limit_performance"],
permission: "can_performance",
signature: {},
async run({ pluginData, message: msg, args }) {
const logItems = getRateLimitStats();
if (logItems.length === 0) {
sendSuccessMessage(pluginData, msg.channel as TextChannel, `No rate limits hit`);
return;
}
logItems.reverse();
const formatted = logItems.map((item) => {
const formattedTime = moment.utc(item.timestamp).format("YYYY-MM-DD HH:mm:ss.SSS");
return `${item.data.global ? "GLOBAL " : ""}${item.data.method} ${item.data.route} stalled for ${
item.data.timeout
}ms`;
});
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}`);
},
});