generated from nhcarrigan/template
This commit is contained in:
+55
-23
@@ -5,23 +5,23 @@
|
||||
*/
|
||||
|
||||
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
||||
import { Client,
|
||||
import {
|
||||
Client,
|
||||
GatewayIntentBits,
|
||||
Events,
|
||||
Partials,
|
||||
MessageFlags } from "discord.js";
|
||||
MessageFlags,
|
||||
} from "discord.js";
|
||||
import { scheduleJob } from "node-schedule";
|
||||
import { App } from "octokit";
|
||||
import { ids } from "./config/ids.js";
|
||||
import { handleMessageCreate } from "./events/handleMessageCreate.js";
|
||||
import { cacheData } from "./modules/cacheData.js";
|
||||
import { checkRetroAchievements } from "./modules/checkAchievements.js";
|
||||
import { getForumTagId } from "./modules/getForumTagId.js";
|
||||
import { logMenteeJoin } from "./modules/logMenteeJoin.js";
|
||||
import { logMenteeLeave } from "./modules/logMenteeLeave.js";
|
||||
import {
|
||||
postFreeCodeCampNews,
|
||||
postHackerNews,
|
||||
} from "./modules/postNews.js";
|
||||
import { postFreeCodeCampNews, postHackerNews } from "./modules/postNews.js";
|
||||
import { postProgressReminders } from "./modules/postProgressReminders.js";
|
||||
import { processMentorshipRole } from "./modules/processMentorshipRole.js";
|
||||
import { processUserGuildTag } from "./modules/processUserGuildTag.js";
|
||||
@@ -30,8 +30,10 @@ import { instantiateServer } from "./server/serve.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
import type { Amari } from "./interfaces/amari.js";
|
||||
|
||||
if (process.env.GH_CLIENT_ID === undefined
|
||||
|| process.env.GH_PRIVATE_KEY === undefined) {
|
||||
if (
|
||||
process.env.GH_CLIENT_ID === undefined
|
||||
|| process.env.GH_PRIVATE_KEY === undefined
|
||||
) {
|
||||
throw new Error("Cannot initialise GitHub!");
|
||||
}
|
||||
|
||||
@@ -41,17 +43,22 @@ const githubApp = new App({
|
||||
});
|
||||
const octokit = await githubApp.getInstallationOctokit(83_119_105);
|
||||
const { data } = await octokit.rest.apps.getAuthenticated();
|
||||
await logger.log("debug", `Authenticated to GitHub as ${data?.name ?? "unknown"}`);
|
||||
await logger.log(
|
||||
"debug",
|
||||
`Authenticated to GitHub as ${data?.name ?? "unknown"}`,
|
||||
);
|
||||
|
||||
const amari: Amari = {
|
||||
discord: new Client({ intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
],
|
||||
partials: [ Partials.Channel ] }),
|
||||
discord: new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
],
|
||||
partials: [ Partials.Channel ],
|
||||
}),
|
||||
github: octokit,
|
||||
lastRssItems: {
|
||||
freeCodeCamp: null,
|
||||
@@ -63,8 +70,10 @@ const amari: Amari = {
|
||||
const analytics = new DiscordAnalytics(amari.discord, logger);
|
||||
|
||||
amari.discord.once(Events.ClientReady, () => {
|
||||
void logger.log("debug",
|
||||
`Authenticated to Discord as ${amari.discord.user?.username ?? "unknown"}`);
|
||||
void logger.log(
|
||||
"debug",
|
||||
`Authenticated to Discord as ${amari.discord.user?.username ?? "unknown"}`,
|
||||
);
|
||||
void cacheData(amari);
|
||||
analytics.startCron();
|
||||
scheduleJob("post news", "0 * * * *", async() => {
|
||||
@@ -98,10 +107,10 @@ amari.discord.on(Events.InteractionCreate, (interaction) => {
|
||||
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
|
||||
if (interaction.isButton() && interaction.customId === "resolve") {
|
||||
if (interaction.user.id !== ids.users.naomi) {
|
||||
return void interaction.reply(
|
||||
{ content: "Who are you????",
|
||||
flags: [ MessageFlags.Ephemeral ] },
|
||||
);
|
||||
return void interaction.reply({
|
||||
content: "Who are you????",
|
||||
flags: [ MessageFlags.Ephemeral ],
|
||||
});
|
||||
}
|
||||
return void interaction.message.delete();
|
||||
}
|
||||
@@ -114,6 +123,29 @@ amari.discord.on(Events.InteractionCreate, (interaction) => {
|
||||
});
|
||||
});
|
||||
|
||||
amari.discord.on(Events.ThreadCreate, (thread) => {
|
||||
if (thread.parent?.isThreadOnly() !== true) {
|
||||
return;
|
||||
}
|
||||
const { bugReports, communityFeedback, featureRequests, policyIdeation }
|
||||
= ids.channels;
|
||||
if (
|
||||
![ bugReports,
|
||||
communityFeedback,
|
||||
featureRequests,
|
||||
policyIdeation ].includes(
|
||||
thread.parent.id,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const tagId = getForumTagId(thread.parent.id);
|
||||
if (tagId === null) {
|
||||
return;
|
||||
}
|
||||
void thread.setAppliedTags([ tagId ]);
|
||||
});
|
||||
|
||||
amari.discord.on(Events.UserUpdate, (_oldUser, updatedUser) => {
|
||||
void processUserGuildTag(amari, updatedUser);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user