Skip to content

Commit

Permalink
feat: add script to pull contributors from db (#474)
Browse files Browse the repository at this point in the history
* feat: add script to pull contributors from db

* chore(tools): sadly bump threshold down
  • Loading branch information
Naomi Carrigan authored Nov 13, 2023
1 parent 2bf1eb6 commit 167da6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"include": ["src/**/*"],
"reporter": ["text", "html"],
"all": true,
"lines": 38
"lines": 37
}
22 changes: 21 additions & 1 deletion src/events/handlers/handleMessageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile, writeFile } from "fs/promises";
import { join } from "path";

import { ChannelType, Message } from "discord.js";
import { AttachmentBuilder, ChannelType, Message } from "discord.js";

import { Camperbot } from "../../interfaces/Camperbot";
import { levelListener } from "../../modules/levelListener";
Expand All @@ -13,6 +13,26 @@ import { levelListener } from "../../modules/levelListener";
* @param {Message} message The message payload from Discord.
*/
export const handleMessageCreate = async (Bot: Camperbot, message: Message) => {
if (
message.author.id === "465650873650118659" &&
message.content === "~contributors" &&
message.guild
) {
await message.reply("Fetching records.");
const allRecords = await Bot.db.levels.findMany({});
const above1000 = allRecords
.filter((r) => r.points >= 1000)
.sort((a, b) => b.points - a.points)
.map((r) => `${r.userTag},${r.points}`);
await message.reply(`Found ${above1000.length} qualifying records.`);
const fileContents = `usertag,points\n${above1000.join("\n")}`;
const file = new AttachmentBuilder(fileContents, {
name: "contributors.csv",
});
await message.reply({
files: [file],
});
}
await levelListener(Bot, message);

if (
Expand Down

0 comments on commit 167da6f

Please sign in to comment.