generated from nhcarrigan/template
This commit is contained in:
+5
-1
@@ -11,8 +11,12 @@ export const ids = {
|
||||
news: "1407804798677418198",
|
||||
resumeReviewForum: "1407807555266154496",
|
||||
},
|
||||
guilds: {
|
||||
nhcarrigan: "1354624415861833870",
|
||||
},
|
||||
roles: {
|
||||
nhcarrigan: "1355033209037127771",
|
||||
nhcarrigan: "1355033209037127771",
|
||||
representing: "1407861842847469598",
|
||||
},
|
||||
tags: {
|
||||
goal: {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
postFreeCodeCampNews,
|
||||
postHackerNews,
|
||||
} from "./modules/postNews.js";
|
||||
import { processUserGuildTag } from "./modules/processUserGuildTag.js";
|
||||
import { respondToDm } from "./modules/respondToDm.js";
|
||||
import { instantiateServer } from "./server/serve.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
@@ -54,5 +55,9 @@ amari.discord.on(Events.InteractionCreate, (interaction) => {
|
||||
}
|
||||
});
|
||||
|
||||
amari.discord.on(Events.UserUpdate, (_oldUser, updatedUser) => {
|
||||
void processUserGuildTag(amari, updatedUser);
|
||||
});
|
||||
|
||||
await amari.discord.login(process.env.BOT_TOKEN);
|
||||
instantiateServer();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { ids } from "../config/ids.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type { Amari } from "../interfaces/amari.js";
|
||||
import type { User } from "discord.js";
|
||||
|
||||
/**
|
||||
* If the user has our guild tag, and does not have the role for
|
||||
* it, give them the role.
|
||||
* @param amari - Amari's instance.
|
||||
* @param user - The user payload from Discord.
|
||||
*/
|
||||
// eslint-disable-next-line complexity -- I don't wanna refactor right now.
|
||||
export const processUserGuildTag = async(
|
||||
amari: Amari,
|
||||
user: User,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const guild = amari.discord.guilds.cache.get(ids.guilds.nhcarrigan)
|
||||
?? await amari.discord.guilds.fetch(ids.guilds.nhcarrigan).catch(() => {
|
||||
return null;
|
||||
});
|
||||
if (guild === null) {
|
||||
return;
|
||||
}
|
||||
const member = guild.members.cache.get(user.id)
|
||||
?? await guild.members.fetch(user.id).catch(() => {
|
||||
return null;
|
||||
});
|
||||
if (member === null) {
|
||||
return;
|
||||
}
|
||||
if (user.primaryGuild?.identityGuildId === ids.guilds.nhcarrigan
|
||||
&& !member.roles.cache.has(ids.roles.representing)) {
|
||||
await member.roles.add(ids.roles.representing);
|
||||
}
|
||||
if (user.primaryGuild?.identityGuildId !== ids.guilds.nhcarrigan
|
||||
&& member.roles.cache.has(ids.roles.representing)) {
|
||||
await member.roles.remove(ids.roles.representing);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
await logger.error("process user guild tag module", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user