generated from nhcarrigan/template
chore: remove prometheus
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 38s
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 38s
This commit is contained in:
parent
1bb5cc0493
commit
4b070607f1
@ -23,7 +23,7 @@ jobs:
|
|||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v2
|
uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "22",
|
"node": "22",
|
||||||
"pnpm": "9"
|
"pnpm": "10"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/nhcarrigan/mod-bot#readme",
|
"homepage": "https://github.com/nhcarrigan/mod-bot#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -3,7 +3,6 @@ import { scheduleJob } from "node-schedule";
|
|||||||
import { ExtendedClient } from "../../interfaces/ExtendedClient";
|
import { ExtendedClient } from "../../interfaces/ExtendedClient";
|
||||||
import { maintainSecurity } from "../../modules/maintainSecurity";
|
import { maintainSecurity } from "../../modules/maintainSecurity";
|
||||||
import { postBirthdays } from "../../modules/postBirthdays";
|
import { postBirthdays } from "../../modules/postBirthdays";
|
||||||
import { Prometheus } from "../../modules/prometheus";
|
|
||||||
import { registerCommands } from "../../utils/registerCommands";
|
import { registerCommands } from "../../utils/registerCommands";
|
||||||
import { sendDebugMessage } from "../../utils/sendDebugMessage";
|
import { sendDebugMessage } from "../../utils/sendDebugMessage";
|
||||||
|
|
||||||
@ -15,8 +14,6 @@ import { sendDebugMessage } from "../../utils/sendDebugMessage";
|
|||||||
export const onReady = async (bot: ExtendedClient) => {
|
export const onReady = async (bot: ExtendedClient) => {
|
||||||
await sendDebugMessage(bot, `Logged in as ${bot.user?.tag}`);
|
await sendDebugMessage(bot, `Logged in as ${bot.user?.tag}`);
|
||||||
await registerCommands(bot);
|
await registerCommands(bot);
|
||||||
bot.analytics = new Prometheus(bot);
|
|
||||||
await bot.analytics.updateEntitlements(bot);
|
|
||||||
|
|
||||||
// Daily at 9am PST
|
// Daily at 9am PST
|
||||||
scheduleJob("birthdays", "0 9 * * *", async () => await postBirthdays(bot));
|
scheduleJob("birthdays", "0 9 * * *", async () => await postBirthdays(bot));
|
||||||
|
@ -15,6 +15,4 @@ export const onGuildCreate = async function (
|
|||||||
await bot.env.debugHook.send({
|
await bot.env.debugHook.send({
|
||||||
content: `JOINED GUILD: ${guild.name} (${guild.id}) - owned by ${owner?.displayName} (${owner.id})`
|
content: `JOINED GUILD: ${guild.name} (${guild.id}) - owned by ${owner?.displayName} (${owner.id})`
|
||||||
});
|
});
|
||||||
bot.analytics.updateGuilds(bot);
|
|
||||||
await bot.analytics.updateEntitlements(bot);
|
|
||||||
};
|
};
|
||||||
|
@ -36,8 +36,6 @@ export const onGuildDelete = async function (
|
|||||||
await bot.db.security
|
await bot.db.security
|
||||||
.deleteMany({ where: { serverId: guild.id } })
|
.deleteMany({ where: { serverId: guild.id } })
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
bot.analytics.updateGuilds(bot);
|
|
||||||
await bot.analytics.updateEntitlements(bot);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await errorHandler(bot, "on guild delete", err);
|
await errorHandler(bot, "on guild delete", err);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ export const onInteraction = async (
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bot.analytics.commandUsed();
|
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
handleChatInputCommand(bot, interaction);
|
handleChatInputCommand(bot, interaction);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ export const onMemberAdd = async (bot: ExtendedClient, member: GuildMember) => {
|
|||||||
await channel.send({
|
await channel.send({
|
||||||
content: `${user.tag} (${user.id}) has joined the server. Total Members: ${guild.memberCount}`
|
content: `${user.tag} (${user.id}) has joined the server. Total Members: ${guild.memberCount}`
|
||||||
});
|
});
|
||||||
bot.analytics.updateUsers(bot);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await errorHandler(bot, "on member add", err);
|
await errorHandler(bot, "on member add", err);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ export const onMemberRemove = async (
|
|||||||
await channel.send({
|
await channel.send({
|
||||||
content: `${user.tag} (${user.id}) has left the server (joined at ${joinStamp}). Total Members: ${guild.memberCount}`
|
content: `${user.tag} (${user.id}) has left the server (joined at ${joinStamp}). Total Members: ${guild.memberCount}`
|
||||||
});
|
});
|
||||||
bot.analytics.updateUsers(bot);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await errorHandler(bot, "on member remove", err);
|
await errorHandler(bot, "on member remove", err);
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ import { Client, WebhookClient } from "discord.js";
|
|||||||
import { Command } from "./Command";
|
import { Command } from "./Command";
|
||||||
import { Context } from "./Context";
|
import { Context } from "./Context";
|
||||||
|
|
||||||
import type { Prometheus } from "../modules/prometheus.js";
|
|
||||||
|
|
||||||
export interface ExtendedClient extends Client {
|
export interface ExtendedClient extends Client {
|
||||||
env: {
|
env: {
|
||||||
token: string;
|
token: string;
|
||||||
@ -14,7 +12,6 @@ export interface ExtendedClient extends Client {
|
|||||||
devMode: boolean;
|
devMode: boolean;
|
||||||
};
|
};
|
||||||
db: PrismaClient;
|
db: PrismaClient;
|
||||||
analytics: Prometheus;
|
|
||||||
commands: Command[];
|
commands: Command[];
|
||||||
contexts: Context[];
|
contexts: Context[];
|
||||||
configs: { [serverId: string]: Omit<configs, "id"> };
|
configs: { [serverId: string]: Omit<configs, "id"> };
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
import client, { Counter, Gauge } from "prom-client";
|
|
||||||
import type { ExtendedClient } from "../interfaces/ExtendedClient";
|
|
||||||
import { checkEntitledGuild } from "../utils/checkEntitledGuild";
|
|
||||||
|
|
||||||
export class Prometheus {
|
|
||||||
private client = client;
|
|
||||||
private guilds: Gauge;
|
|
||||||
private entitled: Gauge;
|
|
||||||
private commands: Counter;
|
|
||||||
private users: Gauge;
|
|
||||||
private errors: Counter;
|
|
||||||
|
|
||||||
constructor(bot: ExtendedClient) {
|
|
||||||
this.guilds = new Gauge({
|
|
||||||
name: "guilds",
|
|
||||||
help: "The number of guilds the bot is in."
|
|
||||||
});
|
|
||||||
this.entitled = new Gauge({
|
|
||||||
name: "entitled",
|
|
||||||
help: "The number of guilds the bot is in."
|
|
||||||
});
|
|
||||||
this.updateGuilds(bot);
|
|
||||||
this.commands = new Counter({
|
|
||||||
name: "commands",
|
|
||||||
help: "The number of commands that have been used since last boot."
|
|
||||||
});
|
|
||||||
this.users = new Gauge({
|
|
||||||
name: "users",
|
|
||||||
help: "The number of users the bot knows."
|
|
||||||
});
|
|
||||||
this.users.set(
|
|
||||||
bot.guilds.cache.reduce(
|
|
||||||
(members, guild) => members + guild.memberCount,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
this.errors = new Counter({
|
|
||||||
name: "errors",
|
|
||||||
help: "The number of errors handled by the process."
|
|
||||||
});
|
|
||||||
this.client.collectDefaultMetrics();
|
|
||||||
}
|
|
||||||
|
|
||||||
public commandUsed() {
|
|
||||||
this.commands.inc();
|
|
||||||
}
|
|
||||||
|
|
||||||
public updateGuilds(bot: ExtendedClient) {
|
|
||||||
this.guilds.set(bot.guilds.cache.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public updateUsers(bot: ExtendedClient) {
|
|
||||||
this.users.set(
|
|
||||||
bot.guilds.cache.reduce(
|
|
||||||
(members, guild) => members + guild.memberCount,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async updateEntitlements(bot: ExtendedClient) {
|
|
||||||
const entitled = bot.guilds.cache.filter(
|
|
||||||
async (g) => await checkEntitledGuild(bot, g)
|
|
||||||
);
|
|
||||||
this.entitled.set(entitled.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public errorHandled() {
|
|
||||||
this.errors.inc();
|
|
||||||
}
|
|
||||||
}
|
|
32
src/temp.ts
32
src/temp.ts
@ -1,32 +0,0 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import data from "../export.json";
|
|
||||||
import { Client, GatewayIntentBits } from "discord.js";
|
|
||||||
|
|
||||||
const id = "443134315778539530";
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const client = new Client({
|
|
||||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers]
|
|
||||||
});
|
|
||||||
await client.login(
|
|
||||||
"MTIzNTEyODcxOTgzNjcxMjk3MA.G46Wds.oXp5dpRKqwfwPhMiLzTgmIVEZI-G_wH2y7lFrk"
|
|
||||||
);
|
|
||||||
const guild = client.guilds.cache.get(id);
|
|
||||||
if (!guild) {
|
|
||||||
throw new Error("Cannot find Caylus' server.");
|
|
||||||
}
|
|
||||||
const members = await guild.members.fetch();
|
|
||||||
const existing = data
|
|
||||||
.filter((d) => members.has(d.userId))
|
|
||||||
.map((d) => ({
|
|
||||||
userId: d.userId,
|
|
||||||
serverId: id,
|
|
||||||
birthday: new Date(d.birthday)
|
|
||||||
}));
|
|
||||||
const db = new PrismaClient({
|
|
||||||
datasourceUrl:
|
|
||||||
"mongodb+srv://modbot:6NriYlDECa3e9nCC@nhcarrigan.4jqem.mongodb.net/modbot?retryWrites=true&w=majority"
|
|
||||||
});
|
|
||||||
await db.birthdays.createMany({ data: existing });
|
|
||||||
await db.$disconnect();
|
|
||||||
})();
|
|
@ -37,6 +37,5 @@ export const errorHandler = async (
|
|||||||
username: bot.user?.username ?? "Mod bot"
|
username: bot.user?.username ?? "Mod bot"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
bot.analytics.errorHandled();
|
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user